From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 16AD82FB620 for ; Mon, 24 Nov 2025 10:53:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763981640; cv=none; b=ml5DcK+4suk5+oT0Bceth7qKU5NtBXjq5F1hzm+geTfDNQCcu4FxVArEZ57EnCDvGzOk/pYDPopOIQLg9TfSdFGKYIJHzKXPIQrRr8riGdF7bUgVI+EhZL4P7neZtdUUo1d3UILFsBNtov2O26xU54Cb7fDA3ipckX/1WjRfaQI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763981640; c=relaxed/simple; bh=JY2i1yUY0cE28oKluKky0lLNF6J76RvUJnJzF/fAa00=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nQzERkwEgQMQl1Ix8ek4ulmPIoMvJl2LZlWm6Bov+q8DMi5RslTt40HFH/GuKPyzCqJP8EkymisWi19+1G7G0yU7z+pS4J3DYI2sEHzF5FIRS7Lr6xoEEgrRgIT/Djf1gXx78bhcmcxzcTGII8TslQVsvO0ybS9EhlDpjthTGCA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ogaqLF0V; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ogaqLF0V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5C24C16AAE; Mon, 24 Nov 2025 10:53:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763981639; bh=JY2i1yUY0cE28oKluKky0lLNF6J76RvUJnJzF/fAa00=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ogaqLF0Voug39wKOhJtK4TsUUWxh59FWw1iP4IujGRJhLAC3V2EXjmLM/PiiL2VYJ MWmVd/Wamu2gks+AU4hWCJwnBj44KvVJHwAXY1vF+ELd6btuFXKuCBuM5EXnpcZ+ek NgLoC1YMrRRYDb+j2YKBUelXA3ExAL65/RVXbtgx42GZ5zCEt66d2YUWAyN/yp2gnV OAFhkitfkbVOgIXveO1zPMctsDGk3e8tVgiYA3ZGm3OYWQT+56QxQ6PC9E1dUsGS4g TMlcjhjEy0DMm1FmXFqiQ2eE3QCepKau9Gmc+7jdsYh3u2hJcVCts4Oso6uuW3nPzQ qicHb9z26SMbw== Message-ID: Date: Mon, 24 Nov 2025 11:53:52 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/3] mm: pagewalk: simplify hugepage boundary calculation using min() To: Sahil Chandna , akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, mhocko@suse.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, hannes@cmpxchg.org, shakeel.butt@linux.dev, zhengqi.arch@bytedance.com, Liam.Howlett@oracle.com, weixugc@google.com, axelrasmussen@google.com, yuanchu@google.com, yosry.ahmed@linux.dev, nphamcs@gmail.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox , David Laight References: From: "David Hildenbrand (Red Hat)" Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/23/25 04:04, Sahil Chandna wrote: > Use the kernel-provided min() macro to compute the minimum value instead > of an explicit ternary expression. This improves readability and matches > common kernel style. Also change the return hugepage boundary expression > by using bitmask for better clarity. > > This was flagged by Coccinelle > (misc/minmax.cocci) as an opportunity to use min(). > > Found by: make coccicheck MODE=report M=mm/ > No functional change intended. > > Suggested-by: Matthew Wilcox > Suggested-by: David Laight > Signed-off-by: Sahil Chandna > --- > changes since v1: > - Updated boundary calculation of huge page range for better clarity. > - No Functional changes intended. > link to v1: https://lore.kernel.org/all/ff24b3c573b766b187b55a38497fbad0a319b9f8.1763227530.git.chandna.sahil@gmail.com/ > --- > mm/pagewalk.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/mm/pagewalk.c b/mm/pagewalk.c > index 9f91cf85a5be..1d38763a502a 100644 > --- a/mm/pagewalk.c > +++ b/mm/pagewalk.c > @@ -312,8 +312,7 @@ static int walk_pgd_range(unsigned long addr, unsigned long end, > static unsigned long hugetlb_entry_end(struct hstate *h, unsigned long addr, > unsigned long end) > { > - unsigned long boundary = (addr & huge_page_mask(h)) + huge_page_size(h); > - return boundary < end ? boundary : end; > + return min((addr | ~huge_page_mask(h)) + 1, end); I know Willy suggested that, but I wonder if we could simplify that to something a bit easier to digest: return min(ALIGN(addr, huge_page_size(h)), end); At least I can make sense of that a bit faster. (I don't think we're interested in micro-optimizations in this code here in particular :) ) -- Cheers David