- Avoid overflowing the swap size counters in human-readable mode
by introducing the new CONVERT_BLOCKS macro which operates on sizes already converted to number of blocks. With this macro it is not longer needed to perform needless multiplication by blocksize just to divide on it later in CONVERT macro. Approved by: re (kib) MFC after: 1 week
This commit is contained in:
parent
70ff501c96
commit
67c601d5f6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=196244
@ -460,6 +460,7 @@ getfiles(struct xfile **abuf, size_t *alen)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define CONVERT(v) ((int64_t)(v) * pagesize / blocksize)
|
#define CONVERT(v) ((int64_t)(v) * pagesize / blocksize)
|
||||||
|
#define CONVERT_BLOCKS(v) ((int64_t)(v) * pagesize)
|
||||||
static struct kvm_swap swtot;
|
static struct kvm_swap swtot;
|
||||||
static int nswdev;
|
static int nswdev;
|
||||||
|
|
||||||
@ -492,10 +493,10 @@ print_swap_line(const char *swdevname, intmax_t nblks, intmax_t bused,
|
|||||||
printf("%-15s %*jd ", swdevname, hlen, CONVERT(nblks));
|
printf("%-15s %*jd ", swdevname, hlen, CONVERT(nblks));
|
||||||
if (humanflag) {
|
if (humanflag) {
|
||||||
humanize_number(usedbuf, sizeof(usedbuf),
|
humanize_number(usedbuf, sizeof(usedbuf),
|
||||||
CONVERT(blocksize * bused), "",
|
CONVERT_BLOCKS(bused), "",
|
||||||
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
||||||
humanize_number(availbuf, sizeof(availbuf),
|
humanize_number(availbuf, sizeof(availbuf),
|
||||||
CONVERT(blocksize * bavail), "",
|
CONVERT_BLOCKS(bavail), "",
|
||||||
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
||||||
printf("%8s %8s %5.0f%%\n", usedbuf, availbuf, bpercent);
|
printf("%8s %8s %5.0f%%\n", usedbuf, availbuf, bpercent);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user