Message ID | 20231119194740.94101-4-ryncsn@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1809589vqn; Sun, 19 Nov 2023 11:48:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEm2NjBsjmqy3goMwuEYhWgNM8oqATmttJgZ/KWckgresFtGDSZJmy/kmDXPgUiFrbyKcgu X-Received: by 2002:a17:902:7e83:b0:1cc:4e79:4b38 with SMTP id z3-20020a1709027e8300b001cc4e794b38mr5615322pla.3.1700423308206; Sun, 19 Nov 2023 11:48:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700423308; cv=none; d=google.com; s=arc-20160816; b=kAOmxdZ/n4pkEvhLCI/KG46rhYKBKrZGyi01PjYRurWGtSGuOlLCt7jw4pxy2l99p8 Wvt+unXDQ14Ghg87E1mZfDED+N9OkFbkvufyjcykBEsXX2SdyE35qiTXG8EKboXvwPlo 0MJVr57btNzk2nj7dw/j1sxYcRQM6YeeBUu7OJOIOh4ma6vM47TZQrnR4Pkai5fD/lLA GvzQ9n9qoVXRNSeoS+2KZCd4JkNVUx7OR59u8gPH1R36g7iLd72GJhrmHQ4ad95ljdLA gJA1x47wowEJOgvMNNOZKrRBUfcWSW7viZGDOSZgcqgfi3hh6E7WvtKIfHw/hZu2lMg6 UdFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NgugyapInVThiGa6OPAw9VMpbPbUYFH6tRNCt397cNY=; fh=4HE/piJoUCKuBTCCBiej4//zvvzywHdOLL9QM/KYjYM=; b=coXjqXpK8S0UIv3f0h6ZAzI8F+qQiqFzdrGFtQ2G26xIvfsHy2FoRO+ySfrNY3A8Si vnafpJdsQLrB8HbhZc7EWHzQCrq/DPVEti19W4qVt1VGorCWB8NlncBAdNBrL5jWhX08 ErMlbJtYsnSmQIGQDA+x3wh741y7fzaWHitOMBISs2i0itCWXce1vauA48ZUzrO8XncC ciIFEQhqlnlCqRh0uASFscUlEgSB0RCUTgOhR6ouRTKEhbUz++GIKLpGppi8jHhrTwFT 3/0tYOrWXRQbtZElU8Taa5RSL9dyL5LOpe3d0KsmbqhOlkP3KT1DYb3kZhicEzeuSG2m oFgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GObJgcqd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f8-20020a170902ce8800b001cc550c83d5si6913554plg.515.2023.11.19.11.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 11:48:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GObJgcqd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 6233080A5F93; Sun, 19 Nov 2023 11:48:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231472AbjKSTsU (ORCPT <rfc822;jaysivo@gmail.com> + 29 others); Sun, 19 Nov 2023 14:48:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231493AbjKSTsS (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 19 Nov 2023 14:48:18 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AB84196 for <linux-kernel@vger.kernel.org>; Sun, 19 Nov 2023 11:48:12 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6bd32d1a040so3864878b3a.3 for <linux-kernel@vger.kernel.org>; Sun, 19 Nov 2023 11:48:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700423292; x=1701028092; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=NgugyapInVThiGa6OPAw9VMpbPbUYFH6tRNCt397cNY=; b=GObJgcqdCADqRZUeGgzpzML598kfsRjsx1/ApIwBRkwyRZfv4JTJNzzVMRhEGnYOus AZIRet3CKOI5UCSlWU96VblTv2eoDprSaflA2IPFtEpQBS907win5ArQrJ2GtII08ELF 8Tf7VnsLtZNTyUJo4U0mYdFaQA7K11AgoSzwUjRIo6dq8XcT4Ny9Hn/E1IfhswM0AZ/y d5QLcXh8DgXNbdepUWhVDW+pNPyVPkVn3pYZdS4vySb6TYSwD1kN3nvKoTALAl3UT0fR Nf2IVyLuNlYmS33XSWQCC2cAr9yIrEPYBfB8dejDBsOqsSePzR6Js7Gk/KgfE4dJ6lvw qbcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700423292; x=1701028092; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=NgugyapInVThiGa6OPAw9VMpbPbUYFH6tRNCt397cNY=; b=ns/c3LVNwQPPucnVHnC5CZD5Ik3PBZEoAfA/LI7JONYthWx9wmeQGmOLCI6D/0Ke0P yRvbURQuiWteqxuKROTOdsXMCIXWyba8YYjSaiQitW/UUvdTLEknMKib1QpSnSfcpZsn +kUObfviycudohqu881n9YXMTJIQChyXCIOfZVP2yrC0LOllPNYZhoTOAKEh0NYcsTTs shPTNW0KqUnyHpLoDS6p/tIk+9cPm13eYWpM4jzfUlbmk8wq93RyGR+6uGbvf9aC4ubv GfHrfailACG3KyDJdQt4+M/z60rPjxfknj1viPMOgyUr40E11oBKH0OBjSJJXMnn8Bq7 r9vA== X-Gm-Message-State: AOJu0YyCmEi39P8k0/lAmouc+Tr2deMjjpDWh4yXeGMDolWRjdJND91n JGdMP3aQkeq6gjIWfxTqFHgsFreWPs1kb56R X-Received: by 2002:a05:6a20:e104:b0:18a:181b:146b with SMTP id kr4-20020a056a20e10400b0018a181b146bmr5052162pzb.29.1700423291675; Sun, 19 Nov 2023 11:48:11 -0800 (PST) Received: from KASONG-MB2.tencent.com ([115.171.40.79]) by smtp.gmail.com with ESMTPSA id a6-20020aa78646000000b006cb7feae74fsm1237140pfo.164.2023.11.19.11.48.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 19 Nov 2023 11:48:11 -0800 (PST) From: Kairui Song <ryncsn@gmail.com> To: linux-mm@kvack.org Cc: Andrew Morton <akpm@linux-foundation.org>, "Huang, Ying" <ying.huang@intel.com>, David Hildenbrand <david@redhat.com>, Hugh Dickins <hughd@google.com>, Johannes Weiner <hannes@cmpxchg.org>, Matthew Wilcox <willy@infradead.org>, Michal Hocko <mhocko@suse.com>, linux-kernel@vger.kernel.org, Kairui Song <kasong@tencent.com> Subject: [PATCH 03/24] mm/swap: move no readahead swapin code to a stand alone helper Date: Mon, 20 Nov 2023 03:47:19 +0800 Message-ID: <20231119194740.94101-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231119194740.94101-1-ryncsn@gmail.com> References: <20231119194740.94101-1-ryncsn@gmail.com> Reply-To: Kairui Song <kasong@tencent.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 19 Nov 2023 11:48:27 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783023070747262067 X-GMAIL-MSGID: 1783023070747262067 |
Series |
Swapin path refactor for optimization and bugfix
|
|
Commit Message
Kairui Song
Nov. 19, 2023, 7:47 p.m. UTC
From: Kairui Song <kasong@tencent.com> No feature change, simply move the routine to a standalone function to be used later. The error path handling is copied from the "out_page" label, to make the code change minimized for easier reviewing. Signed-off-by: Kairui Song <kasong@tencent.com> --- mm/memory.c | 33 +++++---------------------------- mm/swap.h | 2 ++ mm/swap_state.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 28 deletions(-)
Comments
On Mon, Nov 20, 2023 at 03:47:19AM +0800, Kairui Song wrote: > + /* skip swapcache and readahead */ > + page = swapin_no_readahead(entry, GFP_HIGHUSER_MOVABLE, > + vmf); > + if (page) > + folio = page_folio(page); I think this should rather be: folio = swapin_no_readahead(entry, GFP_HIGHUSER_MOVABLE, vma); page = &folio->page; and have swapin_no_readahead() work entirely in terms of folios.
Matthew Wilcox <willy@infradead.org> 于2023年11月20日周一 05:00写道: > > On Mon, Nov 20, 2023 at 03:47:19AM +0800, Kairui Song wrote: > > + /* skip swapcache and readahead */ > > + page = swapin_no_readahead(entry, GFP_HIGHUSER_MOVABLE, > > + vmf); > > + if (page) > > + folio = page_folio(page); > > I think this should rather be: > > folio = swapin_no_readahead(entry, > GFP_HIGHUSER_MOVABLE, vma); > page = &folio->page; > > and have swapin_no_readahead() work entirely in terms of folios. > Thanks for the review! Good suggestion, I was actually thinking about converting more swapin function to use folio in later series, since that involved more changes, and this series is getting a bit too long. I'll try to see if I can reorganize the series to cover that too in a sensible way.
Hi Kairui, kernel test robot noticed the following build warnings: https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Kairui-Song/mm-swap-fix-a-potential-undefined-behavior-issue/20231120-035926 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20231119194740.94101-4-ryncsn%40gmail.com patch subject: [PATCH 03/24] mm/swap: move no readahead swapin code to a stand alone helper config: um-randconfig-r081-20231120 (https://download.01.org/0day-ci/archive/20231120/202311201135.iG2KLShW-lkp@intel.com/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce: (https://download.01.org/0day-ci/archive/20231120/202311201135.iG2KLShW-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Reported-by: Dan Carpenter <error27@gmail.com> | Closes: https://lore.kernel.org/r/202311201135.iG2KLShW-lkp@intel.com/ smatch warnings: mm/swap_state.c:881 swapin_no_readahead() warn: use 'gfp_mask' here instead of GFP_KERNEL? vim +/gfp_mask +881 mm/swap_state.c 19f582d2684e47 Kairui Song 2023-11-20 856 /** 19f582d2684e47 Kairui Song 2023-11-20 857 * swapin_no_readahead - swap in pages skipping swap cache and readahead 19f582d2684e47 Kairui Song 2023-11-20 858 * @entry: swap entry of this memory 19f582d2684e47 Kairui Song 2023-11-20 859 * @gfp_mask: memory allocation flags 19f582d2684e47 Kairui Song 2023-11-20 860 * @vmf: fault information 19f582d2684e47 Kairui Song 2023-11-20 861 * 19f582d2684e47 Kairui Song 2023-11-20 862 * Returns the struct page for entry and addr after the swap entry is read 19f582d2684e47 Kairui Song 2023-11-20 863 * in. 19f582d2684e47 Kairui Song 2023-11-20 864 */ 19f582d2684e47 Kairui Song 2023-11-20 865 struct page *swapin_no_readahead(swp_entry_t entry, gfp_t gfp_mask, 19f582d2684e47 Kairui Song 2023-11-20 866 struct vm_fault *vmf) 19f582d2684e47 Kairui Song 2023-11-20 867 { 19f582d2684e47 Kairui Song 2023-11-20 868 struct vm_area_struct *vma = vmf->vma; 19f582d2684e47 Kairui Song 2023-11-20 869 struct page *page = NULL; 19f582d2684e47 Kairui Song 2023-11-20 870 struct folio *folio; 19f582d2684e47 Kairui Song 2023-11-20 871 void *shadow = NULL; 19f582d2684e47 Kairui Song 2023-11-20 872 19f582d2684e47 Kairui Song 2023-11-20 873 folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, 19f582d2684e47 Kairui Song 2023-11-20 874 vma, vmf->address, false); 19f582d2684e47 Kairui Song 2023-11-20 875 if (folio) { 19f582d2684e47 Kairui Song 2023-11-20 876 __folio_set_locked(folio); 19f582d2684e47 Kairui Song 2023-11-20 877 __folio_set_swapbacked(folio); 19f582d2684e47 Kairui Song 2023-11-20 878 19f582d2684e47 Kairui Song 2023-11-20 879 if (mem_cgroup_swapin_charge_folio(folio, 19f582d2684e47 Kairui Song 2023-11-20 880 vma->vm_mm, GFP_KERNEL, s/GFP_KERNEL/gfp_mask/? 19f582d2684e47 Kairui Song 2023-11-20 @881 entry)) { 19f582d2684e47 Kairui Song 2023-11-20 882 folio_unlock(folio); 19f582d2684e47 Kairui Song 2023-11-20 883 folio_put(folio); 19f582d2684e47 Kairui Song 2023-11-20 884 return NULL; 19f582d2684e47 Kairui Song 2023-11-20 885 } 19f582d2684e47 Kairui Song 2023-11-20 886 mem_cgroup_swapin_uncharge_swap(entry); 19f582d2684e47 Kairui Song 2023-11-20 887 19f582d2684e47 Kairui Song 2023-11-20 888 shadow = get_shadow_from_swap_cache(entry); 19f582d2684e47 Kairui Song 2023-11-20 889 if (shadow) 19f582d2684e47 Kairui Song 2023-11-20 890 workingset_refault(folio, shadow); 19f582d2684e47 Kairui Song 2023-11-20 891 19f582d2684e47 Kairui Song 2023-11-20 892 folio_add_lru(folio); 19f582d2684e47 Kairui Song 2023-11-20 893 19f582d2684e47 Kairui Song 2023-11-20 894 /* To provide entry to swap_readpage() */ 19f582d2684e47 Kairui Song 2023-11-20 895 folio->swap = entry; 19f582d2684e47 Kairui Song 2023-11-20 896 page = &folio->page; 19f582d2684e47 Kairui Song 2023-11-20 897 swap_readpage(page, true, NULL); 19f582d2684e47 Kairui Song 2023-11-20 898 folio->private = NULL; 19f582d2684e47 Kairui Song 2023-11-20 899 } 19f582d2684e47 Kairui Song 2023-11-20 900 19f582d2684e47 Kairui Song 2023-11-20 901 return page; 19f582d2684e47 Kairui Song 2023-11-20 902 }
On Sun, Nov 19, 2023 at 11:48 AM Kairui Song <ryncsn@gmail.com> wrote: > > From: Kairui Song <kasong@tencent.com> > > No feature change, simply move the routine to a standalone function to > be used later. The error path handling is copied from the "out_page" > label, to make the code change minimized for easier reviewing. > > Signed-off-by: Kairui Song <kasong@tencent.com> > --- > mm/memory.c | 33 +++++---------------------------- > mm/swap.h | 2 ++ > mm/swap_state.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 55 insertions(+), 28 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 70ffa867b1be..fba4a5229163 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3794,7 +3794,6 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > swp_entry_t entry; > pte_t pte; > vm_fault_t ret = 0; > - void *shadow = NULL; > > if (!pte_unmap_same(vmf)) > goto out; > @@ -3858,33 +3857,11 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > if (!folio) { > if (data_race(si->flags & SWP_SYNCHRONOUS_IO) && > __swap_count(entry) == 1) { > - /* skip swapcache */ > - folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, > - vma, vmf->address, false); > - if (folio) { > - __folio_set_locked(folio); > - __folio_set_swapbacked(folio); > - > - if (mem_cgroup_swapin_charge_folio(folio, > - vma->vm_mm, GFP_KERNEL, > - entry)) { > - ret = VM_FAULT_OOM; > - goto out_page; > - } > - mem_cgroup_swapin_uncharge_swap(entry); > - > - shadow = get_shadow_from_swap_cache(entry); > - if (shadow) > - workingset_refault(folio, shadow); > - > - folio_add_lru(folio); > - page = &folio->page; > - > - /* To provide entry to swap_readpage() */ > - folio->swap = entry; > - swap_readpage(page, true, NULL); > - folio->private = NULL; > - } > + /* skip swapcache and readahead */ > + page = swapin_no_readahead(entry, GFP_HIGHUSER_MOVABLE, > + vmf); A minor point, swapin_no_readahead() is expressed in negative words. Better use positive words to express what the function does rather than what the function does not do. I am terrible at naming functions myself. I can think of something along the lines of: swapin_direct (no cache). swapin_minimal? swapin_entry_only? Please suggest better names for basic, bare minimum. Chris
Chris Li <chrisl@kernel.org> 于2023年11月21日周二 13:35写道: > > On Sun, Nov 19, 2023 at 11:48 AM Kairui Song <ryncsn@gmail.com> wrote: > > > > From: Kairui Song <kasong@tencent.com> > > > > No feature change, simply move the routine to a standalone function to > > be used later. The error path handling is copied from the "out_page" > > label, to make the code change minimized for easier reviewing. > > > > Signed-off-by: Kairui Song <kasong@tencent.com> > > --- > > mm/memory.c | 33 +++++---------------------------- > > mm/swap.h | 2 ++ > > mm/swap_state.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 55 insertions(+), 28 deletions(-) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index 70ffa867b1be..fba4a5229163 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -3794,7 +3794,6 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > swp_entry_t entry; > > pte_t pte; > > vm_fault_t ret = 0; > > - void *shadow = NULL; > > > > if (!pte_unmap_same(vmf)) > > goto out; > > @@ -3858,33 +3857,11 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > if (!folio) { > > if (data_race(si->flags & SWP_SYNCHRONOUS_IO) && > > __swap_count(entry) == 1) { > > - /* skip swapcache */ > > - folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, > > - vma, vmf->address, false); > > - if (folio) { > > - __folio_set_locked(folio); > > - __folio_set_swapbacked(folio); > > - > > - if (mem_cgroup_swapin_charge_folio(folio, > > - vma->vm_mm, GFP_KERNEL, > > - entry)) { > > - ret = VM_FAULT_OOM; > > - goto out_page; > > - } > > - mem_cgroup_swapin_uncharge_swap(entry); > > - > > - shadow = get_shadow_from_swap_cache(entry); > > - if (shadow) > > - workingset_refault(folio, shadow); > > - > > - folio_add_lru(folio); > > - page = &folio->page; > > - > > - /* To provide entry to swap_readpage() */ > > - folio->swap = entry; > > - swap_readpage(page, true, NULL); > > - folio->private = NULL; > > - } > > + /* skip swapcache and readahead */ > > + page = swapin_no_readahead(entry, GFP_HIGHUSER_MOVABLE, > > + vmf); > > A minor point, swapin_no_readahead() is expressed in negative words. > > Better use positive words to express what the function does rather > than what the function does not do. > I am terrible at naming functions myself. I can think of something > along the lines of: > swapin_direct (no cache). > swapin_minimal? > swapin_entry_only? > > Please suggest better names for basic, bare minimum. Thanks for the suggestions, I prefer swapin_direct here, will update with this name and also make it return a folio directly.
diff --git a/mm/memory.c b/mm/memory.c index 70ffa867b1be..fba4a5229163 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3794,7 +3794,6 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) swp_entry_t entry; pte_t pte; vm_fault_t ret = 0; - void *shadow = NULL; if (!pte_unmap_same(vmf)) goto out; @@ -3858,33 +3857,11 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (!folio) { if (data_race(si->flags & SWP_SYNCHRONOUS_IO) && __swap_count(entry) == 1) { - /* skip swapcache */ - folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, - vma, vmf->address, false); - if (folio) { - __folio_set_locked(folio); - __folio_set_swapbacked(folio); - - if (mem_cgroup_swapin_charge_folio(folio, - vma->vm_mm, GFP_KERNEL, - entry)) { - ret = VM_FAULT_OOM; - goto out_page; - } - mem_cgroup_swapin_uncharge_swap(entry); - - shadow = get_shadow_from_swap_cache(entry); - if (shadow) - workingset_refault(folio, shadow); - - folio_add_lru(folio); - page = &folio->page; - - /* To provide entry to swap_readpage() */ - folio->swap = entry; - swap_readpage(page, true, NULL); - folio->private = NULL; - } + /* skip swapcache and readahead */ + page = swapin_no_readahead(entry, GFP_HIGHUSER_MOVABLE, + vmf); + if (page) + folio = page_folio(page); } else { page = swapin_readahead(entry, GFP_HIGHUSER_MOVABLE, vmf); diff --git a/mm/swap.h b/mm/swap.h index 73c332ee4d91..ea4be4791394 100644 --- a/mm/swap.h +++ b/mm/swap.h @@ -56,6 +56,8 @@ struct page *swap_cluster_readahead(swp_entry_t entry, gfp_t flag, struct mempolicy *mpol, pgoff_t ilx); struct page *swapin_readahead(swp_entry_t entry, gfp_t flag, struct vm_fault *vmf); +struct page *swapin_no_readahead(swp_entry_t entry, gfp_t flag, + struct vm_fault *vmf); static inline unsigned int folio_swap_flags(struct folio *folio) { diff --git a/mm/swap_state.c b/mm/swap_state.c index 85d9e5806a6a..ac4fa404eaa7 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -853,6 +853,54 @@ static struct page *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask, return page; } +/** + * swapin_no_readahead - swap in pages skipping swap cache and readahead + * @entry: swap entry of this memory + * @gfp_mask: memory allocation flags + * @vmf: fault information + * + * Returns the struct page for entry and addr after the swap entry is read + * in. + */ +struct page *swapin_no_readahead(swp_entry_t entry, gfp_t gfp_mask, + struct vm_fault *vmf) +{ + struct vm_area_struct *vma = vmf->vma; + struct page *page = NULL; + struct folio *folio; + void *shadow = NULL; + + folio = vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, + vma, vmf->address, false); + if (folio) { + __folio_set_locked(folio); + __folio_set_swapbacked(folio); + + if (mem_cgroup_swapin_charge_folio(folio, + vma->vm_mm, GFP_KERNEL, + entry)) { + folio_unlock(folio); + folio_put(folio); + return NULL; + } + mem_cgroup_swapin_uncharge_swap(entry); + + shadow = get_shadow_from_swap_cache(entry); + if (shadow) + workingset_refault(folio, shadow); + + folio_add_lru(folio); + + /* To provide entry to swap_readpage() */ + folio->swap = entry; + page = &folio->page; + swap_readpage(page, true, NULL); + folio->private = NULL; + } + + return page; +} + /** * swapin_readahead - swap in pages in hope we need them soon * @entry: swap entry of this memory