Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am running top to monitor my server performance and 2 of my java processes show virtual memory of up to 800MB-1GB. Is that a bad thing?

What does virtual memory mean?

And oh btw, I have swap of 1GB and it shows 0% used. So I am confused.

Java process = 1 Tomcat server + my own java daemon Server = Ubuntu 9.10 (karmic)

share|improve this question
See:… – Juliano May 5 '10 at 3:11

5 Answers 5

Virtual memory isn't even necessarily memory. For example, if a process memory-maps a large file, the file is actually stored on disk, but it still takes up "address space" in the process.

Address space (ie. virtual memory in the process list) doesn't cost anything; it's not real. What's real is the RSS (RES) column, which is resident memory. That's how much of your actual memory a process is occupying.

But even that isn't the whole answer. If a process calls fork(), it splits into two parts, and both of them initially share all their RSS. So even if RSS was initially 1 GB, the result after forking would be two processes, each with an RSS of 1 GB, but you'd still only be using 1 GB of memory.

Confused yet? Here's what you really need to know: use the free command and check the results before and after starting your program (on the +/- buffers/cache line). That difference is how much new memory your newly-started program used.

share|improve this answer
"Check results before and after starting your program", alternatively, use USS (Unique Set Size) as returned by smem. – Hubert Kario Dec 31 '12 at 10:35
So is there a tool that gives the true amount of memory being used, tools that are not third party. – CMCDragonkai Jul 21 '14 at 8:23
@CMCDragonkai Yes, free. – deviantfan Jun 2 at 9:57

From the top(1) man page:

o: VIRT  --  Virtual Image (kb)
      The  total  amount  of  virtual  memory  used  by the task.  It
      includes all code, data and shared libraries  plus  pages  that
      have been swapped out.

      VIRT = SWAP + RES.

Where RES means RESident memory (physical memory used).

Actually that's not correct (anymore). When it says "swap," that also includes files that the program has mapped into its address space, which may or may not actually be consuming real RAM yet. This memory is file-backed but isn't really swap.

VIRT also includes pages that have been allocated but not used for anything yet. Any page in this state is mapped to the kernel Zero Page (brilliant concept--you should look it up) so it shows up in VIRT but doesn't actually consume any memory.

share|improve this answer
well thats interesting, so is VIRT = SWAP + RES, how come my SWAP usage is zero, while virtual memory for the 2 java processes is close to a 1GB?? – user42159 May 4 '10 at 18:20
basically Top shows.... Swap: 1048568k total, 0k used, 1048568k free, 505728k cached – user42159 May 4 '10 at 18:21
@user42159 This answer is WRONG! There's NO 'VIRT = SWAP + RES' in man top! -m : VIRT/USED toggle Reports USED (sum of process rss and swap total count) instead of VIRT. It's a pity that I can't downvote this answer. – duleshi Nov 4 at 1:53

VIRT column in the ps/top output is almost irrelevant to measure memory usage. Don't worry about it.

share|improve this answer
Thanks, I got worried and confused, because while swap usage was 0%, virtual memory column is very high. And also I have only 1.7GB of the total 2.7GB physical memory used, while virtual memory is high? – user42159 May 4 '10 at 15:56

Linux supports virtual memory, that is, using a disk as an extension of RAM so that the effective size of usable memory grows correspondingly. The kernel will write the contents of a currently unused block of memory to the hard disk so that the memory can be used for another purpose. When the original contents are needed again, they are read back into memory. This is all made completely transparent to the user; programs running under Linux only see the larger amount of memory available and don't notice that parts of them reside on the disk from time to time. Of course, reading and writing the hard disk is slower (on the order of a thousand times slower) than using real memory, so the programs don't run as fast. The part of the hard disk that is used as virtual memory is called the swap space.

Linux can use either a normal file in the filesystem or a separate partition for swap space. A swap partition is faster, but it is easier to change the size of a swap file (there's no need to repartition the whole hard disk, and possibly install everything from scratch). When you know how much swap space you need, you should go for a swap partition, but if you are uncertain, you can use a swap file first, use the system for a while so that you can get a feel for how much swap you need, and then make a swap partition when you're confident about its size.

You should also know that Linux allows one to use several swap partitions and/or swap files at the same time. This means that if you only occasionally need an unusual amount of swap space, you can set up an extra swap file at such times, instead of keeping the whole amount allocated all the time.

A note on operating system terminology: computer science usually distinguishes between swapping (writing the whole process out to swap space) and paging (writing only fixed size parts, usually a few kilobytes, at a time). Paging is usually more efficient, and that's what Linux does, but traditional Linux terminology talks about swapping anyway.


share|improve this answer

I found this talk very helpful in understanding the subject:

share|improve this answer
Welcome to ServerFault! We prefer answers to contain an actual answer and not just a link to an answer because links go dead over time. Your answer would be better if you could add a summary of the important parts of that video to it. – Ladadadada Jan 11 '13 at 10:35

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.