Posts

How to Delete Buffers and Cache Memory in Linux

Step 1: Check Buffers & Cache Memory

To check the buffers and cache memory in linux, execute the following command:

# free
              total        used        free      shared  buff/cache   available
Mem:        1015944      211640       94724       57700      709580      562416
Swap:             0           0           0

Step 2: Check Buffers & Cache Memory

Now delete and check the buffers and cache memory it will be reduced:

# sync && echo 3 > /proc/sys/vm/drop_caches && free

Following are the Linux Kernal that how can we drop the various aspects of cached items by changing the numeric argument to the above command
To free pagecache:

# echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:

# echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:

# echo 3 > /proc/sys/vm/drop_caches

How to Check CPU Detailed Information

There are several ways in order to check the CPU detailed Information.

1) /proc/cpuinfo

The /proc/cpuinfo and sysfs stores info about your CPU architecture ike number of CPUs, threads, cores, sockets, NUMA nodes, information about CPU caches, CPU family, model, bogoMIPS, yte order and much more:

# less /proc/cpuinfo

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 62
model name      : Intel(R) Xeon(R) CPU E5-2695 v2 @ 2.40GHz
stepping        : 4
cpu MHz         : 2400.084
cache size      : 30720 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu de tsc msr pae cx8 sep cmov pat clflush mmx fxsr sse sse2 ss ht nx constant_tsc aperfmperf pni pclmulqdq ssse3 sse4_1 sse4_2 x2apic popcnt aes f16c rdrand hypervisor ida arat
bogomips        : 4800.16
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

2) nproc

The nproc command just prints out the number of processing units available. Note that the number of processing units might not always be the same as number of cores.

# nproc
2

3) getconf

The most simplest tool comes with glibc and is called getconf:

# getconf _NPROCESSORS_ONLN
2

4) lscpu

lscpu is a small and quick command that does not need any options. It would simply print the cpu hardware details in a user-friendly format.

# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                1
On-line CPU(s) list:   0
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 62
Model name:            Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
Stepping:              4
CPU MHz:               2494.094
BogoMIPS:              4988.18
Hypervisor vendor:     Xen
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              25600K
NUMA node0 CPU(s):     0

5) dmidecode

The dmidecode command displays some information about the cpu, which includes the socket type, vendor name and various flags.

# dmidecode -t 4 | grep CPU
        Socket Designation: CPU1
        Version: Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz
        Socket Designation: CPU2
        Version: Intel(R) Xeon(R) CPU           X5670  @ 2.93GHz

How to Check Memory in Linux

Following are some useful commands to check the memory status of machine:

free Command

Use free command to check the memory, buffers, cache memory

# free -m
             total       used       free     shared    buffers     cached
Mem:          6082       5801        280          0        155       3887
-/+ buffers/cache:       1759       4322
Swap:         1707         33       1674

top Command

Top command tells the detailed information of CPU i.e time, load average, CPU utilization, memory, swap memory.

# top
top - 09:36:16 up 33 days, 16:47,  2 users,  load average: 0.49, 0.47, 0.52
Tasks: 157 total,   1 running, 155 sleeping,   1 stopped,   0 zombie
Cpu(s): 30.0%us,  2.4%sy,  0.0%ni, 67.0%id,  0.5%wa,  0.0%hi,  0.0%si,  0.1%st
Mem:   6228500k total,  5975956k used,   252544k free,   159264k buffers
Swap:  1748984k total,    34100k used,  1714884k free,  3980880k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
11774 www-data  20   0 99.8m  56m 6780 S   55  0.9   1:02.52 apache2
21086 www-data  20   0  100m  54m 5620 S   39  0.9   0:04.14 apache2
21075 www-data  20   0 66524  19m 4848 S    4  0.3   0:21.04 apache2

htop Command

Install htop on server, htop command also tells the detailed information of CPU i.e time, load average, CPU utilization, memory, swap memory but in a nice format.

# htop

Check Memory Consumption Processes

Process that are eating more memory

# ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 20