From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35B253537FB for ; Thu, 9 Apr 2026 02:36:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775702185; cv=none; b=O978B6jQRiNRvj2HrMve2O8CMu8JDXS9JhV9qnh4DWvo+cXl9IdG3zuMSz4ixW/OvcZs/RoKxp5NMls8aurxc7GQX/SY+t6ihOWPKmkyknPxFqwN5rsszb+2lyvQoaHx9LoAwuvD37ezkDQLFZiYIjT5ZvEXpwNzs9+pLqDmTUw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775702185; c=relaxed/simple; bh=mUgJ9gNC6/kJyF4YcWw2rC9fYFif+peaopsPceIy5Rs=; h=From:To:Cc:Subject:In-Reply-To:Date:Message-ID:References: MIME-version:Content-type; b=c5OPdCHF6+6KnGguJSZ/MaIPGH3TiETfGErj6IsrYgmxOPxnVtJhFEyW5JP8P4S5U9YYxH6dOzDK+S2i0CoOqH65F2ZXp7V8DfkuTUWS8UWzaNNGtK5CLLzRPV34u85+I5+X1CCpDZj+D7f4xy3IQ/Yp4iwirPWg1tMHAJvX1mQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LjHZ26V0; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LjHZ26V0" Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-c6e2355739dso180285a12.2 for ; Wed, 08 Apr 2026 19:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775702182; x=1776306982; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:message-id:date :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Lw0Tv+5NbELb9GtHhwh2AbG2K6I+ORA+QMsewcCrAeQ=; b=LjHZ26V0Z9gwhWZ+npXQIXVU2vn95J6nMqUzeZXTEfJW3bb8ae2i5aKEXXagoADy/p 21s7LChSsYZ7pDlELzCtWoXeDf36VzSv6rsFx2vbewCg2t0z4KRWvA9u2sjVwGlnAv2M t8RVdviR26ly/adBMUkJ3h0W4xpqgBH5OcUPvOSrgT0whCqgPZ1BnDvnTO3lqqaecD/Q bt3y2oxWPB7zI2d+R3S8OWD0gt+U1Bd/Ks0E0CRHdpIukwsEs6xzrEuNAFxCLnojRLQV N+Xbkd7oW7L8RKambGDq6gEZzIJ2L8sOjfxCXf5RRSk8edhkFvnRPAk7oukVhmes7uLk JPOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775702182; x=1776306982; h=content-transfer-encoding:mime-version:references:message-id:date :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Lw0Tv+5NbELb9GtHhwh2AbG2K6I+ORA+QMsewcCrAeQ=; b=XvAJquP20AqbKNBQfzcmpxlb3mTasUGcbKIkxC13u+5lSI61oGoLqBl//Ip2Fxp+xY gz5j7qtPsYD+XdWIS0nN7qdiCSGAF6Qrp8GuTYOdmVHi+q/flDyk2Va6OTdVzm2Yn/XM Ym0EkiRZlNuF2yIX49KwTLCkZzOO67VzabsU5IRbTe9J6DJrUbyBnfwfon28GO22niw/ he4hOwytK3JFZqwfuYS2bti/Wd+ZblJ/dIrIULNq8W8mLu224TLIz7JVk0cQKh18qF5f 1FfdctHWAt20bfWBOZpEGLrLFmTz6UxqQAEmFgDArVw5E4PwUKxKD8ofWjFM3ysFK2b0 kigA== X-Gm-Message-State: AOJu0YxAthfkUGQOBksjexySRIwAA/15awpYFlVd8OvpDX3FLzb2S8C0 coe273SRuih/HinJshMrui5PL9Ur8ZGj1z44hZ0gWfmbLOlf9AxEHiD5 X-Gm-Gg: AeBDieuuugZM/epI55Y641HjOc7UC/xk6O2wNhg80XzX/wXnFpuIqtwfoCIwLWsX4fa mX1wG54Bdhn6R6eEO0w4KOe1Cfa2JyUqab+/vtG7hdZLCznGewIG3OjqRYh4OFnuBvSx1CUeI3J x3SXqhzCjRMMXPQ0i0EiKcn+9QwlTExqIpJ5oRE2zKziLDiw4Qxkm0fkbTjASP/Yvu7wwSFp6ap Uh0ymrp8lXCM1RflXNAqGDJcuX8ZNgE9C+Ou+Pt8UnihjLL0b8+lUcN02BtHhmEbFcIQsnExBw9 rJLYF0O1h8S01EwitFaDyNOO4+0752OnMBSxNOGzT92HM9bKnnoDtEYtfZC7i72m7eMp+LE30eD FjzOkkzfX/rxrm8Y3M3zypIe90gRXzTccG0wqKF3/GV/1owuTgXrq2xLB+IIwv3KR02yfUEohyZ 3P4Og/YONC6Svn4f78CfOxFRpLtYXnW2Qc X-Received: by 2002:a17:903:238b:b0:2ad:d0ff:2ed4 with SMTP id d9443c01a7336-2b28164c3d7mr267295685ad.6.1775702182377; Wed, 08 Apr 2026 19:36:22 -0700 (PDT) Received: from pve-server ([49.205.216.49]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b2749ce29esm233858135ad.81.2026.04.08.19.36.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 19:36:21 -0700 (PDT) From: Ritesh Harjani (IBM) To: Jeff Layton , Alexander Viro , Christian Brauner , Jan Kara , "Matthew Wilcox (Oracle)" , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Mike Snitzer , Jens Axboe , Chuck Lever Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, Jeff Layton Subject: Re: [PATCH v2 1/3] mm: kick writeback flusher instead of inline flush for IOCB_DONTCACHE In-Reply-To: <20260408-dontcache-v2-1-948dec1e756b@kernel.org> Date: Thu, 09 Apr 2026 07:10:32 +0530 Message-ID: References: <20260408-dontcache-v2-0-948dec1e756b@kernel.org> <20260408-dontcache-v2-1-948dec1e756b@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Jeff Layton writes: > The IOCB_DONTCACHE writeback path in generic_write_sync() calls > filemap_flush_range() on every write, submitting writeback inline in > the writer's context. Perf lock contention profiling shows the > performance problem is not lock contention but the writeback submission > work itself — walking the page tree and submitting I/O blocks the > writer for milliseconds, inflating p99.9 latency from 23ms (buffered) > to 93ms (dontcache). > > Replace the inline filemap_flush_range() call with a > wakeup_flusher_threads_bdi() call that kicks the BDI's flusher thread > to drain dirty pages in the background. This moves writeback > submission completely off the writer's hot path. The flusher thread > handles writeback asynchronously, naturally coalescing and rate-limiting > I/O without any explicit skip-if-busy or dirty pressure checks. > Thanks Jeff for explaining this. It make sense now. > Add WB_REASON_DONTCACHE as a new writeback reason for tracing > visibility. > > Signed-off-by: Jeff Layton > --- > fs/fs-writeback.c | 14 ++++++++++++++ > include/linux/backing-dev-defs.h | 1 + > include/linux/fs.h | 6 ++---- > include/trace/events/writeback.h | 3 ++- > 4 files changed, 19 insertions(+), 5 deletions(-) > > diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c > index 3c75ee025bda..88dc31388a31 100644 > --- a/fs/fs-writeback.c > +++ b/fs/fs-writeback.c > @@ -2466,6 +2466,20 @@ void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi, > rcu_read_unlock(); > } > > +/** > + * filemap_dontcache_kick_writeback - kick flusher for IOCB_DONTCACHE writes > + * @mapping: address_space that was just written to > + * > + * Wake the BDI flusher thread to start writeback of dirty pages in the > + * background. > + */ > +void filemap_dontcache_kick_writeback(struct address_space *mapping) This api gives a wrong sense that we are kicking writeback to write dirty pages which belongs to only this inode's address space mapping. But instead we are starting wb for everything on the respective bdi. So instead why not just export symbol for wakeup_flusher_threads_bdi() and use it instead? If not, then IMO at least making it... filemap_kick_writeback_all(mapping, enum wb_reason) ... might be better. > +{ > + wakeup_flusher_threads_bdi(inode_to_bdi(mapping->host), > + WB_REASON_DONTCACHE); > +} > +EXPORT_SYMBOL(filemap_dontcache_kick_writeback); > + > /* > * Wakeup the flusher threads to start writeback of all currently dirty pages > */ > diff --git a/include/linux/backing-dev-defs.h b/include/linux/backing-dev-defs.h > index c88fd4d37d1f..4a81c90a8928 100644 > --- a/include/linux/backing-dev-defs.h > +++ b/include/linux/backing-dev-defs.h > @@ -55,6 +55,7 @@ enum wb_reason { > */ > WB_REASON_FORKER_THREAD, > WB_REASON_FOREIGN_FLUSH, > + WB_REASON_DONTCACHE, > > WB_REASON_MAX, > }; > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 8b3dd145b25e..2fd36608ac73 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2610,6 +2610,7 @@ extern int __must_check file_write_and_wait_range(struct file *file, > loff_t start, loff_t end); > int filemap_flush_range(struct address_space *mapping, loff_t start, > loff_t end); > +void filemap_dontcache_kick_writeback(struct address_space *mapping); > > static inline int file_write_and_wait(struct file *file) > { > @@ -2643,10 +2644,7 @@ static inline ssize_t generic_write_sync(struct kiocb *iocb, ssize_t count) > if (ret) > return ret; > } else if (iocb->ki_flags & IOCB_DONTCACHE) { > - struct address_space *mapping = iocb->ki_filp->f_mapping; > - > - filemap_flush_range(mapping, iocb->ki_pos - count, > - iocb->ki_pos - 1); > + filemap_dontcache_kick_writeback(iocb->ki_filp->f_mapping); > } > > return count; > diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h > index 4d3d8c8f3a1b..9727af542699 100644 > --- a/include/trace/events/writeback.h > +++ b/include/trace/events/writeback.h > @@ -44,7 +44,8 @@ > EM( WB_REASON_PERIODIC, "periodic") \ > EM( WB_REASON_FS_FREE_SPACE, "fs_free_space") \ > EM( WB_REASON_FORKER_THREAD, "forker_thread") \ > - EMe(WB_REASON_FOREIGN_FLUSH, "foreign_flush") > + EM( WB_REASON_FOREIGN_FLUSH, "foreign_flush") \ > + EMe(WB_REASON_DONTCACHE, "dontcache") > > WB_WORK_REASON > > > -- > 2.53.0