From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from outbound.qs.icloud.com (qs-2006h-snip4-11.eps.apple.com [57.103.85.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1F872D97BB for ; Mon, 20 Jul 2026 05:08:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=57.103.85.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784524095; cv=none; b=IMmOIJqA9iTN5OXnJmnrcVxs/BNqxA+IBtty3emb3CaPeaLH2TJZp7ae7FViQQDEpQtQaLhju9kFJJXr5AhUebCzTKobNVuo7p+ybAZTmvlKiY2aa4MU1+MmhlLqDoLZlbp5vl8To3A0gXRyOqvvsHHJsb7BixjT7nAKC0T0vrk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784524095; c=relaxed/simple; bh=l+BMBCV4bE1SQ4xqKdkiAu5ODtsRbK+KeBkmi8ZvYtM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Nc2KhKytxOXVHWQ67G8EHYrNRC5MLiHFgj1mDw3qBS3b/gIA6wm/4dDYZaPJuakFmm7I3pRy8s01+sK6I8w8X2H9Lxq0ElE1JzFvZU0KSbfoJ4L1Xo0eTrbpjJWMgEaLeFg3i4eM1VjBpnYpir3upHfR1CdtJ06BXnyFE7YuZrE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com; spf=pass smtp.mailfrom=icloud.com; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b=ZH6PEq/n; arc=none smtp.client-ip=57.103.85.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=icloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=icloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=icloud.com header.i=@icloud.com header.b="ZH6PEq/n" Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-60-percent-7 (Postfix) with ESMTPS id BCFAA1800094; Mon, 20 Jul 2026 05:08:09 +0000 (UTC) X-ICL-RepId: 019f7dec-a959-7740-851f-8b0f8f71ecbf X-ICL-Out-Info: HUtFAUMEWwJACUgBTUQeDx5WFlZNRAJCTQhMHVwGXRxCCkEdXgBLVxQEAlodRw5AHVYWWAhOK1sTVRdGCRkIXR0ZHldQXgheH0wcHQ5YBhICWkUBXRcDVxxWRVwYQwldBVccHRxERVsTVRdGCRkIXR0ZCEcfCjADQg5WA0MHRQAtGRxXUF4IXh9MHB0OWAYSHVAcDlEFWwBGCU8BXRoJUwRaEB4ZWwkfFlUNQAUaHQddClVXDw5fAREJHAMJAQlyGVoUXBhTRVEfVEYTGU4bV01QG18CQg8= Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1784524092; x=1787116092; bh=EsyP5irdsQmvLw/lSwMp6yzpUiFqRmMgjYO2e0T/6PY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:x-icloud-hme; b=ZH6PEq/n7EF6ttWD+sQmQGhBz67cZwgnvFO7VlmkFe57n+8Zwmlr5EphsZODxmOl8hYKo/ykWEKipDaqDchQFniG0jB5oHmHDuVH8035kurVuSXwMLJeWrhrVHV6IpOe0GBLB1zu5Yf4E3Z5YC8BuFWkhbvvbu1Qvn7m8jGxW9X7eo8pn07GkBCDPtDIkV5jhnLzKMBK5BJnlJsZGW/38bj5lrVMiO/r/PO6sYlDF81Riw4XhzOZ6HP7cPHAbANaYLBAeJeCCYCHQoppdGsFaxYJGb2Zd0AUSuzo5BaX1beIYuC4XZZGmP8Th0cd4cwIXo5jc0ntSa9OlyvwUUTIXA== Received: from [21.6.122.162] (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-60-percent-7 (Postfix) with ESMTPSA id 30CDB1800153; Mon, 20 Jul 2026 05:08:02 +0000 (UTC) From: Zhang Peng Date: Mon, 20 Jul 2026 13:07:40 +0800 Subject: [PATCH v5 3/5] mm/vmscan: extract pageout_one() from shrink_folio_list() 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260720-batch-tlb-flush-v5-3-db943a0d0d6b@icloud.com> References: <20260720-batch-tlb-flush-v5-0-db943a0d0d6b@icloud.com> In-Reply-To: <20260720-batch-tlb-flush-v5-0-db943a0d0d6b@icloud.com> To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Johannes Weiner , Shakeel Butt , Axel Rasmussen , Yuanchu Xie , Wei Xu , Michal Hocko , Qi Zheng , "Liam R. Howlett" , Qi Zheng Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song , Kairui Song , Zhang Peng X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784524064; l=4293; i=zippermonkey@icloud.com; s=20260309; h=from:subject:message-id; bh=l+BMBCV4bE1SQ4xqKdkiAu5ODtsRbK+KeBkmi8ZvYtM=; b=s9/X+XJmXWZJHCGfES1UArzwc9PYINiT2yqXEOrpNsPIR8ow12vpoftGTs9JFz4tFXW8/BwWh Rdf4e32+7epDNexK7cWPfQxaFy8jTAF1BtJ+voGRpU+DXH6ZElLoy+i X-Developer-Key: i=zippermonkey@icloud.com; a=ed25519; pk=tPCLpFnBfIyHsp0k7eaUTUREEa36bQNW/69X+NS8wBU= X-Proofpoint-GUID: N5T4eMakfuls9gzg2ocoGR5sco53UcYa X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzIwMDA1NCBTYWx0ZWRfXzyk1OZOlY0jB PXGCZLeXDDRdTfmZZb89tH6u6ihldkVUk3XA+9PUHITim49G6I5DisTizDnJt1XQwxfE00KxJQQ NjdVL+1c1HNTLNj+SybrR9M96ixdk+/iKxcyUWKNK5B8ViNSoXmENTqXbjUN3c3eukZ42BQaqw0 R7GOI4ds7bNWKPSoNPFN5jpKCW5AIWAPG55crnVrbs43W6CuBnhKu99QQXtZtit3cFBSZzAEjgB dQGmfGSo41Oena+wmZMQOwGAcygvjBNAL67xefp8/HO2bQEk5/olPI8h6LiPkhoVUTo1VzFX+5B uIktOytflSG50jhLTJB X-Proofpoint-ORIG-GUID: N5T4eMakfuls9gzg2ocoGR5sco53UcYa shrink_folio_list() contains a self-contained pageout() dispatch state machine. Extract it into pageout_one() to reduce the size of shrink_folio_list() and make the pageout step independently readable. No functional change. Signed-off-by: Zhang Peng --- mm/vmscan.c | 104 ++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 42 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index a0807dd01c5a..3e18948e90d1 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1163,8 +1163,65 @@ static bool folio_try_reclaim_free(struct folio *folio, return true; } +static bool folio_try_pageout(struct folio *folio, + struct folio_batch *free_folios, + struct scan_control *sc, struct reclaim_stat *stat, + struct swap_iocb **plug, struct list_head *folio_list, + unsigned int *nr_reclaimed) +{ + struct address_space *mapping = folio_mapping(folio); + unsigned int nr_pages = folio_nr_pages(folio); + + switch (pageout(folio, mapping, plug, folio_list)) { + case PAGE_ACTIVATE: + /* + * If shmem folio is split when writeback to swap, the + * tail pages will make their own pass through this + * function and be accounted then. + */ + if (nr_pages > 1 && !folio_test_large(folio)) + sc->nr_scanned -= (nr_pages - 1); + folio_activate_locked(folio, stat); + folio_unlock(folio); + return false; + case PAGE_KEEP: + folio_unlock(folio); + return false; + case PAGE_SUCCESS: + if (nr_pages > 1 && !folio_test_large(folio)) { + sc->nr_scanned -= (nr_pages - 1); + nr_pages = 1; + } + stat->nr_pageout += nr_pages; + + if (folio_test_writeback(folio)) + return false; + if (folio_test_dirty(folio)) + return false; + + /* + * A synchronous write - probably a ramdisk. Go ahead + * and try to reclaim the folio. + */ + if (!folio_trylock(folio)) + return false; + if (folio_test_dirty(folio) || + folio_test_writeback(folio)) { + folio_unlock(folio); + return false; + } + fallthrough; + case PAGE_CLEAN: + ; /* try to free the folio below */ + } + if (folio_try_reclaim_free(folio, free_folios, sc, stat, nr_reclaimed)) + return true; + folio_unlock(folio); + return false; +} + /* - * shrink_folio_list() returns the number of reclaimed pages + * Reclaimed folios are counted in the return value. */ static unsigned int shrink_folio_list(struct list_head *folio_list, struct pglist_data *pgdat, struct scan_control *sc, @@ -1501,53 +1558,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, goto keep_locked; if (!sc->may_writepage) goto keep_locked; - /* * Folio is dirty. Flush the TLB if a writable entry * potentially exists to avoid CPU writes after I/O * starts and then write it out here. */ try_to_unmap_flush_dirty(); - switch (pageout(folio, mapping, &plug, folio_list)) { - case PAGE_KEEP: - goto keep_locked; - case PAGE_ACTIVATE: - /* - * If shmem folio is split when writeback to swap, - * the tail pages will make their own pass through - * this function and be accounted then. - */ - if (nr_pages > 1 && !folio_test_large(folio)) { - sc->nr_scanned -= (nr_pages - 1); - nr_pages = 1; - } - goto activate_locked; - case PAGE_SUCCESS: - if (nr_pages > 1 && !folio_test_large(folio)) { - sc->nr_scanned -= (nr_pages - 1); - nr_pages = 1; - } - stat->nr_pageout += nr_pages; - - if (folio_test_writeback(folio)) - goto keep; - if (folio_test_dirty(folio)) - goto keep; - - /* - * A synchronous write - probably a ramdisk. Go - * ahead and try to reclaim the folio. - */ - if (!folio_trylock(folio)) - goto keep; - if (folio_test_dirty(folio) || - folio_test_writeback(folio)) - goto keep_locked; - mapping = folio_mapping(folio); - fallthrough; - case PAGE_CLEAN: - ; /* try to free the folio below */ - } + if (!folio_try_pageout(folio, &free_folios, sc, stat, + &plug, folio_list, &nr_reclaimed)) + goto keep; + continue; } if (!folio_try_reclaim_free(folio, &free_folios, sc, stat, -- 2.43.7