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 4748A314A98 for ; Thu, 14 May 2026 17:58:51 +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=1778781531; cv=none; b=pGxnLg7SNAm+WOWrvjGL1wv/+3YfUqPqfS8ya+9Mb5gEJq0g9+cB4u5AtQhnxpB3rF3JXCn684COuDPOI+XWW/99GpuQlu6NL7YMNqPZRjaqkM6iDNQjNiZe8pwAZUHRyfYAoeTVT9US5saF46ZexKF+yjl7t885kDNEaOFGzXE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778781531; c=relaxed/simple; bh=5jYYAQPIFrE5faSs1LQIhG34B0KhsYAN32zDBGGGAeU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j2UlhNGOSOxdXr9HDqbaR1T+u3B6+B0l0O2OnfE59J03/tXqfwzNMx6l2T7+ITzmY2EIIQjQ2Do8uDcHgvGYebVkaPhn5tOdwgvB7/4iWO3nLdaJaPtP82rrG68BX6s5wViYPSFQUrc0eQ0lnMn+AVsYw3G9SnLRQC3io9p8m4w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ao6Gb+n5; 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="Ao6Gb+n5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CA50C2BCB3; Thu, 14 May 2026 17:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778781530; bh=5jYYAQPIFrE5faSs1LQIhG34B0KhsYAN32zDBGGGAeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ao6Gb+n5MBtP1NZmZ/DQEiFeUG29Ns8I4fe4ezZIyoXHwT6CDq/ZkxAPxPDVkZKuP D7XJL7VfBRg4PMps2Klnv6xQQUqWFmIrYA/KLbW5U69lMuq35MvfTVms1PnHNyjrm8 BawBjburSYnTb141mewaX4oBpElzUy4IuDCv3U0rk+qCXYq6ZzEKKpkTHoIyjJGy5o 8ggZqWn709AoOgMN+qCXyH7s6GezNT1mWQ2Il4B3RDuVpwuScNUJ+eIW2tamLlyBQZ EQ5UBlr8uUECbGZ/DsGuvzKpv7ocDCZeG/vDVZN6OQ51aSE71rJiYCLPc/adi7/J8O pN89PboZg3N5Q== From: Sasha Levin To: stable@vger.kernel.org Cc: Sang-Heon Jeon , Muchun Song , David Hildenbrand , Oscar Salvador , Andrew Morton , Sasha Levin Subject: [PATCH 5.10.y] mm/hugetlb_cma: round up per_node before logging it Date: Thu, 14 May 2026 13:58:48 -0400 Message-ID: <20260514175848.530234-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026051243-dagger-atlantic-8f34@gregkh> References: <2026051243-dagger-atlantic-8f34@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Sang-Heon Jeon [ Upstream commit 8f5ce56b76303c55b78a87af996e2e0f8535f979 ] When the user requests a total hugetlb CMA size without per-node specification, hugetlb_cma_reserve() computes per_node from hugetlb_cma_size and the number of nodes that have memory per_node = DIV_ROUND_UP(hugetlb_cma_size, nodes_weight(hugetlb_bootmem_nodes)); The reservation loop later computes size = round_up(min(per_node, hugetlb_cma_size - reserved), PAGE_SIZE << order); So the actually reserved per_node size is multiple of (PAGE_SIZE << order), but the logged per_node is not rounded up, so it may be smaller than the actual reserved size. For example, as the existing comment describes, if a 3 GB area is requested on a machine with 4 NUMA nodes that have memory, 1 GB is allocated on the first three nodes, but the printed log is hugetlb_cma: reserve 3072 MiB, up to 768 MiB per node Round per_node up to (PAGE_SIZE << order) before logging so that the printed log always matches the actual reserved size. No functional change to the actual reservation size, as the following case analysis shows 1. remaining (hugetlb_cma_size - reserved) >= rounded per_node - AS-IS: min() picks unrounded per_node; round_up() returns rounded per_node - TO-BE: min() picks rounded per_node; round_up() returns rounded per_node (no-op) 2. remaining < unrounded per_node - AS-IS: min() picks remaining; round_up() returns round_up(remaining) - TO-BE: min() picks remaining; round_up() returns round_up(remaining) 3. unrounded per_node <= remaining < rounded per_node - AS-IS: min() picks unrounded per_node; round_up() returns rounded per_node - TO-BE: min() picks remaining; round_up() returns round_up(remaining) equals rounded per_node Link: https://lore.kernel.org/20260422143353.852257-1-ekffu200098@gmail.com Fixes: cf11e85fc08c ("mm: hugetlb: optionally allocate gigantic hugepages using cma") # 5.7 Signed-off-by: Sang-Heon Jeon Reviewed-by: Muchun Song Cc: David Hildenbrand Cc: Oscar Salvador Cc: Signed-off-by: Andrew Morton [ applied the one-line `round_up` to `mm/hugetlb.c` ] Signed-off-by: Sasha Levin --- mm/hugetlb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 27fe947b8c697..ef556f6fe970e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5842,6 +5842,7 @@ void __init hugetlb_cma_reserve(int order) * let's allocate 1 GB on first three nodes and ignore the last one. */ per_node = DIV_ROUND_UP(hugetlb_cma_size, nr_online_nodes); + per_node = round_up(per_node, PAGE_SIZE << order); pr_info("hugetlb_cma: reserve %lu MiB, up to %lu MiB per node\n", hugetlb_cma_size / SZ_1M, per_node / SZ_1M); -- 2.53.0