Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp445305rdb; Mon, 15 Jan 2024 02:25:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHflbYjZ30KUyci43+3GMtYTV3Xmc90NgeFyJcLUb37pyOEpSIc7NPfSmmeeMvpCHUKcK0f X-Received: by 2002:a05:6402:26cd:b0:554:4d7f:a054 with SMTP id x13-20020a05640226cd00b005544d7fa054mr2647619edd.1.1705314347646; Mon, 15 Jan 2024 02:25:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705314347; cv=none; d=google.com; s=arc-20160816; b=PJktg08x3hO8nAvNYK7xedAkTqRgJ1893PrCpYqTj2DxQTb6IswwDbtNAxMrJRi0db 2gP7lJsRyiozyPnHHjL1JzmCUyB2X6oS263XMq/J0sVmi4W9sY6DfqVYTUeXjYWzwwNs qPhcEwQUslT6YnxLn/haoadSlBBEX4iJyBMmGoJw4vZZ2vdYGf8dVSg/ZvTmdHq5bCem kOTC8FL15wAYCNdYF6P9UmxaCn9PvQgPJKdczdCsqol95cYH5J1dgP5zUmgObnOVOXiF MGPApg07CF5v1zbdKtk4om3Vu6lO05jTtBUu0OJ+8xF3mKJQVKOlkiO8kgf+fxmpIZOx ElZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=I6WPSYrEhpH179qV+EG35SRGfadWNyiGiKrky1Z1nu8=; fh=HgmhsKZb3ZjmxgYE7lJ+kbwkbkgwK5AI2RZl7mZ35n4=; b=DHZXtFonBRyqnUtqMohTeVaNaKMiXRWzuZSdQqcfRQM28J9OXzx0pBDkDXyPh1A5ZD yV5CWrWvJwIZUoVZAWEeyU1fP9l14rb9VHunZs23mN4aQN+gQmdIiLzea7zbV3YxEvRh zdgmwAjZ0yhh649tbhEdXir0EapehLMw6jfbQ2rLv1nb39U+kI1VONUKBhYl9728lqmo 9/n/nFJnzeD9PS7UVVd6xsuLSknJJol3brIx3HWgYyJh+5VpEnfCOem4i+hRksk99ycl WPdqUoWWjMZn81n5Cl+4aBwQ9FAVszaGKyRYSZbDSslYcU1RWahYhpCCg5naLIXbWXph Zz2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=Ma9o8yAA; spf=pass (google.com: domain of linux-kernel+bounces-25886-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25886-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g13-20020a056402090d00b0055703da55aasi3732549edz.225.2024.01.15.02.25.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 02:25:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25886-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=Ma9o8yAA; spf=pass (google.com: domain of linux-kernel+bounces-25886-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25886-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 629F01F221A5 for ; Mon, 15 Jan 2024 10:25:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 23ACE12E63; Mon, 15 Jan 2024 10:25:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="Ma9o8yAA" Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9286101C1; Mon, 15 Jan 2024 10:25:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pankajraghav.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pankajraghav.com 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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(-) 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); base-commit: 8d04a7e2ee3fd6aabb8096b00c64db0d735bc874 -- 2.43.0