All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] tools/vm/page_owner_sort.c: fix comments
@ 2022-03-01 15:14 Jiajian Ye
  2022-03-01 15:14 ` [PATCH 2/3] tools/vm/page_owner_sort.c: add a security check Jiajian Ye
  2022-03-01 15:14 ` [PATCH 3/3] tools/vm/page_owner_sort.c: support sorting by tgid and update documentation Jiajian Ye
  0 siblings, 2 replies; 3+ messages in thread
From: Jiajian Ye @ 2022-03-01 15:14 UTC (permalink / raw)
  To: akpm
  Cc: sfr, caoyixuan2019, hanshenghong2019, zhaochongxi2019,
	weizhenliang, zhangyinan2019, linux-kernel, Jiajian Ye

Two adjustments are made:

1. Correct a grammatical error: replace the "what" in
"Do the job what you want to debug" with "that".

2. Replace "has not been" with "has been" in the description
of the -f option: According to Commit b1c9ba071e7d
("tools/vm/page_owner_sort.c: fix the instructions for use"),
the description of the "-f" option is "Filter out the information
of blocks whose memory has been released."

Signed-off-by: Jiajian Ye <yejiajian2018@email.szu.edu.cn>
---
 Documentation/vm/page_owner.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/vm/page_owner.rst b/Documentation/vm/page_owner.rst
index 6591e518819f..2ddb632d847b 100644
--- a/Documentation/vm/page_owner.rst
+++ b/Documentation/vm/page_owner.rst
@@ -78,7 +78,7 @@ Usage
 
 2) Enable page owner: add "page_owner=on" to boot cmdline.
 
-3) Do the job what you want to debug
+3) Do the job that you want to debug.
 
 4) Analyze information from page owner::
 
@@ -126,4 +126,4 @@ Usage
 		-c		Cull by comparing stacktrace instead of total block.
 
 	Filter:
-		-f		Filter out the information of blocks whose memory has not been released.
+		-f		Filter out the information of blocks whose memory has been released.
-- 
2.25.1




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/3] tools/vm/page_owner_sort.c: add a security check
  2022-03-01 15:14 [PATCH 1/3] tools/vm/page_owner_sort.c: fix comments Jiajian Ye
@ 2022-03-01 15:14 ` Jiajian Ye
  2022-03-01 15:14 ` [PATCH 3/3] tools/vm/page_owner_sort.c: support sorting by tgid and update documentation Jiajian Ye
  1 sibling, 0 replies; 3+ messages in thread
From: Jiajian Ye @ 2022-03-01 15:14 UTC (permalink / raw)
  To: akpm
  Cc: sfr, caoyixuan2019, hanshenghong2019, zhaochongxi2019,
	weizhenliang, zhangyinan2019, linux-kernel, Jiajian Ye

Add a security check after using malloc() to allocate memory.

Signed-off-by: Jiajian Ye <yejiajian2018@email.szu.edu.cn>
---
 tools/vm/page_owner_sort.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/vm/page_owner_sort.c b/tools/vm/page_owner_sort.c
index 79d69c3b84ed..69fb6ca7c0b7 100644
--- a/tools/vm/page_owner_sort.c
+++ b/tools/vm/page_owner_sort.c
@@ -217,7 +217,13 @@ static void add_list(char *buf, int len)
 		printf("max_size too small??\n");
 		exit(1);
 	}
+
 	list[list_size].txt = malloc(len+1);
+	if (!list[list_size].txt) {
+		printf("Out of memory\n");
+		exit(1);
+	}
+
 	list[list_size].len = len;
 	list[list_size].num = 1;
 	list[list_size].page_num = get_page_num(buf);
-- 
2.25.1




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 3/3] tools/vm/page_owner_sort.c: support sorting by tgid and update documentation
  2022-03-01 15:14 [PATCH 1/3] tools/vm/page_owner_sort.c: fix comments Jiajian Ye
  2022-03-01 15:14 ` [PATCH 2/3] tools/vm/page_owner_sort.c: add a security check Jiajian Ye
@ 2022-03-01 15:14 ` Jiajian Ye
  1 sibling, 0 replies; 3+ messages in thread
From: Jiajian Ye @ 2022-03-01 15:14 UTC (permalink / raw)
  To: akpm
  Cc: sfr, caoyixuan2019, hanshenghong2019, zhaochongxi2019,
	weizhenliang, zhangyinan2019, linux-kernel, Jiajian Ye

When the "page owner" information is read, the information sorted
by TGID is expected.

As a result, the following adjustments have been made:

1. Add a new -P option to sort the information of blocks by TGID
in ascending order.

2. Adjust the order of member variables in block_list strust
to avoid one 4 byte hole.

3. Add -P option explanation in the document.

Signed-off-by: Jiajian Ye <yejiajian2018@email.szu.edu.cn>
---
 Documentation/vm/page_owner.rst |  1 +
 tools/vm/page_owner_sort.c      | 40 ++++++++++++++++++++++++++++++---
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/Documentation/vm/page_owner.rst b/Documentation/vm/page_owner.rst
index 2ddb632d847b..941543a797fe 100644
--- a/Documentation/vm/page_owner.rst
+++ b/Documentation/vm/page_owner.rst
@@ -116,6 +116,7 @@ Usage
 		-a		Sort by memory allocation time.
 		-m		Sort by total memory.
 		-p		Sort by pid.
