Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5362855iob; Mon, 9 May 2022 14:51:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw39Un1OsUoaT5vSN76qljZX+N2DTL0oWR5pqUNRB9Z//h7vOHnBFWMRE4mqcwp5kChpQ/I X-Received: by 2002:a17:906:9b86:b0:6f8:24e7:af7d with SMTP id dd6-20020a1709069b8600b006f824e7af7dmr12838263ejc.295.1652133079763; Mon, 09 May 2022 14:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652133079; cv=none; d=google.com; s=arc-20160816; b=V/qfrlIkD1L3aMiO9YvIIpcnlaJQXG3kHGYRCKoIHFW/4dKANQTJcfr8BMvgs8buVs YlprLwAUPk2Lr8JXMG4pd9T0YH1zZfORvf2UsU+W47iiOve1UqOzzUy4o3DNEkWnTxCi QuVlJHFSaXJ/rkGlqYIShV+S4Lm0u2sGBuF8GqcRwJUmQ2bzuGlySOXjmIvjjLdDMjvL m9Ia1Bb/31po/VcQECWSvGwv/sCyBhk5rmJn2TlHbX3IoKuUJlJKn7VzeV3jaBTRG9Qs 4k/2ETvPvcTNfyOYbdDF3BJhXwO7piIZudrnXWGqwf/M1qcJIArmIc97WxA/71UfpL8u RxGQ== 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=8Z+HOhy62ZqMKN7EDHNh/jiEtD3wj4X9GtWgTwK9Sfk=; b=q3PvD7uswjWnL2GUJW7iJJmcf/O7TRoyrMP+6mC+HFpZHst3NPZnSWjGlE3qk+pUUb VgVtwhClQ6IJ3hvdSPAfMukzB+sN+Nn2MjXorKj76y7x4lZITjOyWXa4pZX5sRo9UNH3 tsYhb9XEuSt7DViwPv27mILL8AnQG0PwBspJoA0sBjVyjXUTQl1Hk2h5mXTWzVAWC7Ut G69IQ8ikp7dVvlHHy/gtKZ9OO34lXXHpAvuz/JCjvKbykZ6Eusp2lJwQkQsYYJeKKpLa Tvd5sXdi7SuVxKCC2MbrbSn27iWNqsrnKQHF8d+KlnVM2dZcs7CFnoE4aYqKmPBvrGkn kTQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=0oWEWV3u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz16-20020a1709077d9000b006f515a9c6a5si13512968ejc.251.2022.05.09.14.50.55; Mon, 09 May 2022 14:51:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=0oWEWV3u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbiEIVUE (ORCPT + 99 others); Mon, 9 May 2022 17:20:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbiEIVUB (ORCPT ); Mon, 9 May 2022 17:20:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3E0F1312AC for ; Mon, 9 May 2022 14:16:04 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5E05961712 for ; Mon, 9 May 2022 21:16:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5712EC385BB; Mon, 9 May 2022 21:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1652130963; bh=N6R2HsKWImGfO3/giNuiFlILG8DRfdGzYPCqhOWYpjk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=0oWEWV3uKiLb2ebg/5Cq5pobzcKiwy2nWOgUAakmacdPw7ntjndvIfvUSCpgPYDQO A488bJEY6ZrYG+2wgrjVhx9WSxVrEmH+shdxHy0Vn0dqkaQDdy3gfzpvzqBgmKYJ14 WHWBPBXLE3fwJhDDCsLmiGzlz5AdXjJh1vGAOS2I= Date: Mon, 9 May 2022 14:16:02 -0700 From: Andrew Morton To: Miaohe Lin Cc: , , , , , , , , , , Subject: Re: [PATCH 10/15] mm/swap: break the loop if matching device is found Message-Id: <20220509141602.b6be120b80d0ab3218fe619a@linux-foundation.org> In-Reply-To: <20220509131416.17553-11-linmiaohe@huawei.com> References: <20220509131416.17553-1-linmiaohe@huawei.com> <20220509131416.17553-11-linmiaohe@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=-8.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Mon, 9 May 2022 21:14:11 +0800 Miaohe Lin wrote: > We can break the loop if matching device is found to save some possible > cpu cycles because there should be only one matching device and there is > no need to continue if the matching one is already found. > > ... > > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -1692,6 +1692,8 @@ int swap_type_of(dev_t device, sector_t offset) > spin_unlock(&swap_lock); > return type; > } > + > + break; > } > } > spin_unlock(&swap_lock); Are you sure? If we have two S_ISREG swapfiles on the same device, don't they have the same sis->bdev? If not, why bother passing `offset' into this function at all?