From patchwork Thu Nov 28 07:40:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13887735 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 B512AD690E2 for ; Thu, 28 Nov 2024 07:41:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26B406B0096; Thu, 28 Nov 2024 02:41:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12F9B6B0085; Thu, 28 Nov 2024 02:41:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB32F6B0092; Thu, 28 Nov 2024 02:41:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 87DE46B008C for ; Thu, 28 Nov 2024 02:41:04 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 268ABC1996 for ; Thu, 28 Nov 2024 07:41:04 +0000 (UTC) X-FDA: 82834707438.12.1603158 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf30.hostedemail.com (Postfix) with ESMTP id 8335780004 for ; Thu, 28 Nov 2024 07:40:49 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=SfIC1BK3; spf=pass (imf30.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732779659; 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=4geB5O7mEfI/X7677yTwrrvC9HQS1VjRPAOpYyMK/zg=; b=8aqqq80DwFRqYcGymlqU7hUkSIhx3LA3/HIaQdqcW2R/OCEUTvztJq+tgV/dWWIoVi3U1C YGTDZqqA0WO8l2w7PvIwTvBqldExmefZkf+URVEqN+lCXWB/zSPvZtPp2efSpZOZmEl7Pt +o07vnkmCXJo1cTjbVf3CmDwhDR8JAs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=SfIC1BK3; spf=pass (imf30.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732779659; a=rsa-sha256; cv=none; b=LZWqD0CaVt2tGe58NB1dV3Xv6HwFjTz9Vw3RkJzbm49xUewhZfXHWY0Ili895mUR2wPKA3 jO+gCtqliN9Lre1gP1XSV6gTaO+CLLUpDP+M4mpZlMPPqI3ihSEfUO2W6R+Ani0OR4xSAW OBw43IjWgZKmm1iwtvtcYvLaG6Fq/8s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1732779659; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=4geB5O7mEfI/X7677yTwrrvC9HQS1VjRPAOpYyMK/zg=; b=SfIC1BK3Ys7utCEX+QZcyL9qxn+Tf7MT0G92Fqd6ZtasU2u4lzolEdOIn0LuQxpUJCROA4ED+6P3sGuhYIwCAJyCZy2rb9RXmk2Rktd4w6wO8j6N2RyH3Ugo8BAWVj1j0o1B+jusOnTMdpEsyTH16l/HQYzshn3OAHh2gyEGTjQ= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WKOx1qd_1732779658 cluster:ay36) by smtp.aliyun-inc.com; Thu, 28 Nov 2024 15:40:59 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, 21cnbao@gmail.com, ryan.roberts@arm.com, ioworker0@gmail.com, da.gomez@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/6] docs: tmpfs: update the large folios policy for tmpfs and shmem Date: Thu, 28 Nov 2024 15:40:43 +0800 Message-Id: <9b7418af30e300d1eb05721b81d79074d0bb0ec9.1732779148.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 8335780004 X-Stat-Signature: hb9dnu1zksmo3rgh3t9s9jynukb7y31s X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1732779649-253679 X-HE-Meta: U2FsdGVkX1/cl3gmBHstUsolT/DLwQnr95mINNjnBNa+8VAxsgNOEeinkZQxYczdzhL0lQhp+7QeJYsMZkUYYR6HfhzT4hLBiewkRg6sv2D3rXpgnrOw24cE7gUtDzSia4BIUfDKhCzFx6tgW1JfHT0YZyQk/fubgO/otO+yhJU0g6qO2sjUlivuwfwN4AHzLV8v3k+KJ6ltgaLOscwi/d1gjcdANUWuBs4lA6SfFY+YoxWsJF9kBwrmiZU2shQfIh2YDpLlCKYuDT8KLdYayWgR/oH8FLPTYa8kBySFnkznDnRio83O7vCgtlDN1aKBrZsy4YwEJO343yfGRwC2kt8W2GuGMELF5g4barATHUmDsrcEeobZZQZDl0li7wt9Ok3LNu9lcn0yCstF83H2htKbYNj9/BKn7sHio67lkSDzluzc4cuGzbhx3jtB090Peca4+wAeyc3e7w6IvoB7Wd9CPsO314BlCkxm+bsvihtw+OXLkmiwDgrjSz0tJnGU0BRT1BFDjeFtM39LHtA2rXMvCewyG9tUlDLd3fyKrJpRh/8pWIC29OEARJlWhoOVrtub62bGYQA5wZ34V8aKMhjFicpQ1zAjZb/iyyTvsx7GAbJDddB4nOjPQH9XTijJna2LXfjkCeza0hgMseUxblhSuoKMDJi2cg+YAiP2angXy3PNJvdLWI+ia6JahNlVLlgeiVvOXgTHLTgIJ+R40MHNgNRVDQSSzt1dMxumdVUFFPuLrDRTu/rtK+zCg5Vj1aRr5lVcOfXdtsFUs/X3Nr+gEig4ooSvCxP05F/ZsFam05uE/Q04U4QuugDmWlIsyNKxR+bVfJg3yDiTWDdRUs1P+59EqQmLXf6qbN6WMD6nHqV/dOSl+7NnFH7kmgtS8NLY2/pOdyBUKelMEsUH7W+W5+o7aIyML+dHwVS/R4XI1FLmQXopL9iBsbr7yJ/CwOgEtLp8U2Coel1zR0S 6HHDFzbw xfzJEXXeB0flRWadbCjsWkb5FEoDiU5IHqFWQPlV8CWaMENjcnrUG/gHkKiWlORukui69OEyBbKa7Q4p3DuVt9M9TVoPK2HayqNL1WxO0xnBwBSJ+/QIgPamq+wugXOApzPOUzTn1FPrDbxGCik6g+VurTVxNhICD+UvYO5QXZQdUpIj8TTlQm6JCQT5ZjHKoXREWMzgtdTRnlBL6gyRXjJcPADTmIiY3wt+CZBv9esipKYeP2z2a/CU+5n1O7ZD4l+2R 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: From: David Hildenbrand Update the large folios policy for tmpfs and shmem. Signed-off-by: David Hildenbrand Signed-off-by: Baolin Wang --- Documentation/admin-guide/mm/transhuge.rst | 58 +++++++++++++++------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index 9ae775eaacbe..ba6edff728ed 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -358,8 +358,21 @@ default to ``never``. Hugepages in tmpfs/shmem ======================== -You can control hugepage allocation policy in tmpfs with mount option -``huge=``. It can have following values: +Traditionally, tmpfs only supported a single huge page size ("PMD"). Today, +it also supports smaller sizes just like anonymous memory, often referred +to as "multi-size THP" (mTHP). Huge pages of any size are commonly +represented in the kernel as "large folios". + +While there is fine control over the huge page sizes to use for the internal +shmem mount (see below), ordinary tmpfs mounts will make use of all available +huge page sizes without any control over the exact sizes, behaving more like +other file systems. + +tmpfs mounts +------------ + +The THP allocation policy for tmpfs mounts can be adjusted using the mount +option: ``huge=``. It can have following values: always Attempt to allocate huge pages every time we need a new page; @@ -374,19 +387,19 @@ within_size advise Only allocate huge pages if requested with fadvise()/madvise(); -The default policy is ``never``. +Remember, that the kernel may use huge pages of all available sizes, and +that no fine control as for the internal tmpfs mount is available. + +The default policy in the past was ``never``, but it can now be adjusted +using the kernel parameter ``transparent_hugepage_tmpfs=``. ``mount -o remount,huge= /mountpoint`` works fine after mount: remounting ``huge=never`` will not attempt to break up huge pages at all, just stop more from being allocated. -There's also sysfs knob to control hugepage allocation policy for internal -shmem mount: /sys/kernel/mm/transparent_hugepage/shmem_enabled. The mount -is used for SysV SHM, memfds, shared anonymous mmaps (of /dev/zero or -MAP_ANONYMOUS), GPU drivers' DRM objects, Ashmem. - -In addition to policies listed above, shmem_enabled allows two further -values: +In addition to policies listed above, the sysfs knob +/sys/kernel/mm/transparent_hugepage/shmem_enabled will affect the +allocation policy of tmpfs mounts, when set to the following values: deny For use in emergencies, to force the huge option off from @@ -394,13 +407,24 @@ deny force Force the huge option on for all - very useful for testing; -Shmem can also use "multi-size THP" (mTHP) by adding a new sysfs knob to -control mTHP allocation: -'/sys/kernel/mm/transparent_hugepage/hugepages-kB/shmem_enabled', -and its value for each mTHP is essentially consistent with the global -setting. An 'inherit' option is added to ensure compatibility with these -global settings. Conversely, the options 'force' and 'deny' are dropped, -which are rather testing artifacts from the old ages. +shmem / internal tmpfs +---------------------- +The mount internal tmpfs mount is used for SysV SHM, memfds, shared anonymous +mmaps (of /dev/zero or MAP_ANONYMOUS), GPU drivers' DRM objects, Ashmem. + +To control the THP allocation policy for this internal tmpfs mount, the +sysfs knob /sys/kernel/mm/transparent_hugepage/shmem_enabled and the knobs +per THP size in +'/sys/kernel/mm/transparent_hugepage/hugepages-kB/shmem_enabled' +can be used. + +The global knob has the same semantics as the ``huge=`` mount options +for tmpfs mounts, except that the different huge page sizes can be controlled +individually, and will only use the setting of the global knob when the +per-size knob is set to 'inherit'. + +The options 'force' and 'deny' are dropped for the individual sizes, which +are rather testing artifacts from the old ages. always Attempt to allocate huge pages every time we need a new page;