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 09426C433EF for ; Mon, 9 May 2022 21:16:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7365A6B0071; Mon, 9 May 2022 17:16:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E54F6B0075; Mon, 9 May 2022 17:16:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5ADD06B0078; Mon, 9 May 2022 17:16:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4D2D86B0071 for ; Mon, 9 May 2022 17:16:07 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1BC7221309 for ; Mon, 9 May 2022 21:16:07 +0000 (UTC) X-FDA: 79447462374.27.1687E3E Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf23.hostedemail.com (Postfix) with ESMTP id E38EA14009A for ; Mon, 9 May 2022 21:15:53 +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 ams.source.kernel.org (Postfix) with ESMTPS id F346CB818F6; 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 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=0oWEWV3u; dmarc=none; spf=pass (imf23.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E38EA14009A X-Rspam-User: X-Stat-Signature: kzd76hne3c1rcotm15sg33ccuasdh1ga X-HE-Tag: 1652130953-655698 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 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?