From patchwork Mon Dec 19 18:58:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13077056 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 D5806C4332F for ; Mon, 19 Dec 2022 18:59:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CCD88E0006; Mon, 19 Dec 2022 13:59:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 67C6F8E0001; Mon, 19 Dec 2022 13:59:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56B898E0006; Mon, 19 Dec 2022 13:59:32 -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 48D088E0001 for ; Mon, 19 Dec 2022 13:59:32 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1336F1205BF for ; Mon, 19 Dec 2022 18:59:32 +0000 (UTC) X-FDA: 80259969384.29.263EDAC Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf24.hostedemail.com (Postfix) with ESMTP id 66B5218000F for ; Mon, 19 Dec 2022 18:59:30 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=eDZyM7UO; spf=pass (imf24.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671476370; h=from:from:sender:reply-to: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=e8B2I+4NRvgsSq6ExVIS5zUbrcMf1l4UJ5x1/qJc8cA=; b=D8jZySqJXbSTOvpBG4oxt9fxlf+crLi3Ihdu1fbsNqlZs5oSdrByLmA/KiZktSRMGUbVqo ptyMgHL2InNAj3cJ31LJYalBPPUloicni1ZCHO8Zf/+0vccs/nCId3wDavnHgxcX1N4hJU meRH2awm6WjNICb7D5PKr8QvgI4HYqc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=eDZyM7UO; spf=pass (imf24.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671476370; a=rsa-sha256; cv=none; b=XCZt7jSIoe/mKR3l+fzfYFCUCGja572/8BOl108UqGivUtwFi7JRBzY6S/h/RwKKxxXzqs CmfL9OQ2jR/Yjjgntl5Cay+3H4Qu8E7A9avEqO11GbeSHrroC+FkNEPg39pPiz1Vt7lrRl sNlSPdSAsOlY5a4zaZi6099DpoAaWKw= Received: by mail-pl1-f169.google.com with SMTP id u7so1747890plq.11 for ; Mon, 19 Dec 2022 10:59:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=e8B2I+4NRvgsSq6ExVIS5zUbrcMf1l4UJ5x1/qJc8cA=; b=eDZyM7UOpN208tVAX+hBqxHyra/S+kQPzV2RhHjUpgkC9oo2h5Ktaz/fro6c2oe/PI AiE0zgUos7a8I423N7mG0KgJrZbDbZjAuWEzhLGcsc4EetSbBy1aMp8FeQIqHi1Hqxqn /mMWiYwsa4h1ySc2e1WYwy1U8XSH06HeDaI3chHznqgvFcCkUMVwJdUKuQPt2Pb1uiRc ZcO5tNFbF1z+vFDCInDRnW/UpVs4kNmOWUagDrXtr1sYk7b4I6IGW+5X49eK1ICfP6Yc 2Nt0p3JG5RSnqmvBmQNcIgP82uZ3RVr5b1D+Vl9i1cIFY/GPycw8aNT5PXlUOLbbE1in hFbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=e8B2I+4NRvgsSq6ExVIS5zUbrcMf1l4UJ5x1/qJc8cA=; b=eQooeBdLbEGcC5rhIY1Ov0dRFW3lD4CZHNe7oCKqlepU9rMT8rMC95ZZMoIDSfi6I+ d3fdCBUkIRdrO/eS6rbiEbxNCaIqjQLMYT8kWmkHK4Kh0BIXA1sd6VOXKT3DFEZ/nYC+ qZvIvpxzHGQdyXxUxZTBRUxsN/7UyHVJkUVNhOsYTjNsIz1x3gFutD+K5ze2d+hWWfvf R8UBZ7TIvcBz8oVB/PmUgWvbvl3m+LdY4uIi8yoHRmPeQu2/nB5tvTCB5lkti9XKWOFw gdKCkqrL5b0XIzqy2LG0rGO8uAvEBdo/J/X0X6iY+WpJWETkcK7yeEM9bwpg6elyG3Ai 5dQg== X-Gm-Message-State: ANoB5pkJYCofHByb2za70hvXPfttQZ0GOdXxRQHrf68OA98s/IOIcULW JbV/hmbFyK2wp+93mQN0olJfWD7szh/oow== X-Google-Smtp-Source: AA0mqf5haLYTtDDLTVNr5GE8KrQCnl2ZPXRQYj++5TqGjcUqyeaN1eo2aDvP3ExoJcIc66C/EvYGTg== X-Received: by 2002:a17:903:2448:b0:189:f277:3830 with SMTP id l8-20020a170903244800b00189f2773830mr65253828pls.68.1671476368808; Mon, 19 Dec 2022 10:59:28 -0800 (PST) Received: from localhost.localdomain ([198.13.51.166]) by smtp.gmail.com with ESMTPSA id i6-20020a170902c94600b00189847cd4acsm7480790pla.237.2022.12.19.10.59.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 19 Dec 2022 10:59:28 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Miaohe Lin , David Hildenbrand , "Huang, Ying" , Hugh Dickins , Matthew Wilcox , Kairui Song Subject: [PATCH v2 3/4] swap: fold swap_ra_clamp_pfn into swap_ra_info Date: Tue, 20 Dec 2022 02:58:39 +0800 Message-Id: <20221219185840.25441-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20221219185840.25441-1-ryncsn@gmail.com> References: <20221219185840.25441-1-ryncsn@gmail.com> Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 66B5218000F X-Stat-Signature: 3ioxf66aydr8ori6qpzjjnkof3c3m4ao X-Rspam-User: X-HE-Tag: 1671476370-329627 X-HE-Meta: U2FsdGVkX1+HwcJ8PtznEw7nY4knDo2XtCFBQcroU2LPJ5kNNT9ezTSSSMh/Sht/bbunBmLU5NjXX62+3BnaVYT30VWIyW8RBrOwNpEi1AaK6EzJAwxftiTXDLaNk9Ld0sAOd8lzIBtZiQZ783pwSlRzjMk35J7uDb1qMocgnpjLeaTPzcFqJ41ZsnE6sSE+hrBWkdDOsXmJ/yqM5WiDMkybtUcoyhtk0B1AWSfJCyOCfkZloYXyRadPsvBTtQQDJC4M38HCMWWF90fgnGX1/tO/g0MPgKLiRMrOEjbGvRSeL8iyPqZXYxAHOlszSGVjzsg0MgTjyYZljk2VENM8xGZ7y5DF3zt9Rac5bXJX+kKR46vSeBLH3lbIpLqzuIVxMVTiGtLVELYF/aVSKkOb65ov9QmGAPkMS8EEoDOga8VyLnsgA1fSI/gTRHFG6t+S8JD4C3LRansAzIDaBQ8zm4KBEzG/mINpV/9vq/hUlBfU06LY+VPGu5HyM40F374y0txZxxtgN2QyKU8gb/JK/8CO8106IsrWUh0B76JBbZZ9dI8Vzv3KuR7vN4hTCldsNQhJ2HhHKZ8OgVTQSVBaB6uMT2AN7AmifFzS0GNmWTYPtbvJEh42m7Dh4XrFix7+q0fsYu5B/vDVCxq6UNhEQAqqLaWUTn0wBeL9P3VcbmiOzR6o1QXCQ27akmDWupyKNJUu7hbFA8hIUX2rUb28srEYMi7x5oCschUuEZM8Rv+Qi0f6r1sktBEmFCVp3kM7Io29yPeuQ0Fn9wtduF78iKd0XuWogBwPTxHPYYo2WiKfVAdDJJ0II3VvrXcDMLqZFzQIK2yjf9upWEMBplByR/Nvq70DCDcTp3G5NmnpeXBbbCw9pkPsG7I0ZnH4MxoRWnljHqdfxMCqME+xK3uSaocOjV2qXD5ZIGtOU+1t79FI0l8MI7u627v0nZ4b8jg42kSC48u/w/qgVSg6+o2 g2Pq3yTO 6a7g5AATpDnK7gaHvXIdQdJphMf3oeJt/t7RkPwYGciqAbXbw2JaDULGQiHAzu1Wk1VKFR3c6foDycLEmhw47CMGIFr9uPIPrm138z/YTZMSpMH+mkmq/jCzAUEBxQ8VXNAs3ybcw8POhSm1iuWaBCmVzNMVZgTebBg53MnGQQR5IQe57yO1QKP8Pc7L/BsPsLRzthCui/k2KebDqde8gTuQO/QZec/w4oSZ1NTdR8sBTll23U3sk6a6/MlO7deIA/D0dGRvHvPkHyyFXQ1vuU8xPE9gdTohmabR/4ikr0H5Egsi6BdAMRmA7Z68+xyyUVIWoFo+Wism0TJ0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Kairui Song This make the code cleaner. This helper is made of only two line of self explanational code and not reused anywhere else. And this actually make the compiled object smaller by a bit. bloat-o-meter results on x86_64 of mm/swap_state.o: add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-35 (-35) Function old new delta swap_ra_info.constprop 512 477 -35 Total: Before=8388, After=8353, chg -0.42% Signed-off-by: Kairui Song Reviewed-by: "Huang, Ying" --- mm/swap_state.c | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index af8bc123b7c4..d8d171195a3a 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -693,28 +693,15 @@ void exit_swap_address_space(unsigned int type) swapper_spaces[type] = NULL; } -static inline void swap_ra_clamp_pfn(struct vm_area_struct *vma, - unsigned long faddr, - unsigned long lpfn, - unsigned long rpfn, - unsigned long *start, - unsigned long *end) -{ - *start = max3(lpfn, PFN_DOWN(vma->vm_start), - PFN_DOWN(faddr & PMD_MASK)); - *end = min3(rpfn, PFN_DOWN(vma->vm_end), - PFN_DOWN((faddr & PMD_MASK) + PMD_SIZE)); -} - static void swap_ra_info(struct vm_fault *vmf, - struct vma_swap_readahead *ra_info) + struct vma_swap_readahead *ra_info) { struct vm_area_struct *vma = vmf->vma; unsigned long ra_val; - unsigned long faddr, pfn, fpfn; + unsigned long faddr, pfn, fpfn, lpfn, rpfn; unsigned long start, end; pte_t *pte, *orig_pte; - unsigned int max_win, hits, prev_win, win, left; + unsigned int max_win, hits, prev_win, win; #ifndef CONFIG_64BIT pte_t *tpte; #endif @@ -742,16 +729,23 @@ static void swap_ra_info(struct vm_fault *vmf, /* Copy the PTEs because the page table may be unmapped */ orig_pte = pte = pte_offset_map(vmf->pmd, faddr); - if (fpfn == pfn + 1) - swap_ra_clamp_pfn(vma, faddr, fpfn, fpfn + win, &start, &end); - else if (pfn == fpfn + 1) - swap_ra_clamp_pfn(vma, faddr, fpfn - win + 1, fpfn + 1, - &start, &end); - else { - left = (win - 1) / 2; - swap_ra_clamp_pfn(vma, faddr, fpfn - left, fpfn + win - left, - &start, &end); + if (fpfn == pfn + 1) { + lpfn = fpfn; + rpfn = fpfn + win; + } else if (pfn == fpfn + 1) { + lpfn = fpfn - win + 1; + rpfn = fpfn + 1; + } else { + unsigned int left = (win - 1) / 2; + + lpfn = fpfn - left; + rpfn = fpfn + win - left; } + start = max3(lpfn, PFN_DOWN(vma->vm_start), + PFN_DOWN(faddr & PMD_MASK)); + 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; pte -= ra_info->offset;