OS

1) How to detect memory leak in the linux
2) top 10 applications using RAM Mamory usage
3) memory for a given pid
4) Physical Memory(RAM) for given pid
5) How to Flush Memory in Linux
6) shared memory segments
7) Virtual memory details
8)  Basic troubleshooting and debugging
9) Heavy swap space used process


How to detect memory leak in the linux

[root@myserver proc]# cat /proc/meminfo | egrep 'AnonPages|Mapped'
AnonPages:      155720 kB
Mapped:         304484 kB
======================================================================
top 10 applications using RAM Mamory usage
[root@myserver proc]# ps -A --sort -rss -o comm,pmem | head -n 11
COMMAND         %MEM
dataserver       9.4
dataserver       3.1
backupserver     2.6
firefox-bin      1.6
vmtoolsd         0.8
nautilus         0.7
puplet           0.6
gnome-panel      0.6
Xorg             0.6

==============================================================================================================================
memory for a given pid:-
1) [sybase@myserver 5307]$ cat /proc/5307/status
Name:   dataserver
State:  S (sleeping)
SleepAVG:       98%
Tgid:   5307
Pid:    5307
PPid:   5306
TracerPid:      0
Uid:    500     500     500     500
Gid:    500     500     500     500
FDSize: 256
Groups: 500 502
VmPeak:   235180 kB
VmSize:   235176 kB---------------------->it is memory size of the given processes
----------------------
2) [sybase@myserver 5307]$ pmap 5307 | grep total
    total   235176K---------------------->it is memory size of the given processes
second exmple:-
[sybase@myserver 9832]$ grep VmSize  /proc/9832/status
VmSize:   260572 kB
[sybase@myserver 9832]$ pmap 9832 | grep total
 total   260572K
=============================================================================================================
Physical Memory(RAM) for given pid
[sybase@myserver 5307]$ cat statm
58794 52478 52177 5029 0 2953 0
size  resident share text lib data dt(dirty pages)

============================================================================================================
How to Flush Memory in Linux
sync; echo 3 > /proc/sys/vm/drop_caches" to clear the memory cache.

=============================================================================================
How to check shared memory segments
Type "ipcs -m" to check your shared memory segments

Read more: How to Understand Linux Memory Management | eHow.com
============================================================================================================
How to check  shared memory limits?
ipcs -lm

#################################################################################
Virtual memory details:


Memory Management Unit (MMU):-Access memory through virtual add by using data structre to track these translation. it main job is translate virtulate add into physical  add
The step from logical address to physical address is called "address translation" - handled by MMU
==========================add
simpelly to say it is a "it point the right add of RAM".

Zoned Buddy allocator:-
=======================
interacts directly with the MMU
providing valid pages when the kernel asks for them
manages lists of pages and keeps track of different categories of memory addresses
manages page allocation to entir system
manages lists of physically contiguous pages and maps them into the MMU page tables
All physical pages in RAM are cataloged by the Buddy Allocator and grouped into lists
It manages  memory zones 1) DMA 2) NORMAL 3) HIGHMEM

DMA:- First 16MB memory allocate to  peripheral to perform direct memory operations
NORAML:-16MB to 1GB used by the kernel for internal data structure as well as other system and user space allocations
HIGHMEM:-above 1GB is used exclusively by system allocations(file system buffers,user space allocations and etc..)

Slab Allocator:-
================
provides the ability to create cache of memory objects in memory

kswapd:-
=======
 handles swapping pages to disk.

bdflush:-
========
manages block device pages (disk IO),
----------------------------------------------------------------------------------------------------------------------
Page table:- OS is maped virtual memory addres to physical memory addres in structe way is know as page table
------------------------------------------------------------------------------------------------------------
9)  Heavy swap space used process
q@sybuat:~> for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | head -20
haveged 2228 kB
dhclient6 2120 kB
systemd 1604 kB
X 1352 kB
cupsd 920 kB
udevd 892 kB
udevd 812 kB
udevd 728 kB
rsyslogd 624 kB
vmtoolsd 556 kB
cron 520 kB
vmware-vmblock- 464 kB
xdm 320 kB
systemd-stdout- 208 kB
klauncher 208 kB
tpvmlp 204 kB
xdm 152 kB
systemd-logind 148 kB
avahi-daemon 132 kB
acpid 124 kB

------------------------------------------------------------------------------------------------------------
Basic troubleshooting and debugging
http://people.redhat.com/alikins/troubleshooting/

http://www.linuxplanet.com/linuxplanet/tutorials/6593/1
http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/mem.html------------>ref
http://www.tutorialspoint.com/operating_system/os_virtual_memory.htm

#############################################################################

https://drive.google.com/file/d/0B-3TCVRoXIuuVXZvZ3RFdUNVSjg/edit?usp=sharing ------> P & T