#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define PAGE_SZ (1<<12)

// assumes you don't have swap configured, because you shouldn't
int main (int argc, char* argv[]) {
    int i;
    float gb = atof(argv[1]); // memory to consume in GB

    for (i = 0; i < (gb * 1024 * 1024 * 1024)/PAGE_SZ ; ++i) {
        void *m = malloc(PAGE_SZ);
        if (!m)
            break;
        // defeat overcommit. setting a single byte is sufficient to activate the entire page
        memset(m, 0, 1);
    }
    printf("allocated %lu MB\n", ((unsigned long)i*PAGE_SZ)>>20);
    getchar();
    return 0;
}