Linux Kernel Memory Usage

最後更新: 2019-05-02

目錄

 


Slab

 

Slab allocation is a memory management mechanism intended for the efficient memory allocation of kernel objects.
It eliminates fragmentation caused by allocations and deallocations.

The technique is used to retain allocated memory that contains a data object of a certain type
for reuse upon subsequent allocations of objects of the same type.
(With slab allocation, memory chunks suitable to fit data objects of certain type or size are preallocated.)
It is analogous(類似) to an object pool, but only applies to memory, not other resources.

 * Slab 包括了系統的 Cache

grep Slab /proc/meminfo

Slab:             125772 kB

# Cleanup Cache

sync

echo 3 > /proc/sys/vm/drop_caches

Slab:              42076 kB

# Much of the details about the SLAB

cat /proc/slabinfo

# name      <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> : tunables <limit> 
fuse_inode              1          5       768            5              1 : tunables      54
  <batchcount> <sharedfactor> : slabdata <active_slabs> <num_slabs> <sharedavail>
            27              8 : slabdata              1           1             0

# display kernel slab cache information in real time

slabtop

 Active / Total Objects (% used)    : 243299 / 409575 (59.4%)
 Active / Total Slabs (% used)      : 20184 / 20206 (99.9%)
 Active / Total Caches (% used)     : 79 / 144 (54.9%)
 Active / Total Size (% used)       : 65844.91K / 89452.66K (73.6%)
 Minimum / Average / Maximum Object : 0.02K / 0.22K / 4096.00K

  OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME
 87048  50358   0%    0.03K    702      124      2808K kmalloc-32
 38454  36288   0%    0.12K   1131       34      4524K kernfs_node_cache
 ...

 


compact_memory

 

Trobleshoot

failed to initialize KVM: Cannot allocate memory

free -m 仍有許多 memory

Fix: The problem is memory fragmentation

# all zones are compacted such that free memory is available in contiguous blocks where possible

echo 1 > /proc/sys/vm/compact_memory

 


 

 

 

 

 

Creative Commons license icon Creative Commons license icon