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 From patchwork Mon Oct 17 17:55:21 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: 13009197 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 B797DC43219 for ; Mon, 17 Oct 2022 17:55:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57FA26B0078; Mon, 17 Oct 2022 13:55:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5090E6B007B; Mon, 17 Oct 2022 13:55:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3AADA6B007D; Mon, 17 Oct 2022 13:55:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2B9906B0078 for ; Mon, 17 Oct 2022 13:55:31 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 05B741C670C for ; Mon, 17 Oct 2022 17:55:31 +0000 (UTC) X-FDA: 80031193662.19.88EAF7F Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf01.hostedemail.com (Postfix) with ESMTP id A193840042 for ; Mon, 17 Oct 2022 17:55:30 +0000 (UTC) Received: by mail-pl1-f202.google.com with SMTP id o17-20020a170902d4d100b0018552c4f4bcso1961244plg.13 for ; Mon, 17 Oct 2022 10:55:30 -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=agT9QZQMe+zYcofiwo2fky7Lo5K5JsV+HiadouuU+xY=; b=S7DlGIdUa4amE9BoDHGwjgJKqiO83psDwvsaprmeCr6GoWIkFEdQbvV1sXIPEdMv9g 0S+OXhabA0N1xRVPgyuPg8TszXx/+yHwEO/CwpGp6XtpFK4Aa0li2Rgx7e8Wep8ZS4Yg D2hoxAMrGZxuAweBsXnXIRb2O4uBtN4Hu9jS5ucQx6yD3+/rFU9BvVSoZ40szyivSNPQ mPYW2ZFLSvD8UW88Br1sKdAu1R5d5pxrbcFyU/efuZkbveR396g+Zsvi7twrPveruTq1 bibaRLQLbg+zlWTHOfH5AEGo01xabCQUJWuWanJovvYb+5EK1z3YP+FGpyatA6wVwCX2 T1wQ== 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=agT9QZQMe+zYcofiwo2fky7Lo5K5JsV+HiadouuU+xY=; b=qFu1nT5nJnyYWj09TUcngZLugGIJfWPdzx3L/k2XCOYuoSjuwuxU8lYdmthT2JqMuw 1YPhWZNeH6P2Lb87iEQnXiI9Dm2J4oRv7uWmoBxTjNWbknr7vFGwwDuzuaj4BVPdFxRp aDkPpA4pe9Sc1VD4cyWAyeNpb5b5NXRbUHTNqbcRVNMdduGj5uQKaRv9ireI523Z/zbF /6I6NYebB1egaJSHwNWG+soDfNR+0t6HS3FcRP8grId6lHx/6hfSPEyvS00j532/a1JI GqrcbVR/bMPgL1wg/8QW0nqs38YEhsEGR4u0q0oubVfrpwLH/RX0KA61VvWL8wo6PI2W AtOQ== X-Gm-Message-State: ACrzQf29PpRHUHPQQvfzgKVvE4+/RR9RTqxcVIoCCubxYm0koDnHYAnt zgHpNBLkuq5Y7LBwK2oeqwYt8Q/9xvHY X-Google-Smtp-Source: AMsMyM5HuNyELUBHl+u6TZZkzRJi+vyJvjs8M4Fo5QyR44pbs2aljP0dCpBB03K1dW9Fpcw4ETF6ejUH7NJA X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:ef92:b0:17e:2618:ee91 with SMTP id iz18-20020a170902ef9200b0017e2618ee91mr13497088plb.122.1666029329663; Mon, 17 Oct 2022 10:55:29 -0700 (PDT) Date: Mon, 17 Oct 2022 10:55:21 -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-3-zokeefe@google.com> Subject: [PATCH man-pages 2/4] madvise.2: document reliable probe for advice support 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=1666029330; 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=agT9QZQMe+zYcofiwo2fky7Lo5K5JsV+HiadouuU+xY=; b=mysZvbMlzJGcabQH0RyKbbdZ/CzDMgKkgeMc8+tqLULLrjRLjdRhtVkfuFRjgtssHr6pmb UBVxOg9K7ndhy4k9MuWze4SOPiy1/fIfk4aeFdxKovmnLjY3GFKipOiNxgmAvFbfY1ZMiW Rn9ZtU/GmPUyBOGLCng8uzZF36NpJ+0= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=S7DlGIdU; spf=pass (imf01.hostedemail.com: domain of 3EZdNYwcKCJYPEA44546EE6B4.2ECB8DKN-CCAL02A.EH6@flex--zokeefe.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3EZdNYwcKCJYPEA44546EE6B4.2ECB8DKN-CCAL02A.EH6@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666029330; a=rsa-sha256; cv=none; b=FvkOe8I5i2XnBIl8ls1sgfyXapi0w8npwwqNXFlt2Gz58YVrTn0P5T/yZw9SGjM5eM5RgW 3Zx3E8sGTn+AuMUt15MK805k6L/1Ae7jRzsnTO43J7OwLKdd3j6joPhF5oXY3rDD8nejaJ PRzr4Zmx5OZrw6cxghbwhi3HuqsTZDM= X-Rspamd-Server: rspam12 X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=S7DlGIdU; spf=pass (imf01.hostedemail.com: domain of 3EZdNYwcKCJYPEA44546EE6B4.2ECB8DKN-CCAL02A.EH6@flex--zokeefe.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3EZdNYwcKCJYPEA44546EE6B4.2ECB8DKN-CCAL02A.EH6@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: 7c9anbdoitaoqgzfm1fgs6z8on37skzj X-Rspamd-Queue-Id: A193840042 X-HE-Tag: 1666029330-661823 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 EINVAL is an overloaded error code for madvise(2) and it's not clear under what context it means "advice is not valid" vs another error. Explicitly document that madvise(0, 0, advice) can reliably be used to probe for kernel support for "advice", returning zero iff "advice" is supported by the kernel. Signed-off-by: Zach O'Keefe --- man2/madvise.2 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/man2/madvise.2 b/man2/madvise.2 index e14e0f7fb..adfe24c24 100644 --- a/man2/madvise.2 +++ b/man2/madvise.2 @@ -789,6 +789,13 @@ that are not mapped, the Linux version of ignores them and applies the call to the rest (but returns .B ENOMEM from the system call, as it should). +.PP +.BR madvise (0, +0, +.IR advice ) +will return zero iff +.I advice +is supported by the kernel and can be relied on to probe for support. .\" .SH HISTORY .\" The .\" .BR madvise () From patchwork Mon Oct 17 17:55:22 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: 13009198 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 2B462C433FE for ; Mon, 17 Oct 2022 17:55:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C36E46B007B; Mon, 17 Oct 2022 13:55:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC05B6B007D; Mon, 17 Oct 2022 13:55:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 977E16B007E; Mon, 17 Oct 2022 13:55:32 -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 81CDD6B007B for ; Mon, 17 Oct 2022 13:55:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4D597AB38E for ; Mon, 17 Oct 2022 17:55:32 +0000 (UTC) X-FDA: 80031193704.07.C4B2FE7 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by imf06.hostedemail.com (Postfix) with ESMTP id E6611180033 for ; Mon, 17 Oct 2022 17:55:31 +0000 (UTC) Received: by mail-pf1-f201.google.com with SMTP id q18-20020aa79832000000b00562d921e30aso6453089pfl.4 for ; Mon, 17 Oct 2022 10:55:31 -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=k4YZ/MZAkRksM7yVQmihehh8ldAEChAETLP25ZBcDQ0=; b=O6/4jT33BaC+RJJLf7veET9jVN1YLLZYIeYsGr0T4FVM9rhiunBt0L4bHC3T6gxRAj iKi31nT/vPp3ptPZIwJ+iIRxMy8LyFAq9TzDmUfgRcs0bF5QUhERUjoocgGQ3PosM1L+ KlOhpZ/cDvr9Vc1iXQ9d8yk2/7B6bcXGQSSdn6Q/hcZePHkf5d6pdjWiQQXZ2XuzC1l0 PuO0IZuMiz2rzPU2zi6hAUViiIQ9Z1LoeF67Sua9BwCrKEc88iunEbRReHb30pVDqVpU hFJC9CvCvf7oytGr6VLz7BN+AmjkuZ+d4Wm0/IwEeHZYqq/yfDa8WAru58mWK1KiV+l3 7/mw== 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=k4YZ/MZAkRksM7yVQmihehh8ldAEChAETLP25ZBcDQ0=; b=Fo9i/M9mu9BNczILEO9bxq7GikBgz9SET8zwnFr3Uri3bcTLS/UoHFgilJzNjAqbmf RgPk7GlHnyy+jQmwJG3GR1HlAmKzc1gKb2kc4llOaOfb1DK2Y5tu/TjSyyiPVwjlcQl8 ms+2LUuduEPMcDyW4xpWMNVfZ7F23koWWHBg00L397IjfqlAk0xDb6+QIBZgfd1XB8VM o/Fb/esXxU5YYj2myLEaklMK3VKfY9MQzpWP8CXgHUJXO6Q0ZFfggviffpLfXBjczjqe 6moE+fumErEmKOzlQATdGRgNosJ56HgUA0OiKn9miLLo4UyTYCQT2xESatC71KGaf2Yl UndA== X-Gm-Message-State: ACrzQf0E6qLAI5WyZ5E04i4RD8O2IbqDaSfO4h7pMZZZgTzRjN1JVlNJ p2AJOVyaj/o+J/ymK8Le5Z6FzxDEE6Xg X-Google-Smtp-Source: AMsMyM4tPJA6Kt7/TvYOFt22YMGQ2eAWnUmfDcpnttaHh5FbPG7jHOHUD8ASdCZt7fk3JvlEgXHbdPCAeqfI X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:90b:3d85:b0:20c:8f6a:8298 with SMTP id pq5-20020a17090b3d8500b0020c8f6a8298mr35396412pjb.242.1666029331036; Mon, 17 Oct 2022 10:55:31 -0700 (PDT) Date: Mon, 17 Oct 2022 10:55:22 -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-4-zokeefe@google.com> Subject: [PATCH man-pages 3/4] process_madvise.2: CAP_SYS_ADMIN cleanup 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=1666029332; 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=k4YZ/MZAkRksM7yVQmihehh8ldAEChAETLP25ZBcDQ0=; b=QdQxQvZdLoXsdtZzyNAXNfRBAfP3IHV4lEhRFTlcJkBZB6ktAgxz8Ffptq76fj6WmmzmGc AlYlrKT+EJ22DLKc6oM2SsvwusL+0wcu0txW6WQJyp4aaeWY1NermE6wlJ3O1G6oVe3ARz Vc0FG9N8OYzCghJY8zZtY1IAwFLNdcw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="O6/4jT33"; spf=pass (imf06.hostedemail.com: domain of 3E5dNYwcKCJgRGC66768GG8D6.4GEDAFMP-EECN24C.GJ8@flex--zokeefe.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3E5dNYwcKCJgRGC66768GG8D6.4GEDAFMP-EECN24C.GJ8@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666029332; a=rsa-sha256; cv=none; b=g6wA38qD7bwHtZb37UOWB/B9SLYwVuz8Wky9xzk4BNKlv1PXauXOcekaG98S0DPok/n2K9 5Q/kjKgGQn8ZxxYShBUe5E+4qHOfuIV/GsNkh7eEJxINd3dynOKIBYegaPFPVvKKbtTEus Jy+5jdQ2iGiQOIvYoeR+zeFOkWE3yF4= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E6611180033 X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="O6/4jT33"; spf=pass (imf06.hostedemail.com: domain of 3E5dNYwcKCJgRGC66768GG8D6.4GEDAFMP-EECN24C.GJ8@flex--zokeefe.bounces.google.com designates 209.85.210.201 as permitted sender) smtp.mailfrom=3E5dNYwcKCJgRGC66768GG8D6.4GEDAFMP-EECN24C.GJ8@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: her99wkmm8k8x7h9ty6omqp4xh4whrph X-HE-Tag: 1666029331-886118 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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 commit 96cfe2c0fd23 ("mm/madvise: replace ptrace attach requirement for process_madvise"), process_madvise(2) has only required CAP_SYS_NICE capability. Update the man page to reflect this. Signed-off-by: Zach O'Keefe --- man2/process_madvise.2 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/man2/process_madvise.2 b/man2/process_madvise.2 index 6208206e4..7bee1a098 100644 --- a/man2/process_madvise.2 +++ b/man2/process_madvise.2 @@ -113,7 +113,8 @@ check (see in addition, because of the performance implications of applying the advice, the caller must have the -.B CAP_SYS_ADMIN +.\" commit 96cfe2c0fd23ea7c2368d14f769d287e7ae1082e +.B CAP_SYS_NICE capability. .SH RETURN VALUE On success, From patchwork Mon Oct 17 17:55:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zach O'Keefe X-Patchwork-Id: 13009199 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 F39FEC43219 for ; Mon, 17 Oct 2022 17:55:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 902026B007D; Mon, 17 Oct 2022 13:55:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88C146B007E; Mon, 17 Oct 2022 13:55:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 669986B0080; Mon, 17 Oct 2022 13:55:34 -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 507696B007D for ; Mon, 17 Oct 2022 13:55:34 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E1FCCA0941 for ; Mon, 17 Oct 2022 17:55:33 +0000 (UTC) X-FDA: 80031193746.27.2C0385B Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf07.hostedemail.com (Postfix) with ESMTP id 77CB34002D for ; Mon, 17 Oct 2022 17:55:33 +0000 (UTC) Received: by mail-pj1-f73.google.com with SMTP id mp3-20020a17090b190300b0020af8232049so4773688pjb.9 for ; Mon, 17 Oct 2022 10:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=9okyg4TxaGr0Wo6DVcaSxPtBJAbQVCSpwbsXFn49vpU=; b=B/VP0B1nCEzdRoZcax9PTsCLDH3r24qt1iRdmWvlrjLxQiOXj1wr/rxqCDqOfAg0LP RWgqWFyjeWxAU4jyMvEfxNxWKpD2/OwsMoCi4bYF6NJ1wV8xOkzUaxpZRXJniqwzEYy7 q34Q3d8W6kCaGDW0tMvh2CG6UISW2Rv9X8zeq0raUo09xB40yc2BWT7jqngEG372WL/X FuI+uOEYAClitf4iL9KGoEpqbU17OQq2A1bNvABB6zE+/j54qNtaUZZgp0IvUshSdvZA IEDpXOJfebXqIrY1aB+WYo8mlr3yvG88m8JMNPs+e6H6kkQODDq7UdLDvIM51qQLgRvd V53g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=9okyg4TxaGr0Wo6DVcaSxPtBJAbQVCSpwbsXFn49vpU=; b=faWZfkxjRn6EMjuIxXjvDeQeB2yOMGfg3BRcSST0WqeCpKGXAPFtr5LQPxiU3judzJ cOKg5/9lObaVLagw0wTrdcfHiOA5hQM7isXsLVVvRj3LBiK2iNEJfae0RAM2iNG/qkem jqiBe4AAo90pX89IN0hllEe/ZB/FAUpbFQUKlGTGNeFEKQbOMHblGYo7rVK/pGdSOUxx lq/jrvnpHL06UsOD5Hwbico9FXIvrirDdOzRXHXDA1+VT86Z9JH9RpE52xpreRT4CdGc qQ+4DZL/ICj8fcPU1R40H8hhpUReYm8ChOvzFvbn4aWItRfDtIzIsqilIeVtoIjV92Kd bTBg== X-Gm-Message-State: ACrzQf2T7OBjEpIlzPpKcrn3GG16jO4Nvo6gPU7uKBaCb+5CncruaPD9 8XDVQsDa17yEEgnK6HDrKMEkf49I/Q1V X-Google-Smtp-Source: AMsMyM5NJSC69gJSADJnOqqIrSWtoQccfj+i9MuTgOiBs2sxbicoi9Z8TRpTa2gEOrozU3pDLyI30ziWkuQg X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:90b:1c06:b0:20a:f070:9f3c with SMTP id oc6-20020a17090b1c0600b0020af0709f3cmr15227035pjb.151.1666029332618; Mon, 17 Oct 2022 10:55:32 -0700 (PDT) Date: Mon, 17 Oct 2022 10:55:23 -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-5-zokeefe@google.com> Subject: [PATCH man-pages 4/4] madvise.2: add documentation for MADV_COLLAPSE From: Zach OKeefe To: Alejandro Colomar , Michael Kerrisk Cc: Yang Shi , linux-mm@kvack.org, linux-man@vger.kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666029333; a=rsa-sha256; cv=none; b=rKpwyIK+8o4SPWwkzkguNZIIsEl3qHp9Z9KpE5FHygAx64YGsxbBlW9DNjyQxLNfGMV1kB EqRr64sCjtCMO9d1PB2DsLTQ+h0tp8EEtJohvQ4eXgfCILpWq4HkvAJGOIKH0ESeRXDGq7 LJVBLPfX0+Q9l9YOIEGf0LResYMFZyM= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="B/VP0B1n"; spf=pass (imf07.hostedemail.com: domain of 3FJdNYwcKCJkSHD77879HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--zokeefe.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3FJdNYwcKCJkSHD77879HH9E7.5HFEBGNQ-FFDO35D.HK9@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=1666029333; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9okyg4TxaGr0Wo6DVcaSxPtBJAbQVCSpwbsXFn49vpU=; b=PEE/TbHAjAlA3cCpbMWx1LRgkKqkkuihMjvEpymCZ+om4zgHChlmdpqXDpVtYqKAHty8wg QAbhBIeI0UoZUF8egfKecYGJMh80/C2HeAklzmFU+vk5GxtxX14ORylDjtgbPu0oekPWta TIAxTpLT9gH/f88QRluPyulegskhvms= X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="B/VP0B1n"; spf=pass (imf07.hostedemail.com: domain of 3FJdNYwcKCJkSHD77879HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--zokeefe.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3FJdNYwcKCJkSHD77879HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--zokeefe.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: xjbt1ibtjgm3818ougszkw3f1cjx5uym X-Rspamd-Queue-Id: 77CB34002D X-Rspamd-Server: rspam10 X-HE-Tag: 1666029333-283322 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 Linux 6.1 introduced MADV_COLLAPSE in upstream commit 7d8faaf15545 ("mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse") and upstream commit 34488399fa08 ("mm/madvise: add file and shmem support to MADV_COLLAPSE"). Update the man-pages for madvise(2) and process_madvise(2). Link: https://lore.kernel.org/linux-mm/20220922224046.1143204-1-zokeefe@google.com/ Link: https://lore.kernel.org/linux-mm/20220706235936.2197195-1-zokeefe@google.com/ Signed-off-by: Zach O'Keefe --- man2/madvise.2 | 91 +++++++++++++++++++++++++++++++++++++++++- man2/process_madvise.2 | 10 +++++ 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/man2/madvise.2 b/man2/madvise.2 index adfe24c24..7da44fac4 100644 --- a/man2/madvise.2 +++ b/man2/madvise.2 @@ -384,9 +384,10 @@ set (see .BR prctl (2) ). .IP The -.B MADV_HUGEPAGE -and +.BR MADV_HUGEPAGE , .B MADV_NOHUGEPAGE +and +.B MADV_COLLAPSE operations are available only if the kernel was configured with .B CONFIG_TRANSPARENT_HUGEPAGE and file/shmem memory is only supported if the kernel was configured with @@ -399,6 +400,82 @@ and .I length will not be backed by transparent hugepages. .TP +.BR MADV_COLLAPSE " (since Linux 6.1)" +.\" commit 7d8faaf155454f8798ec56404faca29a82689c77 +.\" commit 34488399fa08faaf664743fa54b271eb6f9e1321 +Perform a best-effort synchronous collapse of the native pages mapped by the +memory range into Transparent Huge Pages (THPs). +.B MADV_COLLAPSE +operates on the current state of memory of the calling process and makes no +persistent changes or guarantees on how pages will be mapped, +constructed, +or faulted in the future. +.IP +.B MADV_COLLAPSE +supports private anonymous pages (see +.BR mmap (2)), +shmem-backed pages +(including tmpfs (see +.BR tmpfs (5)), +and file-backed pages. See +.B MADV_HUGEPAGE +for general information on memory requirements for THP. +If the range provided spans multiple VMAs, +the semantics of the collapse over each VMA is independent from the others. +If collapse of a given huge page-aligned/sized region fails, +the operation may continue to attempt collapsing the remainder of the +specified memory. +.B MADV_COLLAPSE +will automatically clamp the provided range to be hugepage-aligned. +.IP +All non-resident pages covered by the range will first be +swapped/faulted-in, +before being copied onto a freshly allocated hugepage. +If the native pages compose the same PTE-mapped hugepage, +and are suitably aligned, +allocation of a new hugepage may be elided and collapse may happen +in-place. +Unmapped pages will have their data directly initialized to 0 in the new +hugepage. +However, +for every eligible hugepage-aligned/sized region to be collapsed, +at least one page must currently be backed by physical memory. +.IP +.BR MADV_COLLAPSE +is independent of any sysfs +(see +.BR sysfs (5) ) +setting under +.IR /sys/kernel/mm/transparent_hugepage , +both in terms of determining THP eligibility, +and allocation semantics. +See Linux kernel source file +.I Documentation/admin\-guide/mm/transhuge.rst +for more information. +.BR MADV_COLLAPSE +also ignores +.B huge= +tmpfs mount when operating on tmpfs files. +Allocation for the new hugepage may enter direct reclaim and/or compaction, +regardless of VMA flags +(though +.BR VM_NOHUGEPAGE +is still respected). +.IP +When the system has multiple NUMA nodes, +the hugepage will be allocated from the node providing the most native +pages. +.IP +If all hugepage-sized/aligned regions covered by the provided range were +either successfully collapsed, +or were already PMD-mapped THPs, +this operation will be deemed successful. +Note that this doesn’t guarantee anything about other possible mappings of +the memory. +Also note that many failures might have occurred since the operation may +continue to collapse in the event collapse of a single hugepage-sized/aligned +region fails. +.TP .BR MADV_DONTDUMP " (since Linux 3.4)" .\" commit 909af768e88867016f427264ae39d27a57b6a8ed .\" commit accb61fe7bb0f5c2a4102239e4981650f9048519 @@ -618,6 +695,11 @@ A kernel resource was temporarily unavailable. .B EBADF The map exists, but the area maps something that isn't a file. .TP +.B EBUSY +(for +.BR MADV_COLLAPSE ) +Could not charge hugepage to cgroup: cgroup limit exceeded. +.TP .B EFAULT .I advice is @@ -715,6 +797,11 @@ maximum resident set size. Not enough memory: paging in failed. .TP .B ENOMEM +(for +.BR MADV_COLLAPSE ) +Not enough memory: could not allocate hugepage. +.TP +.B ENOMEM Addresses in the specified range are not currently mapped, or are outside the address space of the process. .TP diff --git a/man2/process_madvise.2 b/man2/process_madvise.2 index 7bee1a098..900210106 100644 --- a/man2/process_madvise.2 +++ b/man2/process_madvise.2 @@ -73,6 +73,10 @@ argument is one of the following values: See .BR madvise (2). .TP +.B MADV_COLLAPSE +See +.BR madvise (2). +.TP .B MADV_PAGEOUT See .BR madvise (2). @@ -170,6 +174,12 @@ The caller does not have permission to access the address space of the process .TP .B ESRCH The target process does not exist (i.e., it has terminated and been waited on). +.PP +See +.BR madvise (2) +for +.IR advice -specific +errors. .SH VERSIONS This system call first appeared in Linux 5.10. .\" commit ecb8ac8b1f146915aa6b96449b66dd48984caacc