From patchwork Mon Oct 17 17:55:20 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: 13009196 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 65981C43217 for ; Mon, 17 Oct 2022 17:55:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C843A6B0075; Mon, 17 Oct 2022 13:55:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0DC76B0078; Mon, 17 Oct 2022 13:55:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A62C86B007B; Mon, 17 Oct 2022 13:55:29 -0400 (EDT) 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 941006B0075 for ; Mon, 17 Oct 2022 13:55:29 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 579321A0DC8 for ; Mon, 17 Oct 2022 17:55:29 +0000 (UTC) X-FDA: 80031193578.06.8A56F2C Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf20.hostedemail.com (Postfix) with ESMTP id E3B401C0046 for ; Mon, 17 Oct 2022 17:55:28 +0000 (UTC) Received: by mail-pg1-f201.google.com with SMTP id e13-20020a63500d000000b0045bf92a0b5aso6830119pgb.22 for ; Mon, 17 Oct 2022 10:55:28 -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=WkqFpi2/V6E2Fhjges484cEMfzRV/sSivyZ4C/2xiBE=; b=sNGR6fEHoPrRwFihWQepoGIt4d5v2xBIB3HzTEOfCVV9c1horVac1VGhc4QFP41N5j 8WiArXDEIX0yndL2S/m1pDuIUtdBu5vbn1jsANrYVL9su48gEsvhEHmoH13OIfC0pd6M 8Ci1IOHX4r5S0PiuMf+NFp/+lPQoxDsZJw+CkslrsEBCCEGeMyYgFPmYGbE3fj1c65ND OEvbPBk5Hi0jLVrvlnts/koVXMATGoB2TJiJsczi2riAWs20sKLu/Bh21SY03DR7rUb5 N+Cd1+9itPBmdZMhitWKaoEG31/ajHdzF2K22TrC1Engg4Wfgqskl2kIcfUO4+l1y1KN ZAqw== 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=WkqFpi2/V6E2Fhjges484cEMfzRV/sSivyZ4C/2xiBE=; b=pxUhIo3PAGjESwlbbq4cH8Pp5QlewxcHFxplvsEqkxsGWUJyXofc3yowtv+5GF1oXe L6Qd2Ph1Y9dCY6W7jasKOhYrZuHLKK1un6TZIguWNBSvE4RAo1+4KX5v08CyikNvMZgS /IwNhykx+afBIPre2QzqcVqEs9P0ynrQiueXwTp7E7cSmpO055h8Z5PhPZmdYMVy9Gcm ZSdK5XVHG2r7VEFbugr0UiyoCACSPiZD+orBnXEuRl3w3/pbMoPHlDf/x7o3pt8UE1Id sCC041WxtoevyRxkS8o9ZsTIhHjkBEf2elAtI3Ejdmuxx0FV2keeryGXTZXpxMsKVx9b wQpQ== X-Gm-Message-State: ACrzQf0UIdNSytRcMBAXnTwrYsXSk9ntsizlOc93aqJjXx1ikYxYH+t8 01K2eHNtdSIMHqkz6sbv6/m9C0/Xh9/V X-Google-Smtp-Source: AMsMyM762UuUMtU1JmhIMwGwjSPwYdacV76xKStC7j9lf6xUPj8PYXW/eZ4Bavo0plZCOCAt7AhCLJQoGn6n X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a05:6a00:10c8:b0:563:1bd1:2ce4 with SMTP id d8-20020a056a0010c800b005631bd12ce4mr13882117pfu.6.1666029328004; Mon, 17 Oct 2022 10:55:28 -0700 (PDT) Date: Mon, 17 Oct 2022 10:55:20 -0700 In-Reply-To: <20221017175523.2048887-1-zokeefe@google.com> Mime-Version: 1.0 References: <20221017175523.2048887-1-zokeefe@google.com> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog Message-ID: <20221017175523.2048887-2-zokeefe@google.com> Subject: [PATCH man-pages 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666029328; 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=WkqFpi2/V6E2Fhjges484cEMfzRV/sSivyZ4C/2xiBE=; b=nVHfX1tcTH9hWvNcnMO9/4Xfu2jFftKI3t4H98ddTHKC+cHH/tHW88eHlZ/VasEPTypBWf 42z6vmYmTAItwovQN8tuvVH4hHA0syJhw9dj8FrevkzTmJ+RXPyupdZ+WfL9b13kuuqoB4 5D0FaJC8O6rg7RIvX8ucvGl46Vz+ato= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sNGR6fEH; spf=pass (imf20.hostedemail.com: domain of 3EJdNYwcKCJUOD933435DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--zokeefe.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3EJdNYwcKCJUOD933435DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666029329; a=rsa-sha256; cv=none; b=BJTPFRonfWivmep+t0ubxOwVjrdBOZpX4FLubliM+2zTsc0EcurD3F3uncjgWlnaaNFzjZ 9Z5PdME+Rd/KDQucCMC/br6T94biXHG+EP7cHjZjDVjKOVLcjfgtwPQY/70BDSOSlrLb3t vgSAgvPOni+/zbNaB1xx5+v52UluvzI= Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sNGR6fEH; spf=pass (imf20.hostedemail.com: domain of 3EJdNYwcKCJUOD933435DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--zokeefe.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3EJdNYwcKCJUOD933435DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E3B401C0046 X-Stat-Signature: kue8sswnh7ru751pdr8r3bzfrhhbeery X-Rspam-User: X-HE-Tag: 1666029328-128084 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 | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/man2/madvise.2 b/man2/madvise.2 index 81cce56af..e14e0f7fb 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,45 @@ 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-backed pages (including tmpfs (see +.BR tmpfs (5)), +and file-backed pages. +For all memory types, +memory may only be replaced by huge pages on hugepage-aligned boundaries. +For file-mapped memory (including tmpfs) the mapping must also be naturally +hugepage-aligned within the file. +Additionally, +for file-backed (not 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