cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Julian Sun <sunjunchao@bytedance.com>
To: Tejun Heo <tj@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org,
	linux-mm@kvack.org,  viro@zeniv.linux.org.uk, brauner@kernel.org,
	jack@suse.cz, hannes@cmpxchg.org,  mhocko@kernel.org,
	roman.gushchin@linux.dev, shakeel.butt@linux.dev,
	 muchun.song@linux.dev, axboe@kernel.dk
Subject: Re: [External] Re: [PATCH] memcg: Don't wait writeback completion when release memcg.
Date: Fri, 22 Aug 2025 02:00:10 +0800	[thread overview]
Message-ID: <CAHSKhtdhj-AuApc8yw+wDNNHMRH-XNMVD=8G7Mk_=1o2FQASQg@mail.gmail.com> (raw)
In-Reply-To: <aKdQgIvZcVCJWMXl@slm.duckdns.org>

Hi,

On Fri, Aug 22, 2025 at 12:59 AM Tejun Heo <tj@kernel.org> wrote:
>
> Hello,
>
> On Thu, Aug 21, 2025 at 10:30:30AM +0800, Julian Sun wrote:
> > On Thu, Aug 21, 2025 at 4:58 AM Tejun Heo <tj@kernel.org> wrote:
> > >
> > > On Wed, Aug 20, 2025 at 07:19:40PM +0800, Julian Sun wrote:
> > > > @@ -3912,8 +3921,12 @@ 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 wb_completion *done = memcg->cgwb_frn[i].done;
> > > > +
> > > > +             if (atomic_dec_and_test(&done->cnt))
> > > > +                     kfree(done);
> > > > +     }
> > > >  #endif
> > >
> > > Can't you just remove done? I don't think it's doing anything after your
> > > changes anyway.
> >
> > Thanks for your review.
> >
> > AFAICT done is also used to track free slots in
> > mem_cgroup_track_foreign_dirty_slowpath() and
> > mem_cgroup_flush_foreign(), otherwise we have no method to know which
> > one is free and might flush more than what MEMCG_CGWB_FRN_CNT allow.
> >
> > Am I missing something?
>
> No, I missed that. I don't think we need to add extra mechanisms in wb for
> this tho. How about shifting wb_wait_for_completion() and kfree(memcg) into
> a separate function and punt those to a separate work item? That's going to
> be a small self-contained change in memcg.
>

Do you mean logic like this?

    for (i = 0; i < MEMCG_CGWB_FRN_CNT; i++)
        wb_wait_for_completion(&memcg->cgwb_frn[i].done);
    kfree(memcg);

But there still exist task hang issues as long as
wb_wait_for_completion() exists.
I think the scope of impact of the current changes should be
manageable. I have checked all the other places where wb_queue_work()
is called, and their free_done values are all 0, and I also tested
this patch with the reproducer in [1] with kasan and kmemleak enabled.
The test result looks fine, so this should not have a significant
impact.
What do you think?

[1]: https://lore.kernel.org/all/20190821210235.GN2263813@devbig004.ftw2.facebook.com/
> Thanks.
>
> --
> tejun


Thanks,
-- 
Julian Sun <sunjunchao@bytedance.com>

  reply	other threads:[~2025-08-21 18:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-20 11:19 [PATCH 0/3] memcg, writeback: Don't wait writeback completion Julian Sun
2025-08-20 11:19 ` [PATCH 1/3] writeback: Rename wb_writeback_work->auto_free to free_work Julian Sun
2025-08-20 11:19 ` [PATCH] writeback: Add wb_writeback_work->free_done Julian Sun
2025-08-20 11:19 ` [PATCH] memcg: Don't wait writeback completion when release memcg Julian Sun
2025-08-20 20:58   ` Tejun Heo
2025-08-21  2:30     ` [External] " Julian Sun
2025-08-21 16:59       ` Tejun Heo
2025-08-21 18:00         ` Julian Sun [this message]
2025-08-21 18:16           ` Julian Sun
2025-08-21 19:01           ` Tejun Heo
2025-08-22  8:22             ` Julian Sun
2025-08-22 17:56               ` Tejun Heo
2025-08-23  6:18                 ` Julian Sun
2025-08-23  8:08                   ` Giorgi Tchankvetadze
2025-08-23  8:22                     ` Julian Sun
2025-08-23 14:08                       ` Giorgi Tchankvetadze
2025-08-23 15:17                         ` Julian Sun
2025-08-25 17:45                 ` Julian Sun
2025-08-25 18:53                   ` Tejun Heo
2025-08-25 19:06                     ` Julian Sun
2025-08-25 10:13       ` Jan Kara
2025-08-25 12:08         ` Julian Sun
2025-08-25 18:57         ` [External] " Tejun Heo
2025-08-20 12:16 ` [PATCH 0/3] memcg, writeback: Don't wait writeback completion Giorgi Tchankvetadze
2025-08-21  2:37   ` [External] " Julian Sun
2025-08-22  9:29     ` Giorgi Tchankvetadze

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='CAHSKhtdhj-AuApc8yw+wDNNHMRH-XNMVD=8G7Mk_=1o2FQASQg@mail.gmail.com' \
    --to=sunjunchao@bytedance.com \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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).