From patchwork Sat Jun 10 01:21:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Triplett X-Patchwork-Id: 13274671 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 51D8EC7EE2E for ; Sat, 10 Jun 2023 01:21:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F1578E0002; Fri, 9 Jun 2023 21:21:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A1C46B0074; Fri, 9 Jun 2023 21:21:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4690C8E0002; Fri, 9 Jun 2023 21:21:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3787A6B0072 for ; Fri, 9 Jun 2023 21:21:27 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E25B014037C for ; Sat, 10 Jun 2023 01:21:26 +0000 (UTC) X-FDA: 80885085372.25.1761758 Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) by imf04.hostedemail.com (Postfix) with ESMTP id AB31B40003 for ; Sat, 10 Jun 2023 01:21:24 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=joshtriplett.org header.s=fm3 header.b=ixy4icfz; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=PQOIbIq4; dmarc=none; spf=pass (imf04.hostedemail.com: domain of josh@joshtriplett.org designates 64.147.123.24 as permitted sender) smtp.mailfrom=josh@joshtriplett.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686360085; a=rsa-sha256; cv=none; b=2H2fOvzyLHX0pDkVS9OhzMOEZodcbo0vTUCX4LJxiVqM9Omsx2GN1PlTXj9rQivcMYXenE oZvbGco5f7Ol9piSQz+kxTtEpJ5QVB0Kv8/HfgxUx+Gse6tNpdc6vetua/oeSryqO8NhWi 9NfyV24mKgXwnBzPR+0FWm6mfJPeGas= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=joshtriplett.org header.s=fm3 header.b=ixy4icfz; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=PQOIbIq4; dmarc=none; spf=pass (imf04.hostedemail.com: domain of josh@joshtriplett.org designates 64.147.123.24 as permitted sender) smtp.mailfrom=josh@joshtriplett.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686360085; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=6g2RVl+GpOZe2oQM/8nONsqThYPCh2VfCuomeQ/pDfE=; b=pumbDiW/q/eqMX8DnumbeaOEUdbkU32MwvVDnZ48cWJe01JozFdV9YK5c2VYw4NdkgE6Cu DfhRYAmxC7TKtaBpQj4mY7UoQ3Z55BRPxy/CkOdDs3Guh9wX31QMX73eR1JzR+pIz6Xzzy q3ZNGCBulEkFQ3IOMHeqFt2MCmN7PCs= 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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AB31B40003 X-Stat-Signature: x49jbdqmrnb6tohorhdiukqsmb4mp16u X-HE-Tag: 1686360084-810740 X-HE-Meta: U2FsdGVkX192MF+ITJnhkZz9hOSTFgbH1l7lb+tmRRkA1n/HLQEmBrgxhwyyJIO7sFNgUj8vtvPXJg6a4CaQeBnUTMoR6w8VXCivDEUI4j28zrqXhOM0gEYl/+37HUpPEMn4lY/CU8Ec2HPJ9tGfhMCmYK9Ov0yTsnKxz5ekRLTHMVBrkV7z8z2E1/tnPBnW18Lw5IA3VcBOpvtABL9BbpSrU+dhDYwd3hrhoyrQca5yk5vHzAbprvbtg0Gegb4UekvWdFGHKFvmrHTFrAC1BbVW8cHpmvy4m2qtBgYd9ABaqfnmVLffZqoEldtz6eIDHTLUz9WgGfwAHo51+rMDyQBsXQFHDFAx+fRlz+NPXQ8Ozg9DLXl/a2hNfaGPZFNmjpx7Es/6MY5eXaVSxoT9WlcUcog3neHPF39zahzBRtUzzwxeHHX40NCT1rxlKuXxyIxC9TCTnwM92IssBDORLqqgehsMC/WdUaBvZyjALQTxOtWKWVTquWGlDYIQkx+IQCLxb6K10jypqYJu37kP0UkERsdK+jQBaLYzWkTXlyHTb3nmxGzPmaV0oNXaDFJZ+50byP+PoymbeidB7xsTKlAIr/K4h+xN7M5bje9nhtiHQqLwuisvqagfb1juPZkx+RpGBb2Guaim68j9E10NKo8ilB1u+q0+VoFrDp45Q4qGmA2ymDKD5PqEILnIfsDyZxVFnYacfzkJ3kmRLsm/6aS3ZVhqK5AsYdjnRI28L5D3MhD7JIsob1nZ45EgqInJ37t0LL3GoiYjVqjTFV74JzyIMgPCy/QvyFNfNTNDKJZ2woXKCCS7/18tFKSPCbcd2xrKRvH8uVudEYyBCSNfbS2L70ifsvKl+sl7DggTiuP1lZumhlm4jUxnlDd4AbKHONVVqCJkR9gviAejBiej4C0qPkd/Kul1Jc1HH/KH0RvcWMC0WqFasmvnbTEePc75G4k9MNVvjOH6CLHVIbF ux5UGJ2X 7s62rI7aQgCMt6+wA664sUJisdWCgk8wP8fLR7IofQeNMCA0YExHaTM0Pp7e6l13xe/0iXIho0Fs61MlyMB0t+zq4gAIAKMWKx8osvxxfMQ2H+3KX3SclfnLRs1SHG2fYWu3RZZb1UBQzc2we2fELQRT+ZefaTO3vaU1hJIXLkYgN4YvvGGta2SlkqWxMaMlwDFQnfxji5zVdROtfZluvKiouvxo3wh50MpeGZiOinJVWySP+3DF3Z2G8mkVBe9hMHlevK4F6MP9nsx+T1jUD5RMsbBUh1gpt/+POHzGe9BY34E9YVIqlfFA0zHjrtzshT3q8IYYfoekP3R4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 endif # TRANSPARENT_HUGEPAGE +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 = order; h->mask = ~(huge_page_size(h) - 1); + if (IS_ENABLED(CONFIG_HUGEPAGE_OVERCOMMIT_DEFAULT_UNLIMITED)) + h->nr_overcommit_huge_pages = ULONG_MAX; for (i = 0; i < MAX_NUMNODES; ++i) INIT_LIST_HEAD(&h->hugepage_freelists[i]); INIT_LIST_HEAD(&h->hugepage_activelist);