Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp114800iob; Tue, 17 May 2022 20:42:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1022L/VrOmDH5Q9bF5/Uej7Vi8Oo5hyLsBebI7sa1KMPdOXiyH9YQgajtv3XOt1mJ4Xdk X-Received: by 2002:a17:902:d212:b0:161:7ffc:6ce7 with SMTP id t18-20020a170902d21200b001617ffc6ce7mr12199934ply.170.1652845366464; Tue, 17 May 2022 20:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652845366; cv=none; d=google.com; s=arc-20160816; b=cgvIA7RiS92lP+dLRBBT6/7nXW/O9QQeCIZm3I6MTgD6mPcE0FLxlp695SOEWASMWH 9zIFflfyZ5Al5UuA2gNHSWvtFDs8z9/0zmFGW6T9yDKidO9ZHknw7CEh3+XFDT5HUBU3 AV/iFNf6+u33JxX6VyE6TjVeTyEtjSP12uMZFbUpYnJ3hNR13r3g/OKMM8ddF6nFZnuP RseSkv01Okx9Pa6dhJ+WQsAiMVYTiacI8E2pYPI58ls8WDRX8AgXvWwkg+Wt6ndGWON4 f8PEFoAK4sRpnn8fv1Suux5eAKblsOZUeGbqTqZb9g9qY4SfRi6F2i9UgBQO6BGzrAWf zutQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=qm7hSw9vabDfmZym5i1pv7SNe4Q4y5lZJnTO96DhJeI=; b=gy51xZmNnNyTshr+zu9U4IIadE/gNqQRlbuvmgOIzB6QU1cxMKOpcsyahalhFc2rlI lAKyQ9eF+OTOBq55Ww0/9vP+hx0GvNkDMeaX/4su6ndcZxivO9BqGYdmjBglmjf2A7dU Bkv5oCZ6KHF4eovixGbE9n+8XRISszFufM1IVa0fhtbJfYvPbENg5PfGG0/Lm636L8Od MprOJRsuunEZBRASWEg9+4pGUAtjze+a5E4jzDiUT40xjFtkhpw6aRKyVVdDW/jHQMX/ YR9ImAQD6hV5OwgX0VfVfRl4mswA/eNAnzpWwJ0wjRuPaD7NQJWus6fHxFslMjGsA9Eg QV1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=1jSisTeT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g15-20020a056a000b8f00b00510950ff7c2si1702566pfj.319.2022.05.17.20.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:42:46 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=1jSisTeT; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3F5116D849; Tue, 17 May 2022 20:30:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231927AbiEQXjY (ORCPT + 99 others); Tue, 17 May 2022 19:39:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231928AbiEQXjV (ORCPT ); Tue, 17 May 2022 19:39:21 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43A4952E48 for ; Tue, 17 May 2022 16:39:20 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 05131B81D66 for ; Tue, 17 May 2022 23:39:19 +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-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(); _