mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tujinjiang@bytedance.com
To: mhocko@suse.com
Cc: shy828301@gmail.com, akpm@linux-foundation.org,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Jinjiang Tu <tujinjiang@bytedance.com>
Subject: [PATCH v2] vmscan: Do not free nr_deferred for memcg aware shrinkers
Date: Thu, 28 Jul 2022 17:13:41 +0800	[thread overview]
Message-ID: <20220728091341.20820-1-tujinjiang@bytedance.com> (raw)

From: Jinjiang Tu <tujinjiang@bytedance.com>

When a memcg aware shrinker is registered by register_shrinker(),
shrinker->nr_deferred will not be initialized. But when the shrinker
is unregistered by unregister_shrinker(), shrinker->nr_deferred
will be freed.

Luckily, the memcg aware shrinkers in the current kernel are pre-zeroed.
But a new memcg aware shrinker may be added in the future, and we should
not assume the shrinker is pre-zeroed.

Another unregister API free_prealloced_shrinker() does not assume the
shrinker is pre-zered and free shrinker->nr_deferred only if it is
not memcg aware. So unregister_shrinker() should do like
free_prealloced_shrinker().

Signed-off-by: Jinjiang Tu <tujinjiang@bytedance.com>
---
 mm/vmscan.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index f7d9a683e3a7..f8a9a5349b6e 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -675,8 +675,11 @@ void unregister_shrinker(struct shrinker *shrinker)
 	down_write(&shrinker_rwsem);
 	list_del(&shrinker->list);
 	shrinker->flags &= ~SHRINKER_REGISTERED;
-	if (shrinker->flags & SHRINKER_MEMCG_AWARE)
+	if (shrinker->flags & SHRINKER_MEMCG_AWARE) {
 		unregister_memcg_shrinker(shrinker);
+		up_write(&shrinker_rwsem);
+		return;
+	}
 	up_write(&shrinker_rwsem);
 
 	kfree(shrinker->nr_deferred);
-- 
2.17.1


             reply	other threads:[~2022-07-28  9:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-28  9:13 tujinjiang [this message]
2022-07-28 11:43 ` Michal Hocko
2022-07-29  2:11   ` Jinjiang Tu

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=20220728091341.20820-1-tujinjiang@bytedance.com \
    --to=tujinjiang@bytedance.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=shy828301@gmail.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®