> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man8/vmstat.8.md).

# vmstat.8

`vmstat` — 报告虚拟内存统计信息

## 名称

`vmstat`

## 概要

`vmstat [--libxo] [-afHhimoPsz] [-M core [-N system]] [-c count] [-n devs] [-p type,if,pass] [-w wait] [disks ...] [wait [count]]`

## 描述

`vmstat` 工具报告有关进程、虚拟内存、磁盘、陷阱和 CPU 活动的某些内核统计信息。

如果未指定 `-M` 选项，则通过 sysctl(3) 接口从当前运行的内核获取信息。否则，从指定的内核转储文件读取信息，使用指定内核映像（或默认映像）中的名称列表。

选项如下：

**`--libxo`** 通过 libxo(3) 以多种人类可读和机器可读格式生成输出。有关命令行参数的详细信息，请参见 xo\_options(7)。

**`-a`** 与 `-i` 一起使用时，包括从未生成的中断的统计信息。

**`-c`** `count` 重复显示 `count` 次。第一次显示的是自重启以来的时间，后续每次报告的是自上次显示以来的时间段。如果未指定重复 `count`，并且指定了 `-w`，则默认为无限次，否则默认为一次。

**`-f`** 报告自系统启动以来 fork(2)、vfork(2) 和 rfork(2) 系统调用的次数，以及每个调用涉及的虚拟内存页数。

**`-h`** 将内存列更改为更易读的形式。如果标准输出是终端设备，则默认启用。

**`-H`** 将内存列更改为纯数字。如果标准输出不是终端设备（如脚本），则默认启用。

**`-i`** 报告自系统启动以来每个设备捕获的中断数。

**`-M`** 从指定的 `core` 提取与名称列表关联的值。

**`-N`** 如果同时指定了 `-M`，则从指定的 `system` 而非默认值（系统引导时使用的内核映像）提取名称列表。

**`-m`** 按类型报告使用 [malloc(9)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man9/malloc.9.md) 分配的内核动态内存的使用情况。

**`-n`** `devs` 将显示的最大磁盘数从默认值 2 更改。

**`-o`** 显示系统中虚拟内存对象列表及每个对象使用的驻留内存。

**`-P`** 报告每个 CPU 的系统/用户/空闲 CPU 统计信息。

**`-p`** 指定要显示的设备类型。设备有三种不同的类别：

设备类型（device type）：

**da** 直接访问设备

**sa** 顺序访问设备

**printer** 打印机

**proc** 处理器设备

**worm** 一次写入多次读取设备

**cd** CD 设备

**scanner** 扫描仪设备

**optical** 光存储设备

**changer** 介质更换设备

**comm** 通信设备

**array** 存储阵列设备

**enclosure** 机箱服务设备

**floppy** 软盘设备

接口（interface）：

**IDE** 集成驱动电子设备

**SCSI** 小型计算机系统接口设备

**NVME** NVM Express 接口设备

**other** 任何其他设备接口

直通（passthrough）：

**pass** 直通设备

用户必须指定至少一种设备类型，且从每个类别中最多指定一种设备类型。单个设备类型语句中的多个设备类型必须用逗号分隔。命令行上可以指定任意数量的 `-p` 参数。所有 `-p` 参数通过或运算组合形成匹配表达式，系统中的所有设备都与该表达式比较。完全匹配任何 `-p` 参数的设备将包含在 `vmstat` 输出中，最多两个设备，或用户指定的最大设备数。

**`-s`** 显示 *sum* 结构的内容，给出自系统启动以来发生的几种分页相关事件的总数。

**`-w`** `wait` 每次显示之间暂停 `wait` 秒。如果未指定重复 `wait` 间隔，默认为 1 秒。`vmstat` 命令接受并使用非整数秒数。

**`-z`** 按区域报告内核区域分配器 uma(9) 使用的内存。

`wait` 和 `count` 参数可以在命令行上 `disks` 参数之前的任何位置跟在各自标志之后，也可以不带标志作为最终参数。后一种形式为向后兼容而接受，但首选使用 `-w` 和 `-c` 的形式以避免歧义。

默认情况下，`vmstat` 显示以下信息：

**procs** 有关各种状态下线程数量的信息：

**r** 运行中或在运行队列中

**b** 因资源（I/O、分页等）阻塞

**w** 已换出

**memory** 有关虚拟和实际内存使用的信息。映射的虚拟内存是属于映射虚拟内存对象的所有虚拟页的总和。注意，即使当前只映射了对象页的子集，整个内存对象的大小也被视为已映射。此统计信息与用于跟踪实际内存的活动页队列无关。

**avm** 映射的虚拟内存（以前在 `vmstat` 输出中称为 active）

**fre** 空闲列表的大小

**page** 有关页错误和分页活动的信息。这些以每秒为单位给出。

**flt** 页错误总数

**re** 重新激活的页（在 laundry 或 inactive 队列中找到）

**pi** 换入的页

**po** 换出的页

**fr** 释放的页

**sr** 页守护进程扫描的页

**disks** 每秒磁盘操作数（此字段取决于系统）。通常分页将分布在可用驱动器上。字段的标题是磁盘名的前两个字符和单元号。如果系统中配置了两个以上的磁盘驱动器，`vmstat` 仅显示前两个驱动器，除非用户指定 `-n` 参数来增加显示的驱动器数。但这可能导致显示超过 80 列。要强制 `vmstat` 显示特定驱动器，可在命令行上提供其名称。`vmstat` 工具默认先显示磁盘，然后是系统中各种其他随机设备，总共最多两个设备（如果系统中有那么多设备）。如果在命令行上指定了设备，或指定了设备类型匹配模式（见上文），`vmstat` 将仅显示给定设备或匹配模式的设备，不会随机选择系统中的其他设备。

**faults** 每秒陷阱/中断率。

**in** 设备中断（包括时钟中断）

**sy** 系统调用

**cs** CPU 上下文切换

**cpu** CPU 时间百分比使用明细。

**us** 正常和低优先级进程的用户时间

**sy** 系统和中断时间

**id** CPU 空闲

## 文件

**/boot/kernel/kernel** 默认内核名称列表

**/dev/kmem** 默认内存文件

## 实例

命令：

```sh
vmstat -w 5
```

将每五秒打印一次系统正在做什么。

命令：

```sh
vmstat -p da -p cd -w 1
```

将让 vmstat 选择前两个直接访问或 CDROM 设备，并显示这些设备的统计信息，以及每秒的其他系统统计信息。

## 参见

fstat(1), [netstat(1)](/man/man1/netstat.1.md), nfsstat(1), [ps(1)](/man/man1/ps.1.md), [systat(1)](/man/man1/systat.1.md), libmemstat(3), libxo(3), xo\_options(7), gstat(8), [iostat(8)](/man/man8/iostat.8.md), pstat(8), [sysctl(8)](/man/man8/sysctl.8.md), [malloc(9)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man9/malloc.9.md), uma(9)

《Installing and Operating 4.3BSD》中以“Interpreting system activity”开头的章节。

## 历史

`vmstat` 工具首次出现于 3BSD。

## 缺陷

`-c` 和 `-w` 选项仅在默认输出中可用。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man8/vmstat.8.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
