MichaelBalack
asked on
The availability and what program taken the memory in linux server?
This is using SuSE Enterprise Linux 11 and 12 servers. We have quite a number of SuSE servers running in production. Up to now, we are still confuse on how the memory used on each server. Take an example, I can type "free -m" and "cat /proc/meminfo", to see the figures on memory as follows. Can some one explain how the memory was used in cached, swap, page table. How about the available memory for user program? What are those "shared", "Buffers", and "cached"? Why swap does not count in the available memory especially for user program?
free -m
total used free shared buffers cached
Mem: 63987 63129 858 124 423 41868
-/+ buffers/cache: 20836 43150
Swap: 16386 570 15816
cat /proc/meminfo
MemTotal: 65522980 kB
MemFree: 887160 kB
Buffers: 433744 kB
Cached: 39731232 kB
SwapCached: 33088 kB
Active: 35971000 kB
Inactive: 23661808 kB
Active(anon): 14914636 kB
Inactive(anon): 975156 kB
Active(file): 21056364 kB
Inactive(file): 22686652 kB
Unevictable: 8668 kB
Mlocked: 8668 kB
SwapTotal: 16780284 kB
SwapFree: 16195956 kB
Dirty: 2500 kB
Writeback: 40 kB
AnonPages: 15739924 kB
Mapped: 241116 kB
Shmem: 127136 kB
Slab: 3785628 kB
SReclaimable: 3100056 kB
SUnreclaim: 685572 kB
KernelStack: 32928 kB
PageTables: 66668 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 49541772 kB
Committed_AS: 23254188 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 392856 kB
VmallocChunk: 34325605160 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 201680 kB
DirectMap2M: 5763072 kB
DirectMap1G: 60817408 kB
Does this means that on "free -m", the value (20820) is equal to the Mem(used) - Buffer - cached = 63115 - 41871 - 423 = 20821?
So, does this means that the available memory for user program is, 20821 MB?
How about the swap memory? What processes/user programs taking the memory? any command to check for it?
Thanks in advance.
free -m
total used free shared buffers cached
Mem: 63987 63129 858 124 423 41868
-/+ buffers/cache: 20836 43150
Swap: 16386 570 15816
cat /proc/meminfo
MemTotal: 65522980 kB
MemFree: 887160 kB
Buffers: 433744 kB
Cached: 39731232 kB
SwapCached: 33088 kB
Active: 35971000 kB
Inactive: 23661808 kB
Active(anon): 14914636 kB
Inactive(anon): 975156 kB
Active(file): 21056364 kB
Inactive(file): 22686652 kB
Unevictable: 8668 kB
Mlocked: 8668 kB
SwapTotal: 16780284 kB
SwapFree: 16195956 kB
Dirty: 2500 kB
Writeback: 40 kB
AnonPages: 15739924 kB
Mapped: 241116 kB
Shmem: 127136 kB
Slab: 3785628 kB
SReclaimable: 3100056 kB
SUnreclaim: 685572 kB
KernelStack: 32928 kB
PageTables: 66668 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 49541772 kB
Committed_AS: 23254188 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 392856 kB
VmallocChunk: 34325605160 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 201680 kB
DirectMap2M: 5763072 kB
DirectMap1G: 60817408 kB
Does this means that on "free -m", the value (20820) is equal to the Mem(used) - Buffer - cached = 63115 - 41871 - 423 = 20821?
So, does this means that the available memory for user program is, 20821 MB?
How about the swap memory? What processes/user programs taking the memory? any command to check for it?
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
wrt. memory hungry programs.. the system call that extends the memory ( sbrk() )only allows for growth.
the runtime library call free() (companion of alloc()/calloc()) cannot release memory to the OS. To release memory to the OS you need to stop the program.
mapped memory (memory mapped files etc.) might be handled differently i never investigated that....
actualy brk CAN lower the breakpoint of the program. BUT any data beyond that point is lost any ponters refering to data there will return access violations or likewise errors.
the runtime library call free() (companion of alloc()/calloc()) cannot release memory to the OS. To release memory to the OS you need to stop the program.
mapped memory (memory mapped files etc.) might be handled differently i never investigated that....
actualy brk CAN lower the breakpoint of the program. BUT any data beyond that point is lost any ponters refering to data there will return access violations or likewise errors.
ASKER
Hi David,
Thanks for the article on 4) swap memory.
However, this given command -
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
only show the program and memory usage, how to get it also showing the pid?
Thanks for the article on 4) swap memory.
However, this given command -
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less
only show the program and memory usage, how to get it also showing the pid?
You'd write a script to do something similar to this PERL snippet...
my @dirs = glob("/proc/*");
foreach my $dir (@dirs) {
my $pid = basename($dir);
next unless ($pid = /^\d+$/o);
# at this point you have both the $pid + $dir of $pid data to work with
}
ASKER
Thanks David in providing the suggestion. It works
VIRT is the total amount of pagetable entries, RES is realy in memory SHR is shared with other processes.