mm, printk: dump full information of page flags in pGp
Subsystems (4)
cover mm, printk: dump full information of page flags in pGp
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.
This patchset also includes some code cleanup in mm/slub.c.
Below is the example of the output in mm/slub.c.
- Before the patchset
[ 6155.716018] INFO: Slab 0x000000004027dd4f objects=33 used=3 fp=0x000000008cd1579c flags=0x17ffffc0010200
- After the patchset
[ 6315.235783] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(Node 0x0,Zone 0x2,Lastcpupid 0x1fffff,slab|head)
Yafang Shao (3):
mm, slub: use pGp to print page flags
mm, slub: don't combine pr_err with INFO
printk: dump full information of page flags in pGp
lib/vsprintf.c | 42 +++++++++++++++++++++++++++++++++++++++++- mm/slub.c | 13 +++++++------ 2 files changed, 48 insertions(+), 7 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 mm, slub: use pGp to print page flags
As pGp has been already introduced in printk, we'd better use it to make the output human readable.
Before this change, the output is,
[ 6155.716018] INFO: Slab 0x000000004027dd4f objects=33 used=3 fp=0x000000008cd1579c flags=0x17ffffc0010200
While after this change, the output is,
[ 8846.517809] INFO: Slab 0x00000000f42a2c60 objects=33 used=3 fp=0x0000000060d32ca8 flags=0x17ffffc0010200(slab|head)
--- mm/slub.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/slub.c +3 -2
@@ -641,8 +641,9 @@ void print_tracking(struct kmem_cache *s, void *object)static void print_page_info (struct page *page) { -pr_err ("INFO: Slab 0x%p objects=%u used=%u fp=0x%p flags=0x%04lx\n" , - page, page->objects, page->inuse, page->freelist, page->flags); +pr_err ("INFO: Slab 0x%p objects=%u used=%u fp=0x%p flags=%#lx(%pGp)\n" , + page, page->objects, page->inuse, page->freelist, + page->flags, &page->flags); }
Signature · 1 line
2.17.1
Re: [PATCH 1/3] mm, slub: use pGp to print page flags
Quoted 11 lines · Yafang Shao
As pGp has been already introduced in printk, we'd better use it to make the output human readable.
Before this change, the output is,
[ 6155.716018] INFO: Slab 0x000000004027dd4f objects=33 used=3 fp=0x000000008cd1579c flags=0x17ffffc0010200While after this change, the output is,
[ 8846.517809] INFO: Slab 0x00000000f42a2c60 objects=33 used=3 fp=0x0000000060d32ca8 flags=0x17ffffc0010200(slab|head)Reviewed-by David Hildenbrand <[email protected]>Signed-off-by Yafang Shao <[email protected]>
Quoted 21 lines
--- mm/slub.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)mm/slub.c +3
-2@@ -641,8 +641,9 @@ void print_tracking(struct kmem_cache *s, void *object)static void print_page_info (struct page *page) { -pr_err ("INFO: Slab 0x%p objects=%u used=%u fp=0x%p flags=0x%04lx\n" , - page, page->objects, page->inuse, page->freelist, page->flags); +pr_err ("INFO: Slab 0x%p objects=%u used=%u fp=0x%p flags=%#lx(%pGp)\n" , + page, page->objects, page->inuse, page->freelist, + page->flags, &page->flags); }
Re: [PATCH 1/3] mm, slub: use pGp to print page flags
In reply to Yafang ShaoQuoted 11 lines · Yafang Shao
As pGp has been already introduced in printk, we'd better use it to make the output human readable.
Before this change, the output is,
[ 6155.716018] INFO: Slab 0x000000004027dd4f objects=33 used=3 fp=0x000000008cd1579c flags=0x17ffffc0010200While after this change, the output is,
[ 8846.517809] INFO: Slab 0x00000000f42a2c60 objects=33 used=3 fp=0x0000000060d32ca8 flags=0x17ffffc0010200(slab|head)Reviewed-by David Hildenbrand <[email protected]>Signed-off-by Yafang Shao <[email protected]>
PATCH 2/3 mm, slub: don't combine pr_err with INFO
In reply to Yafang ShaoIt is strange to combine "pr_err" with "INFO", so let's clean them up. This patch is motivated by David's comment[1].
- before the patch
[ 8846.517809] INFO: Slab 0x00000000f42a2c60 objects=33 used=3 fp=0x0000000060d32ca8 flags=0x17ffffc0010200(slab|head)
- after the patch
[ 6312.639698] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(slab|head)
[1]. https://lore.kernel.org/linux-mm/[email protected]/#t
--- mm/slub.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
mm/slub.c +5 -5
@@ -615,7 +615,7 @@ static void print_track(const char *s, struct track *t, unsigned long pr_time)if (!t->addr)return ; -pr_err ("INFO: %s in %pS age=%lu cpu=%u pid=%d\n" , +pr_err ("ERR: %s in %pS age=%lu cpu=%u pid=%d\n" , s, (void *)t->addr, pr_time - t->when, t->cpu, t->pid);#ifdef CONFIG_STACKTRACE {
@@ -641,7 +641,7 @@ void print_tracking(struct kmem_cache *s, void *object)static void print_page_info (struct page *page) { -pr_err ("INFO: Slab 0x%p objects=%u used=%u fp=0x%p flags=%#lx(%pGp)\n" , +pr_err ("ERR: Slab 0x%p objects=%u used=%u fp=0x%p flags=%#lx(%pGp)\n" , page, page->objects, page->inuse, page->freelist, page->flags, &page->flags);
@@ -698,7 +698,7 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)print_page_info (page); -pr_err ("INFO: Object 0x%p @offset=%tu fp=0x%p\n\n" , +pr_err ("ERR: Object 0x%p @offset=%tu fp=0x%p\n\n" , p, p - addr,get_freepointer (s, p));if (s->flags &SLAB_RED_ZONE )
@@ -791,7 +791,7 @@ static int check_bytes_and_report(struct kmem_cache *s, struct page *page, end--;slab_bug (s,"%s overwritten" , what); -pr_err ("INFO: 0x%p-0x%p @offset=%tu. First byte 0x%x instead of 0x%x\n" , +pr_err ("ERR: 0x%p-0x%p @offset=%tu. First byte 0x%x instead of 0x%x\n" , fault, end -1 , fault - addr, fault[0 ], value);print_trailer (s, page, object);
@@ -3855,7 +3855,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,for_each_object (p, s, addr, page->objects) {if (!test_bit (__obj_to_index (s, addr, p), map)) { -pr_err ("INFO: Object 0x%p @offset=%tu\n" , p, p - addr); +pr_err ("ERR: Object 0x%p @offset=%tu\n" , p, p - addr);print_tracking (s, p); } }
Signature · 1 line
2.17.1
Re: [PATCH 2/3] mm, slub: don't combine pr_err with INFO
Quoted 6 lines · Yafang Shao
It is strange to combine "
pr_err" with "INFO", so let's clean them up. This patch is motivated by David's comment[1].- before the patch
[ 8846.517809] INFO: Slab 0x00000000f42a2c60 objects=33 used=3 fp=0x0000000060d32ca8 flags=0x17ffffc0010200(slab|head)
Quoted 7 lines
- after the patch
[ 6312.639698] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(slab|head)[1]. https://lore.kernel.org/linux-mm/[email protected]/#t
Cc David Hildenbrand <[email protected]>Signed-off-by Yafang Shao <[email protected]>
These are usually printed as part of slab_bug() with its prominent banner. In that sense it's additional details, thus INFO. The details itself are not error, thus ERR makes little sense imho. How about removing the prefix completely, or just replacing with an ident to make it visually part of the BUG report.
Quoted 54 lines
--- mm/slub.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/slub.c +5
-5@@ -615,7 +615,7 @@ static void print_track(const char *s, struct track *t, unsigned long pr_time)if (!t->addr)return ; -pr_err ("INFO: %s in %pS age=%lu cpu=%u pid=%d\n" , +pr_err ("ERR: %s in %pS age=%lu cpu=%u pid=%d\n" , s, (void *)t->addr, pr_time - t->when, t->cpu, t->pid);#ifdef CONFIG_STACKTRACE {@@ -641,7 +641,7 @@ void print_tracking(struct kmem_cache *s, void *object)static void print_page_info (struct page *page) { -pr_err ("INFO: Slab 0x%p objects=%u used=%u fp=0x%p flags=%#lx(%pGp)\n" , +pr_err ("ERR: Slab 0x%p objects=%u used=%u fp=0x%p flags=%#lx(%pGp)\n" , page, page->objects, page->inuse, page->freelist, page->flags, &page->flags);@@ -698,7 +698,7 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)print_page_info (page); -pr_err ("INFO: Object 0x%p @offset=%tu fp=0x%p\n\n" , +pr_err ("ERR: Object 0x%p @offset=%tu fp=0x%p\n\n" , p, p - addr,get_freepointer (s, p));if (s->flags &SLAB_RED_ZONE )@@ -791,7 +791,7 @@ static int check_bytes_and_report(struct kmem_cache *s, struct page *page, end--;slab_bug (s,"%s overwritten" , what); -pr_err ("INFO: 0x%p-0x%p @offset=%tu. First byte 0x%x instead of 0x%x\n" , +pr_err ("ERR: 0x%p-0x%p @offset=%tu. First byte 0x%x instead of 0x%x\n" , fault, end -1 , fault - addr, fault[0 ], value);print_trailer (s, page, object);@@ -3855,7 +3855,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,for_each_object (p, s, addr, page->objects) {if (!test_bit (__obj_to_index (s, addr, p), map)) { -pr_err ("INFO: Object 0x%p @offset=%tu\n" , p, p - addr); +pr_err ("ERR: Object 0x%p @offset=%tu\n" , p, p - addr);print_tracking (s, p); } }
Re: [PATCH 2/3] mm, slub: don't combine pr_err with INFO
Quoted 13 lines · Vlastimil Babka
Quoted 11 lines · Yafang Shao
It is strange to combine "
pr_err" with "INFO", so let's clean them up. This patch is motivated by David's comment[1].- before the patch
[ 8846.517809] INFO: Slab 0x00000000f42a2c60 objects=33 used=3 fp=0x0000000060d32ca8 flags=0x17ffffc0010200(slab|head)- after the patch
[ 6312.639698] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(slab|head)
Quoted 8 lines
Quoted 2 lines
Cc David Hildenbrand <[email protected]>Signed-off-by Yafang Shao <[email protected]>These are usually printed as part of
slab_bug()with its prominent banner. In that sense it's additional details, thus INFO. The details itself are not error, thus ERR makes little sense imho. How about removing the prefix completely, or just replacing with an ident to make it visually part of the BUG report.
Thanks for the explanation. I will remove the prefix completely in the next version.
Quoted 55 lines
Quoted 54 lines
--- mm/slub.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/slub.c +5
-5@@ -615,7 +615,7 @@ static void print_track(const char *s, struct track *t, unsigned long pr_time)if (!t->addr)return ; -pr_err ("INFO: %s in %pS age=%lu cpu=%u pid=%d\n" , +pr_err ("ERR: %s in %pS age=%lu cpu=%u pid=%d\n" , s, (void *)t->addr, pr_time - t->when, t->cpu, t->pid);#ifdef CONFIG_STACKTRACE {@@ -641,7 +641,7 @@ void print_tracking(struct kmem_cache *s, void *object)static void print_page_info (struct page *page) { -pr_err ("INFO: Slab 0x%p objects=%u used=%u fp=0x%p flags=%#lx(%pGp)\n" , +pr_err ("ERR: Slab 0x%p objects=%u used=%u fp=0x%p flags=%#lx(%pGp)\n" , page, page->objects, page->inuse, page->freelist, page->flags, &page->flags);@@ -698,7 +698,7 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)print_page_info (page); -pr_err ("INFO: Object 0x%p @offset=%tu fp=0x%p\n\n" , +pr_err ("ERR: Object 0x%p @offset=%tu fp=0x%p\n\n" , p, p - addr,get_freepointer (s, p));if (s->flags &SLAB_RED_ZONE )@@ -791,7 +791,7 @@ static int check_bytes_and_report(struct kmem_cache *s, struct page *page, end--;slab_bug (s,"%s overwritten" , what); -pr_err ("INFO: 0x%p-0x%p @offset=%tu. First byte 0x%x instead of 0x%x\n" , +pr_err ("ERR: 0x%p-0x%p @offset=%tu. First byte 0x%x instead of 0x%x\n" , fault, end -1 , fault - addr, fault[0 ], value);print_trailer (s, page, object);@@ -3855,7 +3855,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,for_each_object (p, s, addr, page->objects) {if (!test_bit (__obj_to_index (s, addr, p), map)) { -pr_err ("INFO: Object 0x%p @offset=%tu\n" , p, p - addr); +pr_err ("ERR: Object 0x%p @offset=%tu\n" , p, p - addr);print_tracking (s, p); } }
Signature · 2 lines
Thanks Yafang
PATCH 3/3 printk: dump full information of page flags in pGp
In reply to Yafang ShaoCurrently 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,
[ 6312.639698] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(slab|head)
- After the patch,
[ 6315.235783] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(Node 0x0,Zone 0x2,Lastcpupid 0x1fffff,slab|head)
--- lib/vsprintf.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
lib/vsprintf.c +41 -1
@@ -1916,6 +1916,46 @@ char *format_flags(char *buf, char *end, unsigned long flags,return buf; } +struct page_flags_layout { +int width; +int shift; +int mask; +char *name; +}; + +struct page_flags_layout pfl[] = { + {SECTIONS_WIDTH ,SECTIONS_PGSHIFT ,SECTIONS_MASK ,"Section " }, + {NODES_WIDTH ,NODES_PGSHIFT ,NODES_MASK ,"Node " }, + {ZONES_WIDTH ,ZONES_PGSHIFT ,ZONES_MASK ,"Zone " }, + {LAST_CPUPID_WIDTH ,LAST_CPUPID_PGSHIFT ,LAST_CPUPID_MASK ,"Lastcpupid " }, + {KASAN_TAG_WIDTH ,KASAN_TAG_PGSHIFT ,KASAN_TAG_MASK ,"Kasantag " }, +}; + +static +char *format_layout (char *buf,char *end,unsigned long flags) +{ +int i; + +for (i =0 ; i <sizeof (pfl) /sizeof (struct page_flags_layout ) && buf < end; i++) { +if (pfl[i].width ==0 ) +continue ; + + buf =string (buf, end, pfl[i].name, default_str_spec); + +if (buf >= end) +break ; + buf =number (buf, end, (flags >> pfl[i].shift) & pfl[i].mask, + default_flag_spec); + +if (buf >= end) +break ; + *buf =',' ; + buf++; + } + +return buf; +} +static noinline_for_stack char *flags_string(char *buf, char *end, void *flags_ptr,struct printf_spec spec,const char *fmt)
@@ -1929,7 +1969,7 @@ char *flags_string(char *buf, char *end, void *flags_ptr,switch (fmt[1 ]) {case 'p' : flags = *(unsigned long *)flags_ptr; -/* Remove zone id */ + buf =format_layout (buf, end, flags & ~((1UL <<NR_PAGEFLAGS ) -1 )); flags &= (1UL <<NR_PAGEFLAGS ) -1 ; names = pageflag_names;break ;
Signature · 1 line
2.17.1
Re: [PATCH 3/3] printk: dump full information of page flags in pGp
Quoted 4 lines · Yafang Shao
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.
[]
lib/vsprintf.c
Quoted 1 line
lib/vsprintf.c +0
-0
[]
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1926
Quoted 12 lines
lib/vsprintf.c +8
-0@@ -1916,6 +1916,46 @@ char *format_flags(char *buf, char *end, unsigned long flags, return buf; } +struct page_flags_layout { +int width; +int shift; +int mask; +char *name; +}; + +struct page_flags_layout pfl[] = {
static const struct page_flags_layout pfl[] = {
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1935
Quoted 9 lines
lib/vsprintf.c +9
-0+ {SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK, "Section "}, + {NODES_WIDTH, NODES_PGSHIFT, NODES_MASK, "Node "}, + {ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK, "Zone "}, + {LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK, "Lastcpupid "}, + {KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK, "Kasantag "}, +}; + +static +char *format_layout (char *buf,char *end,unsigned long flags)
poor name. perhaps format_page_flags
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1939
Quoted 4 lines
lib/vsprintf.c +4
-0+{ +int i; + +for (i =0 ; i <sizeof (pfl) /sizeof (struct page_flags_layout ) && buf < end; i++) {
for (i = 0; i < ARRAY_SIZE(pfl) && buf < end; i++) {Quoted 7 lines
lib/vsprintf.c +0
-0@@ -1929,7 +1969,7 @@ char *flags_string(char *buf, char *end, void *flags_ptr, switch (fmt[1]) {case 'p':
flags = *(unsigned long *)flags_ptr;lib/vsprintf.c +1
-1-/* Remove zone id */ + buf =format_layout (buf, end, flags & ~((1UL <<NR_PAGEFLAGS ) -1 ));flags &= (1UL <<
NR_PAGEFLAGS) - 1;
Perhaps store the bitshift into a temp and use the temp twice
foo = BIT(NR_PAGEFLAGS) - 1; buf = format_layout(buf, end, flags & ~foo); flags &= foo;
Re: [PATCH 3/3] printk: dump full information of page flags in pGp
Quoted 13 lines · Joe Perches
Quoted 4 lines · Yafang Shao
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.
[]
lib/vsprintf.c
Quoted 1 line
lib/vsprintf.c +0
-0[]
Quoted 4 lines
lib/vsprintf.c +0
-0@@ -1916,6 +1916,46 @@ char *format_flags(char *buf, char *end, unsigned long flags,return buf; }
Quoted 10 lines
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1926
Quoted 8 lines
lib/vsprintf.c +8
-0+struct page_flags_layout { +int width; +int shift; +int mask; +char *name; +}; + +struct page_flags_layout pfl[] = {static const struct
page_flags_layoutpfl[] = {
Sure.
Quoted 13 lines
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1935
Quoted 10 lines
lib/vsprintf.c +9
-0+ {SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK, "Section "}, + {NODES_WIDTH, NODES_PGSHIFT, NODES_MASK, "Node "}, + {ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK, "Zone "}, + {LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK, "Lastcpupid "}, + {KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK, "Kasantag "}, +}; + +static +char *format_layout (char *buf,char *end,unsigned long flags)poor name. perhaps
format_page_flags
Thanks for the suggestion.
Quoted 7 lines
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1939
Quoted 4 lines
lib/vsprintf.c +4
-0+{ +int i; + +for (i =0 ; i <sizeof (pfl) /sizeof (struct page_flags_layout ) && buf < end; i++) {for (i = 0; i < ARRAY_SIZE(pfl) && buf < end; i++) {
Sure.
Quoted 11 lines
lib/vsprintf.c char *flags_string(char *buf, char *end, void *flags_ptr, · line 1973
Quoted 8 lines
lib/vsprintf.c +1
-1@@ -1929,7 +1969,7 @@ char *flags_string(char *buf, char *end, void *flags_ptr,switch (fmt[1 ]) {case 'p' : flags = *(unsigned long *)flags_ptr; -/* Remove zone id */ + buf =format_layout (buf, end, flags & ~((1UL <<NR_PAGEFLAGS ) -1 )); flags &= (1UL <<NR_PAGEFLAGS ) -1 ;Perhaps store the bitshift into a temp and use the temp twice
Quoted 6 lines
foo = BIT(NR_PAGEFLAGS) - 1;
buf = format_layout(buf, end, flags & ~foo);
flags &= foo;Thanks for the suggestion. I will change them all.
Signature · 2 lines
Thanks Yafang
Re: [PATCH 3/3] printk: dump full information of page flags in pGp
In reply to Yafang ShaoHi:
Quoted 11 lines · Yafang Shao
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,
[ 6312.639698] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(slab|head)- After the patch,
[ 6315.235783] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(Node 0x0,Zone 0x2,Lastcpupid 0x1fffff,slab|head)
Thanks. This really helps!
Quoted 11 lines
Cc David Hildenbrand <[email protected]>Signed-off-by Yafang Shao <[email protected]>--- lib/vsprintf.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)lib/vsprintf.c +0
-0
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1923
Quoted 8 lines
lib/vsprintf.c +5
-0@@ -1916,6 +1916,46 @@ char *format_flags(char *buf, char *end, unsigned long flags,return buf; } +struct page_flags_layout { +int width; +int shift; +int mask; +char *name;
Should we add const for name ?
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1926
Quoted 3 lines
lib/vsprintf.c +3
-0+}; + +struct page_flags_layout pfl[] = {
Should we add static const for pfl[] as we won't change its value and use it outside this file ?
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1939
Quoted 13 lines
lib/vsprintf.c +13
-0+ {SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK, "Section "}, + {NODES_WIDTH, NODES_PGSHIFT, NODES_MASK, "Node "}, + {ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK, "Zone "}, + {LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK, "Lastcpupid "}, + {KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK, "Kasantag "}, +}; + +static +char *format_layout (char *buf,char *end,unsigned long flags) +{ +int i; + +for (i =0 ; i <sizeof (pfl) /sizeof (struct page_flags_layout ) && buf < end; i++) {
I think we can use ARRAY_SIZE here.
Quoted 24 lines
lib/vsprintf.c +19
-0+if (pfl[i].width ==0 ) +continue ; + + buf =string (buf, end, pfl[i].name, default_str_spec); + +if (buf >= end) +break ; + buf =number (buf, end, (flags >> pfl[i].shift) & pfl[i].mask, + default_flag_spec); + +if (buf >= end) +break ; + *buf =',' ; + buf++; + } + +return buf; +} +static noinline_for_stack char *flags_string(char *buf, char *end, void *flags_ptr,struct printf_spec spec,const char *fmt)
lib/vsprintf.c char *flags_string(char *buf, char *end, void *flags_ptr, · line 1975
Quoted 8 lines
lib/vsprintf.c +1
-1@@ -1929,7 +1969,7 @@ char *flags_string(char *buf, char *end, void *flags_ptr,switch (fmt[1 ]) {case 'p' : flags = *(unsigned long *)flags_ptr; -/* Remove zone id */ + buf =format_layout (buf, end, flags & ~((1UL <<NR_PAGEFLAGS ) -1 )); flags &= (1UL <<NR_PAGEFLAGS ) -1 ; names = pageflag_names;break ;
Many thanks.
Re: [PATCH 3/3] printk: dump full information of page flags in pGp
Quoted 31 lines · Miaohe Lin
Hi:
Quoted 11 lines · Yafang Shao
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,
[ 6312.639698] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(slab|head)- After the patch,
[ 6315.235783] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(Node 0x0,Zone 0x2,Lastcpupid 0x1fffff,slab|head)Thanks. This really helps!
Quoted 14 lines
Cc David Hildenbrand <[email protected]>Signed-off-by Yafang Shao <[email protected]>--- lib/vsprintf.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)lib/vsprintf.c +0
-0@@ -1916,6 +1916,46 @@ char *format_flags(char *buf, char *end, unsigned long flags,return buf; }
Quoted 8 lines
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1923
Quoted 5 lines
lib/vsprintf.c +5
-0+struct page_flags_layout { +int width; +int shift; +int mask; +char *name;Should we add const for name ?
Good suggestion.
Quoted 6 lines
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1926
Quoted 3 lines
lib/vsprintf.c +3
-0+}; + +struct page_flags_layout pfl[] = {Should we add static const for pfl[] as we won't change its value and use it outside this file ?
Sure.
Quoted 7 lines
Quoted 7 lines
lib/vsprintf.c +7
-0+ {SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK, "Section "}, + {NODES_WIDTH, NODES_PGSHIFT, NODES_MASK, "Node "}, + {ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK, "Zone "}, + {LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK, "Lastcpupid "}, + {KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK, "Kasantag "}, +}; +
Quoted 9 lines
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1939
Quoted 6 lines
lib/vsprintf.c +6
-0+static +char *format_layout (char *buf,char *end,unsigned long flags) +{ +int i; + +for (i =0 ; i <sizeof (pfl) /sizeof (struct page_flags_layout ) && buf < end; i++) {I think we can use
ARRAY_SIZEhere.
Sure.
Quoted 33 lines
Quoted 24 lines
lib/vsprintf.c +19
-0+if (pfl[i].width ==0 ) +continue ; + + buf =string (buf, end, pfl[i].name, default_str_spec); + +if (buf >= end) +break ; + buf =number (buf, end, (flags >> pfl[i].shift) & pfl[i].mask, + default_flag_spec); + +if (buf >= end) +break ; + *buf =',' ; + buf++; + } + +return buf; +} +static noinline_for_stack char *flags_string(char *buf, char *end, void *flags_ptr,struct printf_spec spec,const char *fmt)lib/vsprintf.c char *flags_string(char *buf, char *end, void *flags_ptr, · line 1975
Quoted 8 lines
lib/vsprintf.c +1
-1@@ -1929,7 +1969,7 @@ char *flags_string(char *buf, char *end, void *flags_ptr,switch (fmt[1 ]) {case 'p' : flags = *(unsigned long *)flags_ptr; -/* Remove zone id */ + buf =format_layout (buf, end, flags & ~((1UL <<NR_PAGEFLAGS ) -1 )); flags &= (1UL <<NR_PAGEFLAGS ) -1 ; names = pageflag_names;break ;Many thanks.
Signature · 2 lines
Thanks Yafang
Re: [PATCH 3/3] printk: dump full information of page flags in pGp
In reply to Yafang ShaoQuoted 10 lines · Yafang Shao
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,
[ 6312.639698] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(slab|head)- After the patch,
[ 6315.235783] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(Node 0x0,Zone 0x2,Lastcpupid 0x1fffff,slab|head)
node, zone could be decimal?
Thanks
Quoted 68 lines
Cc David Hildenbrand <[email protected]>Signed-off-by Yafang Shao <[email protected]>--- lib/vsprintf.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)lib/vsprintf.c +41
-1@@ -1916,6 +1916,46 @@ char *format_flags(char *buf, char *end, unsigned long flags,return buf; } +struct page_flags_layout { +int width; +int shift; +int mask; +char *name; +}; + +struct page_flags_layout pfl[] = { + {SECTIONS_WIDTH ,SECTIONS_PGSHIFT ,SECTIONS_MASK ,"Section " }, + {NODES_WIDTH ,NODES_PGSHIFT ,NODES_MASK ,"Node " }, + {ZONES_WIDTH ,ZONES_PGSHIFT ,ZONES_MASK ,"Zone " }, + {LAST_CPUPID_WIDTH ,LAST_CPUPID_PGSHIFT ,LAST_CPUPID_MASK ,"Lastcpupid " }, + {KASAN_TAG_WIDTH ,KASAN_TAG_PGSHIFT ,KASAN_TAG_MASK ,"Kasantag " }, +}; + +static +char *format_layout (char *buf,char *end,unsigned long flags) +{ +int i; + +for (i =0 ; i <sizeof (pfl) /sizeof (struct page_flags_layout ) && buf < end; i++) { +if (pfl[i].width ==0 ) +continue ; + + buf =string (buf, end, pfl[i].name, default_str_spec); + +if (buf >= end) +break ; + buf =number (buf, end, (flags >> pfl[i].shift) & pfl[i].mask, + default_flag_spec); + +if (buf >= end) +break ; + *buf =',' ; + buf++; + } + +return buf; +} +static noinline_for_stack char *flags_string(char *buf, char *end, void *flags_ptr,struct printf_spec spec,const char *fmt)@@ -1929,7 +1969,7 @@ char *flags_string(char *buf, char *end, void *flags_ptr,switch (fmt[1 ]) {case 'p' : flags = *(unsigned long *)flags_ptr; -/* Remove zone id */ + buf =format_layout (buf, end, flags & ~((1UL <<NR_PAGEFLAGS ) -1 )); flags &= (1UL <<NR_PAGEFLAGS ) -1 ; names = pageflag_names;break ;
Re: [PATCH 3/3] printk: dump full information of page flags in pGp
Quoted 7 lines · Vlastimil Babka
Quoted 5 lines · Yafang Shao
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.
Quoted 7 lines
Quoted 5 lines
- Before the patch,
[ 6312.639698] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(slab|head)- After the patch,
[ 6315.235783] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(Node 0x0,Zone 0x2,Lastcpupid 0x1fffff,slab|head)node, zone could be decimal?
Make sense to me. Will change it.
Quoted 70 lines
Quoted 69 lines
Cc David Hildenbrand <[email protected]>Signed-off-by Yafang Shao <[email protected]>--- lib/vsprintf.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)lib/vsprintf.c +41
-1@@ -1916,6 +1916,46 @@ char *format_flags(char *buf, char *end, unsigned long flags,return buf; } +struct page_flags_layout { +int width; +int shift; +int mask; +char *name; +}; + +struct page_flags_layout pfl[] = { + {SECTIONS_WIDTH ,SECTIONS_PGSHIFT ,SECTIONS_MASK ,"Section " }, + {NODES_WIDTH ,NODES_PGSHIFT ,NODES_MASK ,"Node " }, + {ZONES_WIDTH ,ZONES_PGSHIFT ,ZONES_MASK ,"Zone " }, + {LAST_CPUPID_WIDTH ,LAST_CPUPID_PGSHIFT ,LAST_CPUPID_MASK ,"Lastcpupid " }, + {KASAN_TAG_WIDTH ,KASAN_TAG_PGSHIFT ,KASAN_TAG_MASK ,"Kasantag " }, +}; + +static +char *format_layout (char *buf,char *end,unsigned long flags) +{ +int i; + +for (i =0 ; i <sizeof (pfl) /sizeof (struct page_flags_layout ) && buf < end; i++) { +if (pfl[i].width ==0 ) +continue ; + + buf =string (buf, end, pfl[i].name, default_str_spec); + +if (buf >= end) +break ; + buf =number (buf, end, (flags >> pfl[i].shift) & pfl[i].mask, + default_flag_spec); + +if (buf >= end) +break ; + *buf =',' ; + buf++; + } + +return buf; +} +static noinline_for_stack char *flags_string(char *buf, char *end, void *flags_ptr,struct printf_spec spec,const char *fmt)@@ -1929,7 +1969,7 @@ char *flags_string(char *buf, char *end, void *flags_ptr,switch (fmt[1 ]) {case 'p' : flags = *(unsigned long *)flags_ptr; -/* Remove zone id */ + buf =format_layout (buf, end, flags & ~((1UL <<NR_PAGEFLAGS ) -1 )); flags &= (1UL <<NR_PAGEFLAGS ) -1 ; names = pageflag_names;break ;
Signature · 2 lines
Thanks Yafang
Andy Shevchenko
reviewerRe: [PATCH 3/3] printk: dump full information of page flags in pGp
In reply to Yafang ShaoQuoted 11 lines · Yafang Shao
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,
[ 6312.639698] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(slab|head)- After the patch,
[ 6315.235783] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(Node 0x0,Zone 0x2,Lastcpupid 0x1fffff,slab|head)
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1939
Quoted 3 lines
lib/vsprintf.c +3
-0+int i; + +for (i =0 ; i <sizeof (pfl) /sizeof (struct page_flags_layout ) && buf < end; i++) {
'buf < end' is redundant.
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1946
Quoted 7 lines
lib/vsprintf.c +6
-0+if (pfl[i].width ==0 ) +continue ; + + buf =string (buf, end, pfl[i].name, default_str_spec); +if (buf >= end) +break ;
Can you rather use usual patter, i.e.
if (buf < end) {
...do something...
}
buf++; // or whatever increase should be doneMoreover, number() and string() IIRC have the proper checks embedded into them.
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1953
Quoted 7 lines
lib/vsprintf.c +6
-0+ buf =number (buf, end, (flags >> pfl[i].shift) & pfl[i].mask, + default_flag_spec); +if (buf >= end) +break ; + *buf =',' ; + buf++;
Here is a very standard pattern can be used, see code around
if (buf < end) *buf = ','; buf++;
Quoted 1 line
(quoted diff) +1
-0+ }
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/3] printk: dump full information of page flags in pGp
Quoted 10 lines · Andy Shevchenko
Quoted 8 lines · Yafang Shao
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,
[ 6312.639698] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(slab|head)
Quoted 9 lines
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1939
Quoted 6 lines
- After the patch,
[ 6315.235783] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(Node 0x0,Zone 0x2,Lastcpupid 0x1fffff,slab|head)lib/vsprintf.c +3
-0+int i; + +for (i =0 ; i <sizeof (pfl) /sizeof (struct page_flags_layout ) && buf < end; i++) {'buf < end' is redundant.
Thanks for pointing this out.
Quoted 8 lines
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1946
Quoted 7 lines
lib/vsprintf.c +6
-0+if (pfl[i].width ==0 ) +continue ; + + buf =string (buf, end, pfl[i].name, default_str_spec); +if (buf >= end) +break ;
Quoted 9 lines
Can you rather use usual patter, i.e.
if (buf < end) { ...do something... } buf++; // or whatever increase should be doneMoreover,
number()andstring()IIRC have the proper checks embedded into them.
I will take a look at the detail in these two functions.
Quoted 8 lines
lib/vsprintf.c char *format_flags(char *buf, char *end, unsigned long flags, · line 1953
Quoted 7 lines
lib/vsprintf.c +6
-0+ buf =number (buf, end, (flags >> pfl[i].shift) & pfl[i].mask, + default_flag_spec); +if (buf >= end) +break ; + *buf =',' ; + buf++;
Quoted 8 lines
Here is a very standard pattern can be used, see code around
if (buf < end) *buf = ','; buf++;Quoted 1 line
+ }
Thanks for the explanation.
I will change it as you suggested.
Signature · 2 lines
Thanks Yafang
Andy Shevchenko
reviewerRe: [PATCH 3/3] printk: dump full information of page flags in pGp
Quoted 2 lines · Yafang Shao
On Thu, Jan 28, 2021 at 8:11 PM Andy Shevchenko
<[email protected]> wrote:
...
Quoted 2 lines
Thanks for the explanation.
I will change it as you suggested.
You are welcome!
Just note, that kasprintf() should work for this as well as for the rest printf() cases. That's why it's very important to return proper buffer pointer.
Also read man snprintf(3) RETURN VALUE section to understand it.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/3] printk: dump full information of page flags in pGp
Quoted 10 lines · Andy Shevchenko
Quoted 2 lines · Yafang Shao
On Thu, Jan 28, 2021 at 8:11 PM Andy Shevchenko
<[email protected]> wrote:...
Quoted 2 lines
Thanks for the explanation.
I will change it as you suggested.
Quoted 7 lines
You are welcome!
Just note, that
kasprintf()should work for this as well as for the restprintf()cases. That's why it's very important to return proper buffer pointer.Also read
man snprintf(3)RETURN VALUE section to understand it.
Thanks for the information. I will take a look at it.
Signature · 2 lines
Thanks Yafang
Andy Shevchenko
reviewerQuoted 5 lines · Yafang Shao
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.
Quoted 8 lines
This patchset also includes some code cleanup in
mm/slub.c.Below is the example of the output in
mm/slub.c.
- Before the patchset[ 6155.716018] INFO: Slab 0x000000004027dd4f objects=33 used=3 fp=0x000000008cd1579c flags=0x17ffffc0010200- After the patchset
[ 6315.235783] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(Node 0x0,Zone 0x2,Lastcpupid 0x1fffff,slab|head)
Please, add a corresponding test cases to test_printf.c. W/o test cases NAK.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Yafang Shao
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.
This patchset also includes some code cleanup in
mm/slub.c.Below is the example of the output in
mm/slub.c.
- Before the patchset[ 6155.716018] INFO: Slab 0x000000004027dd4f objects=33 used=3 fp=0x000000008cd1579c flags=0x17ffffc0010200
Quoted 6 lines
Quoted 2 lines
- After the patchset
[ 6315.235783] ERR: Slab 0x000000006d1133b9 objects=33 used=3 fp=0x000000006d0779d1 flags=0x17ffffc0010200(Node 0x0,Zone 0x2,Lastcpupid 0x1fffff,slab|head)Please, add a corresponding test cases to
test_printf.c. W/o test cases NAK.
Sure. Will add the test cases in the next version.
Signature · 2 lines
Thanks Yafang