From patchwork Fri Oct 21 22:32:57 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: 13015558 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 9554EC3A59D for ; Fri, 21 Oct 2022 22:33:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35A718E0005; Fri, 21 Oct 2022 18:33:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E2718E0001; Fri, 21 Oct 2022 18:33:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15D6A8E0005; Fri, 21 Oct 2022 18:33:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 00F708E0001 for ; Fri, 21 Oct 2022 18:33:12 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C75661C6274 for ; Fri, 21 Oct 2022 22:33:12 +0000 (UTC) X-FDA: 80046408624.09.4934C0C Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf30.hostedemail.com (Postfix) with ESMTP id 6856280035 for ; Fri, 21 Oct 2022 22:33:12 +0000 (UTC) Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-3584be56efbso41710747b3.8 for ; Fri, 21 Oct 2022 15:33:12 -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=UQIfOxRnlwRRwhWBO+p+5sf8htyV9CkZvkGFbADgqo4=; b=J8FQd3gsTR8s3Po46QnUbCcF1zAKwjsTF/q7AFSouetX0+G+1Rfi/UFIUWZtP/VMtN y3vQUPhUC20FPxpkNLVEO3vP7gT1h66wqxxc9sDsxETC8t43yuzQ4reM0O9cZmObc4o6 aCRFjf4SohxTnroY4G0CsJ2PNj1Oy3HkWR6BLfTijl8BT3+vdpul5wIZKx92L4VQploK X8Ufy8HlNlL3R9o1thXcAWA+jZc+Uxf6FqqRTTsnwiIC/r2BUuOkcOOy9vzzUeCE9c4D yiIabya8h9uONz0LytMhFHj2UGgqyWryZqcwCJfO3rWd9KJVsC9v9QwYeRvrgY/Px+On WHPg== 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=UQIfOxRnlwRRwhWBO+p+5sf8htyV9CkZvkGFbADgqo4=; b=UuvNfldoB9/F1fS78wRYhLDSGWkw9s/aMDSPcOwizEaW8OlBGtNJsYSzk1tAaLDtXS g5xpPhElkaNtTgNe5pbFocvcNdNyQov3tdB4iJkr1mwhoncXVoLtuX63nmBRkoXFVpzC P2wHU52/ZwPjqvjQJVxUldXUJpQ1rvjXfw15iii1NtQXEemux0LEmV7WGdmCXn1Wq0x7 dV79x10X/kZI8iLpIcEXiUcA1R3HJIGIlfuQL3jylDb1bBwN+wS7UmeiIiE5q5Dlwuiv oVo7VM9WRrACPO7bRPN5cN/H5YEDMFI6NESKvbkJcr8Pwliu/rKLdomQLjQUwOJThNK0 O47g== X-Gm-Message-State: ACrzQf3hbgU8NwudeHz5U6HTTUfrLNktVk8JZI39IhR481KNODtD5/z+ 9ZG7Ng70ULn80B/wIA7e+h9FyMQwcGVv X-Google-Smtp-Source: AMsMyM48OQoNtRhgvDbQpBn956ebPCd9YP3ElWOp9cq6UrF7FeGGnbi2A4XkVoszNMT0+oU5sO9aXZ0xI340 X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6902:1209:b0:6bc:7da1:cd9b with SMTP id s9-20020a056902120900b006bc7da1cd9bmr18950874ybu.0.1666391591620; Fri, 21 Oct 2022 15:33:11 -0700 (PDT) Date: Fri, 21 Oct 2022 15:32:57 -0700 In-Reply-To: <20221021223300.3675201-1-zokeefe@google.com> Mime-Version: 1.0 References: <20221021223300.3675201-1-zokeefe@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221021223300.3675201-2-zokeefe@google.com> Subject: [PATCH man-pages v3 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666391592; a=rsa-sha256; cv=none; b=WR/enqGI7dow8WUz5ZnwlK9yhCNiwZh+qToodK2LHKiDvX9+apygsQ41ds6il61dgSPzKN IRz+HhtHQdle8j4ATdPxkbbNToSDidsSyxMfQ4ArJaurmUhLsitPei8upFVQ59udwzdWQq tMQDizLZLDlfPcoYBqBlmrHg45PfJXg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=J8FQd3gs; spf=pass (imf30.hostedemail.com: domain of 3Jx5TYwcKCNALA600102AA270.yA8749GJ-886Hwy6.AD2@flex--zokeefe.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Jx5TYwcKCNALA600102AA270.yA8749GJ-886Hwy6.AD2@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666391592; 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=UQIfOxRnlwRRwhWBO+p+5sf8htyV9CkZvkGFbADgqo4=; b=iuZOEgOn7KemqBHf8AftyPxs5Jc+87frnoetyQNWBj34CJlswhox6fiZhFn0CP1mJ8qM9+ 3eqsbEEcljEWw1YbE0mZYk5CMVdUZLhS4a3LGhQ56fxgzfY0jHahR+br8TGIAowbkYqxu1 M0vLQQeQaL75BkcOxls1IH/tv3BmfE0= X-Stat-Signature: m4kicmi4pcn3io5sr9oeiyxwpjr5mfas X-Rspamd-Queue-Id: 6856280035 Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=J8FQd3gs; spf=pass (imf30.hostedemail.com: domain of 3Jx5TYwcKCNALA600102AA270.yA8749GJ-886Hwy6.AD2@flex--zokeefe.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3Jx5TYwcKCNALA600102AA270.yA8749GJ-886Hwy6.AD2@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1666391592-732639 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