Why is swap being used even though I have plenty of free RAM?

1

On 27.05.2014 07:33, Alan Corey wrote:

> Mostly so when I switch to a different application, maybe on a

> different page of the FVWM desktop, it isn't sitting there swapped

> out

> and it's responsive. I've usually got 20 or more applications open at

> once (most just RXVT windows) and reboot about once a week. If I

> invest in RAM I expect it to get used. Seems like Linux and FreeBSD

> are better about this but I don't use them often. Now I've got 864

> free, 25 swapped out (restarted Firefox).

LOL at Linux better about this...........

Fresh Ubuntu 14.04 LTS with updates

user@laptop:~$ free -m
total used free shared buffers cached
Mem: 3819 834 2984 1 3
141
-/+ buffers/cache: 689 3129
Swap: 3959 313 3646
user@laptop:~$ sysctl vm.swappiness
vm.swappiness = 10
user@laptop:~$

With vm.swappiness on...

0 0
2
...
0 0
3

Windows uses a page file to store data that can’t be held by your computer’s random-access memory when it fills up. While you can tweak the page file settings, Windows can manage the page file fine on its own.

The Windows page file is somewhat misunderstood. People see it as the cause of slowdowns because it’s slower to use the page file than your computer’s RAM, but having a page file is better than not having one.

Image Credit: Blake Patterson on Flickr

How The Page File Works

The page file, also known as the swap file, pagefile, or paging file, is a file on your hard drive. It’s located at C:\pagefile.sys by default, but you won’t see it unless you tell Windows Explorer not to hide protected operating system files.

Your computer stores files, programs, and other data you’re using in your RAM (random access memory) because it’s much faster to read from RAM than it is to read from a hard drive. For example, when you open...

0 0
4

There are a few different aspects to your question.

Firstly, what your definition of "free" is. It is actually not as simple as it sounds in Linux (or any modern operating system).

How Linux uses RAM (very simplified)

Each application can use some of your memory. Linux uses all otherwise unoccupied memory (except for the last few Mb) as "cache". This includes the page cache, inode caches, etc. This is a good thing - it helps speed things up heaps. Both writing to disk and reading from disk can be sped up immensely by cache.

Ideally, you have enough memory for all your applications, and you still have several hundred Mb left for cache. In this situation, as long as your applications don't increase their memory use and the system isn't struggling to get enough space for cache, there is no need for any swap.

Once applications claim more RAM, it simply goes into some of the space that was used by cache, shrinking the cache. De-allocating cache is...

0 0
5

I’m trying to start a process on Red Hat Enterprise Linux Server release 6.5 (Santiago), which is failing because it is not able to allocate sufficient memory.

# There is insufficient memory for the Java Runtime Environment to continue. # Cannot create GC thread. Out of system resources. # An error report file with more information is saved as:

The problem is not with the Java application itself - I get the error too when I simply run:

java -version

Looking at memory consumption:

free -m

total used free shared buffers cached Mem: 32069 31276 792 0 556 16948 -/+ buffers/cache: 13771 18297 Swap: 9325 38 9287

So Mem is reporting that 31 out of 32 Gb of memory is being used, but there should be 18Gb of memory available that is being used by the cache. Should the OS not free up some of this when a process requests memory?

The details of the error dump is

# # There is insufficient memory...
0 0
6

As izx has commented, this should only be able to happen due to a kernel bug. So anyone who can currently produce this problem--including and especially the original poster of this question--would be well-advised to report it as a bug by reading that page thoroughly and carefully, and then running ubuntu-bug linux on the affected machine. This should be reported against linux in Ubuntu, and not against a mainline (upstream) kernel, unless you can produce it on a mainline kernel (you'd have to have yama loaded).

The expected behavior in every version of Ubuntu starting with Ubuntu 10.10 is that process A cannot trace a running process B unless B is a direct child of A (or A runs as root). This is a security enhancement, which makes it so that a process that has been compromised by an attacker cannot use debugging facilities provided by the kernel to discover information from other processes. This is explained in the ptrace scope section of the Security Features community wiki...

0 0
7

No matter how much RAM you have, you want the system to be able to use it efficiently. Having no paging file at all forces the operating system to use RAM inefficiently for two reasons. First, it can't make pages discardable, even if they haven't been either accessed or modified in a very long time, which forces the disk cache to be smaller. Second, it has to reserve physical RAM to back allocations that are very unlikely to ever require it (for example, a private, modifiable file mapping), leading to a case where you can have plenty of free physical RAM and yet allocations are refused to avoid overcommitting.

Consider, for example, if a program makes a writable, private memory mapping of a 4GB file. The OS has to reserve 4GB of RAM for this mapping, because the program could conceivably modify every byte and there's no place but RAM to store it. So immediately, 4GB of RAM is basically wasted (it can be used to cache clean disk pages, but that's about it).

You need to...

0 0
8

isamuelson said:

Free – This one is quite simple. This memory has nothing at all in it. It’s not being used and it contains nothing but 0s.

Available – This numbers includes all physical memory which is immediately available for use by applications. It wholly includes the Free number, but also includes most of the Cached number. Specifically, it includes pages on what is called the “standby list.” These are pages holding cached data which can be discarded, allowing the page to be zeroed and given to an application to use.

Cached – Here things get a little more confusing. This number does not include the Free portion of memory. And yet imight see that it is larger than the Available area of memory. That’s because Cached includes cache pages on both the “standby list” and what is called the “modified list.” Cache pages on the modified list have been altered in memory. No process has specifically asked for this data to be in memory, it is merely there as a...

0 0
9

You can also set your "swappiness" value from the default of 60, this way the swap won't grow so large to begin with. Why the shipping default is set to 60 when the recommended value is 10 perplexes me. From the Ubuntu SwapFAQ:

The default setting in Ubuntu is swappiness=60. Reducing the default value of swappiness will probably improve overall performance for a typical Ubuntu desktop installation. A value of swappiness=10 is recommended, but feel free to experiment.

By changing this value to 10 or even 0, you can add a significant and perceivable speed boost to an older system with a slow drive. Setting this value to 0 does not turn swap off for Linux kernel 3.4 and below but with 3.5+ it does so you will want to use a value of 1 if you want to keep it on its lowest setting*.

I see no reason not to set this to 0 since anything that hits disk is slower than RAM. I have a 8 virtual cores, a fast SSD & 8 GB of memory and my swap is set to 0. As of this moment...

0 0
10
...
0 0
11

Re your last Q - the short version: The error message is about "committed" virtual address space. If you look at the Commit Charge graph in your second screen snapshot you will see that it is indeed at or very near the limit. The amount of RAM that is "free", "available", or "in use" does not matter.

The commit limit is equal to total RAM + pagefile size. When committed memory is allocated it is immediately charged to "commit charge" even though it has not actually been used yet... meaning that no RAM or PF space is used immediately. Physical space (whether in RAM or the pagefile) is only used when the memory is actually referenced. From then on it must have someplace to be, until the program frees it, or the entire process ends.

Example: Suppose you have no pagefile, hence your commit limit is 16 GB (your RAM size). Now, suppose that 8 processes each try to VirtualAlloc(MEM_COMMIT) 1 GB. Result: Commit charge is increased by 8 GB. There is no immediate impact on RAM,...

0 0