From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f174.google.com (mail-yw1-f174.google.com [209.85.128.174]) (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 7CF0C1990A7 for ; Mon, 24 Aug 2026 14:55:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787583349; cv=none; b=JwyCfDmVXebsDownWGU+6DUVVWuBhqqVF6R0c2aFx/YqqIK1TcnQEfVAE86rlqPXPjoRkNTmbJuF/gMrA2HnJDsaBADVjglh+0a4pFZidRGSdQSE3BBMkvnGf3kz9HFhIo0bot/SzuiK4uVAq/qhbY6iTbX+dQ0FB4A7475af6w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787583349; c=relaxed/simple; bh=knm7pNivTIqFlTYKZzBy1Fjr0y42IVz+KXlnpElvreo=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=TjZUDWffLUFokbYogoqx2ap7nBe8tsufJAYG+mUe8HDYGTwGwSqF8avv/SL/ga4HHfdIFOONr6vhZwmbm9HolMWqQrig5jYWqRzDB8FqK5SeoanvhufVGL84892dyLMQUyfPAgkgyHIqkOqe45bJI9H+Nl+39Rb2+oYZfobAA8o= 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=I8hsbrbg; arc=none smtp.client-ip=209.85.128.174 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="I8hsbrbg" Received: by mail-yw1-f174.google.com with SMTP id 00721157ae682-836c4474028so41618107b3.0 for ; Mon, 24 Aug 2026 07:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787583345; x=1788188145; 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=z3p4N+WdGfy0YyEKXl3GFU0ih7nRgZs+zJqtEvKEyhU=; b=I8hsbrbgAAmY8zEWm6yN3s2tydzvsexhIsqS5axTXsiPjqZmWrBrbpgjRxjYJpheHi b3jZUbaSx0pQ3NmciCmGaU96IjLJ57GGaXomC/QKP5lRWFyjLDW1qG+tVUNOUL3EuWHy CN5Lm+JdOkUPVIh1f2HjYc2+qFYEHBid6+g+U26B0lkzdpXtANpROwewBL/0e84hP4fY M6xWKtW/XPxD+5b5ZBiLqutnvdEpeMupUPgolBhU6i6ZDn5+Xhs1SlKB7enTEzX6EQVm qmmhXH5Wg9zhzCBiBnd9oVbZFZ7vedAoP0D+xs2YsZIcWnYZudWtldo0Xe7Btrfe6Arb UoJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787583345; x=1788188145; 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=z3p4N+WdGfy0YyEKXl3GFU0ih7nRgZs+zJqtEvKEyhU=; b=KfqTil2LgqSydy6uWOWPK9YUkf+ohkfmmvNhk2z+BApzxbkYLNIb6rh/v8J8j3fGJt ndNdoay5wAM85KoS7UHM2wPryDOrp5fuKEkyQJFmkY3vuib/LGnExDSZLt0SB4i+X17d es24ApQzBYeE3mMBlBIk+BWYcV5LoTjUdARcTbd+X1lHJXqWV0cnYvUvU/CuZJL5LD9j URPWj8KU/lz7hazZilY74s0PFv90c96D0Xzrjp0lmehm55+PH1HrqHeUYj4WeK955cNn 8xumpocqFYhbqYKfCLm2yKmROTod7c9jSlDRcXwCqnRHWwQ6iObzwZUcLpixlppyFaFV K2gw== X-Forwarded-Encrypted: i=1; AHgh+RqsidVBR3lM56OMRABcjsV5AJ6m/YF3MJLTWgQwvenjb2uwE0H+sHmlKaylDTjT0Wz0REjjvD3zGrYoPXc=@vger.kernel.org X-Gm-Message-State: AFuF++k/V9u7yQ9wbIxuomnmejvMGnfo/WHoVFGBCaMXhi590hUT25Gy 3WtsvxjchCEV7Yb/xFPqPnr4VoIzGM2S35uar/DJ39bza4gIKaYKipnx9uTt0PsASA== X-Gm-Gg: AR+sD11oMAJCADI//J4/67Ao0VeEqxLFY+QoP/cppyzeqi/l8qNuttjBJJaMVa4Qd2R VBI0+kLaaqWXVaFampOngLRmwXcKr+qbFn691G4j1dYuJ6g6hDM3eyTcF8J7SjrSe3BWSWDvE6e 0NuETJ5/a12BCKhpVX1qDNV67icGM3e2zGCjJ43X4jBRNdUrWA0Jr85MKQMVtiyH+ppjwmdDYEI PQibK9klln3s+dUp/3hOSce7M0Q7sOD8lYFXQDD36XUC0JNo0lhJTsNaZydvPLajRCJN/JLap31 0/6rs9hBHB//clv6ZXIhI5ANPWsRM61NDUR3Vy0+cxrZbkUeExkt0kv6dK9TR/TucSxrDh0nGCI SR3qgYuqgSUaNB1z/vJ1iEZgVo/nAfyMROe6CshTQZZspr2PqXHjQhe1GgQDCesrbk5DNEUL48N MBq+TkCJHHorp61YJ3TQXYsvdGmtcq+Km2KdEZpIwrdF9VEiKTlwG8zX3jIgvu+23fVVa+4Y7+R 1UJIrax3g0Yhi69OJRI380e9hu44xbu6uovhUx3OKR+Dgbh X-Received: by 2002:a05:690c:b96:b0:845:ddf4:a399 with SMTP id 00721157ae682-849f3007b00mr110178637b3.11.1787583344519; Mon, 24 Aug 2026 07:55:44 -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-84ca5c2c52csm35086077b3.11.2026.08.24.07.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 07:55:43 -0700 (PDT) Date: Mon, 24 Aug 2026 07:55:39 -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 alt 13/25] mm/fbatch: no lru_add_drain() to collect_longterm_unpinnable_folios() In-Reply-To: Message-ID: <333bb765-a36d-e07e-d3c4-5ea2f1cadfcb@google.com> 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 collect_longterm_unpinnable_folios() has no use for lru_add_drain() nor lru_add_drain_all(), now that the per-cpu fbatch references are gone. So remove the recently added lru_cache_drain_for_folio(). Signed-off-by: Hugh Dickins --- Alternate version for use once David Hildenbrand's two commits here have been pulled from mm.git into linux.git for 7.3-rc1. include/linux/swap.h | 8 -------- mm/folio.c | 46 -------------------------------------------- mm/gup.c | 9 --------- 3 files changed, 63 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 17c60956c553..ecb877fe61ed 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -302,14 +302,6 @@ static inline void folio_add_lru(struct folio *folio) void folio_mark_accessed(struct folio *folio); void lru_add_drain_all(void); -enum lru_cache_drained { - LRU_CACHE_NOT_DRAINED, - LRU_CACHE_DRAINED, - LRU_CACHE_DRAINED_ALL, -}; -void lru_cache_drain_for_folio(const struct folio *folio, - unsigned int extra_refs, enum lru_cache_drained *drained); - /* linux/mm/folio-compat.c */ void mark_page_accessed(struct page *page); diff --git a/mm/folio.c b/mm/folio.c index 1c03b44362c1..7b309059b302 100644 --- a/mm/folio.c +++ b/mm/folio.c @@ -842,52 +842,6 @@ void lru_add_drain_all(void) } #endif /* CONFIG_SMP */ -/** - * lru_cache_drain_for_folio() - drain LRU caches if the caches might hold - * folio references - * @folio: The folio. - * @extra_refs: Extra folio references held by the caller. - * @drained: Drain status for batch folio processing. - * - * Drain LRU caches if the caches might hold folio references. Start - * with a local LRU cache drain, to then drain LRU caches on all CPUs if - * local draining was insufficient. - * - * This function detects LRU cache references by comparing the folio refcount - * with the sum of the expected folio refcount + extra references held by the - * caller. Note that we cannot rely on PG_lru to reliably detect all LRU - * cache references, and there are rare scenarios (concurrent folio (un)mapping) - * where this function might miss detecting LRU cache references. - * - * If @drained is not NULL, the function will avoid re-draining LRU caches - * when processing multiple folios in a row. In that case, the variable - * @drained points at must be initialized to LRU_CACHE_NOT_DRAINED before - * the first invocation by the caller. - */ -void lru_cache_drain_for_folio(const struct folio *folio, - unsigned int extra_refs, enum lru_cache_drained *drained) -{ - if (!folio_may_be_lru_cached(folio)) - return; - - if (!drained || *drained == LRU_CACHE_NOT_DRAINED) { - if (folio_ref_count(folio) == - folio_expected_ref_count(folio) + extra_refs) - return; - lru_add_drain(); - if (drained) - *drained = LRU_CACHE_DRAINED; - } - if (!drained || *drained == LRU_CACHE_DRAINED) { - if (folio_ref_count(folio) == - folio_expected_ref_count(folio) + extra_refs) - return; - lru_add_drain_all(); - if (drained) - *drained = LRU_CACHE_DRAINED_ALL; - } -} - atomic_t lru_disable_count = ATOMIC_INIT(0); /* diff --git a/mm/gup.c b/mm/gup.c index 98fdf7b7baca..e87a77dacdb6 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2273,14 +2273,12 @@ static unsigned long collect_longterm_unpinnable_folios( struct list_head *movable_folio_list, struct pages_or_folios *pofs) { - enum lru_cache_drained drained = LRU_CACHE_NOT_DRAINED; unsigned long collected = 0; struct folio *folio; long i = 0; for (folio = pofs_get_folio(pofs, i); folio; folio = pofs_next_folio(folio, pofs, &i)) { - const int pin_refs = folio_has_pincount(folio) ? 1 : GUP_PIN_COUNTING_BIAS; if (folio_is_longterm_pinnable(folio)) continue; @@ -2295,13 +2293,6 @@ static unsigned long collect_longterm_unpinnable_folios( continue; } - /* - * We drain not only to make the folio_isolate_lru() succeed, - * but also to remove any other folio references from LRU - * caches. - */ - lru_cache_drain_for_folio(folio, pin_refs, &drained); - if (!folio_isolate_lru(folio)) continue;