Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1103516ybz; Wed, 29 Apr 2020 15:08:18 -0700 (PDT) X-Google-Smtp-Source: APiQypJDz5kLGbIAaBKs9SRsJpYC1Jq1Mm1WE08AM8Pba+oXIXgqDdBBIF88Nwn9lg2aIXU+7LoV X-Received: by 2002:a50:f381:: with SMTP id g1mr96823edm.219.1588198098702; Wed, 29 Apr 2020 15:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588198098; cv=none; d=google.com; s=arc-20160816; b=Yuu1rf0xOryn7YX4K/+RhyeZgPKCptIAAGWHppbgkyXPcyHIPx74ezqVbywxu5J48z lxh+Sr8xqmwvhRvaKSA5ZOuqBYheWAaefyg9JRM5oJN8zU+djCmkfrqvd+eliheCEhx2 DtsME2WZL8nPeJVlAOCW8yHdZgdIXeCyc/mDbXpcUK7HfjY+JYrus3HPg1+H7U7l4a/f mTp+Zcq0w3sqvhl4l1ec2YRa65GRs5FMB8fDJbI6gGiWFq5JmeRfat/5Of5LiXMyNUtk opQkUT+Tk3ZbzmOAiAjdE/vPG2yTTrOeS21GNHSyOJem4hcEn+ixYVBvvCWYdhcCnB6G VnVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=cCQp738aB3EKIql2WfuztXLmbJQqMy+ioYt0kyitzeg=; b=ETNyL3550ziz5q51aS4onzkg72dEm2c9eqQhuVEXVaEpQIQRLxFA5p1wjOJ6FvVWmY 92SNo6HgFiyIyf9uaNwx6L29P3OU2uK/YClr+CiEjD1Apu1aqHw3ZocW16z/Cf1otAWf Rf2PGtlqWvGk8oNWxmkaqoaDn1f5LRn+q+8L50EYZMFnM+JYTZ1Gy5iCn/T8XCIZVAP3 5rgmjBJpVYI+bRIBsyMjuEswizXCASwJu4fCUhf5bspnPWaz9zUnGcd4UF3pVli4s/Wf 9rXWoX79h+j9T6hCWiGR4OQPx5uSMR1xI4YdtTrsFWl1piQAIc3dphFc5D6WWvZKUGcg tntA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UQiUrx5f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk23si4025083edb.282.2020.04.29.15.07.55; Wed, 29 Apr 2020 15:08:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UQiUrx5f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727079AbgD2WGX (ORCPT + 99 others); Wed, 29 Apr 2020 18:06:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726481AbgD2WGW (ORCPT ); Wed, 29 Apr 2020 18:06:22 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 497CAC03C1AE for ; Wed, 29 Apr 2020 15:06:22 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id f13so4376419wrm.13 for ; Wed, 29 Apr 2020 15:06:22 -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=cCQp738aB3EKIql2WfuztXLmbJQqMy+ioYt0kyitzeg=; b=UQiUrx5f5W1aLl+2WI8LlsiEdNagBQjTtcRSovBQy059wBqGokeFUEbSo3Drtq86zm vWNpZJ8q2Gm0f3ziAQHtNwrKkq8eZHM/pQX599+6PWCKKp58kH3nZKjKuBBKLUvgwYy9 kpHzRrtMlOlHW7rMc8nkipoxJ/++Gkekh0VvMhNj1ifSas81oApZi3lUPmd6YhT0oyc7 2njxRhXRxorJM8gm9dN+X5boHUw2sGJ/hmY/PSAdrmb9+Nec85Y62A+GsL/uMtE2KmD8 u5t2pUaDlV7e/pH10rJCijeDHNEyo2IyTqHgZP+Vk7QoVk67vVwusbH5+Rdk0+rbvS63 QVEg== 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=cCQp738aB3EKIql2WfuztXLmbJQqMy+ioYt0kyitzeg=; b=JzPrQPdXrnLtoJpUDoqYcBRiuqS4C6VhQXuYzb7ebnvJJy9zBfTYvMyUN0PMZ3/Kjk XELjbjYRBEQRiB7BDiqpO1W5YgytEELoCJnterx1lPGGfw5ivN0LHalEP4wDNJ+Ns1XK z+ZEwX5kv7B7ujxBs9vYXaZQLVFDy1hQdviEX1nqB5wc9y0SgWN9PHgAkIPTXuHGHtjy m83/mcPhZ4i5INlRxsc2E86v3SyQhZoknvR1zpdo4L3/oj5fqHoWnf5OX9xbQkUpq0AW /fBC4ozZpSQ1ZVSM4nFZ8VrqSIzuK8qTP5OzkFa6Fv30PkmNW43Zown1rQvlTfPjbZx0 4iGw== X-Gm-Message-State: AGi0PuZ7MfjoAoHJyVbVANLAgGU+nFgCbumTQDD0UxqUBGzZp70/jfnp Avk8lLtUbbPNb0E26q7s+HqwkUN0 X-Received: by 2002:a05:6000:10:: with SMTP id h16mr37758wrx.295.1588197980770; Wed, 29 Apr 2020 15:06:20 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 185sm11208606wmc.32.2020.04.29.15.06.19 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Apr 2020 15:06:19 -0700 (PDT) Date: Wed, 29 Apr 2020 22:06:19 +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: <20200429220619.f6xhmo7jm36xf64b@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> <20200426211958.m7aheswirqaj2nte@master> <87d07tycfu.fsf@yhuang-dev.intel.com> <20200428212230.3aobygpy62bto4gz@master> <874kt3xgdf.fsf@yhuang-dev.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <874kt3xgdf.fsf@yhuang-dev.intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 29, 2020 at 08:52:44AM +0800, Huang, Ying wrote: >Wei Yang writes: > >> On Mon, Apr 27, 2020 at 08:55:33AM +0800, Huang, Ying wrote: >>>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. >>> >> >> Yes, I am trying to think about it in parallel mode. >> >> Here are the cases, it might happen in parallel when task B change highest_bit >> to be less than scan_base. >> >> (1) >> offset >> v >> +-------------------+------------------+ >> ^ ^ ^ >> lowest_bit highest_bit scan_base >> >> >> (2) >> offset >> v >> +-------------------+------------------+ >> ^ ^ ^ >> lowest_bit highest_bit scan_base >> > >This is the case in my mind. But my original understanding to your code >wasn't correct. As you said, loop can stop because offset is kept >increasing. Sorry about that. > NP. >But I still don't like your new code. It's not as obvious as the >original one. Sure, thanks for your time. > >Best Regards, >Huang, Ying > >> (3) >> offset >> v >> +-------------------+------------------+ >> ^ ^ ^ >> lowest_bit highest_bit scan_base >> >> Case (1), (offset > highest) && (offset > scan_base), offset would be set to >> lowest_bit. This looks good. >> >> Case (2), (offset > highest) && (offset < scan_base), since offset is less >> than scan_base, it wouldn't be set to lowest. Instead it will continue to >> scan_base. >> >> Case (3), almost the same as Case (2). >> >> In Case (2) and (3), one thing interesting is the loop won't stop at >> highest_bit, while the behavior is the same as original code. >> >> Maybe your concern is this one? I still not figure out your point about the >> infinite loop. Hope you would share some light on it. >> >> >>>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 -- Wei Yang Help you, Help me