From patchwork Tue Nov 12 07:45:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13871830 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 AE847D41D5F for ; Tue, 12 Nov 2024 07:46:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D2D4F6B00E8; Tue, 12 Nov 2024 02:46:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C925A6B00E9; Tue, 12 Nov 2024 02:46:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0A116B00EA; Tue, 12 Nov 2024 02:46:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8A08A6B00E8 for ; Tue, 12 Nov 2024 02:46:06 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1BB2D80D6C for ; Tue, 12 Nov 2024 07:46:06 +0000 (UTC) X-FDA: 82776658188.21.73558FA Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by imf23.hostedemail.com (Postfix) with ESMTP id BD317140017 for ; Tue, 12 Nov 2024 07:45:36 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=J9x9ZEkl; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf23.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731397502; a=rsa-sha256; cv=none; b=nkcCibTHfaGEhcM03cWqrIn1bRuQPkk1GB2S4bT/qYaS5MIVlrSx00wsuUqCBw7ZVxxcs4 cFrxR+3trxSrh+oGxdvaJJBylAoM424jAkQfSVNgakBDgzAOr01CUstgYYWDRleDKNDUto b8aeY9+68e9pBiHu8ua8dh7wBjdcP6Y= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=J9x9ZEkl; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf23.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.111 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731397502; 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=QrGwmL/EZQwRk4LD22fvlkOHU0IkeaUKNMscFX8f1w0=; b=F7RSElNStSzeSU54ElTH3ACpCiEnksUrkXnJ7D1amtv2VTIYFwMtmLVe2UmLykQDHGgzlx gVovQsrKuWEuplvw8I01s8WgMEiobbSTH5i9fP+AarrbdLGkKldjDF/TzvQXo8dC4ABy2+ IZiBGtI0++Wt4FR+hcwimTz3TUYm31k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1731397561; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=QrGwmL/EZQwRk4LD22fvlkOHU0IkeaUKNMscFX8f1w0=; b=J9x9ZEkl3hPePvX8j2T0pRH26LEcJiMJGaWm69ms2kPBJ+jT4UZbNuz2FpWo47vp69QNXKk9J0WiinF9VRQuqUDJIjIo83SB0yz2x5kW14K1F8HVYp9bJiYyg+fehjcgILKjO+L3sGtAsKrX5Q8gTZPGIKqAG9vi+F6ewaER2Bo= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WJGDWo8_1731397559 cluster:ay36) by smtp.aliyun-inc.com; Tue, 12 Nov 2024 15:46:00 +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 v2 5/5] docs: tmpfs: update the huge folios policy for tmpfs and shmem Date: Tue, 12 Nov 2024 15:45:52 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: BD317140017 X-Rspamd-Server: rspam01 X-Stat-Signature: wkbgn7byt8j7mk3seqa19qsjjxqqfegy X-HE-Tag: 1731397536-782738 X-HE-Meta: U2FsdGVkX1+/r2cHlONpRX69z7zGoWI4c+hhPD3uanr9p/B8u6mHLnu363Z+2S4OKF42ew4HoOosxxRNKBBQM5pmM8lfm6SqeQx1sbX7afog12HQ70P82CJjLerD1B7K+RLISDICB77zl6t3u+vUgGKL4flgh7c5Lw0MeGi0b70r1lRGkQBDIELdWuZ+mLikWsW/6KS6kac8gFcbQwI9Cm+9KPwGNExx4CYD0E0qOFV5TYRF0l0mj7FIcHT5yaBbRVbPpr3wLX+2wtf/QweRUJuJrTtSAl/7mkN5AZKeVPy3/1eooVpDm9oWtaU/cQgrX2FwC/6/U+4HRPs6qxBsi/TAyUhUwp3Y0S8kElOvV7BZZ3ghBKrTolA8ZtLi+DuHtYFDAyGnci08zma+mvaiRsK+hoLT9/m/QdJSVsiK6V7B676mNz+trRTUZV1PA1a8L3wO22S6rE/lbDsyOa3th0DgTRtBzYAXv7YyZ4qu2IyO84zOTtPhACaMKb6d0lk33VbQ7WJDPGQLmcIaICH35sjBCyE4FhRlRwZwhO8R4iMVHEVMYndLtbP7KIYrSlVKTFZWTx5SI8x00B9gMgxYxR7RC90hLzsL+aAA0Nte31ZxKlYV6Va8nUKMirE3EJag0L4wrQpX14BsEvUaL/4sPIuS/iOUEEiEYLz7sF3n6c1od2ErSvpvfN0K/P6r3asYBPWFBFeuJy7OQ060cziczMR/wRC3EPWu3Xg3xCJMNDuyxiXk+bNiACWaN2rJO5Eo3phAJGxo/vulP6foudSDFviIweBjhKNWpcBOL0LXTx4VZkGj/FXiPGI1s7NFzeu3NFVffnRXQ6UBMAN8A3SQ+In2iRyLu5ZEzNAYvuvn2efmbQxXzSkNyTUV7Kw2e1LOC3iTeY6PgYN2ikKjorDa7ARlUT7HDkhbKI0RzwUfcwbF1yrUpFT9U9/RCdo1E3tNRpSiRA0R2IDVy8dAVBN QHpWCR+Y 6W1kvoTCg269SmBKCY9wtJXDuE2XAPFDgHUZEpzILKtM/0EYbkyToSObqAcjme0T77yrx08OReFpv01Ecng07/DXAJS0GT7HqEhJU8VqayOxPv7+04LWU0DDouEhmfhMn9KtgAP89nD096D+K/c9S/FduQAr3tDaSXiIx+o4cYt67fKvG65lDOpilEQah05qNugjO/Vp+2zt4Kfw8/bImTEHsW9TFdwkhqvjQvdHU9AGGcfx+pixn8GtpeqO9C3Ag1AVy 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 huge 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;