TrumanWong

slabtop

Real-time display of kernel slab memory cache information

Supplementary instructions

slabtop command displays the details of the kernel "slab" buffer in real time.

grammar

slabtop(option)

Options

--delay=n, -d n: Update the displayed information every n seconds, the default is every 3 seconds;
--sort=S, -s S: Specify the sorting standard for sorting (for the sorting standard, refer to the following or the man manual);
--once, -o: Exit after displaying once;
--version, -V: display version;
--help: Display help information.

Sorting criteria:

  • a: sort by number of active objects
  • b: sort by objects per slab
  • c: sort by cache size
  • l: sort by number of slabs
  • v: sort by number of active slabs
  • n: sort by name
  • o: sort by number of objects
  • p: sort by pages per slab
  • s: sort by object size
  • u: sort by cache utilization

Knowledge expansion

When kernel modules allocate resources, in order to improve efficiency and resource utilization, they are allocated through slab. Through the slab information and the source code, you can get a rough understanding of the system's operation, such as whether there are abnormally many resources or whether there are any leaks. The Linux system exposes slab usage to users through /proc/slabinfo.

The slab allocator used by Linux is based on an algorithm first introduced by Jeff Bonwick for the SunOS operating system. Jeff's allocator is built around object caching. In the kernel, large amounts of memory are allocated for a limited set of objects, such as file descriptors and other common structures. Jeff found that the time required to initialize a normal object in the kernel exceeded the time required to allocate and deallocate it. Therefore, he concluded that memory should not be released back to a global memory pool, but should be kept in a state initialized for a specific purpose. The Linux slab allocator uses this idea and others to build a memory allocator that is efficient in both space and time.

The file that holds information about all active slab caches in the monitoring system is /proc/slabinfo.

Example

slabtop

 Active / Total Objects (% used)    : 897519 / 1245930 (72.0%)
 Active / Total Slabs (% used)      : 38605 / 38605 (100.0%)
 Active / Total Caches (% used)     : 94 / 145 (64.8%)
 Active / Total Size (% used)       : 129558.22K / 153432.58K (84.4%)
 Minimum / Average / Maximum Object : 0.01K / 0.12K / 128.00K

  OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME                   
440136 171471  38%    0.05K   6113       72     24452K buffer_head
190086 148576  78%    0.05K   2437       78      9748K selinux_inode_security
151840 146366  96%    0.48K  18980        8     75920K ext3_inode_cache
144333 144143  99%    0.02K    711      203      2844K avtab_node
130529 128488  98%    0.13K   4501       29     18004K dentry_cache
 99214  99071  99%    0.03K    878      113      3512K size-32
 43834  28475  64%    0.27K   3131       14     12524K radix_tree_node
 17818   9450  53%    0.06K    302       59      1208K size-64
  4602   4562  99%    0.05K     59       78       236K sysfs_dir_cache
  3220   2855  88%    0.08K     70       46       280K vm_area_struct
  2460   2114  85%    0.12K     82       30       328K size-128
  1564   1461  93%    0.04K     17       92        68K Acpi-Operand
  1540   1540 100%    0.33K    140       11       560K inode_cache
  1524    466  30%    0.01K      6      254        24K anon_vma
  1440    515  35%    0.05K     20       72        80K avc_node
  1440   1154  80%    0.19K     72       20       288K filp
  1170   1023  87%    0.05K     15       78        60K ext3_xattr
   845    724  85%    0.02K      5      169        20K Acpi-Namespace
   638    315  49%    0.35K     58       11       232K proc_inode_cache
   450    434  96%    0.25K     30       15       120K size-256
   424    386  91%    0.50K     53        8       212K size-512
   312    107  34%    0.05K      4       78        16K delayacct_cache
   306    284  92%    0.43K     34        9       136K shmem_inode_cache
   303    108  35%    0.04K      3      101        12K pid
   300    261  87%    0.19K     15       20        60K skbuff_head_cache
   300    300 100%    0.12K     10       30        40K bio
   260    260 100%   32.00K    260        1      8320K size-32768
   254      6   2%    0.01K      1      254         4K revoke_table
   236     55  23%    0.06K      4       59        16K fs_cache
   216    203  93%    1.00K     54        4       216K size-1024
   214    214 100%    2.00K    107        2       428K size-2048
   203     83  40%    0.02K      1      203         4K biovec-1