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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32AC8C433EF for ; Tue, 17 May 2022 23:39:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 788056B0073; Tue, 17 May 2022 19:39:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75F128D0003; Tue, 17 May 2022 19:39:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6260A8D0002; Tue, 17 May 2022 19:39:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 555FD6B0073 for ; Tue, 17 May 2022 19:39:21 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 2CAA261B57 for ; Tue, 17 May 2022 23:39:21 +0000 (UTC) X-FDA: 79476853722.17.3B28242 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 06F63180050 for ; Tue, 17 May 2022 23:39:17 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 09F2A6146E; Tue, 17 May 2022 23:39:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E868C3411F; Tue, 17 May 2022 23:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1652830757; bh=aQy6tkYog1Mp778DJe+lW+xbkRM8taLZzQIq09aiLTA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=1jSisTeT7F2wn8Pg7Jq0hHU1jm6tvO1jQr4nntqCqF3VIZj+bchU1iyxYn1QZd3PQ lI19nkHGCQlnz2KxobTVShI64XC8lcKQ8OVm27tPeyh+6dZ2whHNL+IvV+oIJCfsyG PA1Hwmb3LC15E7Mb7gwHRStYHTCtI4XnEC6pSEJ8= Date: Tue, 17 May 2022 16:39:16 -0700 From: Andrew Morton To: Miaohe Lin Cc: NeilBrown , , , , , , , , , , Subject: Re: [PATCH 11/15] mm/swap: add helper swap_offset_available() Message-Id: <20220517163916.71ab9aa1ec095bbc57b82f98@linux-foundation.org> In-Reply-To: <9319a62b-f43d-8ee9-77b9-a1afee7dbc10@huawei.com> References: <20220509131416.17553-1-linmiaohe@huawei.com> <20220509131416.17553-12-linmiaohe@huawei.com> <165214355418.14782.13896859043718755300@noble.neil.brown.name> <9319a62b-f43d-8ee9-77b9-a1afee7dbc10@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 06F63180050 X-Stat-Signature: 1d6a76whxkrweexw7gtba9w6qw88dwew X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=1jSisTeT; spf=pass (imf06.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-HE-Tag: 1652830757-47759 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 Tue, 10 May 2022 10:03:19 +0800 Miaohe Lin wrote: > On 2022/5/10 8:45, NeilBrown wrote: > > On Mon, 09 May 2022, Miaohe Lin wrote: > >> Add helper swap_offset_available() to remove some duplicated codes. > >> Minor readability improvement. > > > > I don't think that putting the spin_lock() inside the inline helper is > > good for readability. > > If the function was called > > swap_offset_available_and_locked() > > Yes, swap_offset_available_and_locked should be more suitable as we do the spin_lock > inside it. Will do this in next version. > --- a/mm/swapfile.c~mm-swap-add-helper-swap_offset_available-fix +++ a/mm/swapfile.c @@ -775,7 +775,8 @@ static void set_cluster_next(struct swap this_cpu_write(*si->cluster_next_cpu, next); } -static inline bool swap_offset_available(struct swap_info_struct *si, unsigned long offset) +static bool swap_offset_available_and_locked(struct swap_info_struct *si, + unsigned long offset) { if (data_race(!si->swap_map[offset])) { spin_lock(&si->lock); @@ -967,7 +968,7 @@ done: scan: spin_unlock(&si->lock); while (++offset <= READ_ONCE(si->highest_bit)) { - if (swap_offset_available(si, offset)) + if (swap_offset_available_and_locked(si, offset)) goto checks; if (unlikely(--latency_ration < 0)) { cond_resched(); @@ -977,7 +978,7 @@ scan: } offset = si->lowest_bit; while (offset < scan_base) { - if (swap_offset_available(si, offset)) + if (swap_offset_available_and_locked(si, offset)) goto checks; if (unlikely(--latency_ration < 0)) { cond_resched(); _