Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2390091ybz; Sun, 26 Apr 2020 18:01:45 -0700 (PDT) X-Google-Smtp-Source: APiQypJroS9uNUfnkCB8/V5OPeuP7rVjL2f/h53JSWHN7NMPbjYKhDjanJPh8MbLR23A/uN1NAvQ X-Received: by 2002:aa7:c497:: with SMTP id m23mr16209362edq.155.1587949305444; Sun, 26 Apr 2020 18:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587949305; cv=none; d=google.com; s=arc-20160816; b=yPjp7Nzgx1ISjLx36SPtlbR80y/bFRn8CLmZxW/rpXnn2zaSqSlWJheDTpTY0Geljw fLwchSxPfcolTtVm/fPc3MmS4t1SmqmMMbsyVI2YSmH59Ipws/BUa0HK009DlVvsRLrj H9fI5Q6TuwigKDOXj5y4a4LuGDKK2BTz6RPNSSfltDbWwvLj5+q0Ld1fLsckTxgddpUu BlWb7R+f7mEppFM6nMXAlYcKC5HcjTG0Ea1XpCkoAtCGFsDxofnR0yAaBVSxpGsYsHXP Z236gczdpMZBtPWxjMCRs8q+8zU2g7/3vASokANSOReyV/lm9CBPPVjvNCWjZ2GVwbr6 HGGQ== 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=Gflkpiifl+SIxdFsQpljcOHxID3+QmdRe9klnpFRz5g=; b=RPcFY8nwJmulGmlzyHTufQESb3IczkN4AYXO122Tg5YVxRlNRq/JQJ0IVd/ouPabN2 HqIhi/fHneHzvGeNz1J3EGN77N+QTu8CPhoQzOHlDwDbek2TJJwquITFypFkD/U7anUD YFdHY+dnOf4vgjRR4J/0JPa+N6eJXgkE5rUE+Ni3suzARllXxYnblUJ+oF2uaDbldWNe 3ijGqBvlnAg3Dz/UT5QLusBYhw4uDWTmrs+ec5nQND8y4CmKV+mkbhoZXI1WmCkxrhjA tzOe9iuEqoY3sGgg9CXA3w/6X/Bo1cu2cwfaQhtST9Mw6e/1ijUFgQyeL4urwUj0YQJP WjtA== 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 a16si9211883edn.579.2020.04.26.18.00.56; Sun, 26 Apr 2020 18:01:45 -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 S1726340AbgD0Azf (ORCPT + 99 others); Sun, 26 Apr 2020 20:55:35 -0400 Received: from mga14.intel.com ([192.55.52.115]:33395 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726227AbgD0Azf (ORCPT ); Sun, 26 Apr 2020 20:55:35 -0400 IronPort-SDR: y4WE4L952xMqiCFELUzg2zzPeGRZ+t1+5MC6epbUTXDl9i8xOZjOYit1OHWX/Kz8Jg28ffV8r5 hx/PMDBBl0Rg== 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:34 -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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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