From patchwork Fri May 31 08:12:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13681305 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 3C3FCC27C44 for ; Fri, 31 May 2024 08:13:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4E606B0092; Fri, 31 May 2024 04:13:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFD8C6B0093; Fri, 31 May 2024 04:13:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 977B16B0095; Fri, 31 May 2024 04:13:06 -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 76E3D6B0092 for ; Fri, 31 May 2024 04:13:06 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 312241C064D for ; Fri, 31 May 2024 08:13:06 +0000 (UTC) X-FDA: 82177975572.06.89923A8 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by imf18.hostedemail.com (Postfix) with ESMTP id 0B6B11C0002 for ; Fri, 31 May 2024 08:13:03 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=fJMqoplf; spf=pass (imf18.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.10 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717143184; 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=wM3YFGw8/QOMhZCJh1DgDX16jiZffFXk1nhrBF8PuCA=; b=OzlBYgW2rVhlSeATeOeG3RQoiGf7DXwIyDxvapPDpXcka3ZDgPl+8IJiQ/66q+Uk4Gx85D OtYGQv4Pj7YEDI4JzoYiSVCGpx7lP30upXqvyTJyZxmWJyeTx0pzP1XtzNG6ZLV5Q+1IKY VC8fckWaoKFtI1VJAxmJmUvfdOUR39U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717143184; a=rsa-sha256; cv=none; b=Y5x2+hiGIZy2gcbr8GXckZIGGd2TurH8JuSuRWNLVfPVOYj/uY/odBzFhSx9c40rJvIRz6 FwmX31iSrXcfWXyzmhRqQ7aBAA7XjACsXVIAFv3UhffUlA2WWQloDqH7u+VRzjUpJjZRaV dfXYED9GItwAj6xn63xtEsULUFosI58= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=fJMqoplf; spf=pass (imf18.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.10 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717143184; x=1748679184; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DJJ27LGVAKyFkd3DhLbHS54xSb3Z7Ev5IjhsRkqv+7A=; b=fJMqoplfzShj4bhcxBehWuDO8KnCqnXDPK1se6e354obd2sMyeCSy+yK JvZ1Sn1yqQXHAE+Ej9T0YuF9JhQMGfu7YLGpaGU7HtLyTrmL6YugN3I3T O82Bz+eELkmiHejpDSNJJv2j1u7X29sZ04vjrx/usvEhSfksh1wpwQSYC 8IgBdBctcL4+hJ3Qu5E7i4PY1JD4OPyBf1+CPA9mvoisdjC07RAiJ8tQZ mD5q1PBQJSXCKk5w6X9h0e6e7hjTpGbqwZ0XSQ21iGszR0+c+LzL97P7h nK5GmeOxHW2vxOFVzDSa6+Zzy0nrtJkVSEtFd0h68EQmKhqwx4jzkINGi A==; X-CSE-ConnectionGUID: H8goqFCYTY6dAB01RRecDw== X-CSE-MsgGUID: UbHwUsGCSLi/0WFzy55z9A== X-IronPort-AV: E=McAfee;i="6600,9927,11088"; a="25079763" X-IronPort-AV: E=Sophos;i="6.08,203,1712646000"; d="scan'208";a="25079763" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2024 01:13:03 -0700 X-CSE-ConnectionGUID: Aoj6Nli8Q8y4dEyZsXEN8g== X-CSE-MsgGUID: OoElfOprR362hwmdpIgRUw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,203,1712646000"; d="scan'208";a="59270947" Received: from unknown (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.30.35]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2024 01:12:59 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Hugh Dickins , Alistair Popple , Anshuman Khandual , David Hildenbrand , Mel Gorman , Miaohe Lin , Minchan Kim , Ryan Roberts , Yang Shi , Yu Zhao , Kairui Song , Barry Song , Chris Li , Yosry Ahmed Subject: [PATCH 2/3] mm,swap: remove struct vma_swap_readahead Date: Fri, 31 May 2024 16:12:29 +0800 Message-Id: <20240531081230.310128-3-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240531081230.310128-1-ying.huang@intel.com> References: <20240531081230.310128-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: j1p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1gC0 n0CPNsRDvQ0+dkCztseQRlMi5LDBr0Gdglf3OhmJMAj0tJeO6gwChm1ClRyTkws7fcqq1mihE8kufhtLa2moGZQ84mO3xlMaysih7HpbcJVxWjLfieAN/8+laorrrXmPw0nR5BanwP5/rT5QPvf45qel5fqWbD0+f8bpouZ/SHgxBAYWDpgym8HtczAwwdzkDkmnBgnpWCt3caZVcVHT9bFBzuOgKDzhDRAIhytkG9maQXp7FO942QdTAkr8FbsOto3CQ8BhRHzQtPwX5WddUZ8VEKPMaQBk+PknsKBmpDztjH7wFauMU7bjAgCf1pEX9kw9zfyU9dvXbjJtnWvEx9EH/w5S2PKTNFhj1voNXydOxQmSjU65cHvnSRxppbL73NrPPt9gG02gToAWX61eYDrui9e43Psz9hcyLFXVEWWNu+CFwfagSf23Gic291lJSUeYb8P84PxZsKUa8hHz+vy9ronCj2r90WvzCBNocShdfi/dEWjXxyKWUIr+81wazzj23KxqDBrCxn+hGxr6FMvGO5B5hvRRzLt3kdqxWo9aZT/qTstc6QN6IIP0KDd7JR/LgtoshFQePL+66nDXmrDr5/qc5e80ABFlKJScYPhNjWoU= 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: When VMA based swap readahead is introduced in commit ec560175c0b6 ("mm, swap: VMA based swap readahead"), "struct vma_swap_readahead" is defined to describe the readahead window. Because we wanted to save the PTE entries in the struct at that time. But after commit 4f8fcf4ced0b ("mm/swap: swap_vma_readahead() do the pte_offset_map()"), we no longer save PTE entries in the struct. The size of the struct becomes so small, that it's better to use the fields of the struct directly. This can simplify the code to improve the code readability. The line number of source code reduces too. No functionality change is expected in this patch. Signed-off-by: "Huang, Ying" Cc: Hugh Dickins Cc: Alistair Popple Cc: Anshuman Khandual Cc: David Hildenbrand Cc: Mel Gorman Cc: Miaohe Lin Cc: Minchan Kim Cc: Ryan Roberts Cc: Yang Shi Cc: Yu Zhao Cc: Kairui Song Cc: Barry Song Cc: Chris Li Cc: Yosry Ahmed --- mm/swap_state.c | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 848c167df530..e1dac70198a6 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -42,6 +42,8 @@ struct address_space *swapper_spaces[MAX_SWAPFILES] __read_mostly; static unsigned int nr_swapper_spaces[MAX_SWAPFILES] __read_mostly; static bool enable_vma_readahead __read_mostly = true; +#define SWAP_RA_ORDER_CEILING 5 + #define SWAP_RA_WIN_SHIFT (PAGE_SHIFT / 2) #define SWAP_RA_HITS_MASK ((1UL << SWAP_RA_WIN_SHIFT) - 1) #define SWAP_RA_HITS_MAX SWAP_RA_HITS_MASK @@ -738,16 +740,9 @@ void exit_swap_address_space(unsigned int type) swapper_spaces[type] = NULL; } -#define SWAP_RA_ORDER_CEILING 5 - -struct vma_swap_readahead { - unsigned short win; - unsigned short offset; - unsigned short nr_pte; -}; - -static void swap_ra_info(struct vm_fault *vmf, - struct vma_swap_readahead *ra_info) +static unsigned short swap_vma_ra_win(struct vm_fault *vmf, + unsigned short *offset, + unsigned short *nr_pte) { struct vm_area_struct *vma = vmf->vma; unsigned long ra_val; @@ -757,10 +752,8 @@ static void swap_ra_info(struct vm_fault *vmf, max_win = 1 << min_t(unsigned int, READ_ONCE(page_cluster), SWAP_RA_ORDER_CEILING); - if (max_win == 1) { - ra_info->win = 1; - return; - } + if (max_win == 1) + return 1; faddr = vmf->address; fpfn = PFN_DOWN(faddr); @@ -768,12 +761,11 @@ static void swap_ra_info(struct vm_fault *vmf, pfn = PFN_DOWN(SWAP_RA_ADDR(ra_val)); prev_win = SWAP_RA_WIN(ra_val); hits = SWAP_RA_HITS(ra_val); - ra_info->win = win = __swapin_nr_pages(pfn, fpfn, hits, - max_win, prev_win); + win = __swapin_nr_pages(pfn, fpfn, hits, max_win, prev_win); atomic_long_set(&vma->swap_readahead_info, SWAP_RA_VAL(faddr, win, 0)); if (win == 1) - return; + return 1; if (fpfn == pfn + 1) { lpfn = fpfn; @@ -794,8 +786,10 @@ static void swap_ra_info(struct vm_fault *vmf, end = min3(rpfn, PFN_DOWN(vma->vm_end), PFN_DOWN((faddr & PMD_MASK) + PMD_SIZE)); - ra_info->nr_pte = end - start; - ra_info->offset = fpfn - start; + *nr_pte = end - start; + *offset = fpfn - start; + + return win; } /** @@ -826,19 +820,17 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask, pgoff_t ilx; unsigned int i; bool page_allocated; - struct vma_swap_readahead ra_info = { - .win = 1, - }; + unsigned short win, nr_pte, offset; - swap_ra_info(vmf, &ra_info); - if (ra_info.win == 1) + win = swap_vma_ra_win(vmf, &offset, &nr_pte); + if (win == 1) goto skip; - addr = vmf->address - (ra_info.offset * PAGE_SIZE); - ilx = targ_ilx - ra_info.offset; + addr = vmf->address - offset * PAGE_SIZE; + ilx = targ_ilx - offset; blk_start_plug(&plug); - for (i = 0; i < ra_info.nr_pte; i++, ilx++, addr += PAGE_SIZE) { + for (i = 0; i < nr_pte; i++, ilx++, addr += PAGE_SIZE) { if (!pte++) { pte = pte_offset_map(vmf->pmd, addr); if (!pte) @@ -858,7 +850,7 @@ static struct folio *swap_vma_readahead(swp_entry_t targ_entry, gfp_t gfp_mask, continue; if (page_allocated) { swap_read_folio(folio, false, &splug); - if (i != ra_info.offset) { + if (i != offset) { folio_set_readahead(folio); count_vm_event(SWAP_RA); }