slabinfo – kernel slab allocator statistics

WHAT IS SLAB ALLOCATION ?

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. It is analogous to an object pool, but only applies to memory, not other resources.
Instead of parsing the highly verbose /proc/slabinfo file manually, the /usr/bin/slabtop program displays kernel slab cache information in real time. This program allows for custom configurations, including column sorting and screen refreshing.

RELATED SHELL SESSION EXPOSURE
[bash]
$sudo slabtop -o
Active / Total Objects (% used) : 535097 / 607019 (88.2%)
Active / Total Slabs (% used) : 21678 / 21678 (100.0%)
Active / Total Caches (% used) : 101 / 124 (81.5%)
Active / Total Size (% used) : 116716.47K / 136870.05K (85.3%)
Minimum / Average / Maximum Object : 0.01K / 0.22K / 8.00K

OBJS ACTIVE USE OBJ SIZE SLABS OBJ/SLAB CACHE SIZE NAME
118209 104139 88% 0.10K 3031 39 12124K buffer_head
103840 103648 99% 0.25K 6490 16 25960K skbuff_head_cache
43225 41001 94% 0.20K 2275 19 9100K vm_area_struct
37590 30689 81% 0.19K 1790 21 7160K dentry
32512 28745 88% 0.03K 254 128 1016K kmalloc-32
32384 27081 83% 0.06K 506 64 2024K anon_vma_chain
29010 28898 99% 0.13K 967 30 3868K kernfs_node_cache
20272 12148 59% 0.57K 724 28 11584K radix_tree_node
18752 16591 88% 0.06K 293 64 1172K kmalloc-64
17342 14540 83% 0.09K 377 46 1508K anon_vma
16578 14490 87% 0.59K 614 27 9824K inode_cache
14576 11558 79% 0.25K 911 16 3644K filp
12800 11906 93% 0.02K 50 256 200K kmalloc-16
12390 9609 77% 1.05K 413 30 13216K ext4_inode_cache
10200 6294 61% 0.05K 120 85 480K ftrace_event_field
8704 7034 80% 0.01K 17 512 68K kmalloc-8
4704 3944 83% 0.09K 112 42 448K kmalloc-96
4256 4200 98% 0.07K 76 56 304K Acpi-Operand
4074 3120 76% 0.19K 194 21 776K cred_jar
3668 3665 99% 0.14K 131 28 524K ext4_groupinfo_4k
3570 3570 100% 0.04K 35 102 140K ext4_extent_status
3450 2422 70% 0.69K 150 23 2400K shmem_inode_cache
3312 2611 78% 0.66K 138 24 2208K proc_inode_cache
3200 2599 81% 0.12K 100 32 400K pid
2754 2751 99% 0.04K 27 102 108K Acpi-Namespace
2688 2432 90% 0.03K 21 128 84K fscrypt_info
2550 1633 64% 0.04K 25 102 100K pde_opener
2448 2137 87% 0.50K 153 16 1224K kmalloc-512
2394 2134 89% 0.19K 114 21 456K kmalloc-192
2384 2171 91% 1.00K 149 16 2384K kmalloc-1024
2176 1898 87% 0.12K 68 32 272K kmalloc-128
2139 1734 81% 0.69K 93 23 1488K sock_inode_cache
2112 2112 100% 0.06K 33 64 132K kmem_cache_node
2037 2037 100% 0.38K 97 21 776K kmem_cache
1932 1006 52% 0.56K 69 28 1104K i915_vma
1840 1819 98% 0.09K 40 46 160K trace_event_file
1568 1386 88% 0.07K 28 56 112K eventpoll_pwq
1488 1382 92% 2.00K 93 16 2976K kmalloc-2048
1472 1200 81% 1.00K 92 16 1472K UNIX
1323 688 52% 0.75K 63 21 1008K xfrm_state
1275 896 70% 0.08K 25 51 100K inotify_inode_mark
945 903 95% 0.19K 45 21 180K proc_dir_entry
896 836 93% 0.25K 56 16 224K kmalloc-256
884 782 88% 0.12K 26 34 104K jbd2_journal_head
882 777 88% 0.38K 42 21 336K mnt_cache
837 663 79% 3.38K 93 9 2976K task_struct
810 590 72% 1.06K 27 30 864K mm_struct
780 618 79% 1.06K 26 30 832K signal_cache
720 593 82% 4.00K 90 8 2880K kmalloc-4096
680 563 82% 0.02K 4 170 16K numa_policy
640 510 79% 0.25K 40 16 160K pool_workqueue
511 292 57% 0.05K 7 73 28K mbcache
506 388 76% 0.69K 22 23 352K files_cache
450 367 81% 2.06K 30 15 960K sighand_cache
288 195 67% 0.12K 9 32 36K secpath_cache
256 2 0% 0.02K 1 256 4K jbd2_revoke_table_s
234 234 100% 0.10K 6 39 24K blkdev_ioc
225 177 78% 1.25K 9 25 288K UDPv6
224 224 100% 0.12K 7 32 28K scsi_sense_cache
219 152 69% 0.05K 3 73 12K Acpi-Parse
208 144 69% 0.25K 13 16 52K dquot
172 171 99% 8.00K 43 4 1376K kmalloc-8192
170 170 100% 0.05K 2 85 8K fscrypt_ctx
168 100 59% 1.12K 6 28 192K RAWv6
165 150 90% 2.12K 11 15 352K TCP
128 128 100% 0.06K 2 64 8K dmaengine-unmap-2
128 128 100% 0.03K 1 128 4K sd_ext_cdb
128 128 100% 0.06K 2 64 8K ext4_io_end
112 82 73% 0.50K 7 16 56K skbuff_fclone_cache
102 102 100% 0.08K 2 51 8K Acpi-State
96 87 90% 0.32K 4 24 32K taskstats
85 68 80% 0.23K 5 17 20K tw_sock_TCP
85 42 49% 0.94K 5 17 80K RAW
80 80 100% 0.20K 4 20 16K file_lock_cache
76 44 57% 0.81K 4 19 64K bdev_cache
75 73 97% 0.62K 3 25 48K task_group
72 60 83% 8.00K 18 4 576K biovec-max
64 42 65% 2.00K 4 16 128K biovec-128
64 64 100% 0.12K 2 32 8K ext4_allocation_context
63 46 73% 0.19K 3 21 12K dmaengine-unmap-16
50 50 100% 0.16K 2 25 8K sigqueue
50 50 100% 0.62K 2 25 32K i915_request
42 42 100% 2.25K 3 14 96K TCPv6
40 20 50% 0.39K 2 20 16K fuse_request
38 19 50% 0.20K 2 19 8K ip4-frags
36 0 0% 0.43K 2 18 16K uts_namespace
34 17 50% 0.23K 2 17 8K posix_timers_cache
34 1 2% 0.94K 2 17 32K mqueue_inode_cache
32 16 50% 4.00K 4 8 128K names_cache
32 32 100% 1.00K 2 16 32K biovec-64
30 30 100% 1.06K 1 30 32K dmaengine-unmap-128
26 26 100% 0.61K 1 26 16K hugetlbfs_inode_cache
25 25 100% 0.62K 1 25 16K rpc_inode_cache
21 21 100% 0.75K 1 21 16K dax_cache
19 19 100% 0.81K 1 19 16K fuse_inode
17 0 0% 0.45K 1 17 8K user_namespace
16 0 0% 0.50K 1 16 8K dma-kmalloc-512
15 6 40% 6.19K 3 5 96K net_namespace
15 15 100% 2.06K 1 15 32K dmaengine-unmap-256
13 13 100% 2.40K 1 13 32K request_queue
8 2 25% 4.00K 1 8 32K sgpool-128
0 0 0% 0.09K 0 42 0K dma-kmalloc-96
0 0 0% 0.19K 0 21 0K dma-kmalloc-192
0 0 0% 0.01K 0 512 0K dma-kmalloc-8
0 0 0% 0.02K 0 256 0K dma-kmalloc-16
0 0 0% 0.03K 0 128 0K dma-kmalloc-32
0 0 0% 0.06K 0 64 0K dma-kmalloc-64
0 0 0% 0.12K 0 32 0K dma-kmalloc-128
0 0 0% 0.25K 0 16 0K dma-kmalloc-256
0 0 0% 1.00K 0 16 0K dma-kmalloc-1024
0 0 0% 2.00K 0 16 0K dma-kmalloc-2048
0 0 0% 4.00K 0 8 0K dma-kmalloc-4096
0 0 0% 8.00K 0 4 0K dma-kmalloc-8192
0 0 0% 0.12K 0 34 0K iint_cache
0 0 0% 0.30K 0 26 0K blkdev_requests
0 0 0% 0.30K 0 26 0K request_sock_TCP
0 0 0% 0.94K 0 17 0K PING
0 0 0% 0.31K 0 25 0K xfrm_dst_cache
0 0 0% 0.03K 0 128 0K dnotify_struct
0 0 0% 0.19K 0 21 0K userfaultfd_ctx_cache
0 0 0% 0.12K 0 34 0K cfq_io_cq
0 0 0% 0.30K 0 26 0K request_sock_TCPv6
0 0 0% 0.23K 0 17 0K tw_sock_TCPv6
0 0 0% 1.12K 0 28 0K PINGv6
$

[/bash]
RELATED CODE PARTS FROM LINUX KERNEL

A
[c]
struct slabinfo {
unsigned long active_objs;
unsigned long num_objs;
unsigned long active_slabs;
unsigned long num_slabs;
unsigned long shared_avail;
unsigned int limit;
unsigned int batchcount;
unsigned int shared;
unsigned int objects_per_slab;
unsigned int cache_order;
};

void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo);
void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *s);
ssize_t slabinfo_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos);
[/c]
B
[c]
void get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo)
{
unsigned long active_objs, num_objs, active_slabs;
unsigned long total_slabs = 0, free_objs = 0, shared_avail = 0;
unsigned long free_slabs = 0;
int node;
struct kmem_cache_node *n;

for_each_kmem_cache_node(cachep, node, n) {
check_irq_on();
spin_lock_irq(&n->list_lock);

total_slabs += n->total_slabs;
free_slabs += n->free_slabs;
free_objs += n->free_objects;

if (n->shared)
shared_avail += n->shared->avail;

spin_unlock_irq(&n->list_lock);
}
num_objs = total_slabs * cachep->num;
active_slabs = total_slabs – free_slabs;
active_objs = num_objs – free_objs;

sinfo->active_objs = active_objs;
sinfo->num_objs = num_objs;
sinfo->active_slabs = active_slabs;
sinfo->num_slabs = total_slabs;
sinfo->shared_avail = shared_avail;
sinfo->limit = cachep->limit;
sinfo->batchcount = cachep->batchcount;
sinfo->shared = cachep->shared;
sinfo->objects_per_slab = cachep->num;
sinfo->cache_order = cachep->gfporder;
}

[/c]

LINKS
https://lkml.org/lkml/2017/3/27/370
http://www.secretmango.com/jimb/Whitepapers/slabs/slab.html
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Reference_Guide/s2-proc-slabinfo.html
https://en.wikipedia.org/wiki/Slab_allocation