+		-P		Sort by tgid.
 		-r		Sort by memory release time.
 		-s		Sort by stack trace.
 		-t		Sort by times (default).
diff --git a/tools/vm/page_owner_sort.c b/tools/vm/page_owner_sort.c
index 69fb6ca7c0b7..d166f2f900eb 100644
--- a/tools/vm/page_owner_sort.c
+++ b/tools/vm/page_owner_sort.c
@@ -25,16 +25,18 @@
 struct block_list {
 	char *txt;
 	char *stacktrace;
+	__u64 ts_nsec;
+	__u64 free_ts_nsec;
 	int len;
 	int num;
 	int page_num;
 	pid_t pid;
-	__u64 ts_nsec;
-	__u64 free_ts_nsec;
+	pid_t tgid;
 };
 
 static regex_t order_pattern;
 static regex_t pid_pattern;
+static regex_t tgid_pattern;
 static regex_t ts_nsec_pattern;
 static regex_t free_ts_nsec_pattern;
 static struct block_list *list;
@@ -91,6 +93,13 @@ static int compare_pid(const void *p1, const void *p2)
 	return l1->pid - l2->pid;
 }
 
+static int compare_tgid(const void *p1, const void *p2)
+{
+	const struct block_list *l1 = p1, *l2 = p2;
+
+	return l1->tgid - l2->tgid;
+}
+
 static int compare_ts(const void *p1, const void *p2)
 {
 	const struct block_list *l1 = p1, *l2 = p2;
@@ -170,6 +179,24 @@ static pid_t get_pid(char *buf)
 
 }
 
+static pid_t get_tgid(char *buf)
+{
+	pid_t tgid;
+	char tgid_str[FIELD_BUFF] = {0};
+	char *endptr;
+
+	search_pattern(&tgid_pattern, tgid_str, buf);
+	errno = 0;
+	tgid = strtol(tgid_str, &endptr, 10);
+	if (errno != 0 || endptr == tgid_str || *endptr != '\0') {
+		printf("wrong/invalid tgid in follow buf:\n%s\n", buf);
+		return -1;
+	}
+
+	return tgid;
+
+}
+
 static __u64 get_ts_nsec(char *buf)
 {
 	__u64 ts_nsec;
@@ -231,6 +258,7 @@ static void add_list(char *buf, int len)
 	list[list_size].txt[len] = 0;
 	list[list_size].stacktrace = strchr(list[list_size].txt, '\n') ?: "";
 	list[list_size].pid = get_pid(buf);
+	list[list_size].tgid = get_tgid(buf);
 	list[list_size].ts_nsec = get_ts_nsec(buf);
 	list[list_size].free_ts_nsec = get_free_ts_nsec(buf);
 	list_size++;
@@ -249,6 +277,7 @@ static void usage(void)
 		"-s	Sort by the stack trace.\n"
 		"-t	Sort by times (default).\n"
 		"-p	Sort by pid.\n"
+		"-P	Sort by tgid.\n"
 		"-a	Sort by memory allocate time.\n"
 		"-r	Sort by memory release time.\n"
 		"-c	Cull by comparing stacktrace instead of total block.\n"
@@ -268,7 +297,7 @@ int main(int argc, char **argv)
 	struct stat st;
 	int opt;
 
-	while ((opt = getopt(argc, argv, "acfmprst")) != -1)
+	while ((opt = getopt(argc, argv, "acfmprstP")) != -1)
 		switch (opt) {
 		case 'a':
 			cmp = compare_ts;
@@ -294,6 +323,9 @@ int main(int argc, char **argv)
 		case 't':
 			cmp = compare_num;
 			break;
+		case 'P':
+			cmp = compare_tgid;
+			break;
 		default:
 			usage();
 			exit(1);
@@ -314,6 +346,7 @@ int main(int argc, char **argv)
 
 	check_regcomp(&order_pattern, "order\\s*([0-9]*),");
 	check_regcomp(&pid_pattern, "pid\\s*([0-9]*),");
+	check_regcomp(&tgid_pattern, "tgid\\s*([0-9]*) ");
 	check_regcomp(&ts_nsec_pattern, "ts\\s*([0-9]*)\\s*ns,");
 	check_regcomp(&free_ts_nsec_pattern, "free_ts\\s*([0-9]*)\\s*ns");
 	fstat(fileno(fin), &st);
@@ -373,6 +406,7 @@ int main(int argc, char **argv)
 	}
 	regfree(&order_pattern);
 	regfree(&pid_pattern);
+	regfree(&tgid_pattern);
 	regfree(&ts_nsec_pattern);
 	regfree(&free_ts_nsec_pattern);
 	return 0;
-- 
2.25.1




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-01 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01 15:14 [PATCH 1/3] tools/vm/page_owner_sort.c: fix comments Jiajian Ye
2022-03-01 15:14 ` [PATCH 2/3] tools/vm/page_owner_sort.c: add a security check Jiajian Ye
2022-03-01 15:14 ` [PATCH 3/3] tools/vm/page_owner_sort.c: support sorting by tgid and update documentation Jiajian Ye

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.