LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-13-2012, 12:28 PM   #1
YellowSnowIsBad
Member
 
Registered: Oct 2010
Posts: 49

Rep: Reputation: Disabled
Swap VS Virtual Memory.


I was under the impression that virtual memory and swap are synonymous; the only real difference being swap describes the space and virtual memory describes the concept.

I have an odd issue with HTOP where the swap space used is only a few MB but the virtual memory in use is well over 10GB. See attachment!

Code:
$ vmstat -s -S M | grep M
         8002 M total memory
         6433 M used memory
         3241 M active memory
         2951 M inactive memory
         1568 M free memory
           76 M buffer memory
         4947 M swap cache
        16383 M total swap
           11 M used swap
        16372 M free swap
I can't explain this...
Attached Thumbnails
Click image for larger version

Name:	Screenshot - 03132012 - 05:09:59 PM.jpg
Views:	96
Size:	45.8 KB
ID:	9227  
 
Old 03-13-2012, 12:38 PM   #2
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
I see tumblerd in the screenshot. That thing makes the thunbnails you see in the filebrowser. As soon as you open a "new" folder (or an external herddrive as I recently did), the thing charges loose eating away at just about all resource it can get its grubby little hands on. Until all the thunmnails are created, then...it falls back into the dark...
Pretty notmal, I'd say, unless thumblerd is alive all te time...

Thor
 
Old 03-13-2012, 02:36 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
"swap" describes the physical resource that is used to map the virtual-memory space that is actually in use and "dirty."

Virtual memory values can be difficult to interpret since so much virtual memory is shared among multiple processes.

Basically, if you are looking for x + y + z = t ... don't.
 
Old 03-13-2012, 06:29 PM   #4
YellowSnowIsBad
Member
 
Registered: Oct 2010
Posts: 49

Original Poster
Rep: Reputation: Disabled
@sundialsvcs, Well I read that on the HTOP website; but 11MB/10GB+ is a rather large discrepancy. What's the point in even providing functionality to calculate swap space if it is so far off?

@Thor_2.0, do I actually need it? I am not concerned with thumbnails.

Thanks.
 
Old 03-13-2012, 06:57 PM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by YellowSnowIsBad View Post
I was under the impression that virtual memory and swap are synonymous;
Not for any reasonable definition of virtual memory.

Quote:
I have an odd issue with HTOP where the swap space used is only a few MB but the virtual memory in use is well over 10GB. See attachment!
If I'm reading that right, the VIRT size of a single process is 10.6GB and you have other processes with large VIRT.

So with your incorrect (common error) assumptions about what virtual memory is, that would obviously not fit.

VIRT counts all mapped portions of the process's address space. The parts of VIRT that is in swap space are only anonymous memory and generally only the part of anonymous memory that is not in that process's RES nor in the system cache.

RES is the portion of VIRT that is physically mapped to ram. Note that VIRT represents logical mappings that page by page might or might not be physically mapped at any given moment.

Logical anonymous mappings are used for the process's stack and heap and any pages of static or global variables that have been modified from compile time initialized values.

But anonymous memory for a process may be much smaller than its logical anonymous mappings. That is primarily because of "demand zero" mapping. A process typically asks for heap in far bigger chunks than it needs at the moment. Heap that has been requested but not yet used exists within VIRT as a demand zero mapping. There are other reasons for demand zero mappings, but heap is typically the big one. The pages represented by demand zero mappings don't physically exist anywhere.

Processes also have non anonymous memory. That is always included in VIRT. Any of that in physical ram it is either in the process's RES or the system wide cache. But when it is not in ram, it is also not in swap. That is a key fact missed by most people who misunderstand Linux swap. The common use for non anonymous memory is the code loaded from the executable file and .so files. So that tends to be a large fraction of VIRT when VIRT is small, but a small fraction when VIRT is large. Large VIRT usually means a lot of anonymous memory. But that isn't always the case. A program could directly map data files creating an enormous non anonymous use of VIRT.

Quote:
Originally Posted by YellowSnowIsBad View Post
Well I read that on the HTOP website; but 11MB/10GB+ is a rather large discrepancy. What's the point in even providing functionality to calculate swap space if it is so far off?
Read what on the HTOP website?

Your misunderstanding of VIRT and swap seems to be larger than the typical, since you don't seem to be including RES.

Most people confused by this, understand that RES is a part of VIRT that is in physical ram. And this process's share of the system wide swap usage is a portion of VIRT that is not in physical ram. So they expect those two things to add up to VIRT, because they don't know how many other places parts of VIRT might be.

Last edited by johnsfine; 03-13-2012 at 07:17 PM.
 
Old 03-14-2012, 09:21 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
There are three things you need to know about this thing called "virtual" memory ...
  1. First and foremost, every process thinks that it has just as much memory as it may require. But "the way the trick is done"is to realize that processes never actually use all of the memory that they require, and that they in any given period of time tend to refer to the same chunks of storage over and over. (So-called locality of reference.)
  2. Processes share a lot of things, such as the gcc runtime library. How many copies of that data do you need in physical memory? Just one.
  3. Even when processes share things such that they need the ability to make their own modifications to it, a separate copy needs to be made only when it is actually needed. (So-called copy on write.)
The reason why you can't "add up" virtual memory numbers is that virtual memory does not correspond directly to a physical resource. In a very real sense, virtual memory is an illusion.
 
Old 03-14-2012, 09:48 AM   #7
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by sundialsvcs View Post
The reason why you can't "add up" virtual memory numbers is that virtual memory does not correspond directly to a physical resource. In a very real sense, virtual memory is an illusion.
There are two different issues mixed into that:

1) You can't meaningfully add VIRT across processes because you don't know how much is shared. With "copy on write" even non shareable portions of memory might be shared. More typically, it is shareable memory that is shared, but there is still no easy way to know how much it is shared.

2) Even a single process (as in the OP's example) may have VIRT larger than the total of ram plus used swap. It could even be larger than all of ram plus all of swap. Pages in VIRT might have no physical existence at all (demand zero) or might be on disk in ordinary files rather than swap.
 
Old 03-15-2012, 06:23 AM   #8
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
Quote:
@Thor_2.0, do I actually need it? I am not concerned with thumbnails.
You dont really need it as such, you'll be fine without it, but it completes your desktop experience.
You should be able to not-start it by commenting it out from the start up script(s)

Thor
 
Old 05-22-2012, 12:37 PM   #9
Kim_Marquar_34
LQ Newbie
 
Registered: May 2012
Posts: 2

Rep: Reputation: Disabled
swap

I always choose swap and it works fine
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
process, memory, swap, virtual memory wakatana Linux - Hardware 1 08-31-2009 07:55 AM
Difference between resident memory,shared memory and virtual memory in system monitor mathimca05 Linux - Newbie 1 11-11-2007 04:05 AM
Swap Memory / Virtual Memory in Fedora Core 6 Jojo_CFT Linux - Newbie 2 10-15-2007 04:23 AM
Difference between Swap Virtrual memory and Swap Parition Nappa Slackware 4 11-27-2003 07:58 PM
virtual memory (swap) starquake Linux - Newbie 7 03-27-2003 07:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:46 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