mm, vsprintf: introduce new format to dump full information of page flags
Subsystems (5)
v3 cover mm, vsprintf: introduce new format to dump full information of page flags
The existed pGp shows the names of page flags only, rather than the full information including section, node, zone, last cpuipid and kasan tag. While it is not easy to parse these information manually because there are so many flavors. We'd better interpret them in printf.
To avoid breaking some tools which parsing pGp via debugfs or affecting the printf buffer, other new formats are introduced, so the user can choose what and in which order they want, suggested by Andy. These new introduced format as follows,
pGpb: print other information first and then the names of page flags
pGpl: print the names of page flags first and then the other info
The differece between them looks like the difference between big-endian and little-endian, that's why they are named like that. The examples of the output as follows,
%pGpb 0x17ffffc0010200(node=0|zone=2|lastcpupid=0x1fffff|slab|head)
%pGpl 0x17ffffc0010200(slab|head|node=0|zone=2|lastcpupid=0x1fffff)To be compitable with the existed format of pGp, the new introduced ones also use '|' as the separator, then the user tools parsing pGp won't need to make change, suggested by Matthew.
The doc and test cases are also updated. Below is the output of the test cases,
[ 4299.847655] test_printf: loaded. [ 4299.848301] test_printf: all 404 tests passed [ 4299.850371] test_printf: unloaded.
This patchset also includes some code cleanup in mm/slub.c.
v3:
- coding improvement, per Joe and Andy
- the possible impact on debugfs and the fix of it, per Joe and Matthew
- introduce new format instead of changing pGp, per Andy
v2:
- various coding improvement, per Joe, Miaohe, Vlastimil and Andy
- remove the prefix completely in patch #2, per Vlastimil
- Update the test cases, per Andy
Yafang Shao (3):
mm, slub: use pGp to print page flags
mm, slub: don't combine pr_err with INFO
vsprintf: introduce new format to dump full information of page flags
Documentation/core-api/printk-formats.rst | 2 + lib/test_printf.c | 126 +++++++++++++++++++--- lib/vsprintf.c | 115 +++++++++++++++++++- mm/slub.c | 13 +-- 4 files changed, 233 insertions(+), 23 deletions(-)
Signature · 1 line
2.17.1
PATCH v3 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
@@ -638,8 +638,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 v3 1/3] mm, slub: use pGp to print page flags
Quoted 6 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=0x17ffffc0010200
Quoted 8 lines
While 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]>Reviewed-by Vlastimil Babka <[email protected]>Acked-by David Rientjes <[email protected]>Signed-off-by Yafang Shao <[email protected]>
Re: [PATCH v3 1/3] mm, slub: use pGp to print page flags
In reply to Yafang ShaoQuoted 6 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=0x17ffffc0010200
Quoted 8 lines
While 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]>Reviewed-by Vlastimil Babka <[email protected]>Acked-by David Rientjes <[email protected]>Signed-off-by Yafang Shao <[email protected]>
LGTM. Thanks.
Quoted 21 lines
--- mm/slub.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)mm/slub.c +3
-2@@ -638,8 +638,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); }
PATCH v3 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 remove the prefix completely.
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
[ 6343.396602] Slab 0x000000004382e02b objects=33 used=3 fp=0x000000009ae06ffc 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
@@ -612,7 +612,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 ("%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 {
@@ -638,7 +638,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 ("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);
@@ -695,7 +695,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 ("Object 0x%p @offset=%tu fp=0x%p\n\n" , p, p - addr,get_freepointer (s, p));if (s->flags &SLAB_RED_ZONE )
@@ -788,7 +788,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 ("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);
@@ -3854,7 +3854,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 ("Object 0x%p @offset=%tu\n" , p, p - addr);print_tracking (s, p); } }
Signature · 1 line
2.17.1
Re: [PATCH v3 2/3] mm, slub: don't combine pr_err with INFO
Quoted 7 lines · Yafang Shao
It is strange to combine "
pr_err" with "INFO", so let's remove the prefix completely.
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 8 lines
- after the patch
[ 6343.396602] Slab 0x000000004382e02b objects=33 used=3 fp=0x000000009ae06ffc flags=0x17ffffc0010200(slab|head)[1]. https://lore.kernel.org/linux-mm/[email protected]/#t
Suggested-by Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>Signed-off-by Yafang Shao <[email protected]>
Quoted 54 lines
--- mm/slub.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/slub.c +5
-5@@ -612,7 +612,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 ("%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 {@@ -638,7 +638,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 ("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);@@ -695,7 +695,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 ("Object 0x%p @offset=%tu fp=0x%p\n\n" , p, p - addr,get_freepointer (s, p));if (s->flags &SLAB_RED_ZONE )@@ -788,7 +788,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 ("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);@@ -3854,7 +3854,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 ("Object 0x%p @offset=%tu\n" , p, p - addr);print_tracking (s, p); } }
Re: [PATCH v3 2/3] mm, slub: don't combine pr_err with INFO
In reply to Yafang ShaoQuoted 2 lines · Yafang Shao
It is strange to combine "
pr_err" with "INFO", so let's remove the prefix completely.
So is this the right thing to do? Should it be pr_info() instead? Many of these messages do not appear to be error messages, but rather informational messages.
Re: [PATCH v3 2/3] mm, slub: don't combine pr_err with INFO
Quoted 7 lines · Matthew Wilcox
Quoted 2 lines · Yafang Shao
It is strange to combine "
pr_err" with "INFO", so let's remove the prefix completely.So is this the right thing to do? Should it be
pr_info()instead? Many of these messages do not appear to be error messages, but rather informational messages.
They are all part of longer error reports. See
https://lore.kernel.org/linux-mm/[email protected]/
Re: [PATCH v3 2/3] mm, slub: don't combine pr_err with INFO
In reply to Yafang ShaoQuoted 7 lines · Yafang Shao
It is strange to combine "
pr_err" with "INFO", so let's remove the prefix completely.
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 8 lines
- after the patch
[ 6343.396602] Slab 0x000000004382e02b objects=33 used=3 fp=0x000000009ae06ffc flags=0x17ffffc0010200(slab|head)[1]. https://lore.kernel.org/linux-mm/[email protected]/#t
Suggested-by Vlastimil Babka <[email protected]>Cc David Hildenbrand <[email protected]>Signed-off-by Yafang Shao <[email protected]>
Looks good,thanks.
Quoted 54 lines
--- mm/slub.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)mm/slub.c +5
-5@@ -612,7 +612,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 ("%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 {@@ -638,7 +638,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 ("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);@@ -695,7 +695,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 ("Object 0x%p @offset=%tu fp=0x%p\n\n" , p, p - addr,get_freepointer (s, p));if (s->flags &SLAB_RED_ZONE )@@ -788,7 +788,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 ("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);@@ -3854,7 +3854,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 ("Object 0x%p @offset=%tu\n" , p, p - addr);print_tracking (s, p); } }
PATCH v3 3/3 vsprintf: introduce new format to dump full information of page flags
In reply to Yafang ShaoThe existed pGp shows the names of page flags only, rather than the full information including section, node, zone, last cpuipid and kasan tag. While it is not easy to parse these information manually because there are so many flavors. We'd better interpret them in printf.
To avoid breaking some tools which parsing pGp via debugfs or affecting the printf buffer, other new formats are introduced, so the user can choose what and in which order they want, suggested by Andy. These new introduced format as follows,
pGpb: print other information first and then the names of page flags
pGpl: print the names of page flags first and then the other info
The differece between them looks like the difference between big-endian and little-endian, that's why they are named like that. The examples of the output as follows,
%pGpb 0x17ffffc0010200(node=0|zone=2|lastcpupid=0x1fffff|slab|head)
%pGpl 0x17ffffc0010200(slab|head|node=0|zone=2|lastcpupid=0x1fffff)To be compitable with the existed format of pGp, the new introduced ones also use '|' as the separator, then the user tools parsing pGp won't need to make change, suggested by Matthew.
The doc and test cases are also updated. Below is the output of the test cases,
[ 4299.847655] test_printf: loaded. [ 4299.848301] test_printf: all 404 tests passed [ 4299.850371] test_printf: unloaded.
--- Documentation/core-api/printk-formats.rst | 2 + lib/test_printf.c | 126 +++++++++++++++++++--- lib/vsprintf.c | 115 +++++++++++++++++++- 3 files changed, 226 insertions(+), 17 deletions(-)
Documentation/core-api/printk-formats.rst +2 -0
@@ -539,6 +539,8 @@ Flags bitfields such as page flags, gfp_flags :: %pGp referenced|uptodate|lru|active|private + %pGpb node=0|zone=2|referenced|uptodate|lru|active|private + %pGpl referenced|uptodate|lru|active|private|node=0|zone=2 %pGg GFP_USER|GFP_DMA32|GFP_NOWARN %pGv read|exec|mayread|maywrite|mayexec|denywrite
lib/test_printf.c +114 -12
148 lines not on this page · raw message
lib/vsprintf.c +110 -5
127 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 6 lines · Yafang Shao
To avoid breaking some tools which parsing pGp via debugfs or affecting the printf buffer, other new formats are introduced, so the user can choose what and in which order they want, suggested by Andy. These new introduced format as follows,
pGpb: print other information first and then the names of page flags
pGpl: print the names of page flags first and then the other info
This is overengineering things. We already print in little-endian order, and the other information should be tacked onto the end. Just extend %pGp. Andy's suggestion to add another flag was a bad one.
Quoted 9 lines · Matthew Wilcox
Quoted 6 lines · Yafang Shao
To avoid breaking some tools which parsing pGp via debugfs or affecting the printf buffer, other new formats are introduced, so the user can choose what and in which order they want, suggested by Andy. These new introduced format as follows,
pGpb: print other information first and then the names of page flags
pGpl: print the names of page flags first and then the other info
Quoted 3 lines
This is overengineering things. We already print in little-endian order, and the other information should be tacked onto the end. Just extend %pGp. Andy's suggestion to add another flag was a bad one.
Fair enough, I can admit this because I don't know the mm specifics. However, my initial point was about the long message which might be cut into pieces during Oops or whatever and the user will get the first parts only. Depends on what you consider as a higher priority to print the order might be different. Initial patch suggested to print the new fields first.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Matthew Wilcox
Quoted 6 lines · Yafang Shao
To avoid breaking some tools which parsing pGp via debugfs or affecting the printf buffer, other new formats are introduced, so the user can choose what and in which order they want, suggested by Andy. These new introduced format as follows,
pGpb: print other information first and then the names of page flags
pGpl: print the names of page flags first and then the other info
Quoted 4 lines
This is overengineering things. We already print in little-endian order, and the other information should be tacked onto the end. Just extend %pGp. Andy's suggestion to add another flag was a bad one.
All right. I will do it in the next version.
Signature · 2 lines
Thanks Yafang