cat /proc/sys/vm/swappiness
cat /proc/sys/vm/overcommit_memory
cat /proc/sys/vm/overcommit_ratio
# LOWER SWAPS LESS
echo 0 > /proc/sys/vm/swappiness
# DISABLES OVERCOMMITING MEMORY
# overcommit_memory — Configures the conditions under which a large memory request is accepted or denied.
# 2 — The kernel fails requests for memory that add up to all of swap plus the percent of physical RAM specified in /proc/sys/vm/overcommit_ratio. This setting is best for those who desire less risk of memory overcommitment.
echo 2 > /proc/sys/vm/overcommit_memory
# USE UP ALL PHYSICAL RAM
# Specifies the percentage of physical RAM considered when /proc/sys/vm/overcommit_memory is set to 2. The default value is 50.
echo 80 > /proc/sys/vm/overcommit_ratio
### TO SYSCTL.CONF
vm.swapiness = 0
vm.overcommit_memory = 2
vm.overcommit_ratio = 80
### C code to use all memory
### https://stackoverflow.com/questions/1865501/c-program-on-linux-to-exhaust-memory/6617363#6617363
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PAGE_SZ (1<<12)
int main() {
int i;
int gb = 2; // memory to consume in GB
for (i = 0; i < ((unsigned long)gb<<30)/PAGE_SZ ; ++i) {
void *m = malloc(PAGE_SZ);
if (!m)
break;
memset(m, 0, 1);
}
printf("allocated %lu MB\n", ((unsigned long)i*PAGE_SZ)>>20);
getchar();
return 0;
}
Author:
Baldwin Sung
Words:
181
Share:
Released under CC BY-NC 4.0