From patchwork Sat Feb 17 02:25:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13561208 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1911FC48260 for ; Sat, 17 Feb 2024 02:26:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F8C76B009E; Fri, 16 Feb 2024 21:25:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D6A8C6B009C; Fri, 16 Feb 2024 21:25:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D4DC6B00A1; Fri, 16 Feb 2024 21:25:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 38B2B6B009F for ; Fri, 16 Feb 2024 21:25:54 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 13BFD140122 for ; Sat, 17 Feb 2024 02:25:54 +0000 (UTC) X-FDA: 81799705428.08.8E506FF Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP id 5F43A80002 for ; Sat, 17 Feb 2024 02:25:51 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LWH6+duI; dmarc=none; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708136751; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+dEHqQtt2ZjC/Vyorv8zVIQOVxePOZ190NejO48fo3g=; b=SUPMe0nz1Du9tnIMToLLCQligzTh8J8IQ/snUByDM1HZdPFeXfcebcoK9X6Mdrz4hcwIdf CtyIBpsLYNcBC/Acajsu5WsD+3iBdaQAu+QBFFxQ3vCrwzCLYkU8wUWFLjiIlofM/biLef rbka/bEsrgo8OuKWXm20Ct6a07kPlJI= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LWH6+duI; dmarc=none; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708136751; a=rsa-sha256; cv=none; b=fYEQvGzU6kwBSFXSfeBaekpXAdnZUBIikM+fhmRUlBcRQXxNk3CKILc6tPvv3BuQQItrHU fT65G0088UEWYb2Ld41z04UWpQmuXS+nIKp1+66ZWsACm8lcRu3mwDl/0D7FYcbbReFP5L QQ10Yl5aIxwOSIbL0M3WUBVqhfDVN2A= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=+dEHqQtt2ZjC/Vyorv8zVIQOVxePOZ190NejO48fo3g=; b=LWH6+duIw2iuCstEZBr1Dm2J6E eto74roIyDFIruVYGMtJPUypuQ3br7LpQR31yt5oB943I21GlOausaMPz1uCrFyYkmCzeLfrdw3CL frOZ6r2Lsfy2CigWJtybTiwUR1tFpilxhEVKFxU9nDdm8NFFkjlqZKAS+fodmRufywq2anfBZvlMZ yhxZykZLoQhbbUvmEQz2lTevaaMLEG3zGwMQiVkr7515xWbIog8SgJEZnbcpXaaZZMHhhshzcuxjD S0tyVy21RZBue2M4lk6XgnNcYccJwgLEvmeA0XACSU+aHhGOvazRl5iTXDCL42W7aF/boHRLqpIyt GG3q2O2g==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbAOj-00000006HED-3bcA; Sat, 17 Feb 2024 02:25:49 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH v2 16/18] mm: Convert free_pages_and_swap_cache() to use folios_put() Date: Sat, 17 Feb 2024 02:25:42 +0000 Message-ID: <20240217022546.1496101-17-willy@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240217022546.1496101-1-willy@infradead.org> References: <20240217022546.1496101-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5F43A80002 X-Stat-Signature: 3s7oyz8p8p4tar7g8yn44ihb1nsfcfy3 X-Rspam-User: X-HE-Tag: 1708136751-39274 X-HE-Meta: U2FsdGVkX1+Tb5y18wvxSTut1oJVOGASzoXkxYcRxbevhqZacjtsOj98qStlHO7I6khf6GJuWmkCB7/+vDBWNBMUn6w3rCLf5c4shVAyACNomvrIdp3vAFHr/eXuhggpK1OfSgPzN1gWZqKmFmzmgdWcu/DjvZhd6YPQkdfC6T8gDOPpoLkyPfLBNfhhsYVkUAq5T1gHGBjMK7b8RtCukQusj/wWgds0Kp5rRtPudXkWx1AATaqMWojS5CTl92zV3Io9dWRpg2zJe74wusq8ufxcTUUatkilELFbeWKVRJv1pFFx5kQVRG573nzi/8wbr7EOV4bF7Wcr8yKCTP6kW+rrEPzKttbKxRxnBY8AeCVmwVR3+gmfnvdMMOnnxHYCJcY6fON7IVkxshDnWeKyBvDfn3EB+eIYj9QWxNPuLS2/rZGo0XkYnoB1hX7F13DkXKUPu9p1Ic5I0kyNql9tboKCH2bmIidvMBj5zFUXhuKuqfi1X5ohUJrtX4bhvNfasm16G2dN1BjkIqycPF1Aw7lsNpt6vQ6JczYd/wVX86OkqrMubFGDoQipmMNRpSHlPO6qeu7CCAu3jxMpjaoFkjRO/qQxkB86kZEo14BZgyV+bp4GcaAOUnbvovsihDtKS1e/tk0IBUnt/oNXTErV5v9IoEUbPPpR4Hi5jPOaoilsQmA+4U54Cvqxh9lS5+DvBVoZ8yhyRBHxwEipXQVU46Aj4B2uYn1tqCYnoDf9lN+6BdW3q25JHFq6Gu0B9QesaEB4ZWbIKavlXg9ub2zADLh3evbbU4UMg54bkQcIuoXJ2M5ihi4Gl9PJJpMmwgNOUWM3EGYByhyIpSLZaEuVT2IABMosd0Zalj0Tp3AHy0DtfdNLp0oev+wA+/ZceEjFvylhd7xSFW3UaPBy2W2Ri5TVdvw7M2EEsr8V0fvb+YMfq4MnpXHRzpU9zH8TaQj3qKs8T/osoH/huHFelKX dfGOr1F+ opFlcBZM0Yp4jM7ou0I2XbHD/Q2sijkaojAvZ+EgUI6A3nE9DiedK1N3kCxY3dfLG2GhI17fXFQUmDwufXITKxrXFtoHsMcp898HndFcFEKvyuE8T0ntQCDlbA9ENjfWi31Jtcv9dkHYTne+rnwQvm3lyWPcNgsOivkyn/zTcy+LjR5Uh+63dIQ40IIwdRctJRdD1zJlbJEgnDWbW937M34Boeg9M9oJKBrc9 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Process the pages in batch-sized quantities instead of all-at-once. Signed-off-by: Matthew Wilcox (Oracle) --- mm/swap_state.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 7255c01a1e4e..f2e07022d763 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -310,10 +311,18 @@ void free_page_and_swap_cache(struct page *page) */ void free_pages_and_swap_cache(struct encoded_page **pages, int nr) { + struct folio_batch folios; + lru_add_drain(); - for (int i = 0; i < nr; i++) - free_swap_cache(encoded_page_ptr(pages[i])); - release_pages(pages, nr); + folio_batch_init(&folios); + for (int i = 0; i < nr; i++) { + struct folio *folio = page_folio(encoded_page_ptr(pages[i])); + free_swap_cache(&folio->page); + if (folio_batch_add(&folios, folio) == 0) + folios_put(&folios); + } + if (folios.nr) + folios_put(&folios); } static inline bool swap_use_vma_readahead(void)