Skip to contentSkip to conversation

+ mmpage_owner-fix-refcount-imbalance.patch added to mm-stable branch

PATCH Andrew Morton 1 participant 1 message Mar 14, 2024

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The patch titled
Subject: mm,page_owner: fix refcount imbalance
has been added to the -mm mm-stable branch. Its filename is
mmpage_owner-fix-refcount-imbalance.patch

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mmpage_owner-fix-refcount-imbalance.patch

This patch will later appear in the mm-stable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

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 the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Oscar Salvador <[email protected]>
Subject: mm,page_owner: fix refcount imbalance
Date: Thu, 14 Mar 2024 15:47:53 +0100

Current code does not contemplate scenarios were an allocation and free operation on the same pages do not handle it in the same amount at once.

To give an example, page_alloc_exact(), where we will allocate a page of enough order to stafisfy the size request, but we will free the remainings right away.

In the above example, we will increment the stack_record refcount only once, but we will decrease it the same number of times as number of unused pages we have to free. This will lead to a warning because of refcount imbalance.

Fix this by recording the number of base pages every stack_record holds, and only let the last decrementing of refcount succeed if the number of base pages equals 0, which means we freed all the pages.

As a bonus, show the aggregate of stack_count + base_pages as this gives a much better picture of the memory usage.

Fixes 217b2119b9e2 ("mm,page_owner: implement the tracking of the stacks count")
Cc Alexander Potapenko <[email protected]>
Cc Andrey Konovalov <[email protected]>
Cc Marco Elver <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Vlastimil Babka <[email protected]>

---

 include/linux/stackdepot.h |    3 +
 mm/page_owner.c            |   57 ++++++++++++++++++++++++++++-------
 2 files changed, 50 insertions(+), 10 deletions(-)
include/linux/stackdepot.h renamed from include/linux/stackdepot.h~mmpage_owner-fix-refcount-imbalance +3 -0
@@ -57,6 +57,9 @@ struct stack_record {
 	u32 size;			/* Number of stored frames */
 	union handle_parts handle;	/* Constant after initialization */
 	refcount_t count;
+#ifdef CONFIG_PAGE_OWNER
+	unsigned long nr_base_pages;
+#endif
 	union {
 		unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES];	/* Frames */
 		struct {
mm/page_owner.c renamed from mm/page_owner.c~mmpage_owner-fix-refcount-imbalance +47 -10

118 lines not on this page · raw message

_

Patches currently in -mm which might be from [email protected] are

mmpage_owner-fix-refcount-imbalance.patch