Skip to contentSkip to conversation

Documentation/vm/page-types enhancements

PATCH In review Alex Chiang 2 participants 7 messages Nov 5, 2009 – Nov 6, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Documentation/vm/page-types enhancements

This is v2 of teaching page-types to decode page flags directly from the command line.

v1 -> v2:
- Use Fengguang's implementation
- Exit early when using new -d|--describe option

---

Alex Chiang (2):
page-types: whitespace alignment
page-types: exit early when invoked with -d|--describe

Wu Fengguang (1):
page-types: learn to describe flags directly from command line

 Documentation/vm/page-types.c |   60 +++++++++++++++++++++++++++--------------
 1 files changed, 39 insertions(+), 21 deletions(-)
#1 lore raw

PATCH v2 1/3 page-types: learn to describe flags directly from command line

From: Wu Fengguang <[email protected]>

Teach page-types to describe page flags directly from the command line.

Why is this useful? For instance, if you're using memory hotplug and see this in /var/log/messages:

	kernel: removing from LRU failed 3836dd0/1/1e00000000000010

It would be nice to decode those page flags without staring at the source.

Example usage and output:

# Documentation/vm/page-types -d 0x10
0x0000000000000010 ____D_____________________________ dirty

# Documentation/vm/page-types -d anon
0x0000000000001000 ____________a_____________________ anonymous

# Documentation/vm/page-types -d anon,0x10
0x0000000000001010 ____D_______a_____________________ dirty,anonymous

[[email protected]: documentation]
Cc Andi Kleen <[email protected]>
Cc Haicheng Li <[email protected]>

---

 Documentation/vm/page-types.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
Documentation/vm/page-types.c +20 -1
index 3ec4f2a..a93c28e 100644
@@ -674,6 +674,7 @@ static void usage(void)
 	printf(
 "page-types [options]\n"
 "            -r|--raw                  Raw mode, for kernel developers\n"
+"            -d|--describe flags        Describe flags\n"
 "            -a|--addr    addr-spec    Walk a range of pages\n"
 "            -b|--bits    bits-spec    Walk pages with specified bits\n"
 "            -p|--pid     pid          Walk process address space\n"
@@ -686,6 +687,10 @@ static void usage(void)
 "            -X|--hwpoison             hwpoison pages\n"
 "            -x|--unpoison             unpoison pages\n"
 "            -h|--help                 Show this usage message\n"
+"flags:\n"
+"            0x10                      bitfield format, e.g.\n"
+"            anon                      bit-name, e.g.\n"
+"            0x10,anon                 comma-separated list, e.g.\n"
 "addr-spec:\n"
 "            N                         one page at offset N (unit: pages)\n"
 "            N+M                       pages range from N to N+M-1\n"
@@ -884,12 +889,22 @@ static void parse_bits_mask(const char *optarg)
 	add_bits_filter(mask, bits);
 }
 
