Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp2967016rwj; Mon, 19 Dec 2022 11:04:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf4GKkBehwkQR99ZRWFr42evpauWbU/ACijqPiErwap7IC/wxCs6baohvM+SVnNEiYLwofMR X-Received: by 2002:a17:906:2315:b0:7c1:1b89:60ed with SMTP id l21-20020a170906231500b007c11b8960edmr34550185eja.18.1671476650490; Mon, 19 Dec 2022 11:04:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671476650; cv=none; d=google.com; s=arc-20160816; b=JjB4yOJ/npE/Ys6q920ouzE3fB2xc+S0+F8mjw8xtdMhZZ3eqXG69DGm7GRgB4wlcL LKEgQlOXIeqV/eu79+KYq9l9lPBuIUbTkvMtRlo49/nbOgaoKkl8R34MyuUyopayMht0 Y+d66hfNdj12aWQgkEX7OGOrOjPA8GImtYoiQVHbr47bKsOUSGR2GgPfokfpzOTMB1ai nUvkBvkvNQGWJ1YY8ztrdJmHamo/wkMtBV5/bcdblSRDDFQmoJ26mVklbCGTYX3b6aBh bDWFXNNjyrKBwq4ztHC/x+IHQA4yBUHP/Z4vWu2yKb6v9xRw7wI36WxJNkFkBCeZuAah 7iHQ== 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=e8B2I+4NRvgsSq6ExVIS5zUbrcMf1l4UJ5x1/qJc8cA=; b=zW6VBBxEUTleHkFqIMgFiCA/LlTij55fbEnHI9aK+P4EaG8AkJmGkpnT4QAuM9LFrU ZsMrDsyy/Sx8DmBpYvrEsVQH2HV84GUC7w4El4RWfg12GzauVopf1C9pOn3IHcC6bz91 XYRoWo+5+TE20OAr7sR2KfwiFV44ABTUTSRlpHdNzjuMhRLw8oS29dUtKQ5Ct1ic2V8N 3PISE5KC/t8AXYS2iktVEsgb5PNXAk6zzM38K1Bj3iYcxJQyi+ks3/1p45EZI4B1auHA 8Lq4xCJ40gmYN9ILF1VR3Z3J2CWEQNrnuDHtVx7tav2PlhMPYjWjLclas/DkEWJx4JhG qBrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=eDZyM7UO; 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 v22-20020a17090690d600b007acf3aed468si8570490ejw.786.2022.12.19.11.03.38; Mon, 19 Dec 2022 11:04:10 -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=eDZyM7UO; 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 S231775AbiLSTAn (ORCPT + 71 others); Mon, 19 Dec 2022 14:00:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232725AbiLSTAC (ORCPT ); Mon, 19 Dec 2022 14:00:02 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 466DB25FA for ; Mon, 19 Dec 2022 10:59:29 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id v23so4802423pju.3 for ; Mon, 19 Dec 2022 10:59:29 -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=Wk9xIU57GBjKJySnb8BqoiWIVD9vksdYkSwP4E3Y55ErakUugSTo1BTARpXCD3WWRt ZYLVwYnHIIEU9KxfUTEssKw79I0HVMsjaU82yoawPUaz5+En87oS0E6pL87aA0nDMW5Y LvD1FgMQDbQ9Sd3rrU0+XFgHN/keAisJhlvOAjBQPkLLVuUpm7ojpkZ6FAx7aXgYVeMJ fbBjb5y4Soi+P/sugrBNVvz/qO/4vnTAJGKf+G4z6TMUjdj9o8/vG7VXRugCQ4NfAwUz umoZliCZdUVntL7S7qg1qee15vDsrMP0vx6rBSCQZkmGiWqrcRtQuH59oJwREfG1u7li /ZQg== X-Gm-Message-State: ANoB5plG1PQdsWTgfoEhiNFy6D+8y7okP5jFBD19WsvEMc6roFNNxfQp s+dS0IiIsAAvednt++pSu7E= 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 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. 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; -- 2.35.2