LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 10-27-2009, 11:10 AM   #1
[ITA]freeware
Member
 
Registered: Jul 2004
Distribution: Debian jessie
Posts: 75

Rep: Reputation: 15
Questions about memory usage general definitions on 'top'


hi everybody

i was playing with top to understand ram memory usage of every thread but i am in trouble with some basic noob questions:

- what difference is between 'thread' and 'process'? (noooooob....)
- what does 'virtual image size' means, and Resident size, Shared Mem size, Code size, Data+Stack size, Swapped size? I thought that the only important field is 'Memory usage', but it is represented as a percent value...

i have googled a bit, but nothing really helped me. before opening top i thought that memory is divided in several pages by every process/thread (?!?!?) and that this occupied memory would be counted as 'used memory', and nothing else.

thank you
 
Old 10-27-2009, 11:33 AM   #2
cantab
Member
 
Registered: Oct 2009
Location: England
Distribution: Kubuntu, Ubuntu, Debian, Proxmox.
Posts: 553

Rep: Reputation: 115Reputation: 115
A process has one or more threads. Most user-level programs are processes, eg. firefox, amarok, whatever. Top lists processes (below the general info).

For the second question, from man top:

Quote:
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.

p: SWAP -- Swapped size (kb)
The swapped out portion of a task's total virtual memory image.

q: RES -- Resident size (kb)
The non-swapped physical memory a task has used.

r: CODE -- Code size (kb)
The amount of virtual memory devoted to executable code, also
known as the 'text resident set' size or TRS.

s: DATA -- Data+Stack size (kb)
The amount of virtual memory devoted to other than executable
code, also known as the 'data resident set' size or DRS.

t: SHR -- Shared Mem size (kb)
The amount of shared memory used by a task. It simply reflects
memory that could be potentially shared with other processes.
"virtual memory" is used in this context to mean both memory and swap space.

Another thing to bear in mind is that the 'free' figure in

Code:
Mem:    508964k total,   495116k used,    13848k free,    14600k buffers
Swap:  1546572k total,    47708k used,  1498864k free,    91920k cached
in the top output is misleading, because the buffers and cached amounts can be made free for processes if needed. The command 'free' will give you something like

Code:
       total       used       free     shared    buffers     cached
Mem:        508964     493744      15220          0      14472      91712
-/+ buffers/cache:     387560     121404
Swap:      1546572      47732    1498840
The second line is how much RAM you 'really' have used and free.
 
Old 10-27-2009, 02:23 PM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by [ITA]freeware View Post
i was playing with top to understand ram memory usage of every thread but i am in trouble with some basic noob questions:
Some of those values are much harder to define than you would expect, because memory usage itself is a much more complex subject than you might expect.

So you can find simplistic definitions of the values, such as those quoted in post 2 of this thread. But when you look at them in a real system they won't mean what you expect.

Quote:
what difference is between 'thread' and 'process'?
The primary difference is that threads share the same address space within a process. But processes might also mostly share the same address space, so the actual difference is more complicated.

Quote:
- what does 'virtual image size' means,
Roughly the total size of all the parts of the address space for which some mapping is defined. That may enormously over estimate what you would logically think of as the virtual memory size of the process. Much of virt might not exist as actual memory or even actual memory mappings anywhere. It might be potential mappings that would be activated on demand but the demand never occurs.

Quote:
Resident size,
Roughly the total of those mappings which point to physical ram at the moment.

If the same physical ram is pointed to by multiple processes, it is included in the Resident size of each. So the total of those Resident sizes across all processes might significantly exceed the actual physical ram occupied by all those processes.

The same physical ram can even be mapped more than once by a single process and I think (not sure) it would count more than once in that process's Resident size.

Quote:
Shared Mem size
I think that is the amount within the Resident size which represent shareable mappings, so it might be Resident for other processes as well. But that doesn't in any way imply it is shared, just that it could be.

Quote:
Swapped size?
Pretty meaningless. It is just Virt minus Res. But Virt minus Res has no significant meaning.

One (usually tiny) part of Virt minus Res is the memory this process is occupying in swap space. That would be a nice number to know. But the Swap value shown by top is not that number.

Quote:
I thought that the only important field is 'Memory usage', but it is represented as a percent value...
That depends on what is important to you. That Memory usage value is just Resident Size scaled. If you don't like seeing it scaled, look at the original Resident size. It is no more nor less meaningful in either form.
 
Old 10-28-2009, 06:52 AM   #4
[ITA]freeware
Member
 
Registered: Jul 2004
Distribution: Debian jessie
Posts: 75

Original Poster
Rep: Reputation: 15
thank you all! so let's see if i've understood something:

every process has its threads, so a thread is a sort of subprocess, and i need no more...

so, virtual memory is divided into shared and resident memory: shared memory is for some shared libraries (gtk++ or something else) and resident memory is the code, data and stack memory, ok?

