From patchwork Thu Dec 8 18:02:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 31445 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp344927wrr; Thu, 8 Dec 2022 10:08:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf4W7MvtyEhKmjBZZECYSrtBNH35NowT/I9MgvCf50sNIPbo6BN5XKaK4S1dpZM0vnyiuvCj X-Received: by 2002:aa7:92c7:0:b0:574:39dd:f162 with SMTP id k7-20020aa792c7000000b0057439ddf162mr73722782pfa.44.1670522924330; Thu, 08 Dec 2022 10:08:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670522924; cv=none; d=google.com; s=arc-20160816; b=o6tL9jSx6OD2PEMuG8HaYlST6GVdkL+3jnNwVSG5craFcV7YZ4PO1W5fjmx6gJe4wL ivSdCvqb8zh+gOIdS811ZUMjP23R/h8bxMwDSV7Yb8oRuwTpSGbt3+OM1az+oOW183yM vppf59y1dBCSRwCDLX4DQsJ5qaNQzpKpqveK6MGNYyl3nQBgrR+OHpbPZeJD3fLApb6b uBorFrIrmyvi3/PemzjdTMqutkDafZ3mpuASjMfh8Wdv6rL3jELUkmK1L2gas/lWq1c4 4gh4FYFLy8XvHsYBZHQ1ns/9vob93KA8Ee3pyzkn2tbbP61TIemTy+BBYysiwVw9Ny7v c+1g== 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=E96Wm/nE/BO1oqx7KrRbQksoP0SM8QfWpUYCtfF7ZOY=; b=h04tEoEPva9IKCWJCYEJpZiuh7L8fJoQ4NS8Z7QRxFa3290aEp/y0FEdSKy6xGvLEv ezQrCZ7yjR/Jnek3hejGp0bunorcTxYN55fckjdJoDsENvx/9Cp0FGl8qGFUofV0QXl+ Zt8sT0cBFnJbH95az+nyQ/MaB63BKD5wmMc1Z29Y47c3c/SA1JkxJexHzLlYBT8h6tjb ilykPPAW/aDWEbLc/XtV/u9G5RbmjJiTeqJIdKsO59AOvqsJRSfpyXbby14KJf0t7EIU fArck1AiG4sPdZbCcyvVQryUr9Ux2cHxt5BtvnsyW7Nq4AO/2v0/MYKudn87AGJYxCX0 AYGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=elKCQdyB; 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 co16-20020a17090afe9000b0020053614bd0si4693671pjb.148.2022.12.08.10.08.31; Thu, 08 Dec 2022 10:08:44 -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=elKCQdyB; 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 S229573AbiLHSDZ (ORCPT + 99 others); Thu, 8 Dec 2022 13:03:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbiLHSDT (ORCPT ); Thu, 8 Dec 2022 13:03:19 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57D0D5BD60 for ; Thu, 8 Dec 2022 10:03:16 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id o12so2306871pjo.4 for ; Thu, 08 Dec 2022 10:03:16 -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=E96Wm/nE/BO1oqx7KrRbQksoP0SM8QfWpUYCtfF7ZOY=; b=elKCQdyBJ0zfJyNZL9MWCMZLH4HbJp0sc16DHkwY2E5BuxBXc6+kjPqmOH0MEON8c+ x1q8YZAV5N61RQT/m3OutBjmiEN7IieOIDAJHd/hq9flNutIgFBfrmAvkwCHiWZpU968 l3IuT9uaAPkuHG77zs7QLsSUC6ld+XhS8pJMfNyXq93eNDv1gMb8XaRWqLbPCQg4FLds Zw5LVsx1I3Bf87bQVz8e4Azxrug7PBuZkoHYH/SIAcF3bH6ttLQh+TrjPhbCygJXcrfP dhI88Wq2hZmQ5pkdV4izpmRYDsPTRa9HKcydpMuA1M6ve9u4TicYtF5kp0e90xqzNGBJ sKCw== 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=E96Wm/nE/BO1oqx7KrRbQksoP0SM8QfWpUYCtfF7ZOY=; b=4w8ywLpr/2ueM0D5+aEjz0b4IF03Y2zZ3ofn/dDlUpb5x1JiUyQHliVmlynL7GRONq GFuRvYC2zlp+8IRnksjUOzgl0FhzSYNEW8jbQT/zfAc4GpNdLDocHXFLZYH2x2RQJ6gG YKe07sATnwSo2xLYug9D1QHtI8gPRf6V3pr7NCdrii3pd8dunhM3KTEwItVtobHWPwOj aNsTeEhkXxwXv7WV3arupWlm0bj+ir/pwDkfOlONDyjKk+sBiepw8lXv/6ZPvW/w8YNB fxvgsh7Ccwnv7RNalfDSWwMNu+XfFvGYPQQdlRpJ3E03BNqi7eLNs/+SkiOvrqLZ5keV izzw== X-Gm-Message-State: ANoB5pmOKyGH2sf0GlR8NjCjW3NuTYAe83iqkT5vPJV0Bt7qAjC+g7zn 0WSCQG8vxNSM0U/ZPyzR7lw= X-Received: by 2002:a17:902:d58a:b0:189:a11e:9995 with SMTP id k10-20020a170902d58a00b00189a11e9995mr3153672plh.13.1670522595747; Thu, 08 Dec 2022 10:03:15 -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.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Dec 2022 10:03:15 -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 1/5] swapfile: get rid of volatile and avoid redundant read Date: Fri, 9 Dec 2022 02:02:05 +0800 Message-Id: <20221208180209.50845-2-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 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?1751670245962868144?= X-GMAIL-MSGID: =?utf-8?q?1751670245962868144?= From: Kairui Song Convert a volatile variable to more readable READ_ONCE. And this actually avoids the code from reading the variable twice redundantly when it races. Signed-off-by: Kairui Song Reviewed-by: "Huang, Ying" --- mm/swapfile.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 72e481aacd5d..ff4f3cb85232 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1836,13 +1836,13 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, pte_t *pte; struct swap_info_struct *si; int ret = 0; - volatile unsigned char *swap_map; si = swap_info[type]; pte = pte_offset_map(pmd, addr); do { struct folio *folio; unsigned long offset; + unsigned char swp_count; if (!is_swap_pte(*pte)) continue; @@ -1853,7 +1853,6 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, offset = swp_offset(entry); pte_unmap(pte); - swap_map = &si->swap_map[offset]; folio = swap_cache_get_folio(entry, vma, addr); if (!folio) { struct page *page; @@ -1870,8 +1869,10 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd, folio = page_folio(page); } if (!folio) { - if (*swap_map == 0 || *swap_map == SWAP_MAP_BAD) + swp_count = READ_ONCE(si->swap_map[offset]); + if (swp_count == 0 || swp_count == SWAP_MAP_BAD) goto try_next; + return -ENOMEM; } From patchwork Thu Dec 8 18:02:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 31446 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp344951wrr; Thu, 8 Dec 2022 10:08:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf6CfIF7h3STKYTA4YcL9t+0A6rcC25Hu16kPwBVSpvPOpL12xV8RQ4MP9aa3HTL4mRJfPq6 X-Received: by 2002:a17:903:1206:b0:188:cd12:c2e1 with SMTP id l6-20020a170903120600b00188cd12c2e1mr81337210plh.171.1670522925939; Thu, 08 Dec 2022 10:08:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670522925; cv=none; d=google.com; s=arc-20160816; b=PQKxdo0VVI9AoWE01gWB5nxssneklHYTg+9WM3zzmGf1ZN23zCN1LDlTHsUTn9GdCZ Hn7qX+gXrE/7K3HCRZQwQP4h5dvWdcORjrb+zHh3J0+Wg75ZAToTcnJL7nSKMjjcvnqy oerEWNSv++izYpJvCqrng8iW4mNgm8ZZa9Hd9WFu+b0DJWQVrU6Uxn6Gyg95R8G103nB tfhqmW0MMtY4jNgVwPL2J7O5eKNGCvtXhl6rEDHvJSUgXmr03fTqAeWQA7sfCiqcEdcu mxqW8zgPuUoiLNq0C1KOpwvB+VzX3U8tfuSVSjWoNxZSav2LcAyfkwiyyws1JH3CHKfB 1NVw== 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=riLhoP57eVPqwj4BrvS8Vazxssa2eImOkYsWKI1T0t8=; b=vdoHRh8IA1UsPyLWc0bC9OFHf2ZWmpRIm1gnOjyq3G8l5UkkEqFLa5vfblFYHBMn1X r3oxPrlegqyBSS68iwVnvrxRePgNtjKC9QQGzxfxLqXphIFzvXbATWYmEbgRRH3Ms+4Y 81sbt5n3XWwZ77gm+P78EDhGIcFBB3KqLpyVjDdZluNB3XeonRLCIq3+zIozcBpUbL2U Ma1+wGPCPi1hqgzuB/2QGs0+Cdek7ZCEWKtrfC571WDMBvPA2Txes3e9zlTkhL7H5czn gMc3YTDotLFJV98Zpj2CDkkt5e0xgA2X22wY8yznJZFYoLHFKEUI37TXwDQnZi96jpxz bLcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=iViaYugs; 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 c21-20020aa78e15000000b0055fa098c388si23406934pfr.259.2022.12.08.10.08.33; Thu, 08 Dec 2022 10:08:45 -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=iViaYugs; 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 S229879AbiLHSD1 (ORCPT + 99 others); Thu, 8 Dec 2022 13:03:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbiLHSDX (ORCPT ); Thu, 8 Dec 2022 13:03:23 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04EDB5BD60 for ; Thu, 8 Dec 2022 10:03:21 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id t11-20020a17090a024b00b0021932afece4so5459620pje.5 for ; Thu, 08 Dec 2022 10:03:21 -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=riLhoP57eVPqwj4BrvS8Vazxssa2eImOkYsWKI1T0t8=; b=iViaYugsyY36Co7pKi2yW3+3twUOGGTtNqIFgF0+7MBH5JAuAvr7KaDfROp3l9GO1t Srqh6rR1dXZMZbpBUXgZqXAo4mtoHxV4pakZa2i/mghgx0d8YgDWCqTQH6v3TePUuhHI yX3yaekIseUtoERJq9NEzxrgtTJrfI8d5Cp1R6AWvyBnz6vV1oUAR2djd1j/hMSt2k+Z 4+LL5CGtnmGv/5ZLisC4P7VAVLqe/cweXpWm3xgkYbR/b+jTCHWNVTBP/iMbpt1jht3L panlWfFI7BbV1LS54KzTKj/isn6g3pxCZzMObb0FaAMwDqDUsIUTZlII4ARmHeQIrm9x GrGw== 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=riLhoP57eVPqwj4BrvS8Vazxssa2eImOkYsWKI1T0t8=; b=pZ5OcCK2yfOwutj/74jiOeQGySPltPyOqYae79+vY8acZPkJckWCwOy0Rk59bTPWTj TkHQTtZsShnQNRk+DBMJJGg1DMvf+EByNGveXo/RbAW6uCkJaotmWQUIQqba5OiTjGlG dhGciw9QFdJI14tkoRNdmROiealM2Jg4818niQXVUtdxKieoVnQP+eXGIyuVAnH5Byl+ S/DZoIiarcUBSeqr8UnojihQcz3p8ilZr01Uw/NalWowd2mXb7a7ZBAapDeCTbksGFQo JjSeLy5NKzkzs/fwrg00AvM4ZF1ycuZRwzFxglvuX6H+T9QtwALeytvGHDcFODRysYtA fqsg== X-Gm-Message-State: ANoB5pk8VJG+qq9uyx/y2e1rq/AGGLiO7HVaJbW3P1KOfAscVK5UWQUv 602ll6c1fdu1viR9492O4iU= X-Received: by 2002:a17:90a:8c82:b0:213:1e29:c8dd with SMTP id b2-20020a17090a8c8200b002131e29c8ddmr2896254pjo.7.1670522601220; Thu, 08 Dec 2022 10:03:21 -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.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Dec 2022 10:03:20 -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 2/5] swap: avoid a redundant pte map if ra window is 1 Date: Fri, 9 Dec 2022 02:02:06 +0800 Message-Id: <20221208180209.50845-3-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 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?1751670247255874067?= X-GMAIL-MSGID: =?utf-8?q?1751670247255874067?= From: Kairui Song Avoid a redundant pte map/unmap when swap readahead window is 1. Signed-off-by: Kairui Song Reviewed-by: "Huang, Ying" --- mm/swap_state.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index 438d0676c5be..60136bda78e3 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -730,8 +730,6 @@ static void swap_ra_info(struct vm_fault *vmf, } faddr = vmf->address; - orig_pte = pte = pte_offset_map(vmf->pmd, faddr); - fpfn = PFN_DOWN(faddr); ra_val = GET_SWAP_RA_VAL(vma); pfn = PFN_DOWN(SWAP_RA_ADDR(ra_val)); @@ -742,12 +740,11 @@ static void swap_ra_info(struct vm_fault *vmf, atomic_long_set(&vma->swap_readahead_info, SWAP_RA_VAL(faddr, win, 0)); - if (win == 1) { - pte_unmap(orig_pte); + if (win == 1) return; - } /* 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) From patchwork Thu Dec 8 18:02:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 31447 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp345011wrr; Thu, 8 Dec 2022 10:08:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf43n0R4S2vxJdhcIdSnWwsAgEaQvSSqhtthCmVnUXq8MWPR0ifVFmXoyTfvasCDyE7Kle3r X-Received: by 2002:a65:58ca:0:b0:470:2c91:9579 with SMTP id e10-20020a6558ca000000b004702c919579mr66577065pgu.22.1670522932918; Thu, 08 Dec 2022 10:08:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670522932; cv=none; d=google.com; s=arc-20160816; b=N86j15ePVD1F0eXLYcwpasQY/mscrFBnSRdQ8INnxX5lNb+cf4eH63Yypr+5cKkZhI PU2gau9XeMJb7i03Mbm9Mi5kgif94Lv1G55OxjF3mlyMm4XUvVsxlrrXam+nVcp6cMwd l76xSYvMqcq212H0sC2jVOqqbYaX+MailXkQqliOFda4h9Qa6VI3wb+laFeQf5cPYNaj RwWle8TE/LtQqrnjJ61TAc9f9NfSV8qEc6ZbuWu8PeIdnFsvqCpyLBprxeqlY0gXbiqe OEtoUoUjVArT3vKzQbX6DXw8FccMwq+FOVdA0EIfGZuNP3dBEVEIPJ9lxxhWEwO521IC GNcQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j6-20020a056a00174600b00571fad2adaasi26303889pfc.224.2022.12.08.10.08.39; Thu, 08 Dec 2022 10:08:52 -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 + 99 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 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?1751670254781350439?= X-GMAIL-MSGID: =?utf-8?q?1751670254781350439?= 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 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 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; From patchwork Thu Dec 8 18:02:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 31448 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp345094wrr; Thu, 8 Dec 2022 10:08:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf6TnJuY4dDD7mrE8qJjakKO44XtK8/8HO+P6zWArWSMi93NBL/Bsxx+8DWsMsTVmQdCbu/l X-Received: by 2002:a17:902:aa06:b0:182:f36b:3221 with SMTP id be6-20020a170902aa0600b00182f36b3221mr77273917plb.36.1670522939630; Thu, 08 Dec 2022 10:08:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670522939; cv=none; d=google.com; s=arc-20160816; b=Tc02Kmi8+t0/iJF8oofQ+70nbrfm+FJNGZmtAY/fYYC13/beisJvXlkjzJ92UDBvaM k5rffi4ZsBUHr1EFpZK/ttOs6otN3Sq47FGhd6Uef9CzhU0AWYa/1w4DGfhkP+SknF9s hp2BWLaUzmen0U3/F9Cb/YRzRl5KuL77dh8kiAUnvGTtpNpg70y2NaPb0r+xOZ/rLYG1 Zi2gOvtzhBm3WKkUKDgqG6nxTAOxtghyVbopK6K/RwXYarOZCoopGm/vyNY7cYZYKAfs Ss5mA5WPf99+Ze57nS/8fFDBdpGhLdz54orDJ5Gbe2eNwZncfH2InxOXzwZOtfFqdJK5 Bz5A== 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=9xhnDKrjvRgwnAVDsuEDmotQGE1PCbtaJeEpVqamujQ=; b=BdFUGxJ6DqEH7kiF3SnfxaV7qz9EI+uqC/MPPDbATm5K5KLFHqc0uvyAYJKjFn0CXH PkaeZeLPsQpf5iXVqmlDwxh0lqQmufzuKcbBTD0CgA6KyFyIK8EfefPce48gaD3ZwIm/ wwgO3Tdlm08HJuT6EDIpU8Ym0Tu4MkEwzt1C/sGarRzHhCQ19R0eP/6AVTydlhoSeT7u FknJIWQ/GNidrq/oELyPoJStHZvJu+VoHa036endhvIeSiu7OAgy41nrzgJtsV1coeLW 6/vCt9Nu6/No6oqrP6HXccpYmZO7FelcSUqWLd7QmAPX4n2bGxGHOwRhHFHNAGHSbDkU 7/IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fYS6yck+; 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 u22-20020a63f656000000b004785dacca57si23183365pgj.457.2022.12.08.10.08.46; Thu, 08 Dec 2022 10:08:59 -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=fYS6yck+; 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 S229954AbiLHSDt (ORCPT + 99 others); Thu, 8 Dec 2022 13:03:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbiLHSDf (ORCPT ); Thu, 8 Dec 2022 13:03:35 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD8B1AD99D for ; Thu, 8 Dec 2022 10:03:32 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id y4so2276709plb.2 for ; Thu, 08 Dec 2022 10:03:32 -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=9xhnDKrjvRgwnAVDsuEDmotQGE1PCbtaJeEpVqamujQ=; b=fYS6yck+ReWd2uxK6tV27Mwp2zNKPzSSjv+tEjGFN0KC2KzjO1Lrmvll2fXcklu/xD 9vsO4te8pgwd8ikSvVhnd3cwQx6jAaJ+vsCjpJpWAcPWuMpTh4kMHQ9/dylSB1sgEc4o boBlj0P69dZgpYTOUuCtE/bC1caINvJKSvgBOFJhQlKFahGnFN6IKytmc7ep9fmjJmPD 3aA6IRu+YJpaJSgbmFX3HXbLKCae+EEYKDBMiBDanJtFjy9xSdATtmt6iO7JXOaXc9+c EalfcbAgPYUi2n4VnkKdxQR6xvSx4sNswYuOd7MIrzR2KOOO13g8om7jQ1QjQuO11Lmi /Jjg== 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=9xhnDKrjvRgwnAVDsuEDmotQGE1PCbtaJeEpVqamujQ=; b=0p5DgSfURVcPNlhHE7WBVAI9QDd2gexfawfrqC6/rM4QIcoe7iHNWUYahJ+tF8wsqP ZhK08EfMWQei/UelzFXalXzMfnDOXHsQn5rgcgPby3bRq9zGzoUvzJApJmjW4Mvnrhpo hBMaeMvDXbIIMm6SymfmPCnWVSAGL6CmIORqt5Pu4cuEY0p20/YK1qYs+lc0d4LLFF2r 2yCaX89nKjiEVkJnv9Mar3NNkDVB9obGw5bkdQ9D3fQMh9I0ZChDR1vJVSiwrWa+m1MH PGIt2lxerxriMRoBBskhx7SZqSd6zy8cjo9oBTHt5lvW0uf3BCHhGf+wa9UJyOs/H0wn Cgbg== X-Gm-Message-State: ANoB5pnFWgvyPhNxFpkndM9xYyQHMEibp9NoY62tQOCm2V0bYy9472mg Ro/r6A1LnPXOVOXddaMSjEw= X-Received: by 2002:a05:6a20:2d29:b0:a3:ba8a:43ea with SMTP id g41-20020a056a202d2900b000a3ba8a43eamr4354489pzl.58.1670522612163; Thu, 08 Dec 2022 10:03:32 -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.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Dec 2022 10:03:31 -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 4/5] swap: remove the swap lock in swap_cache_get_folio Date: Fri, 9 Dec 2022 02:02:08 +0800 Message-Id: <20221208180209.50845-5-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 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?1751670261776519464?= X-GMAIL-MSGID: =?utf-8?q?1751670261776519464?= From: Kairui Song There is only one caller not keep holding a reference or lock the swap device while calling this function. Just move the lock out of this function, it only used to prevent swapoff, and this helper function is very short so there is no performance regression issue. Help saves a few cycles. Signed-off-by: Kairui Song --- mm/shmem.c | 8 +++++++- mm/swap_state.c | 8 ++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index c1d8b8a1aa3b..0183b6678270 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1725,6 +1725,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, struct address_space *mapping = inode->i_mapping; struct shmem_inode_info *info = SHMEM_I(inode); struct mm_struct *charge_mm = vma ? vma->vm_mm : NULL; + struct swap_info_struct *si; struct folio *folio = NULL; swp_entry_t swap; int error; @@ -1737,7 +1738,12 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, return -EIO; /* Look it up and read it in.. */ - folio = swap_cache_get_folio(swap, NULL, 0); + si = get_swap_device(swap); + if (si) { + folio = swap_cache_get_folio(swap, NULL, 0); + put_swap_device(si); + } + if (!folio) { /* Or update major stats only when swapin succeeds?? */ if (fault_type) { diff --git a/mm/swap_state.c b/mm/swap_state.c index 19089417abd1..eba388f67741 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -324,19 +324,15 @@ static inline bool swap_use_vma_readahead(void) * unlocked and with its refcount incremented - we rely on the kernel * lock getting page table operations atomic even if we drop the folio * lock before returning. + * + * Caller must lock the swap device or hold a reference to keep it valid. */ struct folio *swap_cache_get_folio(swp_entry_t entry, struct vm_area_struct *vma, unsigned long addr) { struct folio *folio; - struct swap_info_struct *si; - si = get_swap_device(entry); - if (!si) - return NULL; folio = filemap_get_folio(swap_address_space(entry), swp_offset(entry)); - put_swap_device(si); - if (folio) { bool vma_ra = swap_use_vma_readahead(); bool readahead; From patchwork Thu Dec 8 18:02:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 31449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp345150wrr; Thu, 8 Dec 2022 10:09:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Hfw1/zutJ5BzwsNn2Zv7eG9evES3BuU6VgPZp/UYjQurxfLS8fml/Ee6KtbcDk8bPTuZ8 X-Received: by 2002:a17:902:da82:b0:189:adf8:54f8 with SMTP id j2-20020a170902da8200b00189adf854f8mr37000735plx.81.1670522945430; Thu, 08 Dec 2022 10:09:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670522945; cv=none; d=google.com; s=arc-20160816; b=fzbFGP2mLsynBAL2sVgD5IsG7MkhYBmd2vGMYE2s9bBfSeUaIOQRp+aRMQ5N+CyEYS RcxJ6BwA4vYySJQxRihzQRA1VF4bU48+venxJaHXXqvPy2EZMu3kHws1TT8qyuDD3Q6w DfZCopo2v2rgKxGeZDIuzEDHxq02SJfNXIzdWBmEupuI/422BPbSkhSd/vk7VD4qky+q bC5W0y2LkyFBWbkvZuoY9a+VuoRI3jcRQmZ5CRYsuCsRhej6iTizHW0hz+/8F1+w+1kJ nylr3Jifr3W6trcSX02Bo5MGqwrFzZ9jVGfgf360bHHQFIwuI/vRrBcHmfFKFZGmT+fH jkiQ== 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=ltPbBrCKZDS7mJn+bR+RqAKCWGPP/Hc1SQkH2hWVmXg=; b=hrYkPDqiBw05WW2ZrSPwE3UrXz3+filTM6o8BrjWt1pOj0IdPEpzT7cj8KObN1fHWM KW46ZFr2Pao8luhk6OFjI5w6Pg3+i8I5jnI6pUe5vEaAyLj9ABlkrzKEPFRFPvJSGbSo oMPCN0ps+DDVecrgiCVCV5q/rn1XDhcCyU634tyAFY4UilJnBhtlbYiX/frLUA7C/CP/ 3kr/UEDKPqcLvAMHHxblJPhU0rbLF/cNWbHW+PdQKGX8PXjGPorQquTsTaaeMOwlcuML eZD5PXnb+66y3LXAkxBAZV0X7bOSbD8gJ9T1VkHgJJGhIGxTFvpSRePzT2xj/8vlZ6Mj eS/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hRgCXWOP; 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 q33-20020a631f61000000b00476ef0d44f6si24086591pgm.672.2022.12.08.10.08.52; Thu, 08 Dec 2022 10:09:05 -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=hRgCXWOP; 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 S230019AbiLHSEC (ORCPT + 99 others); Thu, 8 Dec 2022 13:04:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230007AbiLHSDq (ORCPT ); Thu, 8 Dec 2022 13:03:46 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38676AE4F4 for ; Thu, 8 Dec 2022 10:03:38 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so5464233pjs.4 for ; Thu, 08 Dec 2022 10:03:38 -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=ltPbBrCKZDS7mJn+bR+RqAKCWGPP/Hc1SQkH2hWVmXg=; b=hRgCXWOPDDo7RlbXFKoM69xuCbwt8WjzTaUsg01akGxMhNwABD12DyylexVFkD/7Mu M+qrq5HV/MDlhFQ2jxpJkr9HNBE7YMfEZaXVGRTNrwlZFE00eokpEecQWj3j6JrbPCbA 1zHxzkaBVjYkjr1s2oWBVUR/5nbzmiSc+/4+6qJl50hF8eFgPh9NnQuk0lo+FhfUqNe6 F3QleTfoMD2zNv1+SBcEq0q4ftrAofnh81ysKVSlErGBas3RbClmzj9QYTQztCMaIqID gUiM72cYqHlrpjl8RiTv3askqJOawjDqYKnOo2KlhUkvFGpDTtXyhTuqVoXIozJUmNZa Jslw== 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=ltPbBrCKZDS7mJn+bR+RqAKCWGPP/Hc1SQkH2hWVmXg=; b=S8GbmdEaaJ15ZfSu89GZnVlKJeE2tH/TE8XGzvRWNebysPFY7GUehDE84EXQCGVG0b xMTrBfJk1IVFdCYcz3hQJ1iNm/sqWerwxAIe7qr/Vui2ojXOX4JSfhEtSc9kTCeVcjfX MhDFvswpvCwi2DDSL7tekgo8hFF6Nq6RssRyabUHXKTZ1pM/k0G91jumERUvN6wCMWP3 rWznlWXlrfpl3DLU2DGtvFv4JW81F6nidahWbkln8/E4nx2zxFRK7us/Uo8AQPsy/bQp aSGrN6xI2iV7RoLL25JZ+mVNhmYuKN3CZEe7oavR9X7hQVl4wCaQZAIeqow+cOkR2zMz n3AQ== X-Gm-Message-State: ANoB5ply8ySWdXqsekZBmbo+21OrIE+1FfirJGQla69sU6ee9CF80pVJ VPNgRtyG6VGWik56JRWplvc= X-Received: by 2002:a17:90a:7606:b0:219:823e:6726 with SMTP id s6-20020a17090a760600b00219823e6726mr2920444pjk.19.1670522617801; Thu, 08 Dec 2022 10:03:37 -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.32 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 08 Dec 2022 10:03:37 -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 5/5] swap: avoid ra statistic lost when swapin races Date: Fri, 9 Dec 2022 02:02:09 +0800 Message-Id: <20221208180209.50845-6-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 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?1751670268023179798?= X-GMAIL-MSGID: =?utf-8?q?1751670268023179798?= From: Kairui Song __read_swap_cache_async should just call swap_cache_get_folio for trying to look up the swap cache. Because swap_cache_get_folio handles the readahead statistic, and clears the RA flag, looking up the cache directly will skip these parts. And the comment no longer applies after commit 442701e7058b ("mm/swap: remove swap_cache_info statistics"), just remove them. Fixes: 442701e7058b ("mm/swap: remove swap_cache_info statistics") Signed-off-by: Kairui Song --- mm/swap_state.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/swap_state.c b/mm/swap_state.c index eba388f67741..f39cfb62551d 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -418,15 +418,12 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, for (;;) { int err; /* - * First check the swap cache. Since this is normally - * called after swap_cache_get_folio() failed, re-calling - * that would confuse statistics. + * First check the swap cache in case of race. */ si = get_swap_device(entry); if (!si) return NULL; - folio = filemap_get_folio(swap_address_space(entry), - swp_offset(entry)); + folio = swap_cache_get_folio(entry, vma, addr); put_swap_device(si); if (folio) return folio_file_page(folio, swp_offset(entry));