Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1472481rwb; Thu, 8 Dec 2022 11:04:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf41BprDk9pqrC279U4wAlMsEFxUQh3D1jFQWgD0OSpudaWvtUeaYsqt9RN/7m7UyxCRnFRj X-Received: by 2002:a17:902:eb8a:b0:189:cca6:396e with SMTP id q10-20020a170902eb8a00b00189cca6396emr9124313plg.120.1670526260786; Thu, 08 Dec 2022 11:04:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670526260; cv=none; d=google.com; s=arc-20160816; b=k8DcMoZBAKqJIVH3MIy5oMsNa9QqWxKH8ar8ldhtOKOFkVMc2gNeqcxWu1emW5JPEE GlnCYr97PLfh6apJKWa9gyJL3CfmZurgVZC+2yxGJdeXl4f1gehxXwwajwKy+hc/wO/O UsVMkmufhrYLWeour80G6EALWlUNKM5rkJsF7UZ+CvWrU+/Kdlpb+/L0q3YOSOht/GKN 00R7r5m3miWssEqGPKAa1kgqn6dl7KHBNYdeJom7vCIKBq3tUzMZKjGxuLmhGJ2qs0AV uoIKjcot4B9D1srWFdL9AuO/58Dkw4chvlEGlm7SSqURCa0UlGof0LA2CuuMn7el1SXi TpVQ== 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=sO5CoFHWHd3hJkT66P6565Tno5APV7gOVtSSvr1Kmak=; b=esB52aTRFqJcCTSzgBHYPnbd3YNIbkG4iso/78lp6kNS7tabVxzFeqzlHSxJgn3i0J HZCmJiUyMIUT6Hfg9n6WT0bOQ9CGAreHYHWaejnkTi1FExzOj3V8wM3+vJjxk7wP/RKS iXLFwt2nhDbRhgP8Tkq/mn6uaNAvguZPnd5r6WXyXjoZ55bD/5zBQJ+hxOe3I97vd1oY AJ7edQMX6z7lDKH5HbjMDy4wIM62V3/OdnaAcc/bZ+NFxH0pW7wU2jYSh0hOi4IPh8W5 eWj4rPeFlo32WYp7ZsKIz71AXR5+X2QHqyGxXv83JcwmdNNBacKcaP/9+6v/OBKdadLN 4adg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OpJs82IF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nl10-20020a17090b384a00b0020dbb8f3695si5381931pjb.172.2022.12.08.11.04.11; Thu, 08 Dec 2022 11:04:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OpJs82IF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229586AbiLHSDd (ORCPT + 72 others); Thu, 8 Dec 2022 13:03:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbiLHSD1 (ORCPT ); Thu, 8 Dec 2022 13:03:27 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CD845BD60 for ; Thu, 8 Dec 2022 10:03:27 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id v13-20020a17090a6b0d00b00219c3be9830so2337108pjj.4 for ; Thu, 08 Dec 2022 10:03:27 -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=sO5CoFHWHd3hJkT66P6565Tno5APV7gOVtSSvr1Kmak=; b=OpJs82IF483zMRR10B9ZK8uXKr26ww50hoZUuCpAvcj54ywnyFbiRuv6Hmy84v5RFq LvLarleVe0COhyAsoDAHvPMzpgopqUQQKO2ZbnnACbczT6d8YP0h0Wp/uJBcnmLwKfYn RnVLhdnDZPZIKpJVOKRkH69LIOnMGPC2BGyImnquIEmGGpbuHsOgGyJsgy2MSMcHx1rf Vq87c4y6s5XMnWQnnDuT5+NYeWEnBW/e5m5cbZwB04aLDpJV98fF+pn7N5Sdj3x+dsLn XMzHsVtrUQslsJQolDztnRuuDqwC7u5gtWQVj7HhF/cd/6Lh2plHxGOrsnFmAuNWKFGZ +yfg== 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=sO5CoFHWHd3hJkT66P6565Tno5APV7gOVtSSvr1Kmak=; b=NmKAOksxwG4aXpwsTjVn0V9cZpCfQnIguaXLA+Fc+ASg+dpkg0CeRnswy+86RYds2G 1zoLvhmm3cZpEDPehFemvSe5o6x7+6LamVrSjqiOdG03cmFjc5bW0tLbULnJb/6CXZLb EwIbgPjjejac9vs3XIFm/nPXUx4McgdcHrKzLZNiYoJjgUSvvpq3MK0QAVn3IbYBzRdl +LzsWtRLRhUE4IPnkH4qIP7ZVz1Cszd4zUiHZ8P92jkLVc29JS0qJRaLOd3zXfia7bh0 EQm1MnyDakHuhn5MeXSHzTO31+QQOGr2KSB+6sbWT8p8ysFzf/f9fhH+PyMpcHGLh0lH 59Yw== X-Gm-Message-State: ANoB5pkYNSOHhnSnlik8xV+RpD+mczLh7EtAX74weQ4pMZXlpdvJn9T7 ryozqijGkTZi86juV9RF1CI= X-Received: by 2002:a17:90a:d347:b0:219:9676:fef5 with SMTP id i7-20020a17090ad34700b002199676fef5mr2840489pjx.12.1670522606635; Thu, 08 Dec 2022 10:03:26 -0800 (PST) Received: from localhost.localdomain ([198.13.51.166]) by smtp.gmail.com with ESMTPSA id x23-20020a63db57000000b004785e505bcdsm13377909pgi.51.2022.12.08.10.03.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Dec 2022 10:03:26 -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 , Kairui Song Subject: [PATCH 3/5] swap: fold swap_ra_clamp_pfn into swap_ra_info Date: Fri, 9 Dec 2022 02:02:07 +0800 Message-Id: <20221208180209.50845-4-ryncsn@gmail.com> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20221208180209.50845-1-ryncsn@gmail.com> References: <20221208180209.50845-1-ryncsn@gmail.com> Reply-To: Kairui Song 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_NONE,SPF_HELO_NONE,SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org 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: text data bss dec hex filename Before: 9502 976 12 10490 28fa mm/swap_state.o After: 9470 976 12 10458 28da mm/swap_state.o Signed-off-by: Kairui Song --- 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 60136bda78e3..19089417abd1 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -696,28 +696,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 @@ -745,16 +732,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; -- 2.35.2