now, there are 2 questions..

- I think that swap memory is used only when RAM memory ends, so the kernel creates new process pages on hard disk swap partition. So swap memory will be free until Ram memory won't be full, it isn't?

- Resident memory is the really process occupied memory. So i have to delete high resident memory usage processes, to really free ram. it is right?
 
Old 10-28-2009, 07:50 AM   #5
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by [ITA]freeware View Post
every process has its threads, so a thread is a sort of subprocess,
Yes.

Quote:
virtual memory is divided into shared and resident memory: shared memory is for some shared libraries (gtk++ or something else) and resident memory is the code, data and stack memory, ok?
Totally wrong.

Virtual memory is divided in Resident and several different forms of non resident.

Virtual memory is also divided into private and shareable. That division is independent of resident vs. non resident. Private memory might be resident or non resident. Shareable memory might be resident or non resident.

The code is usually shareable memory. The data is usually private anonymous memory. The stack is almost certainly private anonymous memory. But any of those might be resident or non resident.

Quote:
I think that swap memory is used only when RAM memory ends,
Not accurate.

Quote:
so the kernel creates new process pages on hard disk swap partition.
Completely wrong.

Quote:
So swap memory will be free until Ram memory won't be full, it isn't?
What??

But even if you had said what you meant, I'm sure what you meant was incorrect. With ordinary settings for the parameters that control swapping, swap space may be used as soon as there is enough file caching to cover almost all the free memory and some page of some process's anonymous memory is less recently used than any of that file caching and any other resident pages. So even if plenty of ram is effectively free (used by file caching while it is effectively free) swap space may get used.

Quote:
- Resident memory is the really process occupied memory.
Yes.

Quote:
So i have to delete high resident memory usage processes, to really free ram. it is right?
What are you trying to accomplish?
 
Old 10-28-2009, 12:14 PM   #6
[ITA]freeware
Member
 
Registered: Jul 2004
Distribution: Debian jessie
Posts: 75

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by johnsfine View Post
Virtual memory is divided in Resident and several different forms of non resident.

Virtual memory is also divided into private and shareable. That division is independent of resident vs. non resident. Private memory might be resident or non resident. Shareable memory might be resident or non resident.

The code is usually shareable memory. The data is usually private anonymous memory. The stack is almost certainly private anonymous memory. But any of those might be resident or non resident.
So, memory is divided in resident-swapped, shareable-private.

Quote:
With ordinary settings for the parameters that control swapping, swap space may be used as soon as there is enough file caching to cover almost all the free memory and some page of some process's anonymous memory is less recently used than any of that file caching and any other resident pages. So even if plenty of ram is effectively free (used by file caching while it is effectively free) swap space may get used.
I thought that swap space is a hard disk space (swap partition), that gets used, like ram memory, every time ram memory gets full.

Quote:
What are you trying to accomplish?
sometimes my pc gets very very slow, and i think it is due to some ram-eating processes. I got to discover and to fire these processes, but i didn't know how much is complicated memory division, and how much is orrible my english..
 
Old 10-28-2009, 01:54 PM   #7
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
Quote:
Originally Posted by [ITA]freeware View Post
I thought that swap space is a hard disk space
Right.

Quote:
that gets used ... every time ram memory gets full.
Wrong.

1) Ram might get full and non anonymous pages might get selected to be made non resident, so swap space might not get used even though ram got full.

2) Depending on your definition of "full", ram might not be "full" when a significant amount of ram is used for recent file caching. If some anonymous pages are less recently used than the caching, swap space might be used even though ram is not full.
 
Old 10-28-2009, 02:06 PM   #8
[ITA]freeware
Member
 
Registered: Jul 2004
Distribution: Debian jessie
Posts: 75

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by johnsfine View Post
1) Ram might get full and non anonymous pages might get selected to be made non resident, so swap space might not get used even though ram got full.

2) Depending on your definition of "full", ram might not be "full" when a significant amount of ram is used for recent file caching. If some anonymous pages are less recently used than the caching, swap space might be used even though ram is not full.
so, swap acts as a less-used pages memory, not like a pure ram extension, and it gets used only when free ram amount is less than a critical value..
 
Old 10-28-2009, 03:24 PM   #9
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194Reputation: 1194
I think it's time for me to stop trying to explain this. I'm sorry if you still don't understand.
 
  


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
TOP command: calculation of memory usage samiralmousawi Linux - Server 7 07-29-2008 03:16 PM
Reported memory usage doesn't tally with top geokker Linux - Server 2 04-04-2008 03:09 PM
Memory usage using TOP FantaJ Linux - Newbie 2 03-05-2008 12:35 PM
How do I read the memory usage in top? jaakkop Linux - Hardware 1 03-10-2006 10:12 AM
Memory usage reported using TOP Kdiver58 Linux - Newbie 1 02-03-2003 01:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:22 PM.

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