From mboxrd@z Thu Jan 1 00:00:00 1970 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 07333C3ABC9 for ; Thu, 15 May 2025 03:40:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 141576B010D; Wed, 14 May 2025 23:40:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EFDE6B010E; Wed, 14 May 2025 23:40:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAC656B010F; Wed, 14 May 2025 23:40:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C97E46B010D for ; Wed, 14 May 2025 23:40:04 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 08F6716149F for ; Thu, 15 May 2025 03:40:05 +0000 (UTC) X-FDA: 83443738770.10.21F6582 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 4FF79180003 for ; Thu, 15 May 2025 03:40:03 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FVVAFK51; spf=pass (imf16.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FVVAFK51; spf=pass (imf16.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1747280403; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=illy9a0IaRLRjpyollQHr/drUNF4chj8Y2TZlHp92rI=; b=O9NNxBNd4xwmFUb9QhJS6ndgI2hQZ+Vi+1KPfW8udsDFOx5n1M18+JLgQ/kNMPlONecl/E JfPy1icUZpBy8vZIrXIdgoM4cNIORPkkfMtDQuKtJ4ElgFyCaIz3k42ZHAIXRIS9cDwJmU meyBj6LoHbT/2WAvVOLfI2GPdakexd8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747280403; a=rsa-sha256; cv=none; b=nWQ2bnBwezK/slAH9xnz/U1HsIYEJC3eAH/LHU3S8ge3EB9sXzOLo9+vkNkbOL/c5Tdwoq RNET8u+iucrBJuxYKgXxswWcmxXM26sqx7PKCoiMVf8fkfly6tlqi4FYf8o5yxTl5sHoCh YhRaVSQlsEBR5O3WAa5VzuquMl83LH8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747280402; 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: in-reply-to:in-reply-to:references:references; bh=illy9a0IaRLRjpyollQHr/drUNF4chj8Y2TZlHp92rI=; b=FVVAFK51M5nKoMpA2ARPekKMJCmbvDmSuBo7iEcHyYnlXExlC+7exH87jezzgahdu9iTD2 HVknDtrGIsFK4oplQw1vNVBboxWCLaM9Vc9A5rjbUIXs06Y3zS5C9FngNlzJkHTnL86sPq 8EEr8VDFhxXPR51D7EggKtrb/6zm1h8= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-131-vUokHE6TMzmJBnlO53tfIg-1; Wed, 14 May 2025 23:40:00 -0400 X-MC-Unique: vUokHE6TMzmJBnlO53tfIg-1 X-Mimecast-MFC-AGG-ID: vUokHE6TMzmJBnlO53tfIg_1747280396 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 39AE21956095; Thu, 15 May 2025 03:39:55 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.88.116]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0E95E1955F24; Thu, 15 May 2025 03:39:38 +0000 (UTC) From: Nico Pache To: linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: rientjes@google.com, hannes@cmpxchg.org, lorenzo.stoakes@oracle.com, rdunlap@infradead.org, mhocko@suse.com, Liam.Howlett@oracle.com, zokeefe@google.com, surenb@google.com, jglisse@google.com, cl@gentwo.org, jack@suse.cz, dave.hansen@linux.intel.com, will@kernel.org, tiwai@suse.de, catalin.marinas@arm.com, anshuman.khandual@arm.com, dev.jain@arm.com, raquini@redhat.com, aarcange@redhat.com, kirill.shutemov@linux.intel.com, yang@os.amperecomputing.com, thomas.hellstrom@linux.intel.com, vishal.moola@gmail.com, sunnanyong@huawei.com, usamaarif642@gmail.com, wangkefeng.wang@huawei.com, ziy@nvidia.com, shuah@kernel.org, peterx@redhat.com, willy@infradead.org, ryan.roberts@arm.com, baolin.wang@linux.alibaba.com, baohua@kernel.org, david@redhat.com, mathieu.desnoyers@efficios.com, mhiramat@kernel.org, rostedt@goodmis.org, corbet@lwn.net, akpm@linux-foundation.org, npache@redhat.com, Bagas Sanjaya Subject: [PATCH v6 2/4] mm: document (m)THP defer usage Date: Wed, 14 May 2025 21:38:55 -0600 Message-ID: <20250515033857.132535-3-npache@redhat.com> In-Reply-To: <20250515033857.132535-1-npache@redhat.com> References: <20250515033857.132535-1-npache@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 4FF79180003 X-Stat-Signature: n7jimx1df55hnnwgt3jz8fidimeqye4a X-Rspam-User: X-HE-Tag: 1747280403-717311 X-HE-Meta: U2FsdGVkX18txmKdCCKdlzaFdIC94C79Eocn15bQpiHHmT4rxg8jAX49nX8znJUrzWaniiLCxYeV+5ua6vrkk+1CwK81qi+LW8T3hrlkiHsSnYxvp1rfWFsJlvTpfvJrDorTmBoAJ1XSSVenGQomZbj8ytIVY/20/5Bcp79rhwPtpkeggdytgxFJPCUFQfpUh9Cr8PYwI19kZt0BytIpNhEzlk/z78nA89eA69yv1ZzUZh4l1PvUgRFQL1aEkI1rKm4clXH3ShH2lDq0CFQ8mmv29332+syw5Bv+PUoWGj5u3kyvKNtwnOMo2mXZ53XCBwkmFjX1hkdgNbHuuc8jO0jETGaQfSegEtLQx8Rx1pm6CgTu++aJYxXYcy+/U4h31RvceDVq1kDg8Pa8tCOjeE3wcTg9+Gq1vUAoQVm3EkTUxTzwtPqaPPoq1xtjQnNgScfJjrd1VlJEVa+RVON/Nt6+/kzwcpy57PFCdv22qlPpTYDWvq6rIyva1YVpmCg8siApIaULDoXimPDIDEj4O7p91bH2PeBot7XUfaVH9pOkhtFf8py8Ght0jeTTYZcmDR7LD6asroTtNlmLA+UT4pIqchwaOIFw+i7NN0GCi9Y1SFk5l9k44e3mGxDw1/sGOPjUYtCn835PilajgYXSEw7GC9938nKplizSh+juWBa6cXhcdW+whBA+al8N2Q7opVg0iJ2UqBgbina2kdLGTo6Hmp0RnxBjXkP2JP0fX86c56w+drGboMq3tLhNDmWerrTsayKHIk3ldmZlG3J3z34pzxCuhoTSANHOmlb4+pyBL9nH1EV+fcY1bAmSIc7AzkamnrgR860427foovBSGEhj0n47yWH8XBovEtAjVLYfFfTpMM9uoaRrAzThzMsk6t+bOaUtT3aBAo89cDacvIOk9+cze4QZ/X+S2EDSNLs31OH78qe53d4qO5wn/PC+W0FET57MKJ0EzPuqyeE sOqGC+aL 8RzpmSxGQFbourWuKGhcfh+0B78tfHFuzQTrO6dQ3+zyH0mSf8VMjzq3x2vAfJfoD3mwE0rOnotebe/VL72YYP0tc4XwbRoHkKI5OxdLJ691OkihtnrgjCgaHcgMTKnbW+o8I 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: List-Subscribe: List-Unsubscribe: The new defer option for (m)THPs allows for a more conservative approach to (m)THPs. Document its usage in the transhuge admin-guide. Reviewed-by: Bagas Sanjaya Signed-off-by: Nico Pache --- Documentation/admin-guide/mm/transhuge.rst | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 5c63fe51b3ad..7e87ef317add 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -88,8 +88,9 @@ In certain cases when hugepages are enabled system wide, application may end up allocating more memory resources. An application may mmap a large region but only touch 1 byte of it, in that case a 2M page might be allocated instead of a 4k page for no good. This is why it's -possible to disable hugepages system-wide and to only have them inside -MADV_HUGEPAGE madvise regions. +possible to disable hugepages system-wide, only have them inside +MADV_HUGEPAGE madvise regions, or defer them away from the page fault +handler to khugepaged. Embedded systems should enable hugepages only inside madvise regions to eliminate any risk of wasting any precious byte of memory and to @@ -99,6 +100,15 @@ Applications that gets a lot of benefit from hugepages and that don't risk to lose memory by using hugepages, should use madvise(MADV_HUGEPAGE) on their critical mmapped regions. +Applications that would like to benefit from THPs but would still like a +more memory conservative approach can choose 'defer'. This avoids +inserting THPs at the page fault handler unless they are MADV_HUGEPAGE. +Khugepaged will then scan all mappings, even those not explicitly marked +with MADV_HUGEPAGE, for potential collapses into (m)THPs. Admins using +this the 'defer' setting should consider tweaking max_ptes_none. The +current default of 511 may aggressively collapse your PTEs into PMDs. +Lower this value to conserve more memory (i.e., max_ptes_none=64). + .. _thp_sysfs: sysfs @@ -109,11 +119,14 @@ Global THP controls Transparent Hugepage Support for anonymous memory can be entirely disabled (mostly for debugging purposes) or only enabled inside MADV_HUGEPAGE -regions (to avoid the risk of consuming more memory resources) or enabled -system wide. This can be achieved per-supported-THP-size with one of:: +regions (to avoid the risk of consuming more memory resources), deferred to +khugepaged, or enabled system wide. + +This can be achieved per-supported-THP-size with one of:: echo always >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled echo madvise >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled + echo defer >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled echo never >/sys/kernel/mm/transparent_hugepage/hugepages-kB/enabled where is the hugepage size being addressed, the available sizes @@ -136,6 +149,7 @@ The top-level setting (for use with "inherit") can be set by issuing one of the following commands:: echo always >/sys/kernel/mm/transparent_hugepage/enabled + echo defer >/sys/kernel/mm/transparent_hugepage/enabled echo madvise >/sys/kernel/mm/transparent_hugepage/enabled echo never >/sys/kernel/mm/transparent_hugepage/enabled @@ -286,7 +300,8 @@ of small pages into one large page:: A higher value leads to use additional memory for programs. A lower value leads to gain less thp performance. Value of max_ptes_none can waste cpu time very little, you can -ignore it. +ignore it. Consider lowering this value when using +``transparent_hugepage=defer`` ``max_ptes_swap`` specifies how many pages can be brought in from swap when collapsing a group of pages into a transparent huge page:: @@ -311,14 +326,14 @@ Boot parameters You can change the sysfs boot time default for the top-level "enabled" control by passing the parameter ``transparent_hugepage=always`` or -``transparent_hugepage=madvise`` or ``transparent_hugepage=never`` to the -kernel command line. +``transparent_hugepage=madvise`` or ``transparent_hugepage=defer`` or +``transparent_hugepage=never`` to the kernel command line. Alternatively, each supported anonymous THP size can be controlled by passing ``thp_anon=[KMG],[KMG]:;[KMG]-[KMG]:``, where ```` is the THP size (must be a power of 2 of PAGE_SIZE and supported anonymous THP) and ```` is one of ``always``, ``madvise``, -``never`` or ``inherit``. +``defer``, ``never`` or ``inherit``. For example, the following will set 16K, 32K, 64K THP to ``always``, set 128K, 512K to ``inherit``, set 256K to ``madvise`` and 1M, 2M -- 2.49.0