LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: linux-kernel@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>
Cc: Zhang Shengju <zhangshengju@cmss.chinamobile.com>,
Tang Bin <tangbin@cmss.chinamobile.com>,
Zhenliang Wei <weizhenliang@huawei.com>,
Changhee Han <ch0.han@lge.com>, Sean Anderson <seanga2@gmail.com>
Subject: [PATCH 1/2] tools/vm/page_owner_sort.c: Sort by stacktrace before culling
Date: Wed, 24 Nov 2021 14:34:39 -0500 [thread overview]
Message-ID: <20211124193440.1805610-1-seanga2@gmail.com> (raw)
The contents of page_owner have changed to include more information than
the stack trace. On a modern kernel, the blocks look like
Page allocated via order 0, mask 0x0(), pid 1, ts 165564237 ns, free_ts 0 ns
register_early_stack+0x4b/0x90
init_page_owner+0x39/0x250
kernel_init_freeable+0x11e/0x242
kernel_init+0x16/0x130
Sorting by the contents of .txt will result in almost no repeated pages, as
the pid, ts, and free_ts will almost never be the same. Instead, sort by
the contents of the stack trace, which we assume to be whatever is after
the first line.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
---
tools/vm/page_owner_sort.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tools/vm/page_owner_sort.c b/tools/vm/page_owner_sort.c
index 9ebb84a9c731..9ad3772a294d 100644
--- a/tools/vm/page_owner_sort.c
+++ b/tools/vm/page_owner_sort.c
@@ -23,6 +23,7 @@
struct block_list {
char *txt;
+ char *stacktrace;
int len;
int num;
int page_num;
@@ -51,11 +52,11 @@ int read_block(char *buf, int buf_size, FILE *fin)
return -1; /* EOF or no space left in buf. */
}
-static int compare_txt(const void *p1, const void *p2)
+static int compare_stacktrace(const void *p1, const void *p2)
{
const struct block_list *l1 = p1, *l2 = p2;
- return strcmp(l1->txt, l2->txt);
+ return strcmp(l1->stacktrace ?: "", l2->stacktrace ?: "");
}
static int compare_num(const void *p1, const void *p2)
@@ -121,6 +122,7 @@ static void add_list(char *buf, int len)
list[list_size].page_num = get_page_num(buf);
memcpy(list[list_size].txt, buf, len);
list[list_size].txt[len] = 0;
+ list[list_size].stacktrace = strchr(list[list_size].txt, '\n');
list_size++;
if (list_size % 1000 == 0) {
printf("loaded %d\r", list_size);
@@ -199,7 +201,7 @@ int main(int argc, char **argv)
printf("sorting ....\n");
- qsort(list, list_size, sizeof(list[0]), compare_txt);
+ qsort(list, list_size, sizeof(list[0]), compare_stacktrace);
list2 = malloc(sizeof(*list) * list_size);
if (!list2) {
@@ -211,7 +213,7 @@ int main(int argc, char **argv)
for (i = count = 0; i < list_size; i++) {
if (count == 0 ||
- strcmp(list2[count-1].txt, list[i].txt) != 0) {
+ strcmp(list2[count-1].stacktrace, list[i].stacktrace) != 0) {
list2[count++] = list[i];
} else {
list2[count-1].num += list[i].num;
--
2.33.0
next reply other threads:[~2021-11-24 19:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-24 19:34 Sean Anderson [this message]
2021-11-24 19:34 ` [PATCH 2/2] tools/vm/page_owner_sort.c: Add Sean Anderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211124193440.1805610-1-seanga2@gmail.com \
--to=seanga2@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ch0.han@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tangbin@cmss.chinamobile.com \
--cc=weizhenliang@huawei.com \
--cc=zhangshengju@cmss.chinamobile.com \
--subject='Re: [PATCH 1/2] tools/vm/page_owner_sort.c: Sort by stacktrace before culling' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).