+static void describe_flags(const char *optarg)
+{
+	uint64_t flags = parse_flag_names(optarg, 0);
+
+	printf("0x%016llx\t%s\t%s\n",
+		(unsigned long long)flags,
+		page_flag_name(flags),
+		page_flag_longname(flags));
+}
 
 static struct option opts[] = {
 	{ "raw"       , 0, NULL, 'r' },
 	{ "pid"       , 1, NULL, 'p' },
 	{ "file"      , 1, NULL, 'f' },
 	{ "addr"      , 1, NULL, 'a' },
+	{ "describe"  , 1, NULL, 'd' },
 	{ "bits"      , 1, NULL, 'b' },
 	{ "list"      , 0, NULL, 'l' },
 	{ "list-each" , 0, NULL, 'L' },
@@ -907,7 +922,7 @@ int main(int argc, char *argv[])
 	page_size = getpagesize();
 
 	while ((c = getopt_long(argc, argv,
-				"rp:f:a:b:lLNXxh", opts, NULL)) != -1) {
+				"rp:f:a:b:d:lLNXxh", opts, NULL)) != -1) {
 		switch (c) {
 		case 'r':
 			opt_raw = 1;
@@ -924,6 +939,10 @@ int main(int argc, char *argv[])
 		case 'b':
 			parse_bits_mask(optarg);
 			break;
+		case 'd':
+			opt_no_summary = 1;
+			describe_flags(optarg);
+			break;
 		case 'l':
 			opt_list = 1;
 			break;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw

Re: [PATCH v2 1/3] page-types: learn to describe flags directly from command line

Quoted 15 lines · Alex Chiang

From: Wu Fengguang <[email protected]>

Teach page-types to describe page flags directly from the command line.

Why is this useful? For instance, if you're using memory hotplug and see this in /var/log/messages:

	kernel: removing from LRU failed 3836dd0/1/1e00000000000010

It would be nice to decode those page flags without staring at the source.

Example usage and output:

Quoted 8 lines

# Documentation/vm/page-types -d 0x10
0x0000000000000010 ____D_____________________________ dirty

# Documentation/vm/page-types -d anon
0x0000000000001000 ____________a_____________________ anonymous

# Documentation/vm/page-types -d anon,0x10
0x0000000000001010 ____D_______a_____________________ dirty,anonymous

Good examples, thanks!

Quoted 14 lines
[[email protected]: documentation]
Cc Andi Kleen <[email protected]>
Cc Haicheng Li <[email protected]>

---

 Documentation/vm/page-types.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
Documentation/vm/page-types.c +0 -0
index 3ec4f2a..a93c28e 100644

Documentation/vm/page-types.c static void usage(void) · line 677

Quoted 4 lines
Documentation/vm/page-types.c +1 -0
@@ -674,6 +674,7 @@ static void usage(void)
 	printf(
 "page-types [options]\n"
 "            -r|--raw                  Raw mode, for kernel developers\n"
+"            -d|--describe flags        Describe flags\n"

"Decode flags number; Encode flags name"?

Thanks,
Fengguang

#3 lore raw

PATCH v2 2/3 page-types: whitespace alignment

In reply to Alex Chiang

Align the output when page-type -h is invoked.

---

 Documentation/vm/page-types.c |   46 +++++++++++++++++++++--------------------
 1 files changed, 23 insertions(+), 23 deletions(-)
Documentation/vm/page-types.c +23 -23
index a93c28e..9c09eb5 100644
@@ -673,35 +673,35 @@ static void usage(void)
 
 	printf(
 "page-types [options]\n"
-"            -r|--raw                  Raw mode, for kernel developers\n"
+"            -r|--raw                   Raw mode, for kernel developers\n"
 "            -d|--describe flags        Describe flags\n"
-"            -a|--addr    addr-spec    Walk a range of pages\n"
-"            -b|--bits    bits-spec    Walk pages with specified bits\n"
-"            -p|--pid     pid          Walk process address space\n"
+"            -a|--addr     addr-spec    Walk a range of pages\n"
+"            -b|--bits     bits-spec    Walk pages with specified bits\n"
+"            -p|--pid      pid          Walk process address space\n"
 #if 0 /* planned features */
-"            -f|--file    filename     Walk file address space\n"
+"            -f|--file     filename     Walk file address space\n"
 #endif
-"            -l|--list                 Show page details in ranges\n"
-"            -L|--list-each            Show page details one by one\n"
-"            -N|--no-summary           Don't show summay info\n"
-"            -X|--hwpoison             hwpoison pages\n"
-"            -x|--unpoison             unpoison pages\n"
-"            -h|--help                 Show this usage message\n"
+"            -l|--list                  Show page details in ranges\n"
+"            -L|--list-each             Show page details one by one\n"
+"            -N|--no-summary            Don't show summary info\n"
+"            -X|--hwpoison              hwpoison pages\n"
+"            -x|--unpoison              unpoison pages\n"
+"            -h|--help                  Show this usage message\n"
 "flags:\n"
-"            0x10                      bitfield format, e.g.\n"
-"            anon                      bit-name, e.g.\n"
-"            0x10,anon                 comma-separated list, e.g.\n"
+"            0x10                       bitfield format, e.g.\n"
+"            anon                       bit-name, e.g.\n"
+"            0x10,anon                  comma-separated list, e.g.\n"
 "addr-spec:\n"
-"            N                         one page at offset N (unit: pages)\n"
-"            N+M                       pages range from N to N+M-1\n"
-"            N,M                       pages range from N to M-1\n"
-"            N,                        pages range from N to end\n"
-"            ,M                        pages range from 0 to M-1\n"
+"            N                          one page at offset N (unit: pages)\n"
+"            N+M                        pages range from N to N+M-1\n"
+"            N,M                        pages range from N to M-1\n"
+"            N,                         pages range from N to end\n"
+"            ,M                         pages range from 0 to M-1\n"
 "bits-spec:\n"
-"            bit1,bit2                 (flags & (bit1|bit2)) != 0\n"
-"            bit1,bit2=bit1            (flags & (bit1|bit2)) == bit1\n"
-"            bit1,~bit2                (flags & (bit1|bit2)) == bit1\n"
-"            =bit1,bit2                flags == (bit1|bit2)\n"
+"            bit1,bit2                  (flags & (bit1|bit2)) != 0\n"
+"            bit1,bit2=bit1             (flags & (bit1|bit2)) == bit1\n"
+"            bit1,~bit2                 (flags & (bit1|bit2)) == bit1\n"
+"            =bit1,bit2                 flags == (bit1|bit2)\n"
 "bit-names:\n"
 	);
 
#5 lore raw

PATCH v2 3/3 page-types: exit early when invoked with -d|--describe

In reply to Alex Chiang

On a system with large amount of memory (256GB), invoking page-types can take quite a long time, which is unreasonable considering the user only wants a description of the flags:

	# time ./page-types -d 0x10
	0x0000000000000010	____D_____________________________	dirty
	real	0m34.285s
	user	0m1.966s
	sys	0m32.313s

This is because we still walk the entire address range.

Exiting early seems like a reasonble solution:

# time ./page-types -d 0x10
	0x0000000000000010	____D_____________________________	dirty
	real	0m0.007s
	user	0m0.001s
	sys	0m0.005s
Cc Andi Kleen <[email protected]>
Cc Haicheng Li <[email protected]>

---

 Documentation/vm/page-types.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
Documentation/vm/page-types.c +1 -2
index 9c09eb5..9cf50ab 100644
@@ -940,9 +940,8 @@ int main(int argc, char *argv[])
 			parse_bits_mask(optarg);
 			break;
 		case 'd':
-			opt_no_summary = 1;
 			describe_flags(optarg);
-			break;
+			exit(0);
 		case 'l':
 			opt_list = 1;
 			break;
Acked-by on v2 3/3
#6 lore raw

Re: [PATCH v2 3/3] page-types: exit early when invoked with -d|--describe

Documentation/vm/page-types.c int main(int argc, char *argv[]) · line 947

Quoted 9 lines
Documentation/vm/page-types.c +1 -2
 		case 'd':
-			opt_no_summary = 1;
 			describe_flags(optarg);
-			break;
+			exit(0);
 		case 'l':
 			opt_list = 1;
 			break;

Good catch, thanks!