Bidyut
Bidyut

Reputation: 55

Impact of memory leak on other process

I have a query related to memory leak.

A 32 bit Linux based system is running multiple active processes A,B,C,D. All the processes are allocating/deallocating memory from the heap. Now if process A is contionusly leaking a significant amount of memory, could it happen that after a certain amount of time process B cant find any memory to allocate from the heap?

As per my understanding, each process is provided with a unque VM of 2GB from the OS. But there is a mappig between the VM and the physical memory.

Upvotes: 1

Views: 595

Answers (2)

Fred Foo
Fred Foo

Reputation: 363858

Yes, if the total amount of VM (RAM + swap space) is exhausted by process A, then malloc in any of the other processes might fail because of that. Linux hides processes' memory spaces from other processes, but it doesn't magically create extra memory in your machine. (Although it may seem to do so due to its overcommit behavior.)

In addition, Linux may employ its OOM killer when memory is running low.

Upvotes: 2

dAm2K
dAm2K

Reputation: 10359

Linux kernel does memory overcommit by default. When a process request a memory segment with malloc() the memory is not automatically allocated. You may have 4 processes malloc()ing 2gb each and not having any problem. The problem arise when the process make use (initialize, bzero, copy) of the malloc()ed memory. You may even malloc more memory than the system may reserve for you, without any problem, and malloc() doesn't even return NULL!!

Upvotes: 0

Related Questions