---
author: ''
category: 技术
comments_data:
- date: '2014-08-28 13:03:01'
  message: nice！~
  postip: 218.192.13.210
  username: 微博评论
count:
  commentnum: 1
  favtimes: 2
  likes: 0
  sharetimes: 3
  viewnum: 27088
date: '2014-08-28 10:10:47'
editorchoice: false
excerpt: Linux内核需要为临时对象如任务或者设备结构和节点分配内存，缓存分配器管理着这些类型对象的缓存。现代Linux内核部署了该缓存分配器以持有缓存，称之为片。不同类型的片缓存由片分配器维护。本文集中讨论slabtop命令，该命令显示了实时内核片缓存信息。1.
  命令用法：该命令用起来很简单，默认执行时不要求任何参数。但是它要求root特权来读取内核片信息。以普通用户执行该命令会出现以下错误：
fromurl: http://linoxide.com/linux-command/kernel-slab-cache-information/
id: 3702
islctt: true
largepic: /images/p/201408/28/100951fqnnrfec6pzcypcc.jpg
permalink: /article-3702-1.html
pic: /images/p/201408/28/100951fqnnrfec6pzcypcc.jpg.thumb.jpg
related: []
reviewer: ''
selector: ''
summary: Linux内核需要为临时对象如任务或者设备结构和节点分配内存，缓存分配器管理着这些类型对象的缓存。现代Linux内核部署了该缓存分配器以持有缓存，称之为片。不同类型的片缓存由片分配器维护。本文集中讨论slabtop命令，该命令显示了实时内核片缓存信息。1.
  命令用法：该命令用起来很简单，默认执行时不要求任何参数。但是它要求root特权来读取内核片信息。以普通用户执行该命令会出现以下错误：
tags:
- Linux
- slabtop
- 命令
thumb: false
title: Linux slabtop命令——显示内核片缓存信息
titlepic: false
translator: GOLinux
updated: '2014-08-28 10:10:47'
---

Linux内核需要为临时对象如任务或者设备结构和节点分配内存，缓存分配器管理着这些类型对象的缓存。现代Linux内核部署了该缓存分配器以持有缓存，称之为片。不同类型的片缓存由片分配器维护。本文集中讨论slabtop命令，该命令显示了实时内核片缓存信息。


![](/images/p/201408/28/100951fqnnrfec6pzcypcc.jpg)


### 1. 命令用法：


该命令用起来很简单，默认执行时不要求任何参数。但是它要求root特权来读取内核片信息。以普通用户执行该命令会出现以下错误：


[![Run slabtop as non-privileged user](https://camo.githubusercontent.com/870d865203f498fc27a62bbfb0c7084f9a5929da/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030312e736c6162746f705f6e6f726d616c5f757365722e706e67)](https://camo.githubusercontent.com/870d865203f498fc27a62bbfb0c7084f9a5929da/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030312e736c6162746f705f6e6f726d616c5f757365722e706e67)


你可以在前面设置“sudo”来运行该命令，默认输出见下图：


[![Slabtop default output](https://camo.githubusercontent.com/ee7965ddf2ae63ef6ef783211f7553949a8f874c/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030322e736c6162746f705f6f75747075742e706e67)](https://camo.githubusercontent.com/ee7965ddf2ae63ef6ef783211f7553949a8f874c/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030322e736c6162746f705f6f75747075742e706e67)


要退出slabtop，只需敲‘q’，就像在top命令中那样。


### 2. Slabtop选项：


#### 2.1 显示间隔：


默认情况下，slabtop每隔3秒刷新一次。但是，如果你想要调整，可以使用-d或者--delay=N选项来调整刷新间隔，以秒为单位：


[![Custom delay interval 01](https://camo.githubusercontent.com/c116fd6a7cd99af53ff8535cd930537317bbdb77/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030332e736c6162746f705f64656c617930312e706e67)](https://camo.githubusercontent.com/c116fd6a7cd99af53ff8535cd930537317bbdb77/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030332e736c6162746f705f64656c617930312e706e67)


[![Custom delay interval 02](https://camo.githubusercontent.com/4a513cb280fede7ce35e524cde7d75563dda9311/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030342e736c6162746f705f64656c617930322e706e67)](https://camo.githubusercontent.com/4a513cb280fede7ce35e524cde7d75563dda9311/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030342e736c6162746f705f64656c617930322e706e67)


#### 2.2 排序标准：


在slabtop输出中有很多字段，-s或--sort=S选项可以根据指定的排序标准对这些字段排序。该选项将在下一节中详细讲述。


#### 2.3 输出一次：


-o或--once选项不会刷新输出，它仅仅将一次输出结果丢给STDOUT，然后退出。


[![Output once and exit](https://camo.githubusercontent.com/991fb5f7539890abdf309573fd331bfc783b9ed5/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030352e736c6162746f705f6f75747075745f6f6e63652e706e67)](https://camo.githubusercontent.com/991fb5f7539890abdf309573fd331bfc783b9ed5/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030352e736c6162746f705f6f75747075745f6f6e63652e706e67)


#### 2.4 版本信息：


-V或--version选项显示命令的版本并退出。


[![Slabtop version](https://camo.githubusercontent.com/8ccca1086a95b0c2a7c20e449810029bcab0cfa2/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030362e736c6162746f705f76657273696f6e2e706e67)](https://camo.githubusercontent.com/8ccca1086a95b0c2a7c20e449810029bcab0cfa2/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030362e736c6162746f705f76657273696f6e2e706e67)


#### 2.5 帮助：


常见选项，-h或--help显示命令的使用帮助。


[![Slabtop help options](https://camo.githubusercontent.com/704470ccd2b7aee559c97607d14075d069d5548d/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030372e736c6162746f705f68656c702e706e67)](https://camo.githubusercontent.com/704470ccd2b7aee559c97607d14075d069d5548d/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030372e736c6162746f705f68656c702e706e67)


### 3. 排序标准：


排序标准确定了哪个片缓存显示在顶部，下面是slabtop的排序标准：


#### 3.1 活跃：


缓存可以通过‘a’来对活跃对象编号进行排序。


[![Sort by Active 01](https://camo.githubusercontent.com/c8a1766e10222ef78d468040d647fc8a255325bf/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030382e736c6162746f705f736f72745f61637469766530312e706e67)](https://camo.githubusercontent.com/c8a1766e10222ef78d468040d647fc8a255325bf/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030382e736c6162746f705f736f72745f61637469766530312e706e67)


[![Sort by Active 02](https://camo.githubusercontent.com/c6776c920132786af55879467fe346b3a8418df8/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030392e736c6162746f705f736f72745f61637469766530322e706e67)](https://camo.githubusercontent.com/c6776c920132786af55879467fe346b3a8418df8/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3030392e736c6162746f705f736f72745f61637469766530322e706e67)


#### 3.2 对象/分片:


每分片对象数可以使用“b”来选择。


[![Sort by objects per slab 01](https://camo.githubusercontent.com/657e3dedcc882e2cb9d7f8dd0a2c9e67d8081ff6/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031302e736c6162746f705f736f72745f6f626a736c616230312e706e67)](https://camo.githubusercontent.com/657e3dedcc882e2cb9d7f8dd0a2c9e67d8081ff6/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031302e736c6162746f705f736f72745f6f626a736c616230312e706e67)


[![Sort by objects per slab 02](https://camo.githubusercontent.com/1118c8ecf09b1c8fae5522048a8cc7f7252a0cfe/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031312e736c6162746f705f736f72745f6f626a736c616230322e706e67)](https://camo.githubusercontent.com/1118c8ecf09b1c8fae5522048a8cc7f7252a0cfe/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031312e736c6162746f705f736f72745f6f626a736c616230322e706e67)


#### 3.3 缓存大小：


要选择缓存大小，你需要提供“c”选项。


[![Sort by cache size 01](https://camo.githubusercontent.com/67ab371d8274fe3fa94d1427b06364a09ba5a108/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031322e736c6162746f705f736f72745f63616368655f73697a6530312e706e67)](https://camo.githubusercontent.com/67ab371d8274fe3fa94d1427b06364a09ba5a108/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031322e736c6162746f705f736f72745f63616368655f73697a6530312e706e67)


[![Sort by cache size 02](https://camo.githubusercontent.com/c2298c754cdbf96080571ad37c6b5b8b6ddc6ff2/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031332e736c6162746f705f736f72745f63616368655f73697a6530322e706e67)](https://camo.githubusercontent.com/c2298c754cdbf96080571ad37c6b5b8b6ddc6ff2/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031332e736c6162746f705f736f72745f63616368655f73697a6530322e706e67)


#### 3.4 分片：


分片数量，使用“l”来选择。


[![Sort by number of slabs 01](https://camo.githubusercontent.com/d21639f60418282b5b03b1da90705dbbe712d605/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031342e736c6162746f705f736f72745f736c61627330312e706e67)](https://camo.githubusercontent.com/d21639f60418282b5b03b1da90705dbbe712d605/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031342e736c6162746f705f736f72745f736c61627330312e706e67)


[![Sort by number of slabs 02](https://camo.githubusercontent.com/bdb20e8661e42a5a0367e341bca28a435b588aff/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031352e736c6162746f705f736f72745f736c61627330322e706e67)](https://camo.githubusercontent.com/bdb20e8661e42a5a0367e341bca28a435b588aff/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031352e736c6162746f705f736f72745f736c61627330322e706e67)


#### 3.5 活跃分片：


活跃分片数量。（注意：这不同于上面讲得活跃对象数量。）使用“v”来根据该标准排序。


[![Sort by Active Slabs 01](https://camo.githubusercontent.com/0575862d850002db7550d86f2dc458a2119537b3/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031362e736c6162746f705f736f72745f6163746976655f736c61627330312e706e67)](https://camo.githubusercontent.com/0575862d850002db7550d86f2dc458a2119537b3/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031362e736c6162746f705f736f72745f6163746976655f736c61627330312e706e67)


[![Sort by Active Slabs 02](https://camo.githubusercontent.com/f6a067be5d7f308655418e8265a36a22718f05e4/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031372e736c6162746f705f736f72745f6163746976655f736c61627330322e706e67)](https://camo.githubusercontent.com/f6a067be5d7f308655418e8265a36a22718f05e4/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031372e736c6162746f705f736f72745f6163746976655f736c61627330322e706e67)


#### 3.6 名称：


缓存名称。相关字符是“n”。


[![Sort by cache name 01](https://camo.githubusercontent.com/b34caf09dfd3dbb5f803cf49a5fcd50806b590d2/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031382e736c6162746f705f736f72745f63616368655f6e616d6530312e706e67)](https://camo.githubusercontent.com/b34caf09dfd3dbb5f803cf49a5fcd50806b590d2/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031382e736c6162746f705f736f72745f63616368655f6e616d6530312e706e67)


[![Sort by cache name 02](https://camo.githubusercontent.com/4d39496b3a80ca137ce00ba377e4a9f52017d596/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031392e736c6162746f705f736f72745f63616368655f6e616d6530322e706e67)](https://camo.githubusercontent.com/4d39496b3a80ca137ce00ba377e4a9f52017d596/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3031392e736c6162746f705f736f72745f63616368655f6e616d6530322e706e67)


#### 3.7 对象：


要根据对象数量排序，使用“o”。


[![Sort by number of objects 01](https://camo.githubusercontent.com/87cfb2e2443efa81a16930c0ed7e164d5d8691fe/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032302e736c6162746f705f736f72745f6f626a6563746e756e62657230312e706e67)](https://camo.githubusercontent.com/87cfb2e2443efa81a16930c0ed7e164d5d8691fe/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032302e736c6162746f705f736f72745f6f626a6563746e756e62657230312e706e67)


[![Sort by number of objects 02](https://camo.githubusercontent.com/0eb88bba4e182b7b29a2028ce9bd2fa5a9a259f8/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032312e736c6162746f705f736f72745f6f626a6563746e756e62657230322e706e67)](https://camo.githubusercontent.com/0eb88bba4e182b7b29a2028ce9bd2fa5a9a259f8/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032312e736c6162746f705f736f72745f6f626a6563746e756e62657230322e706e67)


#### 3.8 每分片页面数：


“p”将根据每分片页面数排序。


[![Sort by pages per slab 01](https://camo.githubusercontent.com/d651e94d59c26d9cea8c19245eb9508d89240263/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032322e736c6162746f705f736f72745f7061676573706572736c616230312e706e67)](https://camo.githubusercontent.com/d651e94d59c26d9cea8c19245eb9508d89240263/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032322e736c6162746f705f736f72745f7061676573706572736c616230312e706e67)


[![Sort by pages per slab 02](https://camo.githubusercontent.com/39244a9379b0ccc1f18461d1f6d0afab66c015ec/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032332e736c6162746f705f736f72745f7061676573706572736c616230322e706e67)](https://camo.githubusercontent.com/39244a9379b0ccc1f18461d1f6d0afab66c015ec/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032332e736c6162746f705f736f72745f7061676573706572736c616230322e706e67)


#### 3.9 对象大小：


对象大小排序由“s”来指定。


[![Sort by object size 01](https://camo.githubusercontent.com/7ee99649fd5b933917b84fbd9a995db2f6529c35/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032342e736c6162746f705f736f72745f6f626a6563745f73697a6530312e706e67)](https://camo.githubusercontent.com/7ee99649fd5b933917b84fbd9a995db2f6529c35/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032342e736c6162746f705f736f72745f6f626a6563745f73697a6530312e706e67)


[![Sort by object size 02](https://camo.githubusercontent.com/be10175f68274599185e0ed8156bf515313f439e/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032352e736c6162746f705f736f72745f6f626a6563745f73697a6530322e706e67)](https://camo.githubusercontent.com/be10175f68274599185e0ed8156bf515313f439e/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032352e736c6162746f705f736f72745f6f626a6563745f73697a6530322e706e67)


#### 3.10 使用：


“u”选项根据缓存使用量排序。


[![Sort by cache utilization 01](https://camo.githubusercontent.com/d22f8ff7906d39a8e10ed9e427ca1683fc7f5d01/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032362e736c6162746f705f736f72745f63616368655f7574696c697a6174696f6e30312e706e67)](https://camo.githubusercontent.com/d22f8ff7906d39a8e10ed9e427ca1683fc7f5d01/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032362e736c6162746f705f736f72745f63616368655f7574696c697a6174696f6e30312e706e67)


[![Sort by cache utilization 02](https://camo.githubusercontent.com/d2cd40768d2df48c39c2724fb967a8b0f789397d/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032372e736c6162746f705f736f72745f63616368655f7574696c697a6174696f6e30322e706e67)](https://camo.githubusercontent.com/d2cd40768d2df48c39c2724fb967a8b0f789397d/687474703a2f2f6c696e6f786964652e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031342f30372f3032372e736c6162746f705f736f72745f63616368655f7574696c697a6174696f6e30322e706e67)




---


via: <http://linoxide.com/linux-command/kernel-slab-cache-information/>


译者：[GOLinux](https://github.com/GOLinux) 校对：[校对者ID](https://github.com/%E6%A0%A1%E5%AF%B9%E8%80%85ID)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译，[Linux中国](http://linux.cn/) 荣誉推出