Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1485780ybz; Wed, 22 Apr 2020 22:59:35 -0700 (PDT) X-Google-Smtp-Source: APiQypK280z3nTsDlkuAe8DPG9FQkVCqZVErNYl6zVOGjHnaeeG3yxj0bQRt2rbpze/kaABKd4Ye X-Received: by 2002:a05:6402:31b1:: with SMTP id dj17mr1402074edb.146.1587621575295; Wed, 22 Apr 2020 22:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587621575; cv=none; d=google.com; s=arc-20160816; b=DcP9v9ekFOVd2KzrCbUf0PTA2Bz7437BjNC7hkkmXtaXY4DqEcowmckEwzUNUEj5Ha ITCASDITOuRfstK5K9w+bqx0PKMj8sfgkEN4/P2Pfx/02F/TRgpVmTvZCbc1/Eoxduph mzDRjxxpfZcR1kkThhui/fsBMsLb7jPD1LK9YaJ3EA2kWTg1D7IQnBoMkDsntirP3en8 fiqgjDe6yql2I9qWB2e4uQMaoozDhzUIAJThzopXuvIv6PZB+7IG97SmzjTvMos0o+64 J/vyh+pdkD5WVM/8MAPWedAVWNq+23jghWebAsspLc3BqfPjmohIKL8wgl1P/R770U2J R0cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=bFWNOKZnAA0PuEG0vhNhMnkQPFqbLKCffhOQiAHCvr0=; b=TvPxJdLXVFND0niVKML7SHL9s6KuJ+zO+sNFcqHGvAECPkKn3+gnJuOQjBTXAfLbsi qvSy+xyDj1TJDUVuOvLabZTVywCSqymkqGEULltwyoHmBIxuyytGvrmv/RDCruRU8+dC yR0uifr3rhkap94zS0mGqGs2Fd+LXP/LPkXt+FnbJ7F2LV24352sfb69q1+21WGLvXKq TI5HKImKFYbGtw+Ks/fXci8Qqp7TmpGoe0GIC6V3w92EemC7NF63DvVk/aEOtwnRUFw2 GTzrDhXKLKaxtNQAHsXQfkNo59aqUdlitBDNKZHFARe+Fg6rzb4iwmBhttZfwWvgI1B/ xnAw== 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 r28si651786edi.545.2020.04.22.22.59.12; Wed, 22 Apr 2020 22:59:35 -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 S1726108AbgDWF5l (ORCPT + 99 others); Thu, 23 Apr 2020 01:57:41 -0400 Received: from mga04.intel.com ([192.55.52.120]:15586 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbgDWF5l (ORCPT ); Thu, 23 Apr 2020 01:57:41 -0400 IronPort-SDR: Xmj4ccdnJ+aC3spofX+ICKWUACpKa4aph2Dmw14QYPca7dCcerk0vlHQk/E/1k6reQSGO9S4oC wqPNPsTNBdNQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Apr 2020 22:57:41 -0700 IronPort-SDR: ejDVh1zgi7oy/DpflGw3T9rYQg4ba8uEkByvioeoGK7V4VDJqnLN1m14ZQi7+kcx49k+a7vYcp UAC8mZg8SZPQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,305,1583222400"; d="scan'208";a="456786339" Received: from yhuang-dev.sh.intel.com (HELO yhuang-dev) ([10.239.159.23]) by fmsmga005.fm.intel.com with ESMTP; 22 Apr 2020 22:57:39 -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() In-Reply-To: <20200422214111.19370-1-richard.weiyang@gmail.com> (Wei Yang's message of "Wed, 22 Apr 2020 21:41:11 +0000") References: <20200422214111.19370-1-richard.weiyang@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Date: Thu, 23 Apr 2020 13:57:34 +0800 Message-ID: <87d07y2181.fsf@yhuang-dev.intel.com> 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: > After commit c60aa176c6de8 ("swapfile: swap allocation cycle if > nonrot"), swap allocation is cyclic. Current approach is done with two > separate loop on the upper and lower half. This looks a little > redundant. I can understand that the redundant code doesn't smell good. But I don't think the new code is easier to be understood than the original one. > From another point of view, the loop iterates [lowest_bit, highest_bit] > range starting with (offset + 1) but except scan_base. So we can > simplify the loop with condition (next_offset() != scan_base) by > introducing next_offset() which makes sure offset fit in that range > with correct order. > > Signed-off-by: Wei Yang > CC: Hugh Dickins > CC: "Huang, Ying" > > --- > v2: > * return scan_base if the lower part is eaten > * only start over when iterating on the upper part > --- > mm/swapfile.c | 31 ++++++++++++++----------------- > 1 file changed, 14 insertions(+), 17 deletions(-) > > diff --git a/mm/swapfile.c b/mm/swapfile.c > index f903e5a165d5..0005a4a1c1b4 100644 > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -729,6 +729,19 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset, > } > } > > +static unsigned long next_offset(struct swap_info_struct *si, > + unsigned long *offset, unsigned long scan_base) > +{ > + /* only start over when iterating on the upper part */ > + if (++(*offset) > si->highest_bit && *offset > scan_base) { > + *offset = si->lowest_bit; > + /* someone has eaten the lower part */ > + if (si->lowest_bit >= scan_base) > + return scan_base; > + } if "offset > si->highest_bit" is true and "offset < scan_base" is true, scan_base need to be returned. Again, the new code doesn't make it easier to find this kind of issues. Best Regards, Huang, Ying