/proc/sys/vm/overcommit_{memory,ratio} for over commit virtual memory!

FILE* fp = fopen("/proc/meminfo", "r");
         if (fp)
             unsigned long physmem = RLIM_INFINITY;
             fscanf(fp, "MemTotal: %lu kB", &physmem);

             // allow drouter and its children to consume no more than 75% of
             // total physical memory (technically this is wayyyy less than the
            // total address space on 64-bit systems, but we don't have swap)
             struct rlimit vmlimit;
            getrlimit(RLIMIT_AS, &vmlimit);

            vmlimit.rlim_cur = (physmem << 10) * 0.75;
             setrlimit(RLIMIT_AS, &vmlimit);
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License