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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 E2F91C54FD0 for ; Mon, 27 Apr 2020 00:56:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 644642070A for ; Mon, 27 Apr 2020 00:56:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 644642070A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CB73F8E0005; Sun, 26 Apr 2020 20:56:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3FFA8E0001; Sun, 26 Apr 2020 20:56:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B55108E0005; Sun, 26 Apr 2020 20:56:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0184.hostedemail.com [216.40.44.184]) by kanga.kvack.org (Postfix) with ESMTP id 9B5E08E0001 for ; Sun, 26 Apr 2020 20:56:00 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4E1F5181AC9CB for ; Mon, 27 Apr 2020 00:56:00 +0000 (UTC) X-FDA: 76751818080.27.knife30_8ba73d24a6402 X-HE-Tag: knife30_8ba73d24a6402 X-Filterd-Recvd-Size: 3705 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Mon, 27 Apr 2020 00:55:59 +0000 (UTC) IronPort-SDR: awCkMWbPfoZmBeq53bVbzihKQP8vR/92S/y3CZUUJLrImHE9W1bOjiXdWSAmvJv5OZGTs6Kuk7 ieS9OnOtRdzg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2020 17:55:56 -0700 IronPort-SDR: S+TmcF8itKGuPoD1D0X8UmVSUnSPDOSPwFvoZTNhIZ6AsfZ6+xu6JwdlhR0ZwFXW4S+XERmA7K 1iqWZ3m2QNsA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,321,1583222400"; d="scan'208";a="281525098" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.159.23]) by fmsmga004.fm.intel.com with ESMTP; 26 Apr 2020 17:55:33 -0700 From: "Huang\, Ying" To: Wei Yang Cc: , , , Hugh Dickins Subject: Re: [PATCH v2] mm/swapfile.c: simplify the scan loop in scan_swap_map_slots() 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> <20200426211958.m7aheswirqaj2nte@master> Date: Mon, 27 Apr 2020 08:55:33 +0800 In-Reply-To: <20200426211958.m7aheswirqaj2nte@master> (Wei Yang's message of "Sun, 26 Apr 2020 21:19:58 +0000") Message-ID: <87d07tycfu.fsf@yhuang-dev.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii 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: Wei Yang writes: > 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? Don't think in single thread model. There's no lock to prevent other tasks to change si->highest_bit simultaneously. For example, task B may change si->highest_bit to be less than scan_base in task A. Best Regards, Huang, Ying >> >>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