From patchwork Mon Aug 26 20:21:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13778383 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 30B01C5321D for ; Mon, 26 Aug 2024 20:21:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA1A76B0085; Mon, 26 Aug 2024 16:21:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B51C36B008A; Mon, 26 Aug 2024 16:21:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A406E6B008C; Mon, 26 Aug 2024 16:21:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 89E3C6B0085 for ; Mon, 26 Aug 2024 16:21:45 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 081A2C137F for ; Mon, 26 Aug 2024 20:21:45 +0000 (UTC) X-FDA: 82495517370.26.227ACE8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id 7C57116001F for ; Mon, 26 Aug 2024 20:21:41 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=IidkViiS; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724703660; a=rsa-sha256; cv=none; b=1gVbNEvZfzVRJcC3eoTwtgdnATTJNMI2g5ygWO4XWxqcnMjKDTM3DCbtyGkXfxfvpHRkgb 7FG4zm6ovdgqUkIaRMf0IVPo0tLfDLl19b5C5Pgh8tJuu/yQGgcuQgYLJnGhxSjCMiSAAN Y5jVQXqjzdn/nN74YBERALZEkafEYdI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=IidkViiS; spf=none (imf08.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724703660; 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:references:dkim-signature; bh=6UktqMB36aQoMRIWISlfX1c0MUx+JUpq42nqRf4TvYk=; b=zJkiJdNOGjgM6R+d0bRr0Ix/M3O/lshugDhyS8ostddfzuAmQzvnjib5f3ABPxFrdW+ZeM DLJ2Izb/oP1+4OmjPhVFdkAUPWG4Y2A4GXFmB+XeUdyVOazhKbg7pMovJfhURDOQsLoPZs pXcm0PNjq7Y3W/CrY1Fd45TTK1U5QeE= 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: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=6UktqMB36aQoMRIWISlfX1c0MUx+JUpq42nqRf4TvYk=; b=IidkViiSJ0/ccwCUjdjL/Nr5q8 G8GYwI/NF7c51TUgcmLAtJMmnfBrB6Yi3XK0cGbSoomDfO2guaERVryDGEQ4Y1s4WLf0TkbAHEMOj m0TWNs7p3f3FiOiokZCWXXfRQ3Z6P0KSwDpqcCDG70Kx0z7aS7jeuwrS/eMm/SoflFNcZFGoBHRAg 0/M4QoDeAG2bVv66V1hgI53ZeIR7E0cJEaJ2qHdaBzNkLH21F6SxFrGijjZhxnos4lu3r+dFaS2sG sp1E1K4TVQAmX3l03zFEbshr0z3jbnS7Po6EdtZkBVb9qrDj9taiF7Et23H0Q1XaQcQNZaxznBUg0 VhfmOnOw==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1sigDb-0000000Fxeu-2s0G; Mon, 26 Aug 2024 20:21:39 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH] swap: Convert swapon() to use a folio Date: Mon, 26 Aug 2024 21:21:35 +0100 Message-ID: <20240826202138.3804238-1-willy@infradead.org> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Stat-Signature: uo3ar75ekizo4zw3mbj55sxr1ump1sa4 X-Rspamd-Queue-Id: 7C57116001F X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724703701-562547 X-HE-Meta: U2FsdGVkX19P/gAv/FyHiikPhXjPVrCLQKgz17vfcwkpabuMw+2Ksosg2oXh5aJEcJ9TDzhlIHi4aZABP01qlm9a2DTLRPrRzJ9Y3xf8MoFKXZiKsom4t5QXFKbrUlSMGDvlAatwyL8jx4x8ebv26zfY+mfxv4RRU35wYsT+wNuA1hy0+IReNcsUIdeHYD31xaSgtZ16Q1pxgM6w2HTb3g0l1qGEcRYDaS6hZseE7lvZCiWmrrFI11o6b8fI+OjfcqEBEU9Fiz3rHDtIEhhZNmvL7eWMf2SH/tl5vIh66ZeGKW6SbDAfFZ4IOWxcvyg2T3wsaWnhsDQzz3PgNvQr/JOm64+xIIsayuh8COpixmggznCvAXCzLDLPLlazuFXNF2Twlya1ewWw+Zd4UrG13DgYX64pENU0W5a78O0cLZjGKVPzh/GBK/FpxsqN5+FN7yBtotAJPpADhe+T8fjRbRPN0CT9+JvH4IqpDKq+sps6C1Z21wj9QEUQLST93qs8Vi5shvIkJ5A73aGgMqQWFgGv+s2KdTca/nMNXVZD9ZjIUKTcx0K1H4bz+TJJuuB4caRLUQkCbC2BM2QntrPWXX9PHVyIsqXUwLoM29S4dq2ipbjAxCVpXR/Ol3bI3npftLWdhmf61MrvAf/oq2uR3FrQCnJYceYStssGERzggBqJvnE6SeC8UjTPAagIsEF/xi0XSnSvaQr2epiT0v4U+oE/F9yI02LNRG8fzsXA7tma+mPGEIuBbZ1KR9j8NgMAZCdx6pLGFeDOWJde1sEHY1f01n5WxldJvzibs29gaT+b5R5jdvYPg65ZqSd+YNimJoXQ9J7DvltGW4gvhfgRGmROgM0WYWUg6E1SNsFhaLiGLbP9I124/UAJIG1DhWJHnjDrLA7uSbKPyelTedHwAUl0Aeud5Mk4Es1QqW9wyaQz6VHTddEAAiTj2SrdEPDV0H64dPZ7xBNvVkp4vca 56vflT/g ebdfR1Xgx6or9/e8duniMP2zZF6k9aNkcqKlaYrRlnUgpRQuYidEc75sLn/hN1n8XeRkfLr6jo7XNIqttH72wSTY/9tds0RzqZOFjTpuKieXA1dtZxxJVzFVsl1vR2Vav8DUFK3WnhT71RfkicKvS/N4H0B7Q4rqpy/iao5FKhqxKlXEUapUOJS9QzpnIFrkk0qTIAEDXseJrGIUfTArm2kFqwQ== 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: Retrieve a folio from the page cache rather than a page. Saves a couple of conversions between page & folio. Signed-off-by: Matthew Wilcox (Oracle) --- mm/swapfile.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 1cfb7c63cdcc..d79376ed504b 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3355,7 +3355,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) unsigned char *swap_map = NULL; unsigned long *zeromap = NULL; struct swap_cluster_info *cluster_info = NULL; - struct page *page = NULL; + struct folio *folio = NULL; struct inode *inode = NULL; bool inced_nr_rotate_swap = false; @@ -3413,12 +3413,12 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) error = -EINVAL; goto bad_swap_unlock_inode; } - page = read_mapping_page(mapping, 0, swap_file); - if (IS_ERR(page)) { - error = PTR_ERR(page); + folio = read_mapping_folio(mapping, 0, swap_file); + if (IS_ERR(folio)) { + error = PTR_ERR(folio); goto bad_swap_unlock_inode; } - swap_header = kmap(page); + swap_header = kmap_local_folio(folio, 0); maxpages = read_swap_header(si, swap_header, inode); if (unlikely(!maxpages)) { @@ -3572,10 +3572,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) if (swap_file) filp_close(swap_file, NULL); out: - if (page && !IS_ERR(page)) { - kunmap(page); - put_page(page); - } + if (!IS_ERR_OR_NULL(folio)) + folio_release_kmap(folio, swap_header); if (name) putname(name); if (inode)