LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-22-2010, 01:49 PM   #1
forbin
Member
 
Registered: Apr 2010
Posts: 40

Rep: Reputation: 0
Why Are VIRT Size and RES Size Different When There is No Swapping?


Top shows a number of processes with VIRT size of approx. 300MB and RES size approximately half that. Swap shows 0k used, so there's no swapping going on.

According to the man pages, RES=CODE+DATA and VIRT=RES+SWAP. If SWAP is 0, then wouldn't RES and VIRT be the same?
 
Old 06-22-2010, 02:44 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190
Which man pages?

Quote:
Originally Posted by forbin View Post
According to the man pages, RES=CODE+DATA
It's a tough call whether that is just seriously misleading or flat out wrong.

Quote:
VIRT=RES+SWAP.
That is only for a tool that defines "SWAP" as VIRT-RES even though VIRT-RES has no significant connection to use of swap space.

I think what will help you understand this topic, is a example/description of two common major parts of VIRT and one often minor part:

1) Your process is running some executable that depends on some .so files. At load time, large areas of the executable and .so files are mapped into your virtual address space. They are just mapped in, they aren't read in. Those pages are still on disk. As they get used, pages from those mappings are read in and become part of your process RES. But all of those mappings are part of VIRT even if never read in for use and none of them use swap space even if kicked back out of RES.

2) The malloc (or similar) support software inside your process requests a big chunk of empty memory from the OS. The OS maps that as "demand zero" memory, that is part of VIRT. But no actual memory is allocated. No swap space is used and none of it goes into RES.

3) Your process writes to a small part of the memory requested in (2). The kernel allocates that small part. That is now "anonymous" memory that is counted in RES. If physical ram were so tight that some of that then got paged out, it would be the swap usage you expect.

All the "memory" I described in (1) and (2) are part of VIRT. Only some of it is part of RES. There are likely big parts of the mapped .so files containing only functions that this executable never calls. The malloc support code can't predict the program's memory use, so it over estimates, so most of the "demand zero" mappings never become real ram pages. If there is a shortage of physical ram, the kernel prefers to kick out pages of read only content of the executable, which then are waiting for next use exactly the way pages that were never used wait for first use. So VIRT may be enormously bigger than RES with no use of swap space.

Last edited by johnsfine; 06-22-2010 at 03:06 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extended a LV size, but df shows orig size, using DEBIAN ETCH, on a AMD64 hector3rd Linux - Newbie 8 04-23-2008 06:36 AM
Screen res and font size tyreth Linux - Laptop and Netbook 3 03-16-2005 09:59 PM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 05:18 PM
Total partition size - User partition size is not equals to Free partition size navaneethanj Linux - General 5 06-14-2004 01:55 PM
increase point size size when printing PDF files newlin Red Hat 0 09-27-2003 08:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration