Skip to content

Commit 1b5c65b

Browse files
21cnbaoakpm00
authored andcommitted
mm/page_owner: record and dump free_pid and free_tgid
While investigating some complex memory allocation and free bugs especially in multi-processes and multi-threads cases, from time to time, I feel the free stack isn't sufficient as a page can be freed by processes or threads other than the one allocating it. And other processes and threads which free the page often have the exactly same free stack with the one allocating the page. We can't know who free the page only through the free stack though the current page_owner does tell us the pid and tgid of the one allocating the page. This makes the bug investigation often hard. So this patch adds free pid and tgid in page_owner, so that we can easily figure out if the freeing is crossing processes or threads. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Barry Song <[email protected]> Cc: Audra Mitchell <[email protected]> Cc: Hyeonggon Yoo <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: Kassey Li <[email protected]> Cc: Kemeng Shi <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 20954c1 commit 1b5c65b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mm/page_owner.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ struct page_owner {
3232
char comm[TASK_COMM_LEN];
3333
pid_t pid;
3434
pid_t tgid;
35+
pid_t free_pid;
36+
pid_t free_tgid;
3537
};
3638

3739
static bool page_owner_enabled __initdata;
@@ -152,6 +154,8 @@ void __reset_page_owner(struct page *page, unsigned short order)
152154
page_owner = get_page_owner(page_ext);
153155
page_owner->free_handle = handle;
154156
page_owner->free_ts_nsec = free_ts_nsec;
157+
page_owner->free_pid = current->pid;
158+
page_owner->free_tgid = current->tgid;
155159
page_ext = page_ext_next(page_ext);
156160
}
157161
page_ext_put(page_ext);
@@ -253,6 +257,8 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old)
253257
new_page_owner->handle = old_page_owner->handle;
254258
new_page_owner->pid = old_page_owner->pid;
255259
new_page_owner->tgid = old_page_owner->tgid;
260+
new_page_owner->free_pid = old_page_owner->free_pid;
261+
new_page_owner->free_tgid = old_page_owner->free_tgid;
256262
new_page_owner->ts_nsec = old_page_owner->ts_nsec;
257263
new_page_owner->free_ts_nsec = old_page_owner->ts_nsec;
258264
strcpy(new_page_owner->comm, old_page_owner->comm);
@@ -495,7 +501,8 @@ void __dump_page_owner(const struct page *page)
495501
if (!handle) {
496502
pr_alert("page_owner free stack trace missing\n");
497503
} else {
498-
pr_alert("page last free stack trace:\n");
504+
pr_alert("page last free pid %d tgid %d stack trace:\n",
505+
page_owner->free_pid, page_owner->free_tgid);
499506
stack_depot_print(handle);
500507
}
501508

0 commit comments

Comments
 (0)