#include #include #include #include #include #include #include #include #include static const size_t M_1GB = (size_t) 1 * (size_t) 1024 * (size_t) 1024 * (size_t) 1024; static const size_t M_2GB = (size_t) 2 * M_1GB; static const size_t M_4GB = (size_t) 4 * M_1GB; static const size_t M_8GB = (size_t) 8 * M_1GB; int main(int argc, char **argv) { if (argc > 1 && argv[1][0] == 'l') { struct rlimit lims = { M_1GB / 4, M_1GB / 4 }; int err = setrlimit(RLIMIT_DATA, &lims); if (err == -1) { error(1, errno, "setrlimit failed"); } } void *addr1 = malloc(M_8GB); if (addr1 == NULL) { error(1, errno, "[addr1] mmap failed: errno=%u, ", errno); } void *addr2 = malloc(M_8GB); if (addr2 == NULL) { free(addr1); error(1, errno, "[addr2] mmap failed"); } free(addr1); free(addr2); return 0; }