summaryrefslogtreecommitdiffstats
path: root/sys-utils/lsmem.c
Commit message (Collapse)AuthorAgeFilesLines
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-8/+7Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: use new ul_path_* APIKarel Zak2018-06-211-40/+53
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: add --output-all optionSami Kerola2018-05-031-1/+8
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lsmem: improve JSON outputKarel Zak2018-04-051-1/+21
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: make output more compatible with another utilsKarel Zak2018-04-051-6/+1Star
| | | | | | | We do not use placeholders (e.g. "-") for missing data in libsmartcols utils, just use empty space in output. Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: remove unused variableKarel Zak2018-04-051-2/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: fix total online/offline memory calculationGerald Schaefer2018-03-201-6/+4Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | lsmem currently calculates the total online/offline memory by iterating over all lsmem->blocks. Depending on the lsmem options, there may be only one lsmem->block, because all sysfs memory blocks could be merged into one. In this case, the calculation is wrong, because the individual online/offline state of the sysfs memory blocks is not preserved, but rather lsmem->blocks[0].state is set to the state of the first sysfs memory block, typically MEMORY_STATE_ONLINE (at least on s390). This means that "Total offline memory" will always be calculated as 0 in such cases, e.g. when using "lsmem --summary", or any options that would merge the table output to one line, like "lsmem -o RANGE": ~# lsmem --summary Memory block size: 1G Total online memory: 20G Total offline memory: 0B Adding the "-a" option shows the real summary, since there is no block merging going on, and the calculation is therefore correct: ~# lsmem -a --summary Memory block size: 1G Total online memory: 16G Total offline memory: 4G Fix this by moving the online/offline calculation into the loop that is iterating over all sysfs memory blocks, instead of iterating over potentially merged lsmem->blocks. Reported-by: Alexander Klein <alkl@linux.vnet.ibm.com> Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
* lsmem: fix memory leak [coverity scan]Karel Zak2018-02-201-6/+13
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: make --split optional, follow output by defaultKarel Zak2017-11-031-19/+30
| | | | | | | | Let's keep lsmem backwardly compatible (<=v2.30) and create ranges according to the output columns by default. This default behavior may be modified by --split command line option. Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: add --splitKarel Zak2017-10-201-27/+52
| | | | | | | | | | | | | | | | | Now the way how lsmem lists memory ranges is affected by used output columns. It makes it very difficult to use in scripts where you want to use for example only one column ranges=$(lsmem -oRANGE) and in this case all is merged to the one (or two) huge ranges and all attributes are ignored. The --split allows to control this behavior ranges=$(lsmem -oRANGE --split=STATE,ZONES) forces lsmem to list ranges by STATE and ZONES differences. Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: improve path_read_xxx() usageKarel Zak2017-10-201-5/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem/chmem: add memory zone awarenessGerald Schaefer2017-10-201-1/+97
| | | | | | | | | | | | | | | | 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. Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | changed in include/c.h and applied via sed: sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c") sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c") Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lsmem: fix, using freed memoryRuediger Meier2017-06-291-9/+10
| | | | | | | | | | | | | Simply avoiding strdup(). Error handling improved. This was the Clang Analyzer warning: Memory Error, Use-after-free sys-utils/lsmem.c:259:3: warning: Use of memory after it is freed err(EXIT_FAILURE, _("Failed to open %s"), path); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/path: fix crash, pathbuf overflowRuediger Meier2017-06-271-1/+2
| | | | | | | | | | | | | | Before: $ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)" Segmentation fault (core dumped) After: $ lscpu -s "$(tr '\0' 'x' < /dev/zero | head -c 10000)" lscpu: invalid argument to --sysroot: File name too long Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | Consolidate --help and --version descriptions. We are now able to align them to the other options. We changed include/c.h. The rest of this patch was generated by sed, plus manually setting the right alignment numbers. We do not change anything but white spaces in the --help output. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: never use usage(stderr)Ruediger Meier2017-06-261-4/+7
| | | | | | | Here we fix all cases where we have usage(FILE*) functions. Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* include/c.h: add USAGE_COMMANDS and USAGE_COLUMNSJ William Piggott2017-06-241-3/+2Star
| | | | | | | | | | | | * login-utils/lslogins.c: all uses changed * misc-utils/findmnt.c: likewise * sys-utils/blkzone.c: likewise * disk-utils/sfdisk.c: likewise * sys-utils/lscpu.c: likewise * sys-utils/lsmem.c: likewise * sys-utils/wdctl.c: likewise Signed-off-by: J William Piggott <elseifthen@gmx.com>
* Fix minor typosYuri Chornoivan2017-05-231-1/+1
|
* build-sys: remove duplicate includesKarel Zak2017-05-121-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-1/+1
| | | | | | | | The current default is to print all usage() output. This is overkill in many case. Addresses: https://github.com/karelzak/util-linux/issues/338 Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: improve node lookupHeiko Carstens2016-11-091-0/+1
| | | | | | | Break the loop as soon as we found the node a memory block belongs to, it doesn't make sense to continue scanning. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
* lsmem: align STATE to the rightKarel Zak2016-11-091-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: add CopyrightKarel Zak2016-11-091-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: add missing placeholdersKarel Zak2016-11-091-0/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: cleanup for --summary=onlyKarel Zak2016-11-091-0/+11
| | | | | | | * don't fill scols table * check for collision with raw,pairs and json options Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: cleanup man pageKarel Zak2016-11-091-5/+5
| | | | | | | | * add missing new options * remove columns description (for ls-like utils we maintains columns description only in the --help output) Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: disable summary for JSONm, raw and export outputKarel Zak2016-11-091-0/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: add --summary[=<when>] optionKarel Zak2016-11-091-12/+48
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: rename control structKarel Zak2016-11-091-67/+67
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: cleanup, use libsmartcols for all outputKarel Zak2016-11-091-188/+213
| | | | | | | | | * add --pairs, --raw a --json outputs * add --noheadings to disable header * add --bytes * add --output <list> Signed-off-by: Karel Zak <kzak@redhat.com>
* lsmem: new toolHeiko Carstens2016-11-091-0/+494
Move the s390 specific lsmem tool to util-linux. The lsmem tool was originally written in perl and is part of the s390-tools package which can be found here: https://www.ibm.com/developerworks/linux/linux390/s390-tools.html Given that the tool is architecture independent, there is no reason to keep it in an s390 specific repository. It seems to be useful for other architectures as well. This patch converts the tool to C and adds it to util-linux, while the command line options stay compatible. The only exception is the option "-v" which used to be the short form of "--version". That got changed to "-V" so it behaves like most other tools contained within util-linux. The lsmem tool inspect the contents of /sys/devices/system/memory and prints a summary output similar to what lscpu does: RANGE SIZE STATE REMOVABLE BLOCK 0x0000000000000000-0x000000005fffffff 1,5G online yes 0-5 0x0000000060000000-0x000000007fffffff 512M online no 6-7 0x0000000080000000-0x000000013fffffff 3G online yes 8-19 0x0000000140000000-0x000000014fffffff 256M offline - 20 0x0000000150000000-0x000000017fffffff 768M online no 21-23 Memory block size : 256M Total online memory : 5,8G Total offline memory: 256M In order to keep the output small the tool merges subsequent address ranges where the attributes are identical. To avoid merging of line the "-a" option can be used. The lsmem tool also has "--extendend" and "--parsable" option which can be used to customize the output, e.g. limit the output to specified columns. This is quite similar to what the lscpu tool does. This is based on a patch from Clemens von Mann. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>