lsmem/chmem: add memory zone awareness
Subsystems (2)
cover lsmem/chmem: add memory zone awareness
These patches are against lsmem/chmem in util-linux, they add support for listing and changing memory zone allocation.
Added Michal Hocko and linux-mm on cc, to raise general awareness for the lsmem/chmem tools, and the new memory zone functionality in particular. I think this can be quite useful for memory hotplug kernel development, and if not, sorry for the noise.
Andre Wild (1):
lsmem/chmem: add memory zone awareness to bash-completion
Gerald Schaefer (2):
lsmem/chmem: add memory zone awareness tests/lsmem: update lsmem test with ZONES column
bash-completion/chmem | 1 + bash-completion/lsmem | 2 +- sys-utils/chmem.8 | 19 +++++ sys-utils/chmem.c | 136 +++++++++++++++++++++++++++++++-- sys-utils/lsmem.1 | 4 +- sys-utils/lsmem.c | 98 +++++++++++++++++++++++- tests/expected/lsmem/lsmem-s390-zvm-6g | 21 +++++ tests/expected/lsmem/lsmem-x86_64-16g | 39 ++++++++++ tests/ts/lsmem/lsmem | 1 + 9 files changed, 309 insertions(+), 12 deletions(-)
Signature · 1 line
2.13.5
PATCH 1/3 lsmem/chmem: add memory zone awareness
With this patch, valid memory zones can be shown with lsmem, and chmem can set memory online/offline in a specific memory zone, if allowed by the kernel. The valid memory zones are read from the "valid_zones" sysfs attribute, and setting memory online to a specific zone is done by echoing "online_kernel" or "online_movable" to the "state" sysfs attribute, in addition to the previous "online".
This patch also changes the default behavior of chmem, when setting memory online without specifying a memory zone. If valid, memory will be set online to the zone Movable. This zone is preferable for memory hotplug, as it makes memory offline much more likely to succeed.
--- sys-utils/chmem.8 | 19 ++++++++ sys-utils/chmem.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++---- sys-utils/lsmem.1 | 4 +- sys-utils/lsmem.c | 98 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 246 insertions(+), 11 deletions(-)
sys-utils/chmem.8 +19 -0
@@ -5,6 +5,7 @@ chmem \- configure memory .B chmem .RB [ \-h "] [" \-V "] [" \-v "] [" \-e | \-d "]" [\fISIZE\fP|\fIRANGE\fP|\fB\-b\fP \fIBLOCKRANGE\fP] +[-z ZONE] .SH DESCRIPTION The chmem command sets a particular size or range of memory online or offline. .
@@ -25,6 +26,19 @@ and <last> is the number of the last memory block in the memory range. Alternatively a single block can be specified. \fIBLOCKRANGE\fP requires the \fB--blocks\fP option. . +.IP "\(hy" 2 +Specify \fIZONE\fP as the name of a memory zone, as shown in the output of the +\fBlsmem -o +ZONES\fP command. The output shows one or more valid memory zones +for each memory range. If multiple zones are shown, then the memory range +currently belongs to the first zone. By default, chmem will set memory online +to the zone Movable, if this is among the valid zones. This default can be +changed by specifying the \fB--zone\fP option with another valid zone. +For memory ballooning, it is recommended to select the zone Movable for memory +online and offline, if possible. Memory in this zone is much more likely to be +able to be offlined again, but it cannot be used for arbitrary kernel +allocations, only for migratable pages (e.g. anonymous and page cache pages). +Use the \fB\-\-help\fR option to see all available zones. +. .PP \fISIZE\fP and \fIRANGE\fP must be aligned to the Linux memory block size, as shown in the output of the \fBlsmem\fP command.
@@ -51,6 +65,11 @@ Set the specified \fIRANGE\fP, \fISIZE\fP, or \fIBLOCKRANGE\fP of memory offline .BR \-e ", " \-\-enable Set the specified \fIRANGE\fP, \fISIZE\fP, or \fIBLOCKRANGE\fP of memory online. .TP +.BR \-z ", " \-\-zone +Select the memory \fIZONE\fP where to set the specified \fIRANGE\fP, \fISIZE\fP, +or \fIBLOCKRANGE\fP of memory online or offline. By default, memory will be set +online to the zone Movable, if possible. +.TP .BR \-h ", " \-\-help Print a short help text, then exit. .TP
sys-utils/chmem.c +128 -8
238 lines not on this page · raw message
sys-utils/lsmem.1 +2 -2
@@ -41,12 +41,12 @@ Do not print a header line. .BR \-o , " \-\-output " \fIlist\fP Specify which output columns to print. Use \fB\-\-help\fR to get a list of all supported columns. +The default list of columns may be extended if \fIlist\fP is +specified in the format \fB+\fIlist\fP (e.g. \fBlsmem \-o +NODE\fP). .TP .BR \-P , " \-\-pairs" Produce output in the form of key="value" pairs. All potentially unsafe characters are hex-escaped (\\x<code>). -The default list of columns may be extended if \fIlist\fP is -specified in the format \fB+\fIlist\fP (e.g. \fBlsmem \-o +NODE\fP). .TP .BR \-r , " \-\-raw" Produce output in raw format. All potentially unsafe characters are hex-escaped
sys-utils/lsmem.c +97 -1
175 lines not on this page · raw message
Signature · 1 line
2.13.5
PATCH 2/3 tests/lsmem: update lsmem test with ZONES column
In reply to Gerald SchaeferThe existing s390 and x86_64 dumps already contain the valid_zones sysfs attribute, so just add a new "lsmem -o +ZONES" test command and update the expected results.
--- tests/expected/lsmem/lsmem-s390-zvm-6g | 21 ++++++++++++++++++ tests/expected/lsmem/lsmem-x86_64-16g | 39 ++++++++++++++++++++++++++++++++++ tests/ts/lsmem/lsmem | 1 + 3 files changed, 61 insertions(+)
tests/expected/lsmem/lsmem-s390-zvm-6g +21 -0
@@ -106,3 +106,24 @@ $ lsmem --json --output RANGE,SIZE,STATE,REMOVABLE,BLOCK,NODE {"range": "0x0000000140000000-0x000000017fffffff", "size": "1G", "state": "offline", "removable": "-", "block": "20-23", "node": "0"} ] } + +--- + +$ lsmem -o +ZONES +RANGE SIZE STATE REMOVABLE BLOCK ZONES +0x0000000000000000-0x000000006fffffff 1.8G online yes 0-6 DMA +0x0000000070000000-0x000000007fffffff 256M online no 7 DMA/Normal +0x0000000080000000-0x000000009fffffff 512M online yes 8-9 Normal +0x00000000a0000000-0x00000000bfffffff 512M online no 10-11 Normal +0x00000000c0000000-0x00000000dfffffff 512M online yes 12-13 Normal +0x00000000e0000000-0x00000000efffffff 256M offline - 14 Normal +0x00000000f0000000-0x00000000ffffffff 256M online yes 15 Normal +0x0000000100000000-0x000000010fffffff 256M online no 16 Normal +0x0000000110000000-0x000000011fffffff 256M online no 17 Normal/Movable +0x0000000120000000-0x000000012fffffff 256M online yes 18 Movable/Normal +0x0000000130000000-0x000000013fffffff 256M online yes 19 Movable +0x0000000140000000-0x000000017fffffff 1G offline - 20-23 Movable + +Memory block size: 256M +Total online memory: 4.8G +Total offline memory: 1.3G
tests/expected/lsmem/lsmem-x86_64-16g +39 -0
@@ -269,3 +269,42 @@ $ lsmem --json --output RANGE,SIZE,STATE,REMOVABLE,BLOCK,NODE {"range": "0x0000000438000000-0x000000043fffffff", "size": "128M", "state": "online", "removable": "no", "block": "135", "node": "0"} ] } + +--- + +$ lsmem -o +ZONES +RANGE SIZE STATE REMOVABLE BLOCK ZONES +0x0000000000000000-0x0000000007ffffff 128M online no 0 None +0x0000000008000000-0x0000000037ffffff 768M online yes 1-6 DMA32 +0x0000000038000000-0x000000003fffffff 128M online no 7 DMA32 +0x0000000040000000-0x0000000077ffffff 896M online yes 8-14 DMA32 +0x0000000078000000-0x000000007fffffff 128M online no 15 DMA32 +0x0000000080000000-0x00000000afffffff 768M online yes 16-21 DMA32 +0x00000000b0000000-0x00000000bfffffff 256M online no 22-23 DMA32 +0x0000000100000000-0x00000001a7ffffff 2.6G online no 32-52 Normal +0x00000001a8000000-0x00000001afffffff 128M online yes 53 Normal +0x00000001b0000000-0x00000001bfffffff 256M online no 54-55 Normal +0x00000001c0000000-0x00000001ffffffff 1G online yes 56-63 Normal +0x0000000200000000-0x0000000207ffffff 128M online no 64 Normal +0x0000000208000000-0x000000021fffffff 384M online yes 65-67 Normal +0x0000000220000000-0x0000000237ffffff 384M online no 68-70 Normal +0x0000000238000000-0x0000000277ffffff 1G online yes 71-78 Normal +0x0000000278000000-0x000000028fffffff 384M online no 79-81 Normal +0x0000000290000000-0x0000000297ffffff 128M online yes 82 Normal +0x0000000298000000-0x00000002a7ffffff 256M online no 83-84 Normal +0x00000002a8000000-0x00000002c7ffffff 512M online yes 85-88 Normal +0x00000002c8000000-0x00000002dfffffff 384M online no 89-91 Normal +0x00000002e0000000-0x00000002efffffff 256M online yes 92-93 Normal +0x00000002f0000000-0x000000034fffffff 1.5G online no 94-105 Normal +0x0000000350000000-0x0000000357ffffff 128M online yes 106 Normal +0x0000000358000000-0x000000036fffffff 384M online no 107-109 Normal +0x0000000370000000-0x0000000377ffffff 128M online yes 110 Normal +0x0000000378000000-0x00000003c7ffffff 1.3G online no 111-120 Normal +0x00000003c8000000-0x00000003e7ffffff 512M online yes 121-124 Normal +0x00000003e8000000-0x000000042fffffff 1.1G online no 125-133 Normal +0x0000000430000000-0x0000000437ffffff 128M online yes 134 Normal +0x0000000438000000-0x000000043fffffff 128M online no 135 None + +Memory block size: 128M +Total online memory: 16G +Total offline memory: 0B
tests/ts/lsmem/lsmem +1 -0
@@ -49,6 +49,7 @@ for dump in $(ls $TS_SELF/dumps/*.tar.bz2 | sort); do do_lsmem --all --output $LSCOLUMNS do_lsmem --raw --output $LSCOLUMNS do_lsmem --json --output $LSCOLUMNS + do_lsmem -o +ZONES ts_finalize_subtest done
Signature · 1 line
2.13.5
PATCH 3/3 lsmem/chmem: add memory zone awareness to bash-completion
In reply to Gerald SchaeferFrom: Andre Wild <[email protected]>
This patch extends the valid --output values with ZONES for the lsmem bash-completion, and adds the --zone option for the chmem bash-completion.
--- bash-completion/chmem | 1 + bash-completion/lsmem | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
bash-completion/chmem +1 -0
@@ -16,6 +16,7 @@ _chmem_module() --disable --blocks --verbose + --zone --help --version "
bash-completion/lsmem +1 -1
@@ -9,7 +9,7 @@ _lsmem_module() local prefix realcur OUTPUT_ALL OUTPUT realcur="${cur##*,}" prefix="${cur%$realcur}" - OUTPUT_ALL='RANGE SIZE STATE REMOVABLE BLOCK NODE' + OUTPUT_ALL='RANGE SIZE STATE REMOVABLE BLOCK NODE ZONES' for WORD in $OUTPUT_ALL; do if ! [[ $prefix == *"$WORD"* ]]; then OUTPUT="$WORD ${OUTPUT:-""}"
Signature · 1 line
2.13.5
Karel Zak
maintainerQuoted 7 lines · Gerald Schaefer
These patches are against lsmem/chmem in util-linux, they add support for listing and changing memory zone allocation.
Added Michal Hocko and linux-mm on cc, to raise general awareness for the lsmem/chmem tools, and the new memory zone functionality in particular. I think this can be quite useful for memory hotplug kernel development, and if not, sorry for the noise.
Seems good.
I'll merge it (probably with some minor changes:-) after v2.31 release. Thanks!
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 10 lines · Gerald Schaefer
bash-completion/chmem | 1 + bash-completion/lsmem | 2 +- sys-utils/chmem.8 | 19 +++++ sys-utils/chmem.c | 136 +++++++++++++++++++++++++++++++-- sys-utils/lsmem.1 | 4 +- sys-utils/lsmem.c | 98 +++++++++++++++++++++++- tests/expected/lsmem/lsmem-s390-zvm-6g | 21 +++++ tests/expected/lsmem/lsmem-x86_64-16g | 39 ++++++++++ tests/ts/lsmem/lsmem | 1 + 9 files changed, 309 insertions(+), 12 deletions(-)
Merged to my "next" branch (in master we have still feature-freeze).
I have also added a note about the way how lsmem merges blocks to create the RANGE column. It seems important, because the number of ranges is affected by ZONES (or REMOVABLE). See:
https://github.com/karelzak/util-linux/commit/ffe5267c91018ca8cac8bedc14b695478c11a5dd
Maybe it's possible to explain it in a better way... (send patch;-)
The another possibility is to *always use* zones and removable attributes to create the ranges (merge blocks) independently on the output columns (e.g. -o ZONES). So, the result will be always the same number of ranges with the same <start>-<end>.
Now (see the first range):
$ lsmem RANGE SIZE STATE REMOVABLE BLOCK 0x0000000000000000-0x0000000047ffffff 1.1G online no 0-8 0x0000000048000000-0x0000000057ffffff 256M online yes 9-10 0x0000000058000000-0x000000005fffffff 128M online no 11 0x0000000060000000-0x0000000067ffffff 128M online yes 12 0x0000000068000000-0x0000000087ffffff 512M online no 13-16 0x0000000088000000-0x000000008fffffff 128M online yes 17 0x0000000090000000-0x00000000afffffff 512M online no 18-21 0x00000000b0000000-0x00000000bfffffff 256M online yes 22-23 0x0000000100000000-0x000000042fffffff 12.8G online no 32-133 0x0000000430000000-0x0000000437ffffff 128M online yes 134 0x0000000438000000-0x000000043fffffff 128M online no 135
lsmem -o+ZONES
RANGE SIZE STATE REMOVABLE BLOCK ZONES
0x0000000000000000-0x0000000007ffffff 128M online no 0 None
0x0000000008000000-0x0000000047ffffff 1G online no 1-8 DMA32 0x0000000048000000-0x0000000057ffffff 256M online yes 9-10 DMA32 0x0000000058000000-0x000000005fffffff 128M online no 11 DMA32 0x0000000060000000-0x0000000067ffffff 128M online yes 12 DMA32 0x0000000068000000-0x0000000087ffffff 512M online no 13-16 DMA32 0x0000000088000000-0x000000008fffffff 128M online yes 17 DMA32 0x0000000090000000-0x00000000afffffff 512M online no 18-21 DMA32 0x00000000b0000000-0x00000000bfffffff 256M online yes 22-23 DMA32 0x0000000100000000-0x000000042fffffff 12.8G online no 32-133 Normal 0x0000000430000000-0x0000000437ffffff 128M online yes 134 Normal 0x0000000438000000-0x000000043fffffff 128M online no 135 None
lsmem -oRANGE,SIZE
RANGE SIZE
0x0000000000000000-0x00000000bfffffff 3G
0x0000000100000000-0x000000043fffffff 13G
I didn't test it, but the question is how usable is 0x0000000000000000-<end> as option for chmem.
It's also seems difficult to use it in scripts if you want to output only a RANGE, for example
FOO=$(lsmem -oRANGE -n --summary=never | head -1)
but the range is affected by missing columns.
Comments?
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 67 lines · On Wed, 18 Oct 2017 13:40:09 +0200 Karel Zak <[email protected]> wrote:
Quoted 10 lines · Gerald Schaefer
bash-completion/chmem | 1 + bash-completion/lsmem | 2 +- sys-utils/chmem.8 | 19 +++++ sys-utils/chmem.c | 136 +++++++++++++++++++++++++++++++-- sys-utils/lsmem.1 | 4 +- sys-utils/lsmem.c | 98 +++++++++++++++++++++++- tests/expected/lsmem/lsmem-s390-zvm-6g | 21 +++++ tests/expected/lsmem/lsmem-x86_64-16g | 39 ++++++++++ tests/ts/lsmem/lsmem | 1 + 9 files changed, 309 insertions(+), 12 deletions(-)Merged to my "next" branch (in master we have still feature-freeze).
I have also added a note about the way how lsmem merges blocks to create the RANGE column. It seems important, because the number of ranges is affected by ZONES (or REMOVABLE). See:
https://github.com/karelzak/util-linux/commit/ffe5267c91018ca8cac8bedc14b695478c11a5dd
Maybe it's possible to explain it in a better way... (send patch;-)
The another possibility is to *always use* zones and removable attributes to create the ranges (merge blocks) independently on the output columns (e.g. -o ZONES). So, the result will be always the same number of ranges with the same <start>-<end>.
Now (see the first range):
$ lsmem RANGE SIZE STATE REMOVABLE BLOCK 0x0000000000000000-0x0000000047ffffff 1.1G online no 0-8 0x0000000048000000-0x0000000057ffffff 256M online yes 9-10 0x0000000058000000-0x000000005fffffff 128M online no 11 0x0000000060000000-0x0000000067ffffff 128M online yes 12 0x0000000068000000-0x0000000087ffffff 512M online no 13-16 0x0000000088000000-0x000000008fffffff 128M online yes 17 0x0000000090000000-0x00000000afffffff 512M online no 18-21 0x00000000b0000000-0x00000000bfffffff 256M online yes 22-23 0x0000000100000000-0x000000042fffffff 12.8G online no 32-133 0x0000000430000000-0x0000000437ffffff 128M online yes 134 0x0000000438000000-0x000000043fffffff 128M online no 135lsmem -o+ZONES
RANGE SIZE STATE REMOVABLE BLOCK ZONES
0x0000000000000000-0x0000000007ffffff 128M online no 0 None0x0000000008000000-0x0000000047ffffff 1G online no 1-8 DMA32 0x0000000048000000-0x0000000057ffffff 256M online yes 9-10 DMA32 0x0000000058000000-0x000000005fffffff 128M online no 11 DMA32 0x0000000060000000-0x0000000067ffffff 128M online yes 12 DMA32 0x0000000068000000-0x0000000087ffffff 512M online no 13-16 DMA32 0x0000000088000000-0x000000008fffffff 128M online yes 17 DMA32 0x0000000090000000-0x00000000afffffff 512M online no 18-21 DMA32 0x00000000b0000000-0x00000000bfffffff 256M online yes 22-23 DMA32 0x0000000100000000-0x000000042fffffff 12.8G online no 32-133 Normal 0x0000000430000000-0x0000000437ffffff 128M online yes 134 Normal 0x0000000438000000-0x000000043fffffff 128M online no 135 Nonelsmem -oRANGE,SIZE
RANGE SIZE
0x0000000000000000-0x00000000bfffffff 3G
0x0000000100000000-0x000000043fffffff 13GI didn't test it, but the question is how usable is 0x0000000000000000-<end> as option for chmem.
Quoted 8 lines
It's also seems difficult to use it in scripts if you want to output only a RANGE, for example
FOO=$(lsmem -oRANGE -n --summary=never | head -1)but the range is affected by missing columns.
Comments?
Sorry for the late answer. I'm not sure if I understand the problem, it "works as designed" that the range merging is done based on the output columns, but I see that it was not really described as such. So I do like the note that you added with the above mentioned commit.
However, regarding the --split option, I think it may be confusing at least for human users, if an "lsmem -oRANGE" will now print more than one range, even if this is now based on a "fixed" set of default columns that are used for merging (but "subject to change" according to the man page).
Now the user will not see the columns that are used for merging if he says "lsmem -oRANGE", as opposed to the previous behavior where only the visible output columns were used for merge decision (and for "lsmem -oRANGE" that would simply be one big range because there are no other columns that may differ).
I also do not really see the benefit for script usage, at least if we define it as "expected behavior" to have the ranges merged based on the output columns. Maybe I am missing something, but I think the --split option does not really solve any problem, but rather introduces potential for future confusion. I would rather only have the behavior documented in the man pages, as you did in the above mentioned commit (and which was then removed with the --split patch).
Regards,
Gerald
Karel Zak
maintainerQuoted 10 lines · Gerald Schaefer
Sorry for the late answer. I'm not sure if I understand the problem, it "works as designed" that the range merging is done based on the output columns, but I see that it was not really described as such. So I do like the note that you added with the above mentioned commit.
However, regarding the --split option, I think it may be confusing at least for human users, if an "lsmem -oRANGE" will now print more than one range, even if this is now based on a "fixed" set of default columns that are used for merging (but "subject to change" according to the man page).
OK, I think we can support both concepts :-) I have modified lsmem to:
- follow output columns for split policy by default (= your original implementation)
- the --split is optional and may be used to override the default behavior
it means for humans it's probably less concussing and advanced users may define by --split another way how to generate the ranges.
I think it's good compromise and it's backwardly compatible with the previous version. OK?
If yes, I need to backport this change to RHEL7.5 :-)
Quoted 2 lines
I also do not really see the benefit for script usage, at least if we define it as "expected behavior" to have the ranges merged based on the
We want to keep it user friendly. The "expected behavior" (now default) forces you to parse lsmem output to filter out unnecessary columns (if you care about RANGE only).
And in all our utils the --output option really control the output, but no another behavior.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 14 lines · On Fri, 3 Nov 2017 11:11:04 +0100 Karel Zak <[email protected]> wrote:
Quoted 10 lines · Gerald Schaefer
Sorry for the late answer. I'm not sure if I understand the problem, it "works as designed" that the range merging is done based on the output columns, but I see that it was not really described as such. So I do like the note that you added with the above mentioned commit.
However, regarding the --split option, I think it may be confusing at least for human users, if an "lsmem -oRANGE" will now print more than one range, even if this is now based on a "fixed" set of default columns that are used for merging (but "subject to change" according to the man page).
OK, I think we can support both concepts :-) I have modified lsmem to:
Quoted 8 lines
- follow output columns for split policy by default (= your original implementation)
- the --split is optional and may be used to override the default behaviorit means for humans it's probably less concussing and advanced users may define by --split another way how to generate the ranges.
I think it's good compromise and it's backwardly compatible with the previous version. OK?
Yes, that looks good.
Quoted 3 lines
If yes, I need to backport this change to RHEL7.5 :-)
Yes, please :-)
Quoted 9 lines
Quoted 2 lines
I also do not really see the benefit for script usage, at least if we define it as "expected behavior" to have the ranges merged based on the
We want to keep it user friendly. The "expected behavior" (now default) forces you to parse lsmem output to filter out unnecessary columns (if you care about RANGE only).
And in all our utils the --output option really control the output, but no another behavior.
OK, that makes sense. I did not have any output selection in the original implementation, and also no focus on script usage, but as (maybe so far the only) human user I did get confused by the new range merging.
Regards,
Gerald
Quoted 8 lines · Gerald Schaefer
These patches are against lsmem/chmem in util-linux, they add support for listing and changing memory zone allocation.
Added Michal Hocko and linux-mm on cc, to raise general awareness for the lsmem/chmem tools, and the new memory zone functionality in particular. I think this can be quite useful for memory hotplug kernel development, and if not, sorry for the noise.
Quoted 6 lines
Andre Wild (1):
lsmem/chmem: add memory zone awareness to bash-completionGerald Schaefer (2):
lsmem/chmem: add memory zone awareness tests/lsmem: update lsmem test with ZONES column
Merged to the master branch.
I have added a new --split=<list> command line option to the lsmem.
It allows to control the way how lsmem merges memory blocks to the ranges. The default is to use differences in STATE,REMOVABLE,NODE and ZONES attributes. The ranges are no more affected by --output, it means commands like
lsmem --output=RANGE
lsmem --output=RANGE,ZONESreturns the same memory ranges. You have to use --split to define your policy:
lsmem --split=REMOVABLE,STATE
will create the ranges according to REMOVABLE and STATE attributes.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com