#Bash 的 lsmem 命令
lsmem [OPTION]...
功能
列出可用内存范围及其在线状态。
类型
可执行文件(/usr/bin/lsmem),属于 util-linux。
参数
OPTION选项:-a,--all- 单独列出每个内存块-b,--bytes- 以字节为单位-J,--json- 以 JSON 格式输出-n,--noheadings- 不显示标题行(列名)-o,--output list- 只输出指定的列--output-all- 输出所有列-P,--pairs- 以键值对(key="value")的格式输出-r,--raw- 以原始格式输出-S,--split list- 指定用于分割内存块范围的列-s,--sysroot directory- 指定根目录,可用于查看来自其它系统的信息--summary[=when]- 何时显示摘要行;取值为never,always或only(默认)-h,--help- 显示帮助-V,--version- 显示版本
#列名
| 列名 | 说明 |
|---|---|
RANGE | 内存地址范围 |
SIZE | 内存大小 |
STATE | 内存在线状态 |
REMOVABLE | 内存是否可删除 |
BLOCK | 内存块编号或范围 |
NODE | 内存的 NUMA 节点 |
ZONES | 内存范围的有效域 |
#示例
$ lsmem
RANGE SIZE STATE REMOVABLE BLOCK
0x0000000000000000-0x000000005fffffff 1.5G online yes 0-11
0x0000000100000000-0x000000041fffffff 12.5G online yes 32-131
Memory block size: 128M
Total online memory: 14G
Total offline memory: 0B
$ lsmem --output-all
RANGE SIZE STATE REMOVABLE BLOCK NODE ZONES
0x0000000000000000-0x0000000007ffffff 128M online yes 0 0 None
0x0000000008000000-0x000000005fffffff 1.4G online yes 1-11 0 DMA32
0x0000000100000000-0x000000041fffffff 12.5G online yes 32-131 0 Normal
Memory block size: 128M
Total online memory: 14G
Total offline memory: 0B
#推荐阅读
#手册
LSMEM(1) User Commands LSMEM(1)
NAME
lsmem - list the ranges of available memory with their online status
SYNOPSIS
lsmem [options]
DESCRIPTION
The lsmem command lists the ranges of available memory with their
online status. The listed memory blocks correspond to the memory block
representation in sysfs. The command also shows the memory block size
and the amount of memory in online and offline state.
The default output is compatible with original implementation from
s390-tools, but it’s strongly recommended to avoid using default
outputs in your scripts. Always explicitly define expected columns by
using the --output option together with a columns list in environments
where a stable output is required.
The lsmem command lists a new memory range always when the current
memory block distinguish from the previous block by some output column.
This default behavior is possible to override by the --split option
(e.g., lsmem --split=ZONES). The special word "none" may be used to
ignore all differences between memory blocks and to create as large as
possible continuous ranges. The opposite semantic is --all to list
individual memory blocks.
Note that some output columns may provide inaccurate information if a
split policy forces lsmem to ignore differences in some attributes. For
example if you merge removable and non-removable memory blocks to the
one range than all the range will be marked as non-removable on lsmem
output.
Not all columns are supported on all systems. If an unsupported column
is specified, lsmem prints the column but does not provide any data for
it.
Use the --help option to see the columns description.
OPTIONS
-a, --all
List each individual memory block, instead of combining memory
blocks with similar attributes.
-b, --bytes
Print the sizes in bytes rather than in a human-readable format.
By default, the unit, sizes are expressed in, is byte, and unit
prefixes are in power of 2^10 (1024). Abbreviations of symbols are
exhibited truncated in order to reach a better readability, by
exhibiting alone the first letter of them; examples: "1 KiB" and "1
MiB" are respectively exhibited as "1 K" and "1 M", then omitting
on purpose the mention "iB", which is part of these abbreviations.
-J, --json
Use JSON output format.
-n, --noheadings
Do not print a header line.
-o, --output list
Specify which output columns to print. Use --help to get a list of
all supported columns. The default list of columns may be extended
if list is specified in the format +list (e.g., lsmem -o +NODE).
--output-all
Output all available columns.
-P, --pairs
Produce output in the form of key="value" pairs. All potentially
unsafe value characters are hex-escaped (\x<code>).
-r, --raw
Produce output in raw format. All potentially unsafe characters are
hex-escaped (\x<code>).
-S, --split list
Specify which columns (attributes) use to split memory blocks to
ranges. The supported columns are STATE, REMOVABLE, NODE and ZONES,
or "none". The other columns are silently ignored. For more details
see DESCRIPTION above.
-s, --sysroot directory
Gather memory data for a Linux instance other than the instance
from which the lsmem command is issued. The specified directory is
the system root of the Linux instance to be inspected.
-h, --help
Display help text and exit.
-V, --version
Print version and exit.
--summary[=when]
This option controls summary lines output. The optional argument
when can be never, always or only. If the when argument is omitted,
it defaults to "only". The summary output is suppressed for --raw,
--pairs and --json.
AUTHORS
lsmem was originally written by Gerald Schaefer for s390-tools in Perl.
The C version for util-linux was written by Clemens von Mann, Heiko
Carstens and Karel Zak.
SEE ALSO
chmem(8)
REPORTING BUGS
For bug reports, use the issue tracker at
https://github.com/util-linux/util-linux/issues.
AVAILABILITY
The lsmem command is part of the util-linux package which can be
downloaded from Linux Kernel Archive
<https://www.kernel.org/pub/linux/utils/util-linux/>.
util-linux 2.39.3 2023-10-23 LSMEM(1)