All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julian Sun <sunjunchao@bytedance.com>
To: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, cgroups@vger.kernel.org, hannes@cmpxchg.org,
	mhocko@kernel.org, roman.gushchin@linux.dev,
	shakeel.butt@linux.dev, muchun.song@linux.dev, axboe@kernel.dk,
	tj@kernel.org
Subject: Re: [PATCH v2] writeback, memcg: skip foreign dirty tracking for bdev inodes
Date: Sat, 5 Sep 2026 19:35:35 +0800	[thread overview]
Message-ID: <00340bf1-a46a-4404-9d38-a5433ca78fbc@bytedance.com> (raw)
In-Reply-To: <j644hkswljrskiivxcimh2ms2zoilfptfhl7bdy6uu3tvqv6yd@m46nuyunp5ni>

On 9/4/26 5:00 PM, Jan Kara wrote:
> On Fri 04-09-26 11:39:23, Julian Sun wrote:
>> On 9/4/26 3:34 AM, Andrew Morton wrote:
>>> On Thu,  3 Sep 2026 16:33:03 +0800 Julian Sun <sunjunchao@bytedance.com> wrote:
>>>
>>>> Foreign dirty flushing handles cases where a dirtied folio's memcg and
>>>> the memcg owning its inode wb differ.
>>>>
>>>> wbc_detach_inode() notes that "concurrent write sharing of an inode is
>>>> expected to be very rare". This expectation does not hold for bdev inodes.
>>>> A bdev inode and mapping are shared by buffered users of the block device,
>>>> while the inode has a single wb owner. On ext4, buffer-cache folios used
>>>> by metadata and journal I/O can therefore be charged to different memcgs
>>>> while sharing the same mapping. Normal bdev activity can thus produce
>>>> frequent folio/wb ownership mismatches.
>>>>
>>>> This was reproduced on cgroup v2 with the memory and I/O controllers
>>>> enabled, using ext4 on a loop device. jbd2 repeatedly generated
>>>> track_foreign_dirty events for bdev folios charged to unrelated memcgs.
>>>> When one of those memcgs entered dirty throttling, the resulting record led
>>>> to a flush_foreign event and queued writeback with reason=foreign_flush for
>>>> the bdev inode's root wb.
>>>>
>>>> Skip foreign dirty tracking when the folio mapping's host inode is on the
>>>> blockdev pseudo superblock. This prevents bdev-originated records from
>>>> triggering later foreign flushes.
>>>>
>>>> The tradeoff is that dirty throttling in the folio's memcg no longer uses
>>>> bdev dirtiness to queue writeback on the bdev inode's owner wb. Those
>>>> folios remain subject to normal writeback. This is preferable because a
>>>> single bdev wb owner does not identify which cgroup is responsible for a
>>>> mapping shared by buffered bdev users. Flushing it can write back data
>>>> unrelated to the throttled memcg. Dirty accounting, normal writeback, and
>>>> foreign dirty tracking for non-bdev inodes remain unchanged.
>>>
>>> When fixing something, please always describe the userspace-visible
>>> runtime effects.
>>
>> Sorry, I overlooked this aspect.
>>>
>>> I'm thinking probably "unnecessary I/O"?  If so, has this been
>>> quantified/measured?  If not, can the effects be guessed about?
>>
>> We suspect that a large amount of prematurely triggered foreign writeback
>> consumes device writeback bandwidth, thereby degrading the performance of
>> the entire writeback path.
>>
>> On one production machine, the total nr_pages of the foreign-flush works was
>> 630,681,285, or about 2.4 TiB, while the machine had only 400 GiB of memory.
>> Although nr_pages does not represent the number of dirty pages that will
>> ultimately be written back, the actual number of pages written back may
>> still be very large because the corresponding wb was continuously
>> accumulating dirty pages.
> 
> As Tejun also wrote, it would be good to really quantify these effects -
> best by demonstrating how this change improved writeback behavior (and we
> are not so much interested in the number of submitted writeback works but
> more in the observed load on the storage or completion of some workload).
> The problem with your solution is that it has its downsided as well
> (possible stalls in dirty throttling) so it should be very clear what are
> we gaining to outweight this risk.
> 
> In principle I agree that a lot of submitted writeback works can degrade
> writeback behavior - a lot of workloads has some set of folios that is
> practically permanently dirty and if you are pushing writeback too much, we
> will be just writing these folios over and over again without useful work
> really done. Also if there's comparably small amount of folios dirty, the
> IO resulting from writeback is generally less efficient. But how severe
> these effects can get in case you describe is not clear...

Thanks for the suggestion. Following your point about repeatedly writing hot
pages, I tested buffered overwrites alongside a concurrent direct-I/O workload.
Skipping bdev tracking reduced actual writes to the overwritten file by 69.6%
and the concurrent workload's completion time by 14.4%.

I also reproduced the downside you described: a metadata-heavy workload
completed 31-33% more slowly with the patch, including final sync. So these
results do not establish that blanket skipping is a net improvement.

I've sent the detailed test setup and results in a separate reply.

https://lore.kernel.org/cgroups/apnYouiUINQR-98e@slm.duckdns.org/T/#mdc87094720abce0162c14cdf8f3d0ab218eea686
> 
> 								Honza

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


  reply	other threads:[~2026-09-05 11:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03  8:33 [PATCH v2] writeback, memcg: skip foreign dirty tracking for bdev inodes Julian Sun
2026-09-03 19:34 ` Andrew Morton
2026-09-04  3:39   ` [External] " Julian Sun
2026-09-04  9:00     ` Jan Kara
2026-09-05 11:35       ` Julian Sun [this message]
2026-09-03 20:29 ` Tejun Heo
2026-09-04  4:34   ` [External] " Julian Sun
2026-09-04  6:36     ` Tejun Heo
2026-09-05 11:31       ` Julian Sun

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=00340bf1-a46a-4404-9d38-a5433ca78fbc@bytedance.com \
    --to=sunjunchao@bytedance.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=jack@suse.cz \
    --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 \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.