Skip to content

Fix wrong unit of meminfo parser #667

@Bluemangoo

Description

@Bluemangoo

meminfo shows data like these:

MemTotal:       30524188 kB
MemFree:         3695720 kB
MemAvailable:   20690088 kB
...

In bytesize::ByteSize::from_str, they will be parsed as KB(source of Unit::from_str, called in ByteSize::from_str).

impl str::FromStr for Unit {
    // ...
    fn from_str(unit: &str) -> Result<Self, Self::Err> {
        match () {
            // ...
            _ if unit.eq_ignore_ascii_case("k") | unit.eq_ignore_ascii_case("kb") => {
                Ok(Self::KiloByte)
            }
            // ...
        }
    }
}

Anyway, it is formatted in KiB instead of KB. Or rather, kB has always been KiB. But bytesize ignored cases(eq_ignore_ascii_case).

See sources of Linux kernel here

static void show_val_kb(struct seq_file *m, const char *s, unsigned long num)
{
	seq_put_decimal_ull_width(m, s, num << (PAGE_SHIFT - 10), 8);
	seq_write(m, " kB\n", 4);
}

Thanks for @Franklin-Qi to mentiond it in #389

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions