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: 34699 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2563877wrn; Mon, 19 Dec 2022 11:02:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf79Hwn8RcJ8GJuBQqh/xRtvxRXv/CJAyOtRwpHXuxn6eHYBq3nopGu+YG6fQeScuBr08J4H X-Received: by 2002:a17:906:804b:b0:7c1:67ca:56f5 with SMTP id x11-20020a170906804b00b007c167ca56f5mr27001067ejw.15.1671476569171; Mon, 19 Dec 2022 11:02:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671476569; cv=none; d=google.com; s=arc-20160816; b=xL36iJQjT4YZb6Ge0eCUuNEPOWE65HJZna+pkYlz63xk4Ze1cWdKt+ASDVwZ8fYxnD b3JzYuuU4AXcfF32CEziyFjckz3AEwHKzL3gTY9Chz8ZXJneIQzcAzwG+O/k9cZFy/gD mIe3cgMkA0jAdgEZZDWEeBdzKg2VY63m3+YXijWFmzWSejft6hDe5+PHF65TB/MkuyA8 ly6eBqIej/1qEKraGQCe0Q4b8t7JQnkYhMmEK1eoFy2oWDhvsca1XG/5saN+P9d91mNP BgHB2LOCYt09Uq6Ogx3z8tjTeGVQXPrb0PED4Fx6sUcKoyiXHe+sRbT+I+ynsuaNgx2g 9F6Q== 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 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.02.26; Mon, 19 Dec 2022 11:02:49 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752670215411718800?= X-GMAIL-MSGID: =?utf-8?q?1752670215411718800?= 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;