From: Dave Chinner via Virtualization <virtualization@lists.linux-foundation.org>
To: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: kvm@vger.kernel.org, djwong@kernel.org, roman.gushchin@linux.dev,
dri-devel@lists.freedesktop.org,
virtualization@lists.linux-foundation.org, linux-mm@kvack.org,
dm-devel@redhat.com, linux-mtd@lists.infradead.org,
cel@kernel.org, x86@kernel.org, steven.price@arm.com,
cluster-devel@redhat.com, xen-devel@lists.xenproject.org,
linux-ext4@vger.kernel.org, paulmck@kernel.org,
linux-arm-msm@vger.kernel.org, linux-nfs@vger.kernel.org,
rcu@vger.kernel.org, linux-bcache@vger.kernel.org,
yujie.liu@intel.com, vbabka@suse.cz, linux-raid@vger.kernel.org,
brauner@kernel.org, tytso@mit.edu, gregkh@linuxfoundation.org,
muchun.song@linux.dev, linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
linux-xfs@vger.kernel.org, senozhatsky@chromium.org,
netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org,
akpm@linux-foundation.org, linux-erofs@lists.ozlabs.org,
linux-btrfs@vger.kernel.org, tkhai@ya.ru
Subject: Re: [PATCH v2 03/47] mm: shrinker: add infrastructure for dynamically allocating shrinker
Date: Wed, 26 Jul 2023 17:26:04 +1000 [thread overview]
Message-ID: <ZMDKjBCZH6+OP5gW@dread.disaster.area> (raw)
In-Reply-To: <20230724094354.90817-4-zhengqi.arch@bytedance.com>
On Mon, Jul 24, 2023 at 05:43:10PM +0800, Qi Zheng wrote:
> Currently, the shrinker instances can be divided into the following three
> types:
>
> a) global shrinker instance statically defined in the kernel, such as
> workingset_shadow_shrinker.
>
> b) global shrinker instance statically defined in the kernel modules, such
> as mmu_shrinker in x86.
>
> c) shrinker instance embedded in other structures.
>
> For case a, the memory of shrinker instance is never freed. For case b,
> the memory of shrinker instance will be freed after synchronize_rcu() when
> the module is unloaded. For case c, the memory of shrinker instance will
> be freed along with the structure it is embedded in.
>
> In preparation for implementing lockless slab shrink, we need to
> dynamically allocate those shrinker instances in case c, then the memory
> can be dynamically freed alone by calling kfree_rcu().
>
> So this commit adds the following new APIs for dynamically allocating
> shrinker, and add a private_data field to struct shrinker to record and
> get the original embedded structure.
>
> 1. shrinker_alloc()
>
> Used to allocate shrinker instance itself and related memory, it will
> return a pointer to the shrinker instance on success and NULL on failure.
>
> 2. shrinker_free_non_registered()
>
> Used to destroy the non-registered shrinker instance.
This is a bit nasty
>
> 3. shrinker_register()
>
> Used to register the shrinker instance, which is same as the current
> register_shrinker_prepared().
>
> 4. shrinker_unregister()
rename this "shrinker_free()" and key the two different freeing
cases on the SHRINKER_REGISTERED bit rather than mostly duplicating
the two.
void shrinker_free(struct shrinker *shrinker)
{
struct dentry *debugfs_entry = NULL;
int debugfs_id;
if (!shrinker)
return;
down_write(&shrinker_rwsem);
if (shrinker->flags & SHRINKER_REGISTERED) {
list_del(&shrinker->list);
debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id);
} else if (IS_ENABLED(CONFIG_SHRINKER_DEBUG)) {
kfree_const(shrinker->name);
}
if (shrinker->flags & SHRINKER_MEMCG_AWARE)
unregister_memcg_shrinker(shrinker);
up_write(&shrinker_rwsem);
if (debugfs_entry)
shrinker_debugfs_remove(debugfs_entry, debugfs_id);
kfree(shrinker->nr_deferred);
kfree(shrinker);
}
EXPORT_SYMBOL_GPL(shrinker_free);
--
Dave Chinner
david@fromorbit.com
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2023-07-26 7:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230724094354.90817-1-zhengqi.arch@bytedance.com>
[not found] ` <20230724094354.90817-4-zhengqi.arch@bytedance.com>
2023-07-24 12:25 ` [PATCH v2 03/47] mm: shrinker: add infrastructure for dynamically allocating shrinker Peter Zijlstra
2023-07-26 7:26 ` Dave Chinner via Virtualization [this message]
[not found] ` <20230724094354.90817-45-zhengqi.arch@bytedance.com>
2023-07-26 8:08 ` [PATCH v2 44/47] mm: shrinker: make global slab shrink lockless Dave Chinner via Virtualization
[not found] ` <19ad6d06-8a14-6102-5eae-2134dc2c5061@bytedance.com>
2023-07-26 23:09 ` Dave Chinner via Virtualization
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=ZMDKjBCZH6+OP5gW@dread.disaster.area \
--to=virtualization@lists.linux-foundation.org \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=cel@kernel.org \
--cc=cluster-devel@redhat.com \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=dm-devel@redhat.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=kvm@vger.kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=muchun.song@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=roman.gushchin@linux.dev \
--cc=senozhatsky@chromium.org \
--cc=steven.price@arm.com \
--cc=tkhai@ya.ru \
--cc=tytso@mit.edu \
--cc=vbabka@suse.cz \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xenproject.org \
--cc=yujie.liu@intel.com \
--cc=zhengqi.arch@bytedance.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;
as well as URLs for NNTP newsgroup(s).