Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 05-25-2005, 05:20 AM   #1
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
memory types - what's what: vm resident shared rss X's


In my nice ps/top/--- gui fronted ("System Monitor 2.8.1", for Gnome), there are a vast number columns reporting memory usage of various types:

Memory, VM Size, Resident Memory, Shared Memory, RSS Memory, X Server's Memory

Exactly what are they? How do they get allocated? When do they get freed? How much mem is freed by killing process <foo>?

(since you probably don't have time to explain this to me (you should be busy doing something else (like hacking at the kernel) if you know this stuff ), I'll gladly take pointers (which I then can point other people to) (and no, I don't program in Lisp (but I do like emacs for (among other things) its parens-matching)))

Btw, google is apparently not my friend (even though he might be your friend).

Kind regards,

Jonas Kölker.

Last edited by jonaskoelker; 05-25-2005 at 05:22 AM.
Old 05-26-2005, 03:57 AM   #2
Senior Member
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 52
i will try this cause it's fun to review (as always i will be more or less correct, most likely less than more)

i don't have that utility so i can't speak to it specifically
like you figured this stuff is memory structures within the kernel

first none of this stuff accounts for the two level paging tables which account for permanent use of some of your memory

user virtual memory space is potentially about 3Gb of mapped pages
all userspace memory is virtual swappable not actual physical ram
kernel space memory is the actual physical ram and is only used when necessary

in the kernel struct task-struct you get
struct mm_struct *mm;
which contains
unsigned long rss, total_vm, locked_vm;
every linux task gets a struct task_struct structure

total_vm is the total virtual size of the process it's code (execuable instructions) ,it's global and statically allocated data structures, and it's stack(local variables and function arguments and return arguments), and the heap( allocated memory using malloc() and free() and freinds in c or dynamically allocated in c++ with new and delete). the stack is cleaned automatically whenever the variables go out of scope but the stack still stays allocated to your process until it terminates. the heap can have the memory freed but that does not necessarily reduce the proccesses address space but it can if the memory subroutines do it that way. sometimes it just kind of grows and grows but as i said earlier not to wory because it is all virtual memory pages not real memory. failure to release memory properly however is memory "leaks" and can cause a process address space to grow without bounds till it fails from lack of memory. This is not generally a problem in Linux but sometimes software has small or large memory leaks. these can sometimes lead to data thrashing and performance problems as the kernel tries to keep needed info in active memory.
all of these memory structures follow GNU coding standard of "no arbitrary limits".
all process memory is returned when the process dies

ok i'm not really sure how this works but these memory structures are actually a part of the executable file itself
(gary) ~  $ size /bin/bash
   text    data     bss     dec     hex filename
 484958    9996   25328  520282   7f05a /bin/bash
text is the executable code
data is non zero initialized daya
bss is zero initialized data

RSS is the actual real life physical memory that has been used to map to the virtual pages above
so RSS is the real program memory use number . This value sums the size of in-use code, data, stack, and allocated heap memory. not including memory shared between two or more processes. which is shared memory duhh.

(gary) ~  $ ps
  PID TTY          TIME CMD
 1506 pts/0    00:00:00 bash
 1721 pts/0    00:00:00 ps
(gary) ~  $ grep "^Vm" /proc/1506/status 
VmSize:     4872 kB
VmLck:         0 kB
VmRSS:      1716 kB
VmData:      580 kB
VmStk:        28 kB
VmExe:       476 kB
VmLib:      1628 kB
VmLib is shared libraries

you mention at the end x server memory usage and that is a unique case
x memory stats can be very confusing and or misleading
x memory shows an amalgamation or video card memory which is fixed and not you RAM at all plus i/o mapping pages to that video card RAM from the server side of x. Also image data from x clients reside on the server side of x looking like x memory usage, and the video driver for your video card often supplied by third party sources does some of the allocation and deallocation of memory that shows up in x server side memory and these drivers often have memory leaks that cause x memory usage to creap up over time but that does not really mean x is taking up more space in physical RAM i don't think.

Last edited by foo_bar_foo; 05-26-2005 at 04:02 AM.
1 members found this post helpful.
Old 05-26-2005, 04:59 AM   #3
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Original Poster
Rep: Reputation: 47
Thank you for a good explanation.

At times a bit too verbose for me: I program in C and major in Computer Science. Then again, it's probably verbose enough for (some) non-hackers I might point to this, so it's good.

But let me check if I got it right:

#define tmem (code + static (static) + stack ((implicitly) auto) + heap (malloc/free))
VM memory: virtual tmem
RSS memory = Resident Memory: physical tmem
Shared: tmem used by shared libraries (used by <process>)

so when I kill -9 firefox, I should expect at least(*) (in pseudo-code) mm_table[firefox].rss bytes to be freed, correct?

(*) shared libraries get freed when their refcount == 0, correct?
... so if FF is the only process that references libhtml-render-foo, killing FF should release (at least(*)) mm_table[firefox].rss + mm_table[lib-html-render-foo].rss

(**) okay, the kernel might do mark and sweep or stop and copy, but I like refcount: It's simple and intuitive. Also, can shared libs be circularly dependent?


Jonas Kölker


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
is shared memory expandable in memory size? Thinking Programming 4 08-16-2005 09:57 AM
c + shared memory dilberim82 Programming 3 03-07-2005 07:49 PM
shared memory blackzone Programming 1 10-14-2004 11:52 AM
About Shared Memory...? aegis_shiva Programming 1 08-25-2004 05:05 AM
shared memory socket9001 Programming 4 02-06-2004 02:08 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:09 PM.

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