Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2078889rwb; Thu, 8 Dec 2022 20:01:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf6uj6STRIO5Q4NBa2ejKr1IMCtktseZuAH1gzO5vDtHZzYOStb4krgW90uJDCnIjqZOb4kd X-Received: by 2002:a17:906:2a10:b0:7c0:cc6d:5df7 with SMTP id j16-20020a1709062a1000b007c0cc6d5df7mr3751410eje.68.1670558474270; Thu, 08 Dec 2022 20:01:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670558474; cv=none; d=google.com; s=arc-20160816; b=MzkNnReMWMuLK/kTT3Xq4f8dvGlC73JBOszWdo0TobW/BFOfnGJc8kcO6DrCuNIjjG jKPNdpBN8tJaRfZ+SA/ApgWOtqUsYrdgjcSA4pnG61SrwBh+8Q2gPOXGQu+4vgSkzDOb bg2tv/xCTDihD8PRo9xGWKCRRmhKfYmZbKm8Y5GaGENttDpyXfawZEGe6v/cFwm7BaPx nCMErUF7cJOLLlBtOHt8e3Dy8DGh/Hn+/bXkb03Siyq4dZwHJAKj+QgG7+BzC1V2iHzW 9oyBxncQALqi3dV7d8a0X05q4umCIpgTM23yNN3tTp6y020ucc/ow2ohbkESbkOY3cHg vUVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=KidJO/fAOjmV2f/BGl3Z5b9iQkZYwh8ZtwFiaXCtBvw=; b=UvBEDv2sX8seEQyFT9HBcjJ9W2gSHKQahhPVMIDaYnL6OaYHT/Eevl0vKzOp3y23Uk 0J2PV21gAfOwVw4eyH3/tbKHx0PTpqgYg9+euBdZ64nuUItLkjotPsrOpEHSaxFQhQO2 tKlKlGCrtE/cE6ZKb+/B/YjJvm0a4axxkQomirh9EZFzJdXVm9xnyaqL2pSMPAbm7CPI B3M8v2UDs1scB1T9CFURsjdvwbv9ayAU4vpP7oGYIZ8DJHTn7NgPm6a/tG6GJnfT6LIn yxtbb59GIS1ndLfvfSV1u1kJ2iXPccIKfg/AezWnNzJBrzWYuEokfYPM3eq65F5//Klm aV+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fJRKmvE2; 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=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf3-20020a170907098300b007a6384d506csi273742ejc.643.2022.12.08.20.00.55; Thu, 08 Dec 2022 20:01:14 -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=@intel.com header.s=Intel header.b=fJRKmvE2; 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=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbiLICt6 (ORCPT + 73 others); Thu, 8 Dec 2022 21:49:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbiLICt4 (ORCPT ); Thu, 8 Dec 2022 21:49:56 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D23EE79C06 for ; Thu, 8 Dec 2022 18:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1670554195; x=1702090195; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=camHpBbJjLrAb2h11w8/RSo9EU+YkLRp9/dJEdKNeDk=; b=fJRKmvE2mEkWGUEM1FGHgd0G0w2phKzerzvwSudZTBqofLY5INi8YLRA v1ph81s3QdZoCAjE8OaE5/Sj9iB67Qs2eP14hN4JQeCaItZDtsK7gra0K AFLxgBBJPFM5j9qhHdkNrTV6fAIKfGLLxcRZX3eShPGFARE/+srW2XmI+ yZzb0WIRL5RLdotNu8z5BYeEUP0KPHOiRw0ZGza5aj5ncT4wqjqDvM+jq 9hCJekDfDkI1KCWCpsjssoOVUkTwulWSTSj5Gk24U1Qx3O7OBRqBWKc7B DI0/cIUlX4C3W5lKYn4Qqn6HLKXfLrfHW0QAlHnJRUaZixrMRwkHsCHhN Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10555"; a="381673157" X-IronPort-AV: E=Sophos;i="5.96,228,1665471600"; d="scan'208";a="381673157" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2022 18:49:55 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10555"; a="710736287" X-IronPort-AV: E=Sophos;i="5.96,228,1665471600"; d="scan'208";a="710736287" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2022 18:49:52 -0800 From: "Huang, Ying" To: Kairui Song Cc: linux-mm@kvack.org, Kairui Song , linux-kernel@vger.kernel.org, Andrew Morton , Miaohe Lin , David Hildenbrand , Hugh Dickins Subject: Re: [PATCH 1/5] swapfile: get rid of volatile and avoid redundant read References: <20221208180209.50845-1-ryncsn@gmail.com> <20221208180209.50845-2-ryncsn@gmail.com> Date: Fri, 09 Dec 2022 10:48:41 +0800 In-Reply-To: <20221208180209.50845-2-ryncsn@gmail.com> (Kairui Song's message of "Fri, 9 Dec 2022 02:02:05 +0800") Message-ID: <874ju5s35i.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 Kairui Song writes: > 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 LGTM, Thanks! 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; > }