From patchwork Wed Dec 13 21:58:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13491924 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 42070C4332F for ; Wed, 13 Dec 2023 21:59:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 467C78D0061; Wed, 13 Dec 2023 16:58:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C43C8D0049; Wed, 13 Dec 2023 16:58:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C84B8D0061; Wed, 13 Dec 2023 16:58:55 -0500 (EST) 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 EAD708D0060 for ; Wed, 13 Dec 2023 16:58:54 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BD0CD140271 for ; Wed, 13 Dec 2023 21:58:54 +0000 (UTC) X-FDA: 81563160588.25.BA2B30B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id 233F2160013 for ; Wed, 13 Dec 2023 21:58:52 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=TgdNg8zX; dmarc=none; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702504733; 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=ainsjTNjsZGiXC+tnF20odH8AOu1mlxTdqaBS1jkk5I=; b=iooK+7EYHbiannCmjEs82T3fTuTWCiu5qg5zoajbIwMqvGA9ho0+8H9XMQvInhHb2Ku7jQ AZWSZjOxxMQcFBPBhz0UZKjiS0vicAt6KCB45OdpvIkP64q/J1akNlmfx/gCO704gnG+AX 360oRvGW4YnN4B1SR2CSeq76YzmX3ZY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=TgdNg8zX; dmarc=none; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702504733; a=rsa-sha256; cv=none; b=XIdQQCnooR+0/VcC6iLQ56wyVRHgUanpXp0vgdGVHsPQWdq/X/uzx1PZh0QJNADSr13Nax 6uXsEj1MokpH0Cg6N3SnqAQctEdyKZVm7fIlUtyPBpDrAtL77sV4mqHC7+bgAm151XHera YhovC65afxtBlJshG+7Hk6K6RWwmBnA= 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=ainsjTNjsZGiXC+tnF20odH8AOu1mlxTdqaBS1jkk5I=; b=TgdNg8zXov8va4OwT+d5Rk7Bi0 w2CkHda7s6cSPIv27eQ2SFskFN1/NgmcJTaX/SvaRovvEcFc8sLrYoPcgAiu4sYeWuvqQGNGa2Vyi dboqHi6gcdt9Z1mI8tqS8IjHskaeFrCkxvDQJTfMAzXesowDD/XsJBAQs3C5LQI6y3+PfU0p3CHaA N2VoeAqr7wtOuVIDN2LLCB2uE0nqNrU8r95/7kMMiYkQQM2oOFAYli+Oqa0UiG+oL55ePDQfb9WXx b1AIDfIlwpHPSGAUuCOZuHoMqLqfrKOCuNxTSYQQH5fCyraJIG55uvfMrodPkh0jx0E1iqrfoZ9oM h8pNA8oQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1rDXFe-002oif-5Y; Wed, 13 Dec 2023 21:58:46 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 12/13] mm: Return a folio from read_swap_cache_async() Date: Wed, 13 Dec 2023 21:58:41 +0000 Message-Id: <20231213215842.671461-13-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20231213215842.671461-1-willy@infradead.org> References: <20231213215842.671461-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 233F2160013 X-Stat-Signature: 89m7smnorm1hqkwhuoiw1bcnx6oxtjep X-HE-Tag: 1702504732-496405 X-HE-Meta: U2FsdGVkX18TRyTs934+cckm2irDfdxQe3AWGcr4XBKCuzRvK+ELmjkMinANh+GHwIFoA+GOT2dO6NCc/hMwPAkRBv4+rGVTsnNNoETar43feMXxPyRmIEpf7Q4kG5F2Juc8nOSTehKgm7k6jOBKkGmd6F6BJ3hslbxvJGk9OM0VolpZGTu4qMOADr+gwGB71+HPmh1Ykrd15NezEmav5FHwWarGz/5GArM+CpehyGRTJhnTk2h+DXpWIJPfSvx7OL80QZSeqShaV9W78JQsUJjOeyZpmNTkX899DMFTwWsJTdSM1G9K3e1l2NphV3Vio52s6kdmvQsysoMua4Nx37Suq7NWLq2ip2GhIBbTQNmGw1YoxO/gc5eE4oDs5l49PnDDYRF9p2OcUmlQiHPbwT8pRiEpdw1PFgTRyNpqifGIjIBdIZvxJmjLoFH11F0WI/0dxl7fIsTO69XNyRWmd/bCdklL/ExFMSBL3iJlgs4inVrvlGvJgnMmEjq1MYzWzcJQQTRXS7LtbimSLW1JXS6sBiZgSTGGyEbzaYk6jW2UHTPSaSE9+ePFEJ9/VCW1KtLcBNB3+Bw6JDtcYWeE7VQ+qwa5QXn3Jo51orPmXMyG0vLEfkz9TZiDNOtApTP75WwqE7yJVPdQ4+ptzUtqBdxsTVWZlXyeM0g8+l8aEdoIQ4M5RE9vHu1ElRNcEvGyiybiZauqaVNK+fs8vP8++qkpMkrS1iFoaJqP4XTK4lc0/K1CzRCgVEjm8EJMYEfCGh6GNLLQilwcv7TkSyGIjsgcWC0LJuqmCV4FNPpiteOxWNwVIs91trv/Dz1zie5PDkvm7AgvaVZjgKn29LAlYxMbioEcVzcQThCDRwcoWfNLuv4eDiAfVLQzMmUx7XK5BPzDDZ9bktc52PiJGZqxtKQ3/HDGB8sitn2Vmf2XUF2H05tuNhTSD5Q2liyv/iA3vk1b6h3xTUrjIIpSCHP e3uS7GZd SV6tj6WKKwrv59L3clA6Zix4Cbxhq5XUrxo/torcoApCBKNK+LMuUurueiXpb2FWmQnmzUswH/djTMnmVmbADQq0N0yxJNXTzKxsW+t7KECBtTWhQD9qStxdE10LDSwxi7RtQ85nf2Rf3kGOyJYxNkv4+UpnHP89Tc+VCC0RTQAsnHdk6EmpQFHDZFDVImOxIzHSzGJn/TqAzc3d6PV6ZnjoZ1cvO+rM0Rfib 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: The only two callers simply call put_page() on the page returned, so they're happier calling folio_put(). Saves two calls to compound_head(). Signed-off-by: Matthew Wilcox (Oracle) --- mm/madvise.c | 22 +++++++++++----------- mm/swap.h | 7 +++---- mm/swap_state.c | 8 ++++---- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 6214a1ab5654..912155a94ed5 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -180,7 +180,7 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, for (addr = start; addr < end; addr += PAGE_SIZE) { pte_t pte; swp_entry_t entry; - struct page *page; + struct folio *folio; if (!ptep++) { ptep = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); @@ -198,10 +198,10 @@ static int swapin_walk_pmd_entry(pmd_t *pmd, unsigned long start, pte_unmap_unlock(ptep, ptl); ptep = NULL; - page = read_swap_cache_async(entry, GFP_HIGHUSER_MOVABLE, + folio = read_swap_cache_async(entry, GFP_HIGHUSER_MOVABLE, vma, addr, &splug); - if (page) - put_page(page); + if (folio) + folio_put(folio); } if (ptep) @@ -223,17 +223,17 @@ static void shmem_swapin_range(struct vm_area_struct *vma, { XA_STATE(xas, &mapping->i_pages, linear_page_index(vma, start)); pgoff_t end_index = linear_page_index(vma, end) - 1; - struct page *page; + struct folio *folio; struct swap_iocb *splug = NULL; rcu_read_lock(); - xas_for_each(&xas, page, end_index) { + xas_for_each(&xas, folio, end_index) { unsigned long addr; swp_entry_t entry; - if (!xa_is_value(page)) + if (!xa_is_value(folio)) continue; - entry = radix_to_swp_entry(page); + entry = radix_to_swp_entry(folio); /* There might be swapin error entries in shmem mapping. */ if (non_swap_entry(entry)) continue; @@ -243,10 +243,10 @@ static void shmem_swapin_range(struct vm_area_struct *vma, xas_pause(&xas); rcu_read_unlock(); - page = read_swap_cache_async(entry, mapping_gfp_mask(mapping), + folio = read_swap_cache_async(entry, mapping_gfp_mask(mapping), vma, addr, &splug); - if (page) - put_page(page); + if (folio) + folio_put(folio); rcu_read_lock(); } diff --git a/mm/swap.h b/mm/swap.h index 6bf25342589f..82c68ccb5ab1 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -46,10 +46,9 @@ struct folio *swap_cache_get_folio(swp_entry_t entry, struct folio *filemap_get_incore_folio(struct address_space *mapping, pgoff_t index); -struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, - struct vm_area_struct *vma, - unsigned long addr, - struct swap_iocb **plug); +struct folio *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, + struct vm_area_struct *vma, unsigned long addr, + struct swap_iocb **plug); struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_flags, struct mempolicy *mpol, pgoff_t ilx, bool *new_page_allocated, bool skip_if_exists); diff --git a/mm/swap_state.c b/mm/swap_state.c index efff7148a59d..1cb1d5d0583e 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -542,9 +542,9 @@ struct folio *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, * __read_swap_cache_async() call them and swap_read_folio() holds the * swap cache folio lock. */ -struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, - struct vm_area_struct *vma, - unsigned long addr, struct swap_iocb **plug) +struct folio *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, + struct vm_area_struct *vma, unsigned long addr, + struct swap_iocb **plug) { bool page_allocated; struct mempolicy *mpol; @@ -558,7 +558,7 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, if (page_allocated) swap_read_folio(folio, false, plug); - return folio_file_page(folio, swp_offset(entry)); + return folio; } static unsigned int __swapin_nr_pages(unsigned long prev_offset,