From patchwork Mon Jan 15 10:25:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pankaj Raghav (Samsung)" X-Patchwork-Id: 13519477 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 CEF29C3DA79 for ; Mon, 15 Jan 2024 10:25:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FAB16B0083; Mon, 15 Jan 2024 05:25:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AABB6B009C; Mon, 15 Jan 2024 05:25:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39AD96B009D; Mon, 15 Jan 2024 05:25:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 29D346B0083 for ; Mon, 15 Jan 2024 05:25:33 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E1274160836 for ; Mon, 15 Jan 2024 10:25:32 +0000 (UTC) X-FDA: 81681163704.09.6385EBB Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by imf22.hostedemail.com (Postfix) with ESMTP id 3BF81C0007 for ; Mon, 15 Jan 2024 10:25:30 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=Ma9o8yAA; dmarc=none; spf=pass (imf22.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705314331; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=I6WPSYrEhpH179qV+EG35SRGfadWNyiGiKrky1Z1nu8=; b=xI2B5N6EatNGlPVZQn5Cwgs6RKh7Av+wMn+RuV6oVHewXhXOJ2b/MX2UjoSQd+iZ2qXuez /h3iNONVkzq5YCruoqxhK9BVAxBYWxXkLOQN4Hl2dYPcIsXgeAJ/Ob0x1Alugu/12UQR3P q8zs8WCzo8YRTSW1JZ7p2VUi+cMUVrA= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b=Ma9o8yAA; dmarc=none; spf=pass (imf22.hostedemail.com: domain of me@pankajraghav.com designates 80.241.56.151 as permitted sender) smtp.mailfrom=me@pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705314331; a=rsa-sha256; cv=none; b=x/DsTb7YwQCyZf1gh49WH3ePZy1leyTgEzjJVPcuIJHsUPqLkCIqnNaspau8XgtJRA9snM Uztmr5+ev9wLvkCX7i0/BGvYdCx3OECwa+m+A0rKI6VccXED5ld+czncPvUvuJ+131+k7y 3YoFbYWjnSMOUQ5Akc+7oE4CpX0++/c= Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4TD7ZG3BF9z9s7D; Mon, 15 Jan 2024 11:25:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1705314326; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=I6WPSYrEhpH179qV+EG35SRGfadWNyiGiKrky1Z1nu8=; b=Ma9o8yAAOszrcoUwv0JAvjwmi5YVn62TpCA5NIRZzsV+GcO0hMuvXSTGBU++kUsjtCQ0KP SvEvXSCi3b4wfIp08MejNwIbYDfxOA7PCAL9U63oagy03VsEA4LurnAj4TqH8UYcMK2v2o qO9q3ovXwmfr9G79/wx9o24uwCQA4vO8x6w6WA4fTvJjT/k0ivpr8lH52cWLReylbfqJIR hmFNQ7zOCT1W/n5luotdnF/Dj65d6WGGTYzoAsgFVj2gz12FVG4svR3GKtJ06kwVegr67I FkvsNMiDngHKwN4CZrvDRLfzwzGRzumnECrMLgcwX6yjHFIl50ZgBY4ioLOfWg== From: "Pankaj Raghav (Samsung)" To: willy@infradead.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, gost.dev@samsung.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Pankaj Raghav Subject: [PATCH] readahead: use ilog2 instead of a while loop in page_cache_ra_order() Date: Mon, 15 Jan 2024 11:25:22 +0100 Message-ID: <20240115102523.2336742-1-kernel@pankajraghav.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 7go37848orkqr4nqwnwsq34x7eiiqi1z X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3BF81C0007 X-HE-Tag: 1705314330-557189 X-HE-Meta: U2FsdGVkX19Ux9uXd6IXdzvDSblrDvf1XenSAKtrnI4GkhEnPz/d/Tx8KRKNJtomkPxdasnb1qy2IoSWT8JYP6QJB4dfxPF6AUSM3EqrPaFpP6C8lPZMqxG5LHiwTbPmp24jRFSZeuguXgwdjc8niFsr+AqlWFid1DCX8EkWLceBQ1XU8Nk6tLfiMAwqGi9qKlTP3waHBTqlypUtXQ52WNHAko6aLCxECzWGkQwVq+JdSRxOHehIO76sf13ubrOKjs8+hmqEU/rpjrLIL6p5ykFNnliikpIkCFToMPAh9eIzYqEORo/1gv5/f14dYZ+AmxoBS5bcRX/imvYiSrZ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precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Pankaj Raghav A while loop is used to adjust the new_order to be lower than the ra->size. ilog2 could be used to do the same instead of using a loop. ilog2 typically resolves to a bit scan reverse instruction. This is particularly useful when ra->size is smaller than the 2^new_order as it resolves in one instruction instead of looping to find the new_order. No functional changes. Signed-off-by: Pankaj Raghav --- mm/readahead.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) base-commit: 8d04a7e2ee3fd6aabb8096b00c64db0d735bc874 diff --git a/mm/readahead.c b/mm/readahead.c index c81234fa655a..18b23126eb52 100644 --- a/mm/readahead.c +++ b/mm/readahead.c @@ -500,10 +500,8 @@ void page_cache_ra_order(struct readahead_control *ractl, if (new_order < MAX_PAGECACHE_ORDER) { new_order += 2; - if (new_order > MAX_PAGECACHE_ORDER) - new_order = MAX_PAGECACHE_ORDER; - while ((1 << new_order) > ra->size) - new_order--; + new_order = min_t(unsigned int, MAX_PAGECACHE_ORDER, new_order); + new_order = min_t(unsigned int, new_order, ilog2(ra->size)); } filemap_invalidate_lock_shared(mapping);