From nobody Mon Feb 9 08:19:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A008C7EE29 for ; Sat, 10 Jun 2023 01:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbjFJBV1 (ORCPT ); Fri, 9 Jun 2023 21:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231938AbjFJBVY (ORCPT ); Fri, 9 Jun 2023 21:21:24 -0400 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A49830F9 for ; Fri, 9 Jun 2023 18:21:23 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id A37AD3200914; Fri, 9 Jun 2023 21:21:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 09 Jun 2023 21:21:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= joshtriplett.org; h=cc:cc:content-type:content-type:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to; s=fm3; t=1686360082; x=1686446482; bh=6g 2RVl+GpOZe2oQM/8nONsqThYPCh2VfCuomeQ/pDfE=; b=ixy4icfz8BrLovCkGr M+huV0302OV6wUxAHuOR+c8W7vhfc09wvPnQtzl/nyMMZlhikc0m2JllT/wBCSx2 DJBNVVsDNBS3gHUHZKMqLwg2jxICrp1LeyH8cNponrqEcFay6AKG1VR0p0ZAlS+w PsgX8lv7a3kWeh8no10JKcbzUDAfMX3VPG44LwghwXywN1GQGuGPSKmX/0+/zTbD zl2S4VGjT1DEh8u6f++9vzvY/9zLESx9j27yQNmdW7GFwGyUcxvDDk2QahYmNfHI 2Wjja2kUQaViuSVi2W767xTAmi7+eM4EEueTCOiFHA+FdYTj4WwcJjjZBL/xESP0 Jw6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1686360082; x=1686446482; bh=6g2RVl+GpOZe2oQM/8nONsqThYPCh2VfCuo meQ/pDfE=; b=PQOIbIq42EKpMxvSNOdVfZdzdFqzS422zwnuMhi1KtYihXf+HQB CDM/53QH55Z7zYu8XI9xwlYd4009UEIy2fa7ZYXyDh5RhrUJiUzu2ta760QrMh7T zDU5OpVdxL+pa0RhzeXRHZOb3h9sO6WGBnTNL68z7ytYOfl5gGhI4zN4lJcbg/7v +ozTSN6y1nQ22+30ITaBGSJJmLoIYYAPykTz3REh3f6TBbB+/fE8Ae0F5biK+DEN IU6PbJMMTItpt69RMEJsl9ihkzxsGKGug3zHQ2NndV0II610u0xINkHKFJTIiGVq YJogkUZEJuS1sUtoAP5RWW/algYrKYYW5iA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgedtledggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugesthdtredttddtvdenucfhrhhomheplfhoshhhucfv rhhiphhlvghtthcuoehjohhshhesjhhoshhhthhrihhplhgvthhtrdhorhhgqeenucggtf frrghtthgvrhhnpeduvdelheettdfgvddvleegueefudegudevffekjeegffefvdeikeeh vdehleekhfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehjohhshhesjhhoshhhthhrihhplhgvthhtrdhorhhg X-ME-Proxy: Feedback-ID: i83e94755:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 9 Jun 2023 21:21:20 -0400 (EDT) Date: Fri, 9 Jun 2023 18:21:19 -0700 From: Josh Triplett To: Andrew Morton , Mike Kravetz , Muchun Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Jens Axboe Subject: [PATCH] mm: hugetlb: Add Kconfig option to set default nr_overcommit_hugepages Message-ID: <88fc41edeb5667534cde344c9220fcdfc00047b1.1686359973.git.josh@joshtriplett.org> MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The default kernel configuration does not allow any huge page allocation until after setting nr_hugepages or nr_overcommit_hugepages to a non-zero value; without setting those, mmap attempts with MAP_HUGETLB will always fail with -ENOMEM. nr_overcommit_hugepages allows userspace to attempt to allocate huge pages at runtime, succeeding if the kernel can find or assemble a free huge page. Provide a Kconfig option to make nr_overcommit_hugepages default to unlimited, which permits userspace to always attempt huge page allocation on a best-effort basis. This makes it easier and more worthwhile for random applications and libraries to opportunistically attempt MAP_HUGETLB allocations without special configuration. In particular, current versions of liburing with IORING_SETUP_NO_MMAP attempt to allocate the rings in a huge page. This seems likely to lead to more applications and libraries attempting to use huge pages. Signed-off-by: Josh Triplett --- mm/Kconfig | 14 ++++++++++++++ mm/hugetlb.c | 2 ++ 2 files changed, 16 insertions(+) diff --git a/mm/Kconfig b/mm/Kconfig index 7672a22647b4..32c13610c5c4 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -824,6 +824,20 @@ config READ_ONLY_THP_FOR_FS =20 endif # TRANSPARENT_HUGEPAGE =20 +config HUGEPAGE_OVERCOMMIT_DEFAULT_UNLIMITED + bool "Allow huge page allocation attempts by default" + depends on HUGETLB_PAGE + help + By default, the kernel does not allow any huge page allocation until + after setting nr_hugepages or nr_overcommit_hugepages to a non-zero + value. nr_overcommit_hugepages allows userspace to attempt to + allocate huge pages at runtime, succeeding if the kernel can find or + assemble a free huge page. + + Enable this option to make nr_overcommit_hugepages default to + unlimited, which permits userspace to always attempt hugepage + allocation. + # # UP and nommu archs use km based percpu allocator # diff --git a/mm/hugetlb.c b/mm/hugetlb.c index f154019e6b84..65abbe254e10 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4305,6 +4305,8 @@ void __init hugetlb_add_hstate(unsigned int order) mutex_init(&h->resize_lock); h->order =3D order; h->mask =3D ~(huge_page_size(h) - 1); + if (IS_ENABLED(CONFIG_HUGEPAGE_OVERCOMMIT_DEFAULT_UNLIMITED)) + h->nr_overcommit_huge_pages =3D ULONG_MAX; for (i =3D 0; i < MAX_NUMNODES; ++i) INIT_LIST_HEAD(&h->hugepage_freelists[i]); INIT_LIST_HEAD(&h->hugepage_activelist); --=20 2.40.1