Zaid Alali
Zaid Alali

Reputation: 69

linux swap space never release memory

I am using Linux kernel 2.6.38, and I am running a process that allocates 4GB of memory, and I have a 4GB of ram available, so when I run my application it allocates around 0.5GB from swap space. however, my application runs for a very long time and accesses data on the swap space several times.

(Edited) To clarify what I am doing:

is this a bug on this kernel version (2.6.38)? is there a fix to it?

Upvotes: 4

Views: 5808

Answers (2)

that other guy
that other guy

Reputation: 123510

There's no memory leak.

You're assuming that when your application needs more memory than what's available, parts of it is written to swap. This is not necessarily true.

The system may (and generally will) write other, completely unrelated processes to swap, because they're not currently in use.

Since this swap space does not belong to your application, it will remain in use after your application exits.

This swap space may further stay in use for a long time since Linux doesn't preemptively load them back when there's free RAM.

Upvotes: 6

Remy J
Remy J

Reputation: 729

I'm not sure my response will answer your question but I asked myself a similar question a while back.

To summarise when Linux allocates memory (RAM/SWAPP) it only frees it when it's needed. That means even after the process has terminated the allocated memory will remain until another process needs the space.

However if you want to free the SWAPP you can do it manually

sudo swapoff -a 

Do not forget to turn it back on

sudo swapon -a 

You can find more information at that link and that one

Upvotes: 5

Related Questions