From: Julian Sun <sunjunchao@bytedance.com>
To: Tejun Heo <tj@kernel.org>
Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, jack@suse.cz,
muchun.song@linux.dev
Subject: Re: [External] Re: [PATCH v3] memcg: Don't wait writeback completion when release memcg.
Date: Thu, 28 Aug 2025 04:49:22 +0800 [thread overview]
Message-ID: <CAHSKhtcqDfQRf1PAVkkR1mfD7AicfFVELM+Y87vzTMZsjCzTWA@mail.gmail.com> (raw)
In-Reply-To: <aK9VTIQDA8I2vvNi@slm.duckdns.org>
Hi,
On Thu, Aug 28, 2025 at 2:58 AM Tejun Heo <tj@kernel.org> wrote:
>
> Hello,
>
> On Thu, Aug 28, 2025 at 02:13:56AM +0800, Julian Sun wrote:
> > diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h
> > index 2ad261082bba..6c1ed286da6a 100644
> > --- a/include/linux/backing-dev-defs.h
> > +++ b/include/linux/backing-dev-defs.h
> > @@ -65,6 +65,13 @@ struct wb_completion {
> > wait_queue_head_t *waitq;
> > };
> >
> > +static inline void wb_completion_init(struct wb_completion *done,
> > + struct wait_queue_head *waitq)
>
> Indentation.
>
> > +{
> > + atomic_set(&done->cnt, 1);
> > + done->waitq = waitq;
> > +}
> > +
> > #define __WB_COMPLETION_INIT(_waitq) \
> > (struct wb_completion){ .cnt = ATOMIC_INIT(1), .waitq = (_waitq) }
> >
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index 785173aa0739..24e881ce4909 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -157,11 +157,17 @@ struct mem_cgroup_thresholds {
> > */
> > #define MEMCG_CGWB_FRN_CNT 4
> >
> > +struct cgwb_frn_wait {
> > + struct wb_completion done;
> > + struct wait_queue_entry wq_entry;
> > +};
> > +
> > struct memcg_cgwb_frn {
> > u64 bdi_id; /* bdi->id of the foreign inode */
> > int memcg_id; /* memcg->css.id of foreign inode */
> > u64 at; /* jiffies_64 at the time of dirtying */
> > - struct wb_completion done; /* tracks in-flight foreign writebacks */
> > + struct wb_completion *done; /* tracks in-flight foreign writebacks */
> > + struct cgwb_frn_wait *wait; /* used to free resources when release memcg */
>
> Is ->done still needed? Can't it just do frn->wait.done?
>
> > +#ifdef CONFIG_CGROUP_WRITEBACK
> > +static int memcg_cgwb_waitq_callback_fn(struct wait_queue_entry *wq_entry, unsigned int mode,
> > + int flags, void *key)
> > +{
> > + struct cgwb_frn_wait *frn_wait = container_of(wq_entry,
> > + struct cgwb_frn_wait, wq_entry);
> > +
> > + list_del(&wq_entry->entry);
> > + kfree(frn_wait);
> > +
> > + return 0;
> > +}
> > +#endif
>
> Note that the above will be called for all queued waits when any one entry
> triggers. It'd need to check whether done is zero before self-deleting and
> freeing.
Ah, yeah, it does need to. Have sent v4 to fix it, thanks :)
>
> > @@ -3912,8 +3938,18 @@ static void mem_cgroup_css_free(struct cgroup_subsys_state *css)
> > int __maybe_unused i;
> >
> > #ifdef CONFIG_CGROUP_WRITEBACK
> > - for (i = 0; i < MEMCG_CGWB_FRN_CNT; i++)
> > - wb_wait_for_completion(&memcg->cgwb_frn[i].done);
> > + for (i = 0; i < MEMCG_CGWB_FRN_CNT; i++) {
> > + struct memcg_cgwb_frn *frn = &memcg->cgwb_frn[i];
> > +
> > + if (atomic_dec_and_test(&frn->done->cnt))
> > + kfree(frn->wait);
> > + else
> > + /*
> > + * Not necessary to wait for wb completion which might cause task hung,
> > + * only used to free resources. See memcg_cgwb_waitq_callback_fn().
> > + */
> > + __add_wait_queue_entry_tail(frn->done->waitq, &frn->wait->wq_entry);
> > + }
>
> And then, this can probably be simplified to sth like:
>
> __add_wait_queue_entry_tail(...);
> if (atomic_dec_and_test(&frn->done->dnt);
> wake_up_all(waitq);
>
> Thanks.
>
> --
> tejun
--
Julian Sun <sunjunchao@bytedance.com>
prev parent reply other threads:[~2025-08-27 20:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 18:13 [PATCH v3] memcg: Don't wait writeback completion when release memcg Julian Sun
2025-08-27 18:58 ` Tejun Heo
2025-08-27 20:49 ` Julian Sun [this message]
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=CAHSKhtcqDfQRf1PAVkkR1mfD7AicfFVELM+Y87vzTMZsjCzTWA@mail.gmail.com \
--to=sunjunchao@bytedance.com \
--cc=cgroups@vger.kernel.org \
--cc=jack@suse.cz \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=tj@kernel.org \
/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).