Linux Memory Overflow Details

I develop software for embedded Linux, and I suffer from a system crash because OOM Killer appears from time to time. Before going beyond that, I would like to solve some confusing problems related to the way the Linux kernel allocates dynamic memory, assuming that / proc / sys / vm / overcommit _memory has 0 and / proc / sys / vm / min _free_kbytes has 712 and does not have swap.

Suppose there is currently physical Linux built-in memory available: 5 MB (5 MB free memory and inaccessible cache or buffer memory) if I write this piece of code:

.....
#define MEGABYTE 1024*1024
.....
.....
void *ptr = NULL;
ptr = (void *) malloc(6*MEGABYTE); //Preserving 6MB
if (!prt) 
    exit(1);
memset(ptr, 1, MEGABYTE);
.....

I would like to know if, when calling memset, the kernel will try to allocate ~ 6 MB or ~ 1 MB (or min_free_kbytes multiple) in the physical memory space.

9 , 32 . ,

# echo 3 > /proc/sys/vm/drop_caches 
# free
            total         used         free       shared      buffers
Mem:        23732        14184         9548            0          220
Swap:            0            0            0
Total:        23732        14184         9548

C, , , oom , , , > 6 . , , oom, , :

  • . VmRSS /proc/pid/ .

  • /proc/sys/vm/overcommit_memory = 2 /proc/sys/vm/overcommit _memory = 75 , - , .

+3
1

, . C-, , , /proc/sys/vm/overcommit_memory.

+7

Source: https://habr.com/ru/post/1584713/


All Articles