Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running 4 java processes with the following command:

java -Xmx256m -jar ...

and the system has 8Gb memory under fedora 12.

however it is apparently going into swap.

how can that be if 4 x 256m = 1Gb ?

EDIT: also, how can all 8Gb of memory be used with so little memory allocated to basically the only thing running?

is it java not garbage collecting because the OS tells it it doesn't need to or what?


top - 20:13:57 up  3:55,  6 users,  load average: 1.99, 2.54, 2.67
Tasks: 251 total,   6 running, 245 sleeping,   0 stopped,   0 zombie
Cpu(s): 50.1%us,  2.9%sy,  0.0%ni, 45.1%id,  1.1%wa,  0.0%hi,  0.8%si,  0.0%st
Mem:   8252304k total,  8195552k used,    56752k free,    34356k buffers
Swap: 10354680k total,    74044k used, 10280636k free,  6624148k cached

 1948 xxxxxxxx  20   0 1624m 240m 4020 S 96.8  3.0 164:33.75 java
 1927 xxxxxxxx  20   0  139m  31m  27m R 91.8  0.4  38:34.55 postgres
 1929 xxxxxxxx  20   0 1624m 200m 3984 S 86.2  2.5 183:24.88 java
 1969 xxxxxxxx  20   0 1624m 292m 3984 S 65.6  3.6 154:06.76 java
 1987 xxxxxxxx  20   0  137m  29m  27m R 28.5  0.4  75:49.82 postgres
 1581 root      20   0  159m  18m 4712 S 22.5  0.2  52:42.54 Xorg
 2411 xxxxxxxx  20   0  309m 9748 4544 S 20.9  0.1  45:05.08 gnome-system-mo
 1947 xxxxxxxx  20   0  137m  28m  27m S 13.3  0.4  44:46.04 postgres
 1772 xxxxxxxx  20   0  135m  25m  25m S  4.0  0.3   1:09.14 postgres
 1966 xxxxxxxx  20   0  137m  29m  27m S  3.0  0.4  64:27.09 postgres
 1773 xxxxxxxx  20   0  135m  732  624 S  1.0  0.0   0:24.86 postgres
 2464 xxxxxxxx  20   0 15028 1156  744 R  0.7  0.0   0:49.14 top
  344 root      15  -5     0    0    0 S  0.3  0.0   0:02.26 kdmflush
    1 root      20   0  4124  620  524 S  0.0  0.0   0:00.88 init
    2 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kthreadd
    3 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration/0
    4 root      15  -5     0    0    0 S  0.0  0.0   0:00.04 ksoftirqd/0
share|improve this question
add comment

4 Answers

up vote 3 down vote accepted

The memory manager will automatically put things in swap even if physical memory is not full based on what it thinks is best. Is there a reason you don't want it to go into swap at all? Is it actually affecting the running of the program?

You would need to turn off swap in order to test the speed with or without swapping.

Also, when does it use swap? Constantly or after it has been running for a bit? You also have to take into account that the underlying system needs memory as well. And any IDEs you are using, and any other programs running. So you may need swap more than you realize.

share|improve this answer
i've got next to nothing else running (besides postgres which i've purposely not allocated a lot of memory to). if swap isn't necessarily a bad thing, why is all 8Gb of memory in use in the first place? how can i tell exactly how much memory my java processes are using? thx. –  pstanton Jan 7 '10 at 20:54
add comment

The overall memory consumption on you system looks fine. Remember to subtract the "cache" and "buffer" from the "used" portion to get an accurate amount of free memory. The cache memory is used to cache files in ram in case of future access. If Linux needs more memory, it will simple reduce this amount of memory, so you generally don't consider it used when determining memory utilization. Since there are 6 gb in the cache pool, there is plenty of ram available if necessary.

The individual processes also look fine. The Res column represents the actual allow rated memory size, which seems close to the heap size specified. The virt column only represents the amount of ram that could be addressed by the process, but not nessessarily allocated at the point.

share|improve this answer
+1 This is a great answer for anyone who takes the time to understand it. –  richj Feb 19 '10 at 21:41
add comment

how can all 8Gb of memory be used with so little memory allocated to basically the only thing running?

This is the way that Linux memory management works by design. It's a performance optimisation that puts memory that would otherwise be empty (and therefore wasted) to cache data that might otherwise need to be read again from the file system.

Although this might seem to be an untidy way of working, it is faster. The operating system can reclaim this memory efficiently as soon as it can be put to a better use.

share|improve this answer
add comment

You've only used 70MB of swap.

The OS' memory manager can put things where ever it deems best. If you want it to avoid using swap space, you need turn it off.

See http://linux.about.com/library/cmd/blcmdl8_swapoff.htm for information on swapoff.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.