From patchwork Tue Feb 11 00:40:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 13968646 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 4DFD4C0219D for ; Tue, 11 Feb 2025 00:42:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5BA2280031; Mon, 10 Feb 2025 19:42:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D039028000C; Mon, 10 Feb 2025 19:42:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA2DC280031; Mon, 10 Feb 2025 19:42:03 -0500 (EST) 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 9E1F628000C for ; Mon, 10 Feb 2025 19:42:03 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5558FC08C6 for ; Tue, 11 Feb 2025 00:42:03 +0000 (UTC) X-FDA: 83105811726.02.FD89FD0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 9E369C0003 for ; Tue, 11 Feb 2025 00:42:01 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e0xydFbA; spf=pass (imf22.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739234521; 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=WeJh2P4bxed8LMp5Ek4gDvhHkD3M/Aeurz6cvFHf2wo=; b=2OTmQf8R4kAHxsKLjxvTp3hcQlrTqkyz1vxnFjjJDSLr7YInZQBO829/kCymrlcZaQ/oT1 XXEhddLkpGu0ZPUZvZd0J/IxMDYXMDSnWs0b6gJ34ipTwQJpFlwyGLRbt/i940JGp2zcHH sjlo9qfhuxecFMD9JJwPy46/GpMgULk= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e0xydFbA; spf=pass (imf22.hostedemail.com: domain of npache@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739234521; a=rsa-sha256; cv=none; b=zZm3UQ3ZTn+sIBrd3tia0sqCPca5H0q9Z7NeJl5dm86tMJTqOCs67YepixH5IzM1We2XZS qsNUz5xZdfhymSNUkRyn0nZhxXjZRzwygc5EGothW18Cw5fMWILW6bbuPHEk79FBXEuKis 4TnMG+0QmVHaI81nFTAjjsDR3DwZN4c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739234521; 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=WeJh2P4bxed8LMp5Ek4gDvhHkD3M/Aeurz6cvFHf2wo=; b=e0xydFbATM9O8kxHahjzbfE+9qp0l+Wip9EIAAchJYMNOD+OCDvakMuo/3qOVk8KZcwDZg g+I1GYZdLvLIGYrcy4IkHItLqvgX6+er3N3U9wpIhNyAbEMEiBBSl3YCglUDEe+QKuHpYQ E/tWFiSIZj3QJIHntwKEMdX8QiS+0t0= Received: from mx-prod-mc-02.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-161-QP1PNo-sPkebWvclG8DInw-1; Mon, 10 Feb 2025 19:41:55 -0500 X-MC-Unique: QP1PNo-sPkebWvclG8DInw-1 X-Mimecast-MFC-AGG-ID: QP1PNo-sPkebWvclG8DInw Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B53FB1956086; Tue, 11 Feb 2025 00:41:50 +0000 (UTC) Received: from h1.redhat.com (unknown [10.22.88.129]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7117518004A7; Tue, 11 Feb 2025 00:41:40 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Cc: ryan.roberts@arm.com, anshuman.khandual@arm.com, catalin.marinas@arm.com, cl@gentwo.org, vbabka@suse.cz, mhocko@suse.com, apopple@nvidia.com, dave.hansen@linux.intel.com, will@kernel.org, baohua@kernel.org, jack@suse.cz, srivatsa@csail.mit.edu, haowenchao22@gmail.com, hughd@google.com, aneesh.kumar@kernel.org, yang@os.amperecomputing.com, peterx@redhat.com, ioworker0@gmail.com, wangkefeng.wang@huawei.com, ziy@nvidia.com, jglisse@google.com, surenb@google.com, vishal.moola@gmail.com, zokeefe@google.com, zhengqi.arch@bytedance.com, jhubbard@nvidia.com, 21cnbao@gmail.com, willy@infradead.org, kirill.shutemov@linux.intel.com, david@redhat.com, aarcange@redhat.com, raquini@redhat.com, dev.jain@arm.com, sunnanyong@huawei.com, usamaarif642@gmail.com, audra@redhat.com, akpm@linux-foundation.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, tiwai@suse.de, baolin.wang@linux.alibaba.com, corbet@lwn.net, shuah@kernel.org Subject: [RFC v2 2/5] mm: document transparent_hugepage=defer usage Date: Mon, 10 Feb 2025 17:40:51 -0700 Message-ID: <20250211004054.222931-3-npache@redhat.com> In-Reply-To: <20250211004054.222931-1-npache@redhat.com> References: <20250211004054.222931-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Rspam-User: X-Stat-Signature: diemjnbdw8t4sjto1wj1dw8443yfodjw X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9E369C0003 X-HE-Tag: 1739234521-425699 X-HE-Meta: U2FsdGVkX19TAqdqmteWF1MAhDu5KrDq/DzHofCdUVQ94MoLyaGx6iSjHxPkOToFtxpCKYodnQshtItzoXUN/hlz1Jjhn9c2MIrnRRhmRtfjK7V/hyLwcxsyy5+TANyYLHcIy21apt26XAWntsbSYAqSj7kyuziJxEonBctJUnv4MlHx7s+bx53GXwSz9yTFISgrpKtS9Wxm9fbH3VeE6SGNj1N/TNvVfEW2w5hHSI2nz8JdRie7hPeIynRVeqRNUpfkS9DxPOV+k4LCAF+jJ9jeXvSmJRI/LvqwMPplXeVW9L5j/XwAmFZt1KVCD7mvb1ZufDjjcZw2G/QfvJ9WP1aVD+S/99Dy06EXiiGUIj3/x5ycZx9GaPvJgw+DIBADlhYQdU1GfJ4M2qhD43ZNyUEh7x4cMtbaShW4px2ObR1X510Pv22xEjX+jjn36fCaHEKp59B3H+1/8AL7sH59/Ns4gvQqgUQwLUAe5vZr9j0ml6/xBkQ9Fr5J7yFSpfbrOjwKQQgrNsPHforQ9YTPmfra9c6zzPL5F+QBOtJpIJeyKMZfOzvaPvymeNVTvdonNXlzIHp0wT56UNq6lDNKTZK1FXhoul+PTa1RsKb4+5PPLHIj1r8MzonRFRrk0tDKlRPoF+Sv/mkshtap4nTMyYi2qMhMw7j3s+LbvfOtnjJr2GmCYCc/Xex3jlp9Y0V6fuhlevBZCddWw/yDh2vveonqiF0btgwckRQeiCctD1nqnk3y5TvJdM8GxJpDlYM0JFv5tl1n0XJyhfQDrysIBmsmv9VLVeYFEkReBhDy3x4+kgwxCK+of5LmFK1tEJ7MYct3/w54z0nw4MRmi2zJpZ77HPzBY2mIbtzqE9TawgM3d4JP9PhWmF4Wxl+aHYzuPh4pWZ4YRmih720LMiMGDlofkzC7eGM/3f472uwze7ebB5K0t61kzj/RsbWeLh695BQ6zA1xK4f5DPVPe13 /7+Ckac7 2RFsPVfj0y9ESRsBbnbtk1RaWPSCj3xhG3UZ7LQKdnXg8o0cF7sKAv9Yr1byqwtCEzKKBbg7xUdGddyd0/uaaFuGeuXQXfyUoqGhvAynsBIDn1AVzEfB3Naruupg8j/pGsWYe/7eaKmGMMDXbwacRkkUQwVzdnXWlcpli5qgmpo6NPXw2+t4hSKtsvyc7Pak/C0BxKFvVevuJtxR4aLSVX/O39vetO5WDHbmNweoyA3Gl3cLqw2rDUjYZ6wLi+kG99OS79P/VCJdW+RYh67dCMZwuHBHXhAATP54aQrFaMiqZYvcCr1HAQE/b0M7JnPIsFQ/xm4fRo8XqSqbhxYOr9y1m6KP8gDTU/I7ZhgwH49HAK309onxnPiM64L3cJgsYuBCIEvTmbThA5P/UAadoqhZqsYdDRHJRh+UHZogue2B3ypLD5vDgtyc9aclVwRRKIpVu 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 transparent_hugepage=defer option allows for a more conservative approach to THPs. Document its usage in the transhuge admin-guide. Signed-off-by: Nico Pache --- Documentation/admin-guide/mm/transhuge.rst | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index dff8d5985f0f..b3b18573bbb4 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 the mappings for potential collapses into PMD +sized pages. Admins using this the 'defer' setting should consider +tweaking khugepaged/max_ptes_none. The current default of 511 may +aggressively collapse your PTEs into PMDs. Lower this value to conserve +more memory (ie. max_ptes_none=64). + .. _thp_sysfs: sysfs @@ -136,6 +146,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 @@ -274,7 +285,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:: @@ -299,8 +311,8 @@ 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]:``,