From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B2DFC55199 for ; Sun, 26 Apr 2020 21:20:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A64B72071C for ; Sun, 26 Apr 2020 21:20:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oloDzFST" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A64B72071C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EE1368E0005; Sun, 26 Apr 2020 17:20:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF4348E0001; Sun, 26 Apr 2020 17:20:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D07E28E0005; Sun, 26 Apr 2020 17:20:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id B3F008E0001 for ; Sun, 26 Apr 2020 17:20:01 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6BCF18248047 for ; Sun, 26 Apr 2020 21:20:01 +0000 (UTC) X-FDA: 76751273802.22.horn65_28af55e3f5d X-HE-Tag: horn65_28af55e3f5d X-Filterd-Recvd-Size: 4895 Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Sun, 26 Apr 2020 21:20:00 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id h4so4115379wmb.4 for ; Sun, 26 Apr 2020 14:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:reply-to:references:mime-version :content-disposition:in-reply-to:user-agent; bh=BjvPjhl3FfO2FNQfurAQAhXjPjZlH3zWtbKhfmVQ/uo=; b=oloDzFSTSo97AMs4LU21xavzxmzRB265Ud9P8mCCmGB29fP5Uhwod2XqEgrgalryEK VUNAIJcl8Srkpy3Yq+JR02qXT0Hbx9sGdApKGNh1Oyh5UonfIiPNG7i+wnxVN+no604D te66H2jawzn1GDEQF30dn1Y9JH4Yyc5pGpA4HEHYvejeVfAoy4pXpkNU1xpkcOpnmbdD zRiZRZ7Y6q0dVj8p8LIqPYQPX0oTiN+oJ8/4ZUOBNMTdm42JyK8jd964sm/5klMU+92c 9N4Hs8+HA+rFMl8ak368mr9egGuUOlC06KfpCofLqw2hHDjKqunXBTY7v6pMbfHiiz9/ jb2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=BjvPjhl3FfO2FNQfurAQAhXjPjZlH3zWtbKhfmVQ/uo=; b=aiV7Q/WwI6iXvakgjksdX9kA+VcPbDEy+L6pTj5ZBSKpVxei4HyCPD9GHVOzWQGV5m ZdjAhE8YM5HSi1EjALxyo1HI4ohwlfwzjcSYUHxuMyMMg/40SDkQSreDUqNEUTSglh1R V7uXTbY9fa40Ckwupsnr6lgq1uUJAg+fEPtOz8Lt11qgudl+NZeOjxdwZeuGGEb9eksx 5ov4geTpEj677DvZY6bamKskb17ItdFlBU/Qw24pw+I6GTfs20RBBY0DexK2C6JgFvlK yqJABPILwZMM5IxrKA9gF1mClcWaBJ2opX6SAnG28oMrD4+GOPRrjIOw+4W8q+ZoZy7Q uuWg== X-Gm-Message-State: AGi0Pub9CCMCW6Bg9aid2E828vjUN1TDRumQZqUB0whZYDqYpRKlmtMw wxX1QLH9DRhx2rU90F+r72M= X-Google-Smtp-Source: APiQypImWK8sOynJOPXWqejPuutlS/ro662B+NUZsGNGN8c5Zizm4x8yijAj55UoP5Bcepe6BMmsnA== X-Received: by 2002:a1c:4d18:: with SMTP id o24mr21599480wmh.141.1587935999751; Sun, 26 Apr 2020 14:19:59 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id z2sm17756359wrm.77.2020.04.26.14.19.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 26 Apr 2020 14:19:59 -0700 (PDT) Date: Sun, 26 Apr 2020 21:19:58 +0000 From: Wei Yang To: "Huang, Ying" Cc: Wei Yang , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hugh Dickins Subject: Re: [PATCH v2] mm/swapfile.c: simplify the scan loop in scan_swap_map_slots() Message-ID: <20200426211958.m7aheswirqaj2nte@master> Reply-To: Wei Yang References: <20200422214111.19370-1-richard.weiyang@gmail.com> <87d07y2181.fsf@yhuang-dev.intel.com> <20200423131507.2rgrk3okh42oo6gh@master> <87r1wdzlm5.fsf@yhuang-dev.intel.com> <20200425003012.uuqh547feq3kz4y5@master> <87tv17xdfk.fsf@yhuang-dev.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87tv17xdfk.fsf@yhuang-dev.intel.com> User-Agent: NeoMutt/20170113 (1.7.2) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, Apr 26, 2020 at 09:07:11AM +0800, Huang, Ying wrote: >Wei Yang writes: > >> On Fri, Apr 24, 2020 at 10:02:58AM +0800, Huang, Ying wrote: >>>Wei Yang writes: >>> >> [...] >>>>> >>>>>if "offset > si->highest_bit" is true and "offset < scan_base" is true, >>>>>scan_base need to be returned. >>>>> >>>> >>>> When this case would happen in the original code? >>> >>>In the original code, the loop can still stop. >>> >> >> Sorry, I don't get your point yet. >> >> In original code, there are two separate loops >> >> while (++offset <= si->highest_bit) { >> } >> >> while (offset < scan_base) { >> } >> >> And for your condition, (offset > highest_bit) && (offset < scan_base), which >> terminates the first loop and fits the second loop well. >> >> Not sure how this condition would stop the loop in original code? > >Per my understanding, in your code, if some other task changes >si->highest_bit to be less than scan_base in parallel. The loop may >cannot stop. When (offset > scan_base), (offset > si->highest_bit) means offset will be set to si->lowest_bit. When (offset < scan_base), next_offset() would always increase offset till offset is scan_base. Sorry, I didn't catch your case. Would you minding giving more detail? > >Best Regards, >Huang, Ying > >>>Best Regards, >>>Huang, Ying >>> >>>>>Again, the new code doesn't make it easier to find this kind of issues. >>>>> >>>>>Best Regards, >>>>>Huang, Ying -- Wei Yang Help you, Help me