From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-2-114.ptr.blmpb.com (va-2-114.ptr.blmpb.com [209.127.231.114]) (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 8271C57C9F for ; Tue, 8 Sep 2026 03:24:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.231.114 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788837878; cv=none; b=YPF/XyfwZ3gcNsxdNkiHG1tWZOzVpSv6I+wEHA/INToVRRgFxRZjL4gCfhPNeX5ud6GByrmHp4wu01jFfLDKFw3q4Gi400oQCzhMKLUHkgdEvAhaCO2+LmLM+1F+6quooMJDCEdDTGqPfBGtEw7hZPMLmwyL9Mo2FiC1KnQZHp4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788837878; c=relaxed/simple; bh=yT+tSgRjiYfs5SQ3x6TOwrKSbFTMyyzh7O4DrLQxvTA=; h=Cc:From:Date:References:Content-Type:Subject:Message-Id: In-Reply-To:To:Mime-Version; b=n8yk45OiIOzasT3v6PbuCkC2t0TdBXxATlgBxpFxw7iBYDJTNVb08u0NJIweL3Au7cVup7EGmwOAWz1Wuj2Bj59zteqg5isM/7/zGgyAL3FfsQGkSc9442lX1NbApoDcyxvHTd9jqu42FAT6evP93sGJ5MatV83v3OEpwcvrqqw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=j/Ah7/gp; arc=none smtp.client-ip=209.127.231.114 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="j/Ah7/gp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1788837872; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=MQ8UTCfaUbpeU5nW9CBGIYMP3Op7scW9OCp3arXnRiA=; b=j/Ah7/gpXkF/LSCivJwhRZlTT062F1Cd2Z0pxP/YKYSFIf1MWgIUyBF4sXSIZBbyVZLZVr cU3Yy8ATZj/fXE2n1InCIaUCK74T4LE6t1kVWTB+E+Ou1jVFizw+eyTcZHTJ71tiUAfzi0 p/lj1dHMfVdfUnKwvi+1wL45VZdlAcVI8HdtYnSWHHi0Z3uO7Iq2BU1fs+zigGeo3ndvES IGZl/o1W0FlcVgUJhdDuC5xApxQP39f19leSJc/ik2JpZuWeHKY/ybsZtnnWNWTniUDNq+ h4t5ki8Ja3ogwDzsZj9xEAfMo4K8NlEoYty4AEcFrs+KE7SaqXwuteQEFANt4A== Cc: "Tejun Heo" , "Jens Axboe" , , , "Xin Yin" From: "Xin Yin" X-Mailer: git-send-email 2.20.1 Date: Tue, 8 Sep 2026 11:23:51 +0800 X-Lms-Return-Path: References: Content-Type: text/plain; charset=UTF-8 Subject: [PATCH v1 1/2] writeback: size foreign flushes by target wb dirty pages Message-Id: In-Reply-To: X-Original-From: Xin Yin To: "Alexander Viro" , "Christian Brauner" , "Jan Kara" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Foreign dirty tracking records the bdi and wb memcg IDs of recently dirtied foreign inodes. When the source memcg needs foreign writeback, mem_cgroup_flush_foreign() queues WB_REASON_FOREIGN_FLUSH to the recorded target bdi_writeback. cgroup_writeback_by_id() currently sizes this best-effort work from the target memcg's NR_FILE_DIRTY counter. The work is scoped to one target wb, so a memcg-wide dirty count can over-size a single-bdi flush when the target memcg has dirty pages on other devices. It can also under-size the flush when the target wb has dirty pages charged to other memcgs. Over-sizing keeps the target wb busy longer and can delay later writeback work. Under-sizing can finish before enough pages are written back for the source memcg. Use the target wb's WB_RECLAIMABLE counter and keep the existing 25% headroom. This keeps the budget aligned with the writeback object being queued. Fixes: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing") Signed-off-by: Xin Yin --- fs/fs-writeback.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 7c75ed7e8979..7c2340a5dead 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1131,7 +1131,7 @@ int cgroup_writeback_by_id(u64 bdi_id, int memcg_id, struct cgroup_subsys_state *memcg_css; struct bdi_writeback *wb; struct wb_writeback_work *work; - unsigned long dirty; + long dirty; int ret; /* lookup bdi and memcg */ @@ -1160,16 +1160,13 @@ int cgroup_writeback_by_id(u64 bdi_id, int memcg_id, } /* - * The caller is attempting to write out most of - * the currently dirty pages. Let's take the current dirty page - * count and inflate it by 25% which should be large enough to - * flush out most dirty pages while avoiding getting livelocked by - * concurrent dirtiers. - * - * BTW the memcg stats are flushed periodically and this is best-effort - * estimation, so some potential error is ok. + * The caller is attempting to write out most of the target wb's + * currently dirty pages. Size the work from the wb's reclaimable pages + * and inflate the count by 25%, which should be large enough to flush + * out most dirty pages while avoiding getting livelocked by concurrent + * dirtiers. */ - dirty = memcg_page_state(mem_cgroup_from_css(memcg_css), NR_FILE_DIRTY); + dirty = wb_stat_sum(wb, WB_RECLAIMABLE); dirty = dirty * 10 / 8; /* issue the writeback work */ -- 2.20.1