* + tools-mm-page_owner_sort-free-per-record-allocations.patch added to mm-new branch
@ 2026-06-29 4:41 Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2026-06-29 4:41 UTC (permalink / raw)
To: mm-commits, ziy, zhen.ni, ye.liu, vishal.moola, chenyichong, akpm
The patch titled
Subject: tools/mm/page_owner_sort: free per-record allocations
has been added to the -mm mm-new branch. Its filename is
tools-mm-page_owner_sort-free-per-record-allocations.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/tools-mm-page_owner_sort-free-per-record-allocations.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Yichong Chen <chenyichong@uniontech.com>
Subject: tools/mm/page_owner_sort: free per-record allocations
Date: Mon, 29 Jun 2026 09:43:15 +0800
add_list() allocates comm and txt for each page owner record, but the
cleanup path only frees the outer list array. This leaks both buffers for
every retained record.
Free partial allocations in add_list(), discarded records during culling,
and retained records on exit.
Link: https://lore.kernel.org/20260629014316.130307-3-chenyichong@uniontech.com
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
Reviewed-by: Vishal Moola <vishal.moola@gmail.com>
Cc: Ye Liu <ye.liu@linux.dev>
Cc: Zhen Ni <zhen.ni@easystack.cn>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
tools/mm/page_owner_sort.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
--- a/tools/mm/page_owner_sort.c~tools-mm-page_owner_sort-free-per-record-allocations
+++ a/tools/mm/page_owner_sort.c
@@ -396,6 +396,12 @@ static char *get_comm(char *buf)
return comm_str;
}
+static void free_block_list(struct block_list *block)
+{
+ free(block->comm);
+ free(block->txt);
+}
+
static int get_arg_type(const char *arg)
{
if (!strcmp(arg, "pid") || !strcmp(arg, "p"))
@@ -502,9 +508,14 @@ static bool add_list(char *buf, int len,
list[list_size].pid = get_pid(buf);
list[list_size].tgid = get_tgid(buf);
list[list_size].comm = get_comm(buf);
- list[list_size].txt = malloc(len+1);
+ if (!list[list_size].comm) {
+ fprintf(stderr, "Out of memory\n");
+ return false;
+ }
+ list[list_size].txt = malloc(len + 1);
if (!list[list_size].txt) {
fprintf(stderr, "Out of memory\n");
+ free(list[list_size].comm);
return false;
}
memcpy(list[list_size].txt, buf, len);
@@ -863,8 +874,10 @@ int main(int argc, char **argv)
} else {
list[count-1].num += list[i].num;
list[count-1].page_num += list[i].page_num;
+ free_block_list(&list[i]);
}
}
+ list_size = count;
qsort(list, count, sizeof(list[0]), compare_sort_condition);
@@ -898,8 +911,11 @@ out_free:
free(ext_buf);
if (buf)
free(buf);
- if (list)
+ if (list) {
+ for (i = 0; i < list_size; i++)
+ free_block_list(&list[i]);
free(list);
+ }
out_ts:
regfree(&ts_nsec_pattern);
out_comm:
_
Patches currently in -mm which might be from chenyichong@uniontech.com are
tools-mm-page_owner_sort-return-explicit-filter-results.patch
tools-mm-page_owner_sort-free-per-record-allocations.patch
tools-mm-page_owner_sort-bound-pattern-output-copies.patch
^ permalink raw reply [flat|nested] 2+ messages in thread* + tools-mm-page_owner_sort-free-per-record-allocations.patch added to mm-new branch
@ 2026-06-26 0:19 Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2026-06-26 0:19 UTC (permalink / raw)
To: mm-commits, vishal.moola, chenyichong, akpm
The patch titled
Subject: tools/mm/page_owner_sort: free per-record allocations
has been added to the -mm mm-new branch. Its filename is
tools-mm-page_owner_sort-free-per-record-allocations.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/tools-mm-page_owner_sort-free-per-record-allocations.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: Yichong Chen <chenyichong@uniontech.com>
Subject: tools/mm/page_owner_sort: free per-record allocations
Date: Fri, 12 Jun 2026 13:50:17 +0800
add_list() allocates comm and txt for each page owner record, but the
cleanup path only frees the outer list array. This leaks both buffers for
every retained record.
Free partial allocations in add_list(), discarded records during culling,
and retained records on exit. Return explicit error, skip, and match
results from filter_record() to handle get_comm() failures.
Link: https://lore.kernel.org/610C3A89A09303F8+20260612055017.632263-1-chenyichong@uniontech.com
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
Reviewed-by: Vishal Moola <vishal.moola@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
tools/mm/page_owner_sort.c | 63 ++++++++++++++++++++++++++++-------
1 file changed, 51 insertions(+), 12 deletions(-)
--- a/tools/mm/page_owner_sort.c~tools-mm-page_owner_sort-free-per-record-allocations
+++ a/tools/mm/page_owner_sort.c
@@ -43,6 +43,13 @@ enum FILTER_BIT {
FILTER_TGID = 1<<2,
FILTER_COMM = 1<<3
};
+
+enum FILTER_RESULT {
+ FILTER_ERROR,
+ FILTER_SKIP,
+ FILTER_MATCH
+};
+
enum CULL_BIT {
CULL_PID = 1<<1,
CULL_TGID = 1<<2,
@@ -372,6 +379,9 @@ static char *get_comm(char *buf)
{
char *comm_str = malloc(TASK_COMM_LEN);
+ if (!comm_str)
+ return NULL;
+
memset(comm_str, 0, TASK_COMM_LEN);
search_pattern(&comm_pattern, comm_str, buf);
@@ -386,6 +396,12 @@ static char *get_comm(char *buf)
return comm_str;
}
+static void free_block_list(struct block_list *block)
+{
+ free(block->comm);
+ free(block->txt);
+}
+
static int get_arg_type(const char *arg)
{
if (!strcmp(arg, "pid") || !strcmp(arg, "p"))
@@ -450,39 +466,57 @@ static bool match_str_list(const char *s
return false;
}
-static bool is_need(char *buf)
+static enum FILTER_RESULT filter_record(char *buf)
{
+ char *comm;
+
if ((filter & FILTER_PID) && !match_num_list(get_pid(buf), fc.pids, fc.pids_size))
- return false;
+ return FILTER_SKIP;
if ((filter & FILTER_TGID) &&
!match_num_list(get_tgid(buf), fc.tgids, fc.tgids_size))
- return false;
-
- char *comm = get_comm(buf);
+ return FILTER_SKIP;
+ if (!(filter & FILTER_COMM))
+ return FILTER_MATCH;
+
+ comm = get_comm(buf);
+ if (!comm)
+ return FILTER_ERROR;
- if ((filter & FILTER_COMM) &&
- !match_str_list(comm, fc.comms, fc.comms_size)) {
+ if (!match_str_list(comm, fc.comms, fc.comms_size)) {
free(comm);
- return false;
+ return FILTER_SKIP;
}
free(comm);
- return true;
+ return FILTER_MATCH;
}
static bool add_list(char *buf, int len, char *ext_buf)
{
+ enum FILTER_RESULT filter_result;
+
if (list_size == max_size) {
fprintf(stderr, "max_size too small??\n");
return false;
}
- if (!is_need(buf))
+ filter_result = filter_record(buf);
+ if (filter_result == FILTER_ERROR) {
+ fprintf(stderr, "Out of memory\n");
+ return false;
+ }
+ if (filter_result == FILTER_SKIP)
return true;
+
list[list_size].pid = get_pid(buf);
list[list_size].tgid = get_tgid(buf);
list[list_size].comm = get_comm(buf);
- list[list_size].txt = malloc(len+1);
+ if (!list[list_size].comm) {
+ fprintf(stderr, "Out of memory\n");
+ return false;
+ }
+ list[list_size].txt = malloc(len + 1);
if (!list[list_size].txt) {
fprintf(stderr, "Out of memory\n");
+ free(list[list_size].comm);
return false;
}
memcpy(list[list_size].txt, buf, len);
@@ -841,8 +875,10 @@ int main(int argc, char **argv)
} else {
list[count-1].num += list[i].num;
list[count-1].page_num += list[i].page_num;
+ free_block_list(&list[i]);
}
}
+ list_size = count;
qsort(list, count, sizeof(list[0]), compare_sort_condition);
@@ -876,8 +912,11 @@ out_free:
free(ext_buf);
if (buf)
free(buf);
- if (list)
+ if (list) {
+ for (i = 0; i < list_size; i++)
+ free_block_list(&list[i]);
free(list);
+ }
out_ts:
regfree(&ts_nsec_pattern);
out_comm:
_
Patches currently in -mm which might be from chenyichong@uniontech.com are
tools-mm-page_owner_sort-free-per-record-allocations.patch
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-29 4:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-29 4:41 + tools-mm-page_owner_sort-free-per-record-allocations.patch added to mm-new branch Andrew Morton
-- strict thread matches above, loose matches on Subject: below --
2026-06-26 0:19 Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox