Re: [PATCH v2 3/3] vsprintf: dump full information of page flags in pGp
From: Joe Perches
Date: Mon Feb 01 2021 - 08:06:29 EST
On Mon, 2021-02-01 at 19:56 +0800, Yafang Shao wrote:
> Currently the pGp only shows the names of page flags, rather than
> the full information including section, node, zone, last cpupid and
> kasan tag. While it is not easy to parse these information manually
> because there're so many flavors. Let's interpret them in pGp as well.
>
> - Before the patch,
> [ 6343.396602] Slab 0x000000004382e02b objects=33 used=3 fp=0x000000009ae06ffc flags=0x17ffffc0010200(slab|head)
>
> - After the patch,
> [ 6871.296131] Slab 0x00000000c0e19a37 objects=33 used=3 fp=0x00000000c4902159 flags=0x17ffffc0010200(Node 0,Zone 2,Lastcpupid 0x1fffff,slab|head)
While debugfs is not an ABI, this format is exported in debugfs to
userspace via mm/page_owner.c read_page_owner/print_page_owner.
Does changing the output format matter to anyone?
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
[]
> +static
> +char *format_page_flags(char *buf, char *end, unsigned long page_flags)
> +{
> + unsigned long flags = page_flags & ((1UL << NR_PAGEFLAGS) - 1);
> + int size = ARRAY_SIZE(pfl);
There's no real value in used-once variables.
> + bool separator = false;
> + int i;
> +
> + for (i = 0; i < size; i++) {
Use ARRAY_SIZE here instead
for (i = 0; i < ARRAY_SIZE(pfl); i++) {
> + if (pfl[i].width == 0)
> + continue;
> +
> + if (separator) {
> + if (buf < end)
> + *buf = ',';
> + buf++;
> + }
> +
> +
> + buf = string(buf, end, pfl[i].name, *pfl[i].spec);
> +
> + buf = number(buf, end, (page_flags >> pfl[i].shift) & pfl[i].mask,
> + *pfl[i].spec);
> + separator = true;
> + }
Style question:
Might this array be more intelligible with pointers instead of indexes?
Something like:
struct page_flags_layout *p;
for (p = pfl; p < pfl + ARRAY_SIZE(pfl); p++) {
if (p->width == 0)
continue;
if (p > pfl) {
if (buf < end)
*buf = ',';
buf++;
}
buf = string(buf, end, p->name, *p->spec);
buf = number(buf, end, (page_flags >> p->shift) & p->mask, *p->spec);
}
> +
> + if (flags) {
Maybe:
if (page_flags & (BIT(NR_PAGEFLAGS) - 1)) {
> + if (buf < end)
> + *buf = ',';
> + buf++;
> + }
> +
> + return buf;
> +}
> +