From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from outbound.pv.icloud.com (pv-2002k-snip4-7.eps.apple.com [57.103.64.158]) (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 12A59387566 for ; Mon, 25 May 2026 14:57:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=57.103.64.158 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779721075; cv=none; b=NkFiN+JhcVIEdegp4LxtLJ5xYnhCIOfz8PwVvvX5QhDUAc7FNSoHtHB/N8nmo/VF8XWiQRXKXMWBsAhNnGXlnSsbqHR5j7b35bShaMPGPxXb7+vZJ5WR/79ar3mXbDw/FTk/cMzkQrq8aB/hN6hKpcoY1TRUKObsBTnvLVObSJY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779721075; c=relaxed/simple; bh=HlCDCjaEuUAcWJgatcyXKXkF6++iV8Wx6KA0xfRDRhs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k//+OQFZKtvxSg8r1wXXYNHB30guBZFh+blEu4fjvF5gNS7/x9vhF4RznWRzOq5jWptvQMt2Rs4eALsL1+nRPBdfDTUV7K0DvZv2tKrvSBZXiZNTPP+9EGwpNNGSi18leDXiy2Wz+uKvaiPbXVxRVOTY+wqKBrnxsKJIWoctVDk= 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=O+Et232F; arc=none smtp.client-ip=57.103.64.158 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="O+Et232F" Received: from outbound.pv.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-1a-60-percent-11 (Postfix) with ESMTPS id 0F00A1800123; Mon, 25 May 2026 14:57:48 +0000 (UTC) X-ICL-Out-Info: HUtFAUMEWwJACUgBTUQeDx5WFlZNRAJCTQhMHV8FRQNBF0kFWBcOVk1DEUMdUhlfH1cTVhR3AlEcVg1XQ1QEX1BfHA4EVAddBV1WUAJaS0ATBEoDTV8OXh8EF0YZVQRHHl1WQxsZAlEcVg1XQ1QEX1BJDEFQbFoARxdIHV0ZWW9QXRwOBFQHXQVdVlACWktfGV1FD18HWQRADEoGQFUKRhNRVUcBVUZUHEwLW0BBXx9DFEAAWg9SVkZYGlBdBytbE1UXRgkZCF0dB1hHFEcODxlaFFwYUw== Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; t=1779721073; x=1782313073; bh=TbidOf+0bR1HgAdWvO64+fM8hMyQOeB8vX0q44hvsZ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:x-icloud-hme; b=O+Et232FeSvG9SPqZpwqGP5l1oV6L2Wk9GHBxcCRSeoGcrcUc5i7qR9TSDA4ddVwJ6+PFjZb28YqwGtwv4rv1HT49LeXjefXin6r1e780KU2Y4nlCkmvPooQCJjC7yZo2+F4T+EPR5hFCQXuzzBw63qKZ+PUoaYrSrkUPVuElhbfdUOBVl3eaXNeKShoC25Ur4o5Azpuf79lzMibpe9XeHQ/YLTjvli2dxsa7wiJirGEFLsXzVaywRAB6v7oxhVocjhKJZFhdde52xdkfNiXhcrOm6TodQ0ymtW7tTfH0bL1Z9k+y1UUt8pGBrZOrO3Mtz/fqgXCP79p8BybTtuUSA== Received: from [21.6.122.162] (unknown [17.56.9.36]) by p00-icloudmta-asmtp-us-west-1a-60-percent-11 (Postfix) with ESMTPSA id 777C41800127; Mon, 25 May 2026 14:57:43 +0000 (UTC) From: Zhang Peng Date: Mon, 25 May 2026 22:57:19 +0800 Subject: [PATCH v4 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: <20260525-batch-tlb-flush-v4-3-83789d6abc00@icloud.com> References: <20260525-batch-tlb-flush-v4-0-83789d6abc00@icloud.com> In-Reply-To: <20260525-batch-tlb-flush-v4-0-83789d6abc00@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 , "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=1779721049; l=4366; i=zippermonkey@icloud.com; s=20260309; h=from:subject:message-id; bh=HlCDCjaEuUAcWJgatcyXKXkF6++iV8Wx6KA0xfRDRhs=; b=Uw+ORlKctNuuGP14pbAYK206TM9iJu+9oCMuARY2+Z7D10MVwgGaeBd1zSXLUxlWxK3A3EB49 o0Sbb0yPGDwAeHKWYcuF+IigkB9NzVfY5shrkIF7why2DVBPWPcPXfP X-Developer-Key: i=zippermonkey@icloud.com; a=ed25519; pk=tPCLpFnBfIyHsp0k7eaUTUREEa36bQNW/69X+NS8wBU= X-Proofpoint-ORIG-GUID: 35a--qBcikftPTJwDqqOP0OrrlzpSt02 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTI1MDE1MyBTYWx0ZWRfX5P0N+GhVwVxW d0vE8rWeJ4yTK1X2Uz5/2tl9cC9YQ8ZUysZHSBD/cHqvv2Y7KZDLjcMSzAnRJChUf+GblQhGzLF 9lmBGRRL6A6IhqPoiz9RKbdyhDIL62RcbYIq/nOXcG0BgCSCzA+yKEeK9HkKLIewgFs2gLjvtga EuL/bdl46yYkYTzR/8xlm31pq6d2dwYO5xJwL/0Sh+hQU8Hm1c8UxlvxG9XlTaJ50FCx2Uz+ks9 J0kHZsbEfeRaF7WKLQlZel83EzWjbB9BNGzzRQnaR6IYwCDz5oXPxCqUsvHrk86CIAJMSP5JtUg esp4sWC5nVThaOoiZxKwFdp//5NxX+OcHW41sV/Ep9Unfl0b8heGY7Rc842SDo= X-Authority-Info-Out: v=2.4 cv=N7Yk1m9B c=1 sm=1 tr=0 ts=6a14636e cx=c_apl:c_pps:t_out a=azHRBMxVc17uSn+fyuI/eg==:117 a=azHRBMxVc17uSn+fyuI/eg==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=x7bEGLp0ZPQA:10 a=YE32fvk_ji8A:10 a=VkNPw1HP01LnGYTKEx00:22 a=GvQkQWPkAAAA:8 a=LeMCXtsDaY_ey64dPfEA:9 a=QEXdDO2ut3YA:10 a=J82S1U87d15UFHHUFZS8:22 a=R6HnoDE5lksTgPyyjrIf:22 X-Proofpoint-GUID: 35a--qBcikftPTJwDqqOP0OrrlzpSt02 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 | 107 ++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 42 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index b31f67801836..456d38eb172c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1161,8 +1161,68 @@ static bool folio_free(struct folio *folio, struct folio_batch *free_folios, return true; } +static bool pageout_one(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); + nr_pages = 1; + } + folio_activate_locked(folio, stat, nr_pages); + 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; + } + mapping = folio_mapping(folio); + fallthrough; + case PAGE_CLEAN: + ; /* try to free the folio below */ + } + if (folio_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, @@ -1499,53 +1559,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 (!pageout_one(folio, &free_folios, sc, stat, &plug, + folio_list, &nr_reclaimed)) + goto keep; + continue; } if (!folio_free(folio, &free_folios, sc, stat, &nr_reclaimed)) -- 2.43.7