
{"id":17105,"date":"2018-08-11T18:48:24","date_gmt":"2018-08-11T18:48:24","guid":{"rendered":"http:\/\/www.beautifulwork.org\/?p=17105"},"modified":"2018-08-11T18:48:24","modified_gmt":"2018-08-11T18:48:24","slug":"slabinfo-kernel-slab-allocator-statistics","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2018\/08\/11\/slabinfo-kernel-slab-allocator-statistics\/","title":{"rendered":"slabinfo &#8211; kernel slab allocator statistics"},"content":{"rendered":"<p>WHAT IS SLAB ALLOCATION ?<\/p>\n<pre>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.\n<\/pre>\n<pre>\nInstead 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.\n<\/pre>\n<p>RELATED SHELL SESSION EXPOSURE<br \/>\n[bash]<br \/>\n$sudo slabtop -o<br \/>\n Active \/ Total Objects (% used)    : 535097 \/ 607019 (88.2%)<br \/>\n Active \/ Total Slabs (% used)      : 21678 \/ 21678 (100.0%)<br \/>\n Active \/ Total Caches (% used)     : 101 \/ 124 (81.5%)<br \/>\n Active \/ Total Size (% used)       : 116716.47K \/ 136870.05K (85.3%)<br \/>\n Minimum \/ Average \/ Maximum Object : 0.01K \/ 0.22K \/ 8.00K<\/p>\n<p>  OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ\/SLAB CACHE SIZE NAME<br \/>\n118209 104139  88%    0.10K   3031       39     12124K buffer_head<br \/>\n103840 103648  99%    0.25K   6490       16     25960K skbuff_head_cache<br \/>\n 43225  41001  94%    0.20K   2275       19      9100K vm_area_struct<br \/>\n 37590  30689  81%    0.19K   1790       21      7160K dentry<br \/>\n 32512  28745  88%    0.03K    254      128      1016K kmalloc-32<br \/>\n 32384  27081  83%    0.06K    506       64      2024K anon_vma_chain<br \/>\n 29010  28898  99%    0.13K    967       30      3868K kernfs_node_cache<br \/>\n 20272  12148  59%    0.57K    724       28     11584K radix_tree_node<br \/>\n 18752  16591  88%    0.06K    293       64      1172K kmalloc-64<br \/>\n 17342  14540  83%    0.09K    377       46      1508K anon_vma<br \/>\n 16578  14490  87%    0.59K    614       27      9824K inode_cache<br \/>\n 14576  11558  79%    0.25K    911       16      3644K filp<br \/>\n 12800  11906  93%    0.02K     50      256       200K kmalloc-16<br \/>\n 12390   9609  77%    1.05K    413       30     13216K ext4_inode_cache<br \/>\n 10200   6294  61%    0.05K    120       85       480K ftrace_event_field<br \/>\n  8704   7034  80%    0.01K     17      512        68K kmalloc-8<br \/>\n  4704   3944  83%    0.09K    112       42       448K kmalloc-96<br \/>\n  4256   4200  98%    0.07K     76       56       304K Acpi-Operand<br \/>\n  4074   3120  76%    0.19K    194       21       776K cred_jar<br \/>\n  3668   3665  99%    0.14K    131       28       524K ext4_groupinfo_4k<br \/>\n  3570   3570 100%    0.04K     35      102       140K ext4_extent_status<br \/>\n  3450   2422  70%    0.69K    150       23      2400K shmem_inode_cache<br \/>\n  3312   2611  78%    0.66K    138       24      2208K proc_inode_cache<br \/>\n  3200   2599  81%    0.12K    100       32       400K pid<br \/>\n  2754   2751  99%    0.04K     27      102       108K Acpi-Namespace<br \/>\n  2688   2432  90%    0.03K     21      128        84K fscrypt_info<br \/>\n  2550   1633  64%    0.04K     25      102       100K pde_opener<br \/>\n  2448   2137  87%    0.50K    153       16      1224K kmalloc-512<br \/>\n  2394   2134  89%    0.19K    114       21       456K kmalloc-192<br \/>\n  2384   2171  91%    1.00K    149       16      2384K kmalloc-1024<br \/>\n  2176   1898  87%    0.12K     68       32       272K kmalloc-128<br \/>\n  2139   1734  81%    0.69K     93       23      1488K sock_inode_cache<br \/>\n  2112   2112 100%    0.06K     33       64       132K kmem_cache_node<br \/>\n  2037   2037 100%    0.38K     97       21       776K kmem_cache<br \/>\n  1932   1006  52%    0.56K     69       28      1104K i915_vma<br \/>\n  1840   1819  98%    0.09K     40       46       160K trace_event_file<br \/>\n  1568   1386  88%    0.07K     28       56       112K eventpoll_pwq<br \/>\n  1488   1382  92%    2.00K     93       16      2976K kmalloc-2048<br \/>\n  1472   1200  81%    1.00K     92       16      1472K UNIX<br \/>\n  1323    688  52%    0.75K     63       21      1008K xfrm_state<br \/>\n  1275    896  70%    0.08K     25       51       100K inotify_inode_mark<br \/>\n   945    903  95%    0.19K     45       21       180K proc_dir_entry<br \/>\n   896    836  93%    0.25K     56       16       224K kmalloc-256<br \/>\n   884    782  88%    0.12K     26       34       104K jbd2_journal_head<br \/>\n   882    777  88%    0.38K     42       21       336K mnt_cache<br \/>\n   837    663  79%    3.38K     93        9      2976K task_struct<br \/>\n   810    590  72%    1.06K     27       30       864K mm_struct<br \/>\n   780    618  79%    1.06K     26       30       832K signal_cache<br \/>\n   720    593  82%    4.00K     90        8      2880K kmalloc-4096<br \/>\n   680    563  82%    0.02K      4      170        16K numa_policy<br \/>\n   640    510  79%    0.25K     40       16       160K pool_workqueue<br \/>\n   511    292  57%    0.05K      7       73        28K mbcache<br \/>\n   506    388  76%    0.69K     22       23       352K files_cache<br \/>\n   450    367  81%    2.06K     30       15       960K sighand_cache<br \/>\n   288    195  67%    0.12K      9       32        36K secpath_cache<br \/>\n   256      2   0%    0.02K      1      256         4K jbd2_revoke_table_s<br \/>\n   234    234 100%    0.10K      6       39        24K blkdev_ioc<br \/>\n   225    177  78%    1.25K      9       25       288K UDPv6<br \/>\n   224    224 100%    0.12K      7       32        28K scsi_sense_cache<br \/>\n   219    152  69%    0.05K      3       73        12K Acpi-Parse<br \/>\n   208    144  69%    0.25K     13       16        52K dquot<br \/>\n   172    171  99%    8.00K     43        4      1376K kmalloc-8192<br \/>\n   170    170 100%    0.05K      2       85         8K fscrypt_ctx<br \/>\n   168    100  59%    1.12K      6       28       192K RAWv6<br \/>\n   165    150  90%    2.12K     11       15       352K TCP<br \/>\n   128    128 100%    0.06K      2       64         8K dmaengine-unmap-2<br \/>\n   128    128 100%    0.03K      1      128         4K sd_ext_cdb<br \/>\n   128    128 100%    0.06K      2       64         8K ext4_io_end<br \/>\n   112     82  73%    0.50K      7       16        56K skbuff_fclone_cache<br \/>\n   102    102 100%    0.08K      2       51         8K Acpi-State<br \/>\n    96     87  90%    0.32K      4       24        32K taskstats<br \/>\n    85     68  80%    0.23K      5       17        20K tw_sock_TCP<br \/>\n    85     42  49%    0.94K      5       17        80K RAW<br \/>\n    80     80 100%    0.20K      4       20        16K file_lock_cache<br \/>\n    76     44  57%    0.81K      4       19        64K bdev_cache<br \/>\n    75     73  97%    0.62K      3       25        48K task_group<br \/>\n    72     60  83%    8.00K     18        4       576K biovec-max<br \/>\n    64     42  65%    2.00K      4       16       128K biovec-128<br \/>\n    64     64 100%    0.12K      2       32         8K ext4_allocation_context<br \/>\n    63     46  73%    0.19K      3       21        12K dmaengine-unmap-16<br \/>\n    50     50 100%    0.16K      2       25         8K sigqueue<br \/>\n    50     50 100%    0.62K      2       25        32K i915_request<br \/>\n    42     42 100%    2.25K      3       14        96K TCPv6<br \/>\n    40     20  50%    0.39K      2       20        16K fuse_request<br \/>\n    38     19  50%    0.20K      2       19         8K ip4-frags<br \/>\n    36      0   0%    0.43K      2       18        16K uts_namespace<br \/>\n    34     17  50%    0.23K      2       17         8K posix_timers_cache<br \/>\n    34      1   2%    0.94K      2       17        32K mqueue_inode_cache<br \/>\n    32     16  50%    4.00K      4        8       128K names_cache<br \/>\n    32     32 100%    1.00K      2       16        32K biovec-64<br \/>\n    30     30 100%    1.06K      1       30        32K dmaengine-unmap-128<br \/>\n    26     26 100%    0.61K      1       26        16K hugetlbfs_inode_cache<br \/>\n    25     25 100%    0.62K      1       25        16K rpc_inode_cache<br \/>\n    21     21 100%    0.75K      1       21        16K dax_cache<br \/>\n    19     19 100%    0.81K      1       19        16K fuse_inode<br \/>\n    17      0   0%    0.45K      1       17         8K user_namespace<br \/>\n    16      0   0%    0.50K      1       16         8K dma-kmalloc-512<br \/>\n    15      6  40%    6.19K      3        5        96K net_namespace<br \/>\n    15     15 100%    2.06K      1       15        32K dmaengine-unmap-256<br \/>\n    13     13 100%    2.40K      1       13        32K request_queue<br \/>\n     8      2  25%    4.00K      1        8        32K sgpool-128<br \/>\n     0      0   0%    0.09K      0       42         0K dma-kmalloc-96<br \/>\n     0      0   0%    0.19K      0       21         0K dma-kmalloc-192<br \/>\n     0      0   0%    0.01K      0      512         0K dma-kmalloc-8<br \/>\n     0      0   0%    0.02K      0      256         0K dma-kmalloc-16<br \/>\n     0      0   0%    0.03K      0      128         0K dma-kmalloc-32<br \/>\n     0      0   0%    0.06K      0       64         0K dma-kmalloc-64<br \/>\n     0      0   0%    0.12K      0       32         0K dma-kmalloc-128<br \/>\n     0      0   0%    0.25K      0       16         0K dma-kmalloc-256<br \/>\n     0      0   0%    1.00K      0       16         0K dma-kmalloc-1024<br \/>\n     0      0   0%    2.00K      0       16         0K dma-kmalloc-2048<br \/>\n     0      0   0%    4.00K      0        8         0K dma-kmalloc-4096<br \/>\n     0      0   0%    8.00K      0        4         0K dma-kmalloc-8192<br \/>\n     0      0   0%    0.12K      0       34         0K iint_cache<br \/>\n     0      0   0%    0.30K      0       26         0K blkdev_requests<br \/>\n     0      0   0%    0.30K      0       26         0K request_sock_TCP<br \/>\n     0      0   0%    0.94K      0       17         0K PING<br \/>\n     0      0   0%    0.31K      0       25         0K xfrm_dst_cache<br \/>\n     0      0   0%    0.03K      0      128         0K dnotify_struct<br \/>\n     0      0   0%    0.19K      0       21         0K userfaultfd_ctx_cache<br \/>\n     0      0   0%    0.12K      0       34         0K cfq_io_cq<br \/>\n     0      0   0%    0.30K      0       26         0K request_sock_TCPv6<br \/>\n     0      0   0%    0.23K      0       17         0K tw_sock_TCPv6<br \/>\n     0      0   0%    1.12K      0       28         0K PINGv6<br \/>\n$<\/p>\n<p>[\/bash]<br \/>\nRELATED CODE PARTS FROM LINUX KERNEL<\/p>\n<p>A<br \/>\n[c]<br \/>\nstruct slabinfo {<br \/>\n\tunsigned long active_objs;<br \/>\n\tunsigned long num_objs;<br \/>\n\tunsigned long active_slabs;<br \/>\n\tunsigned long num_slabs;<br \/>\n\tunsigned long shared_avail;<br \/>\n\tunsigned int limit;<br \/>\n\tunsigned int batchcount;<br \/>\n\tunsigned int shared;<br \/>\n\tunsigned int objects_per_slab;<br \/>\n\tunsigned int cache_order;<br \/>\n};<\/p>\n<p>void get_slabinfo(struct kmem_cache *s, struct slabinfo *sinfo);<br \/>\nvoid slabinfo_show_stats(struct seq_file *m, struct kmem_cache *s);<br \/>\nssize_t slabinfo_write(struct file *file, const char __user *buffer,<br \/>\n\t\t       size_t count, loff_t *ppos);<br \/>\n[\/c]<br \/>\nB<br \/>\n[c]<br \/>\nvoid get_slabinfo(struct kmem_cache *cachep, struct slabinfo *sinfo)<br \/>\n{<br \/>\n\tunsigned long active_objs, num_objs, active_slabs;<br \/>\n\tunsigned long total_slabs = 0, free_objs = 0, shared_avail = 0;<br \/>\n\tunsigned long free_slabs = 0;<br \/>\n\tint node;<br \/>\n\tstruct kmem_cache_node *n;<\/p>\n<p>\tfor_each_kmem_cache_node(cachep, node, n) {<br \/>\n\t\tcheck_irq_on();<br \/>\n\t\tspin_lock_irq(&amp;n-&gt;list_lock);<\/p>\n<p>\t\ttotal_slabs += n-&gt;total_slabs;<br \/>\n\t\tfree_slabs += n-&gt;free_slabs;<br \/>\n\t\tfree_objs += n-&gt;free_objects;<\/p>\n<p>\t\tif (n-&gt;shared)<br \/>\n\t\t\tshared_avail += n-&gt;shared-&gt;avail;<\/p>\n<p>\t\tspin_unlock_irq(&amp;n-&gt;list_lock);<br \/>\n\t}<br \/>\n\tnum_objs = total_slabs * cachep-&gt;num;<br \/>\n\tactive_slabs = total_slabs &#8211; free_slabs;<br \/>\n\tactive_objs = num_objs &#8211; free_objs;<\/p>\n<p>\tsinfo-&gt;active_objs = active_objs;<br \/>\n\tsinfo-&gt;num_objs = num_objs;<br \/>\n\tsinfo-&gt;active_slabs = active_slabs;<br \/>\n\tsinfo-&gt;num_slabs = total_slabs;<br \/>\n\tsinfo-&gt;shared_avail = shared_avail;<br \/>\n\tsinfo-&gt;limit = cachep-&gt;limit;<br \/>\n\tsinfo-&gt;batchcount = cachep-&gt;batchcount;<br \/>\n\tsinfo-&gt;shared = cachep-&gt;shared;<br \/>\n\tsinfo-&gt;objects_per_slab = cachep-&gt;num;<br \/>\n\tsinfo-&gt;cache_order = cachep-&gt;gfporder;<br \/>\n}<\/p>\n<p>[\/c]<\/p>\n<p>LINKS<br \/>\n<a href=\"https:\/\/lkml.org\/lkml\/2017\/3\/27\/370\">https:\/\/lkml.org\/lkml\/2017\/3\/27\/370<\/a><br \/>\n<a href=\"http:\/\/www.secretmango.com\/jimb\/Whitepapers\/slabs\/slab.html\">http:\/\/www.secretmango.com\/jimb\/Whitepapers\/slabs\/slab.html<\/a><br \/>\n<a href=\"https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/4\/html\/Reference_Guide\/s2-proc-slabinfo.html\">https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/4\/html\/Reference_Guide\/s2-proc-slabinfo.html<\/a><br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Slab_allocation\">https:\/\/en.wikipedia.org\/wiki\/Slab_allocation<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2018\/08\/11\/slabinfo-kernel-slab-allocator-statistics\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;slabinfo &#8211; kernel slab allocator statistics&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[83],"tags":[1014,1108],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/17105"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=17105"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/17105\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=17105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=17105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=17105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}