LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 12:49 PM   #1
forbin
Member
 
Registered: Apr 2010
Posts: 43

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, 01:44 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
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 02:06 PM.
 
  


Reply



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 05:36 AM
Screen res and font size tyreth Linux - Laptop and Netbook 3 03-16-2005 08:59 PM
file system size larger than fysical size:superblock or partition table corrupt klizon Linux - General 0 06-18-2004 04:18 PM
Total partition size - User partition size is not equals to Free partition size navaneethanj Linux - General 5 06-14-2004 12:55 PM
increase point size size when printing PDF files newlin Red Hat 0 09-27-2003 07:13 AM

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

All times are GMT -5. The time now is 04:30 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
Open Source Consulting | Domain Registration