Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp49234ybz; Tue, 28 Apr 2020 17:57:04 -0700 (PDT) X-Google-Smtp-Source: APiQypIegeMkxy8OpfMZL1VvvXF9w0/0z6AuP1xuf7imuLRJZB32oritf1u5pX8wqDdwZfnJD4LM X-Received: by 2002:a17:906:1443:: with SMTP id q3mr402778ejc.325.1588121824020; Tue, 28 Apr 2020 17:57:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588121824; cv=none; d=google.com; s=arc-20160816; b=fF2dIMM2TPBpNLtKjEgVcA35F7FM4BCovsCpH32En4UKykFMQoRY6MKhLIrUQxJE4m w3DdtpcHoTiNPNo8NAuokMha/xACgmZwMYeaSWOQkcgFy+8jaVIec6qwZakFBUB5QCO8 T3JboElG+yZGH2ZzvJBhMzn0QfJn38yWaN/gRewPIQTJjYMgIHgnWiSI0E9JcxaRRVBX WsXTKY8wjatvk/UZaFRZJNUD/fRUyVodwokf+FAY/JBM3vUqty+nk9eMHeYwA8JehEHU c8r8aFCTH7PQbQbKOJa2OB5UxOwTnCVeIrAVqGSSxLTkNZiG2R3Bav6qYi1Fk3XdN9bI BqCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from:ironport-sdr :ironport-sdr; bh=9m9xI7IGTfw/q9AHozIMX5v6Fvoxli5Wr/pVmHRtJTo=; b=AkmDGZo9H4rDL39Fy/fetigEoplXH5f2vIc4ewE8HLCZJouciaI3ge3R48PINxQwkY tGqLAxvdcTybyQb9zyYn7ZReTT93ydG4XVTFvnXb11PcS88J9CWaAqR4IgV/+up+LpES anF9txnoCe97gpO63V17Yd6rwCCM29A4t+XMHjgtiPiN6ICSi8L7iPONSfbPoGG6Sy7j xNKr6uA1a7Ertl+BEK/+rFu324bGzd2aMGUgn8/9eMo6BBiNPfDupLeEEU+ePTlZN0BT q2QZ4+9mEJiHf3U8zUbpblM/kds6thvtGsTSRuv70yao6kRXT6I4j/jotPjQThW8Bs+g jHOQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c8si2543135edn.192.2020.04.28.17.56.41; Tue, 28 Apr 2020 17:57:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726544AbgD2Awr (ORCPT + 99 others); Tue, 28 Apr 2020 20:52:47 -0400 Received: from mga02.intel.com ([134.134.136.20]:22099 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726353AbgD2Awr (ORCPT ); Tue, 28 Apr 2020 20:52:47 -0400 IronPort-SDR: rlI7tY2MeIdhqLi3R+AiGtAswfr8CN/0TSUTl2+n2fLkJtWUKcbRWRDivs1j4kJTsLbkqYGb1/ wfZO0zflwFwg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2020 17:52:46 -0700 IronPort-SDR: Fd6uQ9lwwQ85EzfLAX6e4y1AEbWHJf6ORQs6hOYnYtB06NkRGVybQKjmw5ymjutF8LgrygL5tg kolmEaxyLZXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,329,1583222400"; d="scan'208";a="404874335" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.159.23]) by orsmga004.jf.intel.com with ESMTP; 28 Apr 2020 17:52:45 -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> <87d07tycfu.fsf@yhuang-dev.intel.com> <20200428212230.3aobygpy62bto4gz@master> Date: Wed, 29 Apr 2020 08:52:44 +0800 In-Reply-To: <20200428212230.3aobygpy62bto4gz@master> (Wei Yang's message of "Tue, 28 Apr 2020 21:22:30 +0000") Message-ID: <874kt3xgdf.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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. But I still don't like your new code. It's not as obvious as the original one. 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