From patchwork Tue Oct 18 23:50:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 13011207 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 E28B7C433FE for ; Tue, 18 Oct 2022 23:51:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58B516B0072; Tue, 18 Oct 2022 19:51:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53B426B0073; Tue, 18 Oct 2022 19:51:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 429EA6B0074; Tue, 18 Oct 2022 19:51:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 335A76B0072 for ; Tue, 18 Oct 2022 19:51:06 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 04041A08EA for ; Tue, 18 Oct 2022 23:51:05 +0000 (UTC) X-FDA: 80035718532.26.2BF4A99 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf20.hostedemail.com (Postfix) with ESMTP id 903FE1C0012 for ; Tue, 18 Oct 2022 23:51:05 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id b1-20020a17090a10c100b0020da29fa5e5so7547297pje.2 for ; Tue, 18 Oct 2022 16:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mwwrA+AKJG2rv4I4FBclmb9mZ0XqPEz5+xc96NXfVbo=; b=TnlJdkmWH28tthLcGelqLd0I/jGxMhGO75+K7nEELFCKTI+s/3/mHiZC3wijcMamyG Vdr221Gocs4t41NOolPIFGBvT8qU79G1GxpyHPnKezD9IRtTKlM8E1BW9TDQZIywBHGi xlDJ2acHFF3P/iQ1AggZTpUbiI1YZ5ChvcwfIR9h4lOAw5tCblDQ817R2IpJ/9GqxIrD DAMF6GlMs1RYg1UOPp0QlzgXnoENnUbjRWWehQY1vEQ/Cr/wkXRL4Wmllp9GkzvKPRue U9uQANY0Z8FVyJzncKJBypYDjKIK4pxHbLmF3zLGB46I2HlHXskig+zShpaJEqy81uBb ubcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mwwrA+AKJG2rv4I4FBclmb9mZ0XqPEz5+xc96NXfVbo=; b=LKqafK8XqijR+GLrkGqhB19oj7AdZEHT40Fiu1tyamKB1XwIWlWOXecOxAWcz0e6Sf LT2Ou2B43kEMamD7a328NIleRK77Id+1g4ZPwRkfmtJDmlwYJIK0ZElG2cL2/6aEGscC wIZiarIEUqZ5aR8hCp7KPxIk+k9fUO2X2cqdGdD3O0hFh8Edknm340Ge7Ol5pmLEPVR7 y9MWa8Zn0rj5jR1kgRAtzZwiNP/jHHkdqqh/sbeZ2UEnTUU8aOtVpjrpkk3folcnoNHO xq/u6rn6YDlkaH4LEg0fQKax0RUzgh5Z3XxbN5ftE3GADSWdvAEDlaH/251xcAAFnBDX rupQ== X-Gm-Message-State: ACrzQf00vNhRlz1TShP0nm744XGOBQKZfMBMTRq65ri0G4bYF/PvDbWB eAD9yGyOClu/mLy632ZAeej7okDXRoH2 X-Google-Smtp-Source: AMsMyM7x5IWjOuzuBkp4TLq/73g6nfs6biMwjKxfPOkF+RuhdxgsQgpU+G1TxT9q5LT270Wsv4OORvzB4H42 X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6a00:1a92:b0:565:d5c0:f627 with SMTP id e18-20020a056a001a9200b00565d5c0f627mr5787283pfv.10.1666137064421; Tue, 18 Oct 2022 16:51:04 -0700 (PDT) Date: Tue, 18 Oct 2022 16:50:48 -0700 In-Reply-To: <20221018235051.152548-1-zokeefe@google.com> Mime-Version: 1.0 References: <20221018235051.152548-1-zokeefe@google.com> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog Message-ID: <20221018235051.152548-2-zokeefe@google.com> Subject: [PATCH man-pages v2 1/4] madvise.2: update THP file/shmem documentation for +5.4 From: Zach OKeefe To: Alejandro Colomar , Michael Kerrisk Cc: Yang Shi , linux-mm@kvack.org, linux-man@vger.kernel.org, "Zach O'Keefe" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666137065; 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:in-reply-to:references:references:dkim-signature; bh=mwwrA+AKJG2rv4I4FBclmb9mZ0XqPEz5+xc96NXfVbo=; b=X5xCGJypexAQ/EWYVRNKeqf2mPIlgqTT4dv9qgbjjbLp7b434dOUKXfgwomHMHmGWYprNa 4khhAIa7Y7UMK/fyhQH732FpLVlZ9K2ba/OX27uGx0cbnaiWYznFJmwxPJzjb2G8NrxYLW eaCh/trkzOWp/gx9tmuj4GccUnp9iSg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=TnlJdkmW; spf=pass (imf20.hostedemail.com: domain of 36DtPYwcKCL02rnhhihjrrjoh.frpolqx0-ppnydfn.ruj@flex--zokeefe.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=36DtPYwcKCL02rnhhihjrrjoh.frpolqx0-ppnydfn.ruj@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666137065; a=rsa-sha256; cv=none; b=JVH1bXmsENqCgUkWJ9s1Edqi73bcvfWBxDeo71yBVA3Vc5eGpSrQAK0XzzPbRx6VWy8rxh DfYKORyvceNNBPa8kN27dr2yw0ZsN9ct+MJnb880cAvWUp90a8MBls6mohUUjUoIqzm4Wr 347pNU0ugQjX687y3S4v3wn2WsRGGt0= Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=TnlJdkmW; spf=pass (imf20.hostedemail.com: domain of 36DtPYwcKCL02rnhhihjrrjoh.frpolqx0-ppnydfn.ruj@flex--zokeefe.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=36DtPYwcKCL02rnhhihjrrjoh.frpolqx0-ppnydfn.ruj@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 903FE1C0012 X-Stat-Signature: w6bug1csahyjwxiq3qsffxnkweefok7i X-Rspam-User: X-HE-Tag: 1666137065-170047 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: From: Zach O'Keefe Since Linux 5.4, Transparent Huge Pages now support both file-backed memory and shmem memory. Update MADV_HUGEPAGE advice description to reflect this. Additionally, expand the description of requirements for memory to be considered eligible for THP: alignment / mapping requirements, VMA flags, prctl(2) settings, inode status, etc. Signed-off-by: Zach O'Keefe --- man2/madvise.2 | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/man2/madvise.2 b/man2/madvise.2 index 81cce56af..64f788ace 100644 --- a/man2/madvise.2 +++ b/man2/madvise.2 @@ -320,8 +320,6 @@ Enable Transparent Huge Pages (THP) for pages in the range specified by .I addr and .IR length . -Currently, Transparent Huge Pages work only with private anonymous pages (see -.BR mmap (2)). The kernel will regularly scan the areas marked as huge page candidates to replace them with huge pages. The kernel will also allocate huge pages directly when the region is @@ -354,12 +352,46 @@ an access pattern that the developer knows in advance won't risk to increase the memory footprint of the application when transparent hugepages are enabled. .IP +.\" commit 99cb0dbd47a15d395bf3faa78dc122bc5efe3fc0 +Since Linux 5.4, +automatic scan of eligible areas and replacement by huge pages works with +private anonymous pages (see +.BR mmap (2)), +shmem pages, +and file-backed pages. +For all memory types, +memory may only be replaced by huge pages on hugepage-aligned boundaries. +For file-mapped memory \(em including tmpfs (see +.BR tmpfs (2)) +\(em the mapping must also be naturally hugepage-aligned within the file. +Additionally, +for file-backed, +non-tmpfs memory, +the file must not be open for write and the mapping must be executable. +.IP +The VMA must not be marked +.BR VM_NOHUGEPAGE , +.BR VM_HUGETLB , +.BR VM_IO , +.BR VM_DONTEXPAND , +.BR VM_MIXEDMAP , +or +.BR VM_PFNMAP , +nor can it be stack memory or backed by a DAX-enabled device +(unless the DAX device is hot-plugged as System RAM). +The process must also not have +.B PR_SET_THP_DISABLE +set (see +.BR prctl (2) ). +.IP The .B MADV_HUGEPAGE and .B MADV_NOHUGEPAGE operations are available only if the kernel was configured with -.BR CONFIG_TRANSPARENT_HUGEPAGE . +.B CONFIG_TRANSPARENT_HUGEPAGE +and file/shmem memory is only supported if the kernel was configured with +.BR CONFIG_READ_ONLY_THP_FOR_FS . .TP .BR MADV_NOHUGEPAGE " (since Linux 2.6.38)" Ensures that memory in the address range specified by