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: 13068643 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 42B78C4332F for ; Thu, 8 Dec 2022 18:03:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C87348E0005; Thu, 8 Dec 2022 13:03:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C12868E0001; Thu, 8 Dec 2022 13:03:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB1748E0005; Thu, 8 Dec 2022 13:03:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9C0A68E0001 for ; Thu, 8 Dec 2022 13:03:19 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6B15A40628 for ; Thu, 8 Dec 2022 18:03:19 +0000 (UTC) X-FDA: 80219910918.09.C34B658 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf19.hostedemail.com (Postfix) with ESMTP id 9B48D1A0022 for ; Thu, 8 Dec 2022 18:03:17 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=elKCQdyB; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670522597; 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=E96Wm/nE/BO1oqx7KrRbQksoP0SM8QfWpUYCtfF7ZOY=; b=YWSzaPIbUeVOnpAGwhhkqOuo8fEAJrn28d+x6HZO+lPI6mdTL7RYVtXpUMk6U6bot7nc4g 9zk4Uk+75K9fOEfXufcJ+QGzj6cj4vZ09Ri+DvoE6k6eJdVOr0quSc+lDpDj3CNaxza264 DVX2ntbhMgnsIlSX4YCy3OTvLvrn/Ag= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=elKCQdyB; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670522597; a=rsa-sha256; cv=none; b=nApUn8QhJTSGl2DkrzOIdNjNZD5gx3SXqEA9HyI0fYUqdZmgzcZyzFKL7CEAu+krTwxWDy AoamAM6vUOZmDTtTQQdKp45KXwpGle7yQQFprI4EDuX1kEQ0F9bpBXHNNrt5g8CRo8W7rW iCYmsnltVF8CXumD6kfaLMyqwB0UF98= Received: by mail-pl1-f172.google.com with SMTP id d3so2246812plr.10 for ; Thu, 08 Dec 2022 10:03:17 -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=3yW1eo7xC6jISnLrrfSyNuPDslrwvc4+vBH5bmEWAULPN/H9rBorXGaKGZV5Fc5fJp Xy/1IGd1K87dN6Y0LTuXohKAno/OeX0WBybUWdz6IiviQPlqOVPWTtaH5REtQVW/dUvY BsOxWeEX28qZ5nm18eIZhu9wrErTCd4RfaWCZ06FHeZUq51c1BKYFyd8OxkMaNsE5uCb kY1x+O2nJKjvK/05mcKOHxwNmIVBFeLf5Q94+ziZWMpDA9D/DscRJUx9F5R6UskSaej+ KjwdFXVpRowf19C0xII/h/6FqX8P+sijBLsiwpGQLf5DoC3Mw9oiGMEl4G7sGXDRb/I9 rDSw== X-Gm-Message-State: ANoB5pmRzzW7PSUqTPR54/HTwvFpas3erROAzHl7RnlDTDVwcZ8aVO7W oadLkhlLYan2NsoPmNyOY/mNyOiuQAiyiTqk X-Google-Smtp-Source: AA0mqf4pM+kGOAZ0I0/E4epPe+dakTrALDjT5h+cTK/rmfAO6gWi5Nw7yw9MBJ7OdK2iYJAqFCaERA== 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-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9B48D1A0022 X-Stat-Signature: 5sti87nseqzwauridoybtrbk1q39nken X-HE-Tag: 1670522597-222098 X-HE-Meta: U2FsdGVkX1/wpCgbQ/Wp++raHm6mdcS6WBgPXyUfk+XeqVVXpDrM8dFvb33d+uu8Mv/E2jAvBRfhEYy0YfGrf8fr03m9mw8RuHaJAZXiqDTk8gW91aYVJ26yMqygUgutdy5MB75tTUJbNDOkDlB/DI6loXD7qU6x4C5l+u2NtPls/vxAB7NPuIxkIzt7jNs99jajC4lcktc69uW53tJYgWLeB2CU3ckXJ5slJwl56lehOqB7a35Dwx9WPxw6FX2N9Q/ZsujU5M/cAoNVnNV3019tAs/gED/23HloA3zKfbvj/BTF7Z/Z3G9idY7Ts74oJ/X97WcaooYairDE5oLo02hZgbXEtKp1N1z2jO7X6wpo2jWYQohjr2V9gRONf0u984dM7sdKcAm/8dmkBbFdK0nCqPWQTS+bEmovobXHQI2GkTs30zwjpWb7jzaPOcz7PgUjkdSMi6oeX/oPfTRGSSt6qk1COZ5Jffa4x/TJ8NsqFvwMFkidbWOEjdNVozuJzWDZ4F2kBfZlIzsJC2IVXg+XBsTgIRN61iSNbWw5/65c8Rdkv6KqRAOBXYXzzFN33A9R3AkijcPqSZvyASCGgRh6ujSqRMWAj+YDKyEaDgsWIDrZPa/N9twMVPrjlMfn6l6EDM03C4pShHYrKm1zd61PWtaQx61bhdwpW1YlZdQYLKwi/ycnOAWogqwUvnY3pqAbPRT44oA5cJiR7Wjo6g/VpnOJZV5x6wo2zGDxZ0vLsicEochrw56rBVJG0BU8ma704X7gnO0ot7Y9i8Cbw+u2D/mZuEUnhE1K+rkS4PqdcOFmCZTwiy56EWyxfhTUnENy/qrt91KNsT4D7NVs6dmKP+gChmU2ryCyrdoykkR+Tgo63F/V9Z6aWN65EF6mo+pVSBkAJBCbr7hlblE28BiS8zcfNsrd046OdpsgoMdc6h0rZnE8XCL1leB7zEe6xTtYNVugpQMO9IyoxLZ lmViyYWY FX6srRXzyplJD7VSuWknxDzv58VzfUADQcrvN2dV44F0/NMYivh23jSWl0Pjv7oSzNkQk1LBnfv5XO38MGLG+SfKDDfD/0XFU/7h0sR0fLRk6LeQ5aWSqBG2Ic/1Uu8iiXxqzVMn2ULHWKArqqMXBLuIGwJxDNuo6PLa3b8dDwRBvxq26b3bkepIKvEMa75BFyJj2i3Tr7l/WYe36ffhKfB+1k/h57J93jfefipKGdjTLnKOs8B88Qe1wwDoQ4XtRVWYlU565+KVh9kG8lvcXJ22HvA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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: 13068644 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 A1710C4332F for ; Thu, 8 Dec 2022 18:03:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2EA438E0006; Thu, 8 Dec 2022 13:03:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29A0F8E0001; Thu, 8 Dec 2022 13:03:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13B038E0006; Thu, 8 Dec 2022 13:03:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 04A4F8E0001 for ; Thu, 8 Dec 2022 13:03:25 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id ADC75406FC for ; Thu, 8 Dec 2022 18:03:24 +0000 (UTC) X-FDA: 80219911128.05.BC3648B Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf14.hostedemail.com (Postfix) with ESMTP id 9BCC0100020 for ; Thu, 8 Dec 2022 18:03:22 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iViaYugs; spf=pass (imf14.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.182 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=1670522602; a=rsa-sha256; cv=none; b=lXaZDBKwmKuDBXOLKmWdWc0z4TmJw8gC0aJRAB7MO/5ZTBxBYhKzXLLdDDfyuPQV8W0PAL 8fJ45utUw3bBrRoi7kWRmORYIgrGsiuTkoDxE5PJVGNMU5zqk6tvUuKiPVby4zUBnY5q+Y LOa6WopYRHdPkFeRpTnQx30OZRzDTps= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=iViaYugs; spf=pass (imf14.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.182 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=1670522602; 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=riLhoP57eVPqwj4BrvS8Vazxssa2eImOkYsWKI1T0t8=; b=vtxvbxw7LW5OiITxpjY5iJb12+rr7gezpE/dvjmArLW+tigIu2dRUofpxvtQenpFjlVx7a KeGAkT+XEpykzi/bUr3fecOklbXIdy4gmH6trzOUh1zUGJTYG9VzgkS9KZthZc5ZvDolsY PnY9tO8OeTEwPNquFsJ74GNtZGVoiXQ= Received: by mail-pl1-f182.google.com with SMTP id k7so2258714pll.6 for ; Thu, 08 Dec 2022 10:03:22 -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=gRM/HM52mQbfuyJXt+/JXrAZWJmaBlZly8RyXfM3uSP9SwxX0sxjKQ1UaMVBQxuY25 iHGixLGS1eOZOYWexy3dkFqY10Qo95ed10d+eRyOP9NOhwrE4t3DrEE/wtoNGW9OaorP 00sQivbcXcjOUHgDp+2BCIcgPDYUGmRMs5JCzmSqTQajm1eGylL0zwdnw7TC3EilHhPa vAfsdxphIw+zi8aaevsKhE7MlNer4czSwjA1nDIAuBb/5zReKWzaSo/U9EdkNi/oqnwJ u9gG7KN2uDbY667vrBvVdnrht8jMj3SRch9s2LM1YCaVDKobP1UqLpFct6kCt3DZt/y1 JJjg== X-Gm-Message-State: ANoB5plEZ5HQovljH9bA+9Gf88Xb47QM20rDkq5blQJJntJFiJR45q/P EeninR/H3wmv2G0FEGZefheIrO4l9JuyFoBy X-Google-Smtp-Source: AA0mqf6+g/Oq8lkThW8oF445SVxUDWkraBM2XVzF2FkZ356SyOkPQrUSg1X2tifk5oVpQEdOJ+/wig== 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-Rspam-User: X-Rspamd-Queue-Id: 9BCC0100020 X-Rspamd-Server: rspam01 X-Stat-Signature: 7hwhhe4guuipsgxs53ubf8hsgnnoxqky X-HE-Tag: 1670522602-245943 X-HE-Meta: U2FsdGVkX18rgLzFwJK/arx8ynT6aDZnHuM7mAPccgsBDv48TiwZf7U5I8UcwQNkW2BCh9QaM05OttvYG79lDUfHmqqsCrUPDI7meoKvYGs6ZSEZ8phxcvFldiwyVSdc1wD/+Kl63PdNVhfFNVzHMT4HjBvkgg4Sa1KVUKxcamTRsajlQgWI5ElrtxAY5py8DbGuFsa6RcAMbPm21pqXqpPf2+2Uq20O4W9XpOWHJPBf83kltlI+2abm2a82/8yHhLd218ujdEfoZFNR7SKlLoSY01HdJGig6JSwEKX1sjSY9Erhh9avZyeZzdPPmH1jYPz91axQxNh3J/+/AZTXw5sftWzYvpEkEFFtx/+T4ABuim+wxhQWqUS8d6nAGiYbwZRvhbMtPJGb4hSbME5HwZ4lODuc5TzPvERYCIo9t57rGsT9tmo1d53cDPuWmQqypk2MRCmqyAZdcqM/CKipNVhtsVmDLYizGRNhkPLIeFN91VoezPQdYhVp1uOr52QUpU4dnr+DPvWOPJTFS+ted2r2XdPpVWF44npxQ4SOwbb8POq0NO603Tvs92xpBowkWf+FXHX5X4xPUtLK/L8zumBOmCc8a7jc5UGK0b4+E/XJYhB5mHqK+anf0P7CQAh9Y4HsISQoNBCXdbWrQiGl3HaQunQUxEP92Pn+66pQLq6xvNmshGt3yc1Rr+3eBl7mShoh/4oZe93kRIpDOrXOcWdGHKsVN329iaDZuWbEA/aYzbFxUjeMmfiiq0SSW2U20Aauvq91FFbhvXtEAQg9rdGMeXk2KGksisxSk0xWaVYT+kfVC3sZ/B8KpT9hfWzh0Hpp/2xJ8QVJ9KhNaLdGap5fUjsM/rgVcZDuxLsLtgNP68NQMmEurjQvIOBfirSvJxWEVVLsQ+as+u8ErPVH6J37v5gthcJFzLfeNk9MBtEn+Jw9OOdEqq1Xrn5QKj6oxQwE8zggKRJhlTHhXbU Nh4MH/1N 1dNMog3DG05E3scsthfzdbfplm9NkGkDs/5yl6+35qOBkfCGcqV++PAdJyAmJHpWMGaUBzMWb8eIV9iMDwn38NRD/BNi/lsD6CkpICea2bIEiPDm5nWJu3cOVUWCNpLinoU2BczMS/0c53adb8HqXCWlLQoYGrGwPCvkUF/vaSTtgqH/Z7TzOHEf7jaPnE+Aa7b0e5piZ+ePf2uz7i8oS+ducLxa3uicQ31xhJ/s0JDrddYesD20JEJ49I8FWJHewS9yo+PSuYwkNCxz2Kxaf2EYArg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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: 13068645 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 EFF86C001B2 for ; Thu, 8 Dec 2022 18:03:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A6AC8E0007; Thu, 8 Dec 2022 13:03:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 72ECA8E0001; Thu, 8 Dec 2022 13:03:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A7FD8E0007; Thu, 8 Dec 2022 13:03:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4BB818E0001 for ; Thu, 8 Dec 2022 13:03:30 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0A40616084B for ; Thu, 8 Dec 2022 18:03:30 +0000 (UTC) X-FDA: 80219911380.30.12E7EDA Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf12.hostedemail.com (Postfix) with ESMTP id 26FD040013 for ; Thu, 8 Dec 2022 18:03:27 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OpJs82IF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670522608; 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=sO5CoFHWHd3hJkT66P6565Tno5APV7gOVtSSvr1Kmak=; b=gUivpDJBH0PlpyG1M/2B/bNISOivgALTuj3/Xd2Dt6kDnSdJ5SEB1B6et6n7ioaPVjgfTD SiOtojMTyBKLVpzFTCFnhSo/EJus8Yk6GcxBSKnsYjQGAsuXhnsjy6hVfBBXhPvgMr49NN xKYnzXA4gTp1uqLml4X3rfom7qSgjTk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OpJs82IF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670522608; a=rsa-sha256; cv=none; b=zfMrZx58CkFwMoBU+gPJnuGN+YuNy2E8C8afH/dBkefIgY+UnBTXI2Y3qj174XJFsTrBv0 PsmhMAeUfs9jpjyeHf4FeVI7lO7KEoHxkFce25Z9HfVDjQqVFgmvuja0iUkOYSJI6i2d2i +tsLo/HnWVJaco+CE7TVymnRsV3BBI8= Received: by mail-pj1-f48.google.com with SMTP id t17so2309724pjo.3 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=JTeXnynOax9QDmwuBUk9SbUpPp2yPo1VGnWr4AiwGjD/X8E9Gw3TZTSoDCLlz9qYmb 65hivRaXccbWQsBgrs6AEhSvOG3GrKdvwrjxxV8zqPTT7VUk8hLn6jeLHQDxDJXNnhEg 6KSg1DpxLfRCLy1Nb7mhPak11hDo/2bUEtJHAEyywi11DHTaWBkGKEyttskWMoqMVJvx 1oLPCtq9yyvaaLQCGonyLJxqQ2A6XQ3w5NhdTNU+f51uRaEiwxb9aHr/pul030qprbLS NU5H5lwXF5zoewO/2jTVxUmIsk7qtq3/ShBJs+SvGeqswZHGBVjWhRVSN9X2W9F/SII1 EJGg== X-Gm-Message-State: ANoB5pmFy1S/GDMcvh8q/5ybdnnKDbuTF6hTXeruyRRMTqiwR0cDAp1n UvKwu/FuKFuN6S02eozkeI5l9gIfGP1s7zKt X-Google-Smtp-Source: AA0mqf4wqo11j3YseWJivRlvVsI70evGtgCftTqnGdlt4+R5iI2+u8R1yWbvNTkV85f+uZLnMttwbg== 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-Rspamd-Queue-Id: 26FD040013 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 5ciw6mzqbkerh7dhcdp5e985bynj6ywz X-HE-Tag: 1670522607-821556 X-HE-Meta: U2FsdGVkX19bYJd0adYRDXcT8rSLbkuGEpZPfYdTmcqWbyXHgGXGmTel5ntv1kLcmptJrn/cHdc+k0Mg20OC+coD+UplJDbgXgpT9388I8lJ7AVDcv1GpfQLx8WMGVD0o3KNTECywHQ9oqXAJS4y02qRNYEpMqGe/MLZc8Y37m0fRHcCye5kZ6E2FKl3GbfAaLsdykNagAgM1DaFgkxRS66I0IveNoM+yROYAwK/yxIJh7vz2wTUCD+1tH0mqHylz420Yx9nITlvVoAxhS8oJm9XKWjlhQoLHjAzh6C706mcErlGP0hZwXFM5ZEErHhrdLq9ieQEFNAYZSu2PbOGzvu3NdnsfHDjiLvCV5eUezMi86Oalc+8qme5hpezz9cqBHmBGx3AEYUemrZCxSyeAt29QPm/d0Lcil+Iz5k6Azc6eZSl5qGQPvHcgRuff20xwkeGkf26sxFuqbj51bqGKrZ81PjDIebUmzk5eroxL7OPOg6wfdd1F2rAAinUTfXdRlt+3tkms5tTiemBlAH7P4AHAhbbErGTIeGpNk+igBZsIM0iqSW8SyfJbSUtKWjOOhfxln14BIAQodrzRjWSHkfC9784RUCVj/cMfCU2nTMOMDbFJWRR8vxCFCVVcz/qbas44eYghpibr59WMAEm8RDT3uA8LtLxqMgMyFrYRli3cjCYVqqgL56ly4hQHB7NF/Zpwm09b8LZFRU4BUOCwhN04yqdqHpfUD5hzKU25FGd146Wb/qy9l+r1YnO2HwlUiDvIPKG2lpjher9JFG0CP6aXg6GULlwqkxzpCGwtDqkj9Pjz4qYC8iWf7jD5svd33+2Xw+wk5WDRT2NIbE6cf6GIFj+yCSy4mhhhO6GZuN6QVZwQVEMwurW352BREToc4+JkWmO6ZhH3AoETsqjOuDlD9zZiR9GvOO0AcsuOL94fEkNoH25bVCSTnia3Z00RI6sCQJ1wPE6rgB5eqW CmA9SzwO V9G4zE6YMaZ7zD4rhccvLug1YIXrD0nB3VdnfBZg58aIvCkvXw3JfeZ6LXHxWYfVu7kzf0d6zUedktbfJ+0NF6RDP8zQ6w9+7nO2rtpbm0EvvPfEMlpRuJGT3I80ZEQK+TpLcTVhBv1KyfsCRq8AUU3BT6Vw5cbvXkkJ+z8WqSpRBLdDpq0RHNAAGTv+cwjwSp7KHzePzzMj88sVvAoltXx8HHDcXV/6hEh0PrM6Ylkq07OeFx1XL++r9yc0aH8EKLJCfogidHvvDIj21+M4rn2izvrz0ObxxWaNJ7QnWNoJBeKHLnP7Kwoddb8q6XZdjH+MQ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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: 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: 13068646 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 4A860C001B2 for ; Thu, 8 Dec 2022 18:03:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E0D758E0008; Thu, 8 Dec 2022 13:03:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D96B28E0001; Thu, 8 Dec 2022 13:03:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C37798E0008; Thu, 8 Dec 2022 13:03:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id ADF158E0001 for ; Thu, 8 Dec 2022 13:03:35 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 730BA1A062E for ; Thu, 8 Dec 2022 18:03:35 +0000 (UTC) X-FDA: 80219911590.14.0CE2453 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf07.hostedemail.com (Postfix) with ESMTP id BEF314001A for ; Thu, 8 Dec 2022 18:03:33 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fYS6yck+; spf=pass (imf07.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.41 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=1670522613; 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=9xhnDKrjvRgwnAVDsuEDmotQGE1PCbtaJeEpVqamujQ=; b=uHqlkUkolullwyxzj8ioGhoPNos7CPL7e3axu+MnUruvq5tmhrZql/vM1AfRDEBYKZ/UtB 1Q+c2KA5VdJtwkatmHvnXyufY7r78C8yXYIHP069/HlEj2QmvTjVcpzLFkCkZNvfkJe9Aw RWMvI3u/uX25N7Tx0u6g87iYCDLbitc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fYS6yck+; spf=pass (imf07.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.41 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=1670522613; a=rsa-sha256; cv=none; b=Qaa8Jh6mdlXGloLCKVW5CviwuIdSrVgCoQDD1qpIfWdvnjspdyXXNyOnhrwRGPLp0oqdUs ipQVEO1lTyxIT3SorVz/2wHetdYs5QoVQETCbz7t/85upR0Oh7QFqruyuiuiXoxynz/yoS 2LJQP3+ls0z1U/Ss9kGjX7j48R/WecM= Received: by mail-pj1-f41.google.com with SMTP id fa4-20020a17090af0c400b002198d1328a0so6529966pjb.0 for ; Thu, 08 Dec 2022 10:03:33 -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=KnPnfXDTtqnhvu/RZfCOm30RBNjq7qfVoXpmqiwPEk80to7iuudJ8zyFvxFhlRNopA 8nU9skTBAd2CQYNHwWkzUp6/h9XDWk/JiorONH02sNN2th5TpC4nojYuwaRrveIKMboZ Pn8qbyJTRfpIxLyXs/HlIUbcFRZosiPtqaMolp/1YAvRtOeBZFhz77VdsAC2KffCIgTo wHdPtJV4TPf0osaNehaASWYHw29g2ZZnQPW3PN3tCDEepeUcaJ5jy33SftPxIXbNAIus ZOFrP98q5byHxL6f67vI60utSdRhEbN3CsAFUczTeY2VHPzK7DABbUu+RmDgcllkVk4X odkw== X-Gm-Message-State: ANoB5pmnQnkmhZi8+wqm4yybp46VazfKRBeo3B3B2j/VjMVyc3B7n8S8 vxYtFrTgFJg44lOUSSHuItnIk56DboOSMnan X-Google-Smtp-Source: AA0mqf40eA3n9hLVOhVvV4ReS4Fw/NzKyEAVdLHHp5a3pHjwNFExX1/Jxq1YuAjRsdgd/lCwVPtNjw== 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BEF314001A X-Rspam-User: X-Stat-Signature: w75zx595dtryrxtq4qhe35fudgdgxfmw X-HE-Tag: 1670522613-726538 X-HE-Meta: U2FsdGVkX1/XKQlAV99Pq3rqvImWu42P1aSjfYj1d6sZqz9RptBR+Dmf9BeZhwYMIxiKkwEeDQYZcXcu1A9hptoMGvruWISJzmVI1jeItBoij4u1iRm0h/wfRqsSc6c+UTSfEn4DSiyeT58fvc1uN/3Yt4ZXo6p3Vl6VJjbpdv92il29oS77ny17bpfg60wuZK5tggeHnDabw0Ey1LPtarrD3d59ipJnZ8D4IElOhIW+CJAdiH1BrpfKV/wS95DSSqWTeTyNHVMvfgNbHhx+9IBtN6iHHgvF2UCBPu7azMEyRSm0ZvtcNviwKAe3+Cu7rbnRUXHsDBE0Ae1zHxAzg6QpQZnlGVppBqU3IQY3h5+3i3/jno3Qg2UXd2EjdXmNChiXb8ZMdJAR1CXi/gX8BlSmA1AJBjGrussDJqjOytKx8KvDvDF92fjkBqvTQt1CTptyerzYDgMTY/SKoULQaaMz2aKuG2znVDUO7KaOA+0U2zAmMKQhg3pv5pb60mgQjHSt63OJO6T+PgpKN16hE5LSgpNxpNAUmTlfOs+laHN2wEto0Db5VOMmEFfKjhZ7895AxD3Ek/qFSKIa9YJNIF74ZDLZZ72+g0Lp6ngA28ttKKvkak94kf8ctPCWUKG+xmAbwKEg1TjTN/++19xX+QJKxEQjNP/AI33dhiVJUGYsSgZhFh9fG8H9fBOO7le6QB5msG4I60jTT65SuzcxNHLPm2pyttJe3Z6O+v45Al9oxOdPHzLeglsGM1Ogmm3fUvN4AX8wtRdFLYqqjLjdYxKlJJDqg7cee9EHtYVkcKIDeCFIAXMH1H2C0CltFkddZJWVP/8iKNtQlM/IUTrkV4EiZ6ngFwGR2GSVgnKHuH0gBLsmxE7kY44uETb6dhn2Y6Lo2G5dshon4xzJ+WGykar5Olpz3KmuXbpS32XXCtuVTv+DccbChJplsEg4GnhvhYpdpf51nkF5js0UU2J xN6aThAQ KtZ65BfqQk6/pPvM5bcotdt69lGKIVDfZZ+yZJcXrcz/KZ2+vUbW4aEtu68YP538N1SCJRiCbeNar3KqiigxW3WbrxCuaUIj4TwoMlGB89u1xiUUi/kGyH/3jLIMeJ7cuv1UJM49eD2J4xVEdOcLT90g57nJD5F0TXmTwcL6oYSXArNwSVZSCCkoNVKd4ngPUgRpXWS1u1p+op3QsL4HnKRs5y33mo5N/LjHZguF8qBbVWXEBsHSyrhJDvs4hsCIPWJts96BcjeiOrw7cUZZ22bZYhcZU7YeinNd5khdYLk3ZVfXr16zYEK8pi+buPkIvdmUB X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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: 13068647 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 D7E3CC4332F for ; Thu, 8 Dec 2022 18:03:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77D8A8E0009; Thu, 8 Dec 2022 13:03:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 754BC8E0001; Thu, 8 Dec 2022 13:03:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F63B8E0009; Thu, 8 Dec 2022 13:03:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4B8998E0001 for ; Thu, 8 Dec 2022 13:03:41 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 14A901608B6 for ; Thu, 8 Dec 2022 18:03:41 +0000 (UTC) X-FDA: 80219911842.19.2967319 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf17.hostedemail.com (Postfix) with ESMTP id 5C4DE40003 for ; Thu, 8 Dec 2022 18:03:39 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hRgCXWOP; spf=pass (imf17.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.41 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=1670522619; a=rsa-sha256; cv=none; b=eouwg8R2VCSb7BFt10MNNpy7DmoWV9zx7LMAnmXf1+TusCawTnCg2OTvnNPaZmY7bJwyKq f+SzgPiXVbrhddq9Or8bLZ1NwHpjjSrn2ZUBefBtcjwW3keunIXgq+Hr6wssijyalyjTmW EcX9iK7TJVJgQMUtLcMcWmr032R9SBc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hRgCXWOP; spf=pass (imf17.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.41 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=1670522619; 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=ltPbBrCKZDS7mJn+bR+RqAKCWGPP/Hc1SQkH2hWVmXg=; b=tti4CXfBNFhB+9cxc6gDtdWxepID5y9LU9oC0DkTofciOUOMse8ybNKFtCtzs+/TwLfQ5C cwjkt3OIyur6MYp4R/NkKpYsfZLCz5OaLGpWkcnSa8UeL+DHPPeqKZg6TJg3EOJsHOGOTW RlBD0zi4QFtAk488rUiBLm5t8SMVtJw= Received: by mail-pj1-f41.google.com with SMTP id t11-20020a17090a024b00b0021932afece4so5460505pje.5 for ; Thu, 08 Dec 2022 10:03:39 -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=JDTAxaPx5+DePerdloiOc/AtICCCOmurbeOngXU8Qh5Gymh7fPRWsX9Lr2QJiYleBE mE5dMvMLaSsnH8vdSq8PjfZM7kcIC9RBhP9LJQdZxYiiEFQLW5AfjdPs4S866A9+22Ss 6m3r+orqJpcSzPFjc17KheKyMowOrmq8QW82g5qtwNXURmEM7R9aBKX1ebb/zJ3pMA+9 dpvoq03UwhR/YZF0SXrksVrfaEBz4UsjtoGIT1T21tSsQ9Nvzs9TtGuBCshdo8qm7KYw 0CJJ9tCiLNp7N0t4T+P4Xjhg0te9+hkAnbtouWswXUtRn7ICAMWnKGKZpfaEvgfg5BB+ N+0g== X-Gm-Message-State: ANoB5pnctF3lCcYWkL+WW8inyKU5L6FESVWwbL9BJmZX/WZNkivlEFCj UXq9+YYf27eWjy/jjKV/OZ+5YAdAT2b7f17Q X-Google-Smtp-Source: AA0mqf7l35N5CcqRRUA9kCptWivxf7XeTYnN81QwD1VXUWMNcNSdS0Hq0NDpeaJYmfVtAUqrHE18Iw== 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-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 5C4DE40003 X-Stat-Signature: nae13tbpx4j8axj8wmm3oryz8aaafs8h X-HE-Tag: 1670522619-983586 X-HE-Meta: U2FsdGVkX1/10Re/8xuqAkjhQ2tq0xfveblIcYvxmca6nTC3Y25/gXLf5O3biyp7rR/dCWMzbFo0S6N0YOq8qKJLIS0ld0VgW8ejx6inJrJ8E6BQjU22ndyXXh82rY/66alrsFsvZ07qernS+pBKXutRwRpu1HiJ4ZH+PVWTQOK8CH6NHrp0khBoypkJ/44HDe/IF/1ZzI1Csqe8m3BpOfN3t5G6ek/K6UA92Q+s1uinPATxQBNhBslweNB8e49rKRpLWTlmuJGvcTy37Eej4bPeG1QuUktz9Y4WeB1uIcFVVyGMzmWWQy8LueYLX9wogcpvSgZk7O50a5wcVteugGIHcVWSmFJZHc8yae3+a3+TI+0dMMLTtAOScVo7cNQcgnHhoLfTPHyD8P8NY2DX2xJS41lwnjIjWPkXLehy+g+NzbY4WvN9ezjZE0+qDyjjGEGzNtJQqzxk8njB5jNuL1s+RbL+6haErMb44C+3lQwy71Yt7KQF0Vyx78kKe3B1BIgzYxhOPKog5RpIPpYFRheSrenhVhb4GSHTsdBtUNcxPZgPJyuM/DwNwbT9eVV4oA3cXKYqJQBHnqjmOowG4+rP/VFKtyolnm661iI0LUjoJozpzEIari9PN3ELETJRFRHHLD0olaPaQ14Mh2GI+heM9YCkSXZ/wbnDV1b1PUVSPDivXIwa0EfR3DFmPxQ6/Kp1BYCX6m1Kpz0mRvMLlpsXTm3FXKuxXBN5D9s0PasknGv2uEmyrM+DR+zXT4DlyHBMQ1mRvuSoUU1duohI8Dw9RmZbaItTkcz8MstodkBkS5opREliKUP4gmA8jBM8l0dmXIrEDaNsYKzh14pRA9bW+Eca/ceh8Ctz11+i1eyVAxCNFI91+G0z98a/vKyd/XR1HgtvUfJjqND+5q+s2z/YLmhHj1du+ufhDQfOg87y45R2B59qsEcYZtXAqStAygQFxfJW7NgKNoqBP/A RftJdBIn 8r3xcE/sgnDOMgHZIL8J86pOi8HcFPzQGLzUttKkctsfQhm/rqHX2+I753OtG7zEzZoSA6Thb5V0n3RcBjjfe7DCr/h46jtWddvawfXhYf9osmlHZJvcB/q5zxL70YAo1eMmCM8/JEVW76NMpOjWCWR3i2B17/Jarqy3SSeafMf4O02emj99hv+oLTcN7W0P6MBFhqXo1HXZ7yBLlRP6Y6Vxrn+mWdI/WJyZ21qFaHdRXuIvWfsJFgvYYnOIJqFi8QufFhU948wcDQl0Du/axYc04+g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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));