From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (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 58DC136F8E6 for ; Mon, 24 Aug 2026 14:47:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787582849; cv=none; b=XRA2mrgc1eGdLO4Sd+AASQOZSL7bUdDAFDMvZRZzK1F0ntGlkayV9MQq2aoiTIWC3EbQxKiFaCezsPHXBG9NvWwH0q+1GkO7LYQ+y1CXo3B5pcPlynEASpNSjkldXaGtTy/Yj3eDhwROA0sw3BnArFMPuRHAKbDprl6DS7azlhM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787582849; c=relaxed/simple; bh=ViLLHeiqDr9S1/zgmlJqAYe2z/6nKsf8TuVaGMbVWp8=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=Tt36R+1vUgaP2LWvrtaz68T6ZXf9f3Im9A9GX1M9drmBK+0HP0RcfPPwecrnKN9+L6d42Yadat79dvSKt9nfqOgBAb4NOFZK7zAqA5DMOzELVGsdypfGXNHWzB5wSz+SlmEqlyC1GSoS57Oj7YEIl/o9ubP/tN5V55aVBw1tpN8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=EukbmAIJ; arc=none smtp.client-ip=209.85.128.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EukbmAIJ" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-81ee6b2da98so49565457b3.3 for ; Mon, 24 Aug 2026 07:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787582847; x=1788187647; darn=vger.kernel.org; h=content-type:mime-version:references:message-id:in-reply-to:subject :cc:to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0ep6UPzJTnZmCqVomVSsdJlCYmmRG8TZidgjUjwtvIo=; b=EukbmAIJamNsedhM9xeGIUSiMYx0kdJ3GJ8Vb+zL6i3L7OhPpWS1/28a3s+4+kIU1Q N7fsyph/8q107NfJzMfv//9pmT2VqByaGZmdYjARLLq2UXB5giDiZkwyoPZ660pgs6JB CM7B1vBxz6wHFMopscgvnbUk/TVHmwqIKPkjYWmLu7ftlZd8/tYC0mdihYoIHdYijx1Z bPsznaWbDeT5taJ3BlBCNxXUoemtlHOOTe1IUoUmbfz8GWmn4D+xFvlYLiUwmiaFHumB leHB00cchwRboyhFGks0ZXW3v6GM5/yIvXqvb49jl4bCy1Q5hFHGq7RIp6GCSVCebuT9 xhIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787582847; x=1788187647; h=content-type:mime-version:references:message-id:in-reply-to:subject :cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0ep6UPzJTnZmCqVomVSsdJlCYmmRG8TZidgjUjwtvIo=; b=lwSXIAGg45tWmseUp4QNsZ1Vb/Oe16zs5T/jbe/b2iDm89LOBpz0WDL8m43Qme+zhB XUt3zjvSpX8LOhoJRGD0GRixdc9vFb7qOgfShWVEF6f5u0bqyvfX99HJ9ThQXOwCfaw0 lIISeL57eN/LqfsX7mgziTd41e6bkoNefc4aIZNX1FfMVSBejRPGli2uv92zqqopQ+co A0Ld6pXqykwTdjHJdjmdAl4HXQ7cs3q71F8pjk6zKX8Y+r29262cN18u4NzwfP31ZQI1 wgIgrub6LfTX/aUxu9GU+pzW016Xdw7UoSTzerrFLRDg0c2FCQRYL9F5bzO1v0jVqcEd 1/Yw== X-Forwarded-Encrypted: i=1; AHgh+RqYxblFfvKvCsTAZU8t/XcGLRAq2db2CZSLYw+ZVjo2tkCTtz2xlzyTNDZmjYMqAVWR9IfVTH57FRmbWPI=@vger.kernel.org X-Gm-Message-State: AFuF++mhZh/8a1gdpqd5drn8AyS6aB7sODQHafAW0IbJOInhYw4a4ru8 b9VkQDpFei9T/M6MSkysrEMdHxMs19lwygJC1xRvpKxwPVznjE0RKoA81J07Sqdp2w== X-Gm-Gg: AR+sD113y5WvD0jGLPhnZnBoIJ7gFLvjeG6zPZifOgh8YUt9PCuVatDcP24x5RGGhby kKhi9AzP3YJq+nzGDz4gcxPBTwndQWkAb4E9PnqjH0BtJdisHBz/78hbepZm8P6cvPn3U0P10lh hc7dZbc14AAXJQCXrz3ankl/9fhCK2/nYFC3R27igsbM2RTxgYAH9pBj3fjt66XEZobdJfjZDAV T3H1MMfWMBnKjHao/lFi/h3Ni88ndM3/nGNyMDQrP9VSlqiTVgagFRVfYe66HjHYgxcMs4ljdgl +8AZGuIBU9GyieekSz4Th2Y1ltQqZJdSFu6ovABD1cXmlfWdE/IVh0+/Nq5pZIVHXZT9NyTCMny q/7ASWHhj/akUqd+7DgZBqHrStWwLsGS+SxLwvpkzwZXAFgHGpypaQBpKJCJLX8rXm5zUr1HWLb 2uRosmGM/5ldJenebjNq+XVOEob84VVNa/7EeseaicMdvY+RMoj3OK2lbM3Di6zuqxd2UY6k3CQ JT/vF6KOC3SX6Smx+8DFambPmVkVfmpJyXeNYfLO3htqsc7 X-Received: by 2002:a05:690c:e013:10b0:7fd:a7b6:8d87 with SMTP id 00721157ae682-849f5a102b1mr80844207b3.25.1787582845685; Mon, 24 Aug 2026 07:47:25 -0700 (PDT) Received: from darker.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 00721157ae682-84caabb9e88sm34369867b3.29.2026.08.24.07.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 07:47:24 -0700 (PDT) Date: Mon, 24 Aug 2026 07:47:20 -0700 (PDT) From: Hugh Dickins To: Andrew Morton cc: Ackerley Tng , Alexander Viro , Baolin Wang , Barry Song , Binbin Wu , Christian Brauner , Christoph Hellwig , Christoph Lameter , Claudio Imbrenda , David Hildenbrand , JP Kobryn , Jan Kara , Jens Axboe , Johannes Weiner , Kairui Song , Kiryl Shutsemau , Lance Yang , Leonardo Bras , Lorenzo Stoakes , Marcelo Tosatti , Matthew Wilcox , Mel Gorman , Miaohe Lin , Michal Hocko , Minchan Kim , Muchun Song , Oscar Salvador , Peter Zijlstra , Qi Zheng , Rik van Riel , Sebastian Andrzej Siewior , Shakeel Butt , Suren Baghdasaryan , Vlastimil Babka , Yang Shi , Yu Zhao , Zach O'Keefe , Zi Yan , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 23/25] fs,mm/fbatch: use invalidate_bh_lrus() not invalidate_bh_lrus_cpu() In-Reply-To: <14a16945-529b-8bc0-ab38-3ea97e54e223@google.com> Message-ID: References: <14a16945-529b-8bc0-ab38-3ea97e54e223@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Whilst there can be a case for including an invalidate_bh_lrus_cpu() in lru_add_drain_all()'s workqueued visits to remote CPUs, wouldn't it now be a preferable cleanup to remove that alternative, and stick with the smp_call_function_many_cond()-based invalidate_bh_lrus() throughout? And fix the UP lru_add_drain_all() to include an invalidate_bh_lrus(), which went missing when 5.15 commit 243418e3925d ("mm: fs: invalidate bh_lrus for only cold path") took that out of lru_add_drain(). Signed-off-by: Hugh Dickins --- fs/buffer.c | 16 +--------------- include/linux/buffer_head.h | 4 ---- mm/folio.c | 25 ++++++------------------- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index ed966fa73b1b..7d114e5b9c62 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -1427,7 +1427,7 @@ static void invalidate_bh_lru(void *arg) put_cpu_var(bh_lrus); } -bool has_bh_in_lru(int cpu, void *dummy) +static bool has_bh_in_lru(int cpu, void *dummy) { struct bh_lru *b = per_cpu_ptr(&bh_lrus, cpu); int i; @@ -1446,20 +1446,6 @@ void invalidate_bh_lrus(void) } EXPORT_SYMBOL_GPL(invalidate_bh_lrus); -/* - * It's called from workqueue context so we need a bh_lru_lock to close - * the race with preemption/irq. - */ -void invalidate_bh_lrus_cpu(void) -{ - struct bh_lru *b; - - bh_lru_lock(); - b = this_cpu_ptr(&bh_lrus); - __invalidate_bh_lrus(b); - bh_lru_unlock(); -} - void folio_set_bh(struct buffer_head *bh, struct folio *folio, unsigned long offset) { diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index fd2c7115c054..f19f9e80be8f 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -518,8 +518,6 @@ bool mmb_has_buffers(struct mapping_metadata_bhs *mmb); void mmb_invalidate(struct mapping_metadata_bhs *mmb); int mmb_sync(struct mapping_metadata_bhs *mmb); void invalidate_bh_lrus(void); -void invalidate_bh_lrus_cpu(void); -bool has_bh_in_lru(int cpu, void *dummy); extern int buffer_heads_over_limit; #else /* CONFIG_BUFFER_HEAD */ @@ -528,8 +526,6 @@ static inline void buffer_init(void) {} static inline bool try_to_free_buffers(struct folio *folio) { return true; } static inline int mmb_sync(struct mapping_metadata_bhs *mmb) { return 0; } static inline void invalidate_bh_lrus(void) {} -static inline void invalidate_bh_lrus_cpu(void) {} -static inline bool has_bh_in_lru(int cpu, void *dummy) { return false; } #define buffer_heads_over_limit 0 #endif /* CONFIG_BUFFER_HEAD */ diff --git a/mm/folio.c b/mm/folio.c index 782b8245d213..3212c7a58623 100644 --- a/mm/folio.c +++ b/mm/folio.c @@ -748,21 +748,6 @@ void lru_add_drain(void) mlock_drain_local(); } -/* - * It's called from per-cpu workqueue context in SMP case so - * lru_add_drain_cpu and invalidate_bh_lrus_cpu should run on - * the same cpu. It shouldn't be a problem in !SMP case since - * the core is only one and the locks will disable preemption. - */ -static void lru_add_and_bh_lrus_drain(void) -{ - local_lock(&cpu_fbatches.lock); - lru_add_drain_cpu(smp_processor_id()); - local_unlock(&cpu_fbatches.lock); - invalidate_bh_lrus_cpu(); - mlock_drain_local(); -} - void lru_add_drain_cpu_zone(struct zone *zone) { local_lock(&cpu_fbatches.lock); @@ -778,7 +763,7 @@ static DEFINE_PER_CPU(struct work_struct, lru_add_drain_work); static void lru_add_drain_per_cpu(struct work_struct *dummy) { - lru_add_and_bh_lrus_drain(); + lru_add_drain(); } static bool cpu_needs_drain(unsigned int cpu) @@ -791,8 +776,7 @@ static bool cpu_needs_drain(unsigned int cpu) folio_batch_count(&fbatches->lru_move_tail) || folio_batch_count(&fbatches->lru_deactivate_file) || folio_batch_count(&fbatches->lru_deactivate) || - need_mlock_drain(cpu)) || - has_bh_in_lru(cpu, NULL); + need_mlock_drain(cpu)); } /* @@ -891,6 +875,8 @@ static inline void __lru_add_drain_all(bool force_all_cpus) } } + invalidate_bh_lrus(); + for_each_cpu(cpu, &has_work) flush_work(&per_cpu(lru_add_drain_work, cpu)); @@ -906,6 +892,7 @@ void lru_add_drain_all(void) void lru_add_drain_all(void) { lru_add_drain(); + invalidate_bh_lrus(); } #endif /* CONFIG_SMP */ @@ -939,7 +926,7 @@ void lru_cache_disable(void) #ifdef CONFIG_SMP __lru_add_drain_all(true); #else - lru_add_and_bh_lrus_drain(); + lru_add_drain_all(); #endif } -- 2.51.0