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 00A9DC83000 for ; Wed, 29 Apr 2020 22:06:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A74BE2076B for ; Wed, 29 Apr 2020 22:06:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UQiUrx5f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A74BE2076B 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 436408E0005; Wed, 29 Apr 2020 18:06:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BFB58E0001; Wed, 29 Apr 2020 18:06:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2876E8E0005; Wed, 29 Apr 2020 18:06:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id 0D7048E0001 for ; Wed, 29 Apr 2020 18:06:23 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B2F8D4DBF for ; Wed, 29 Apr 2020 22:06:22 +0000 (UTC) X-FDA: 76762277004.03.heart21_8ef2f6cbb373c X-HE-Tag: heart21_8ef2f6cbb373c X-Filterd-Recvd-Size: 7744 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Wed, 29 Apr 2020 22:06:22 +0000 (UTC) Received: by mail-wr1-f68.google.com with SMTP id i10so4408570wrv.10 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=QmlTUlSlcNq5RjmnrstEiaq/q9G9EHyy0AmMgfRpY9FyO5KD4HA+yOL4keKZScp8Pg X5IfkHsCb9hOb9qZyavSgCNNixY6SRARX89Wd5e+zGrQHLtZxLzcz/q+eFE/5QEn/ewf Tw0wLhE5BYTxoI7eVkfgKYE7pOAzg8EejCdGqOIW8TSp4sHShKgA+Oi8Qsh79FZghpQL gO7wxozVmjp1MiOF8YJBEWCK3FZ0oahBma1yvCjQ8vsh2EdDoJqiq1UzNK/123BmJdPl c8bI8Qi87ds+7yH9hjDtQbmH6h/3mW/2QAuP36kF8cwcB4rQUBwCBaLxp4CcKV8CaZye S+aQ== X-Gm-Message-State: AGi0PubD3gPQ4EzUvWcV9tzyWJwW9nFor02ZBa3hCEP0urrrIY1BQWrI rO2wu8O0d0cCbDxu3oGe2Ow= X-Google-Smtp-Source: APiQypIyFGxtCjZpfmnuieRhdwIzSZesVXbYO4+TkIHwwrXDnYpMdgq9g1PXPVdj35DT57PiuSi0zQ== 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) 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: 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