From patchwork Fri Oct 21 22:33:00 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: 13015561 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 C040BC38A2D for ; Fri, 21 Oct 2022 22:33:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 619E88E0008; Fri, 21 Oct 2022 18:33:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 52BEE8E0001; Fri, 21 Oct 2022 18:33:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 332428E0008; Fri, 21 Oct 2022 18:33:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 200F88E0001 for ; Fri, 21 Oct 2022 18:33:18 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E42AAC0A91 for ; Fri, 21 Oct 2022 22:33:17 +0000 (UTC) X-FDA: 80046408834.12.DFD035C Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) by imf24.hostedemail.com (Postfix) with ESMTP id 7F4DE180019 for ; Fri, 21 Oct 2022 22:33:17 +0000 (UTC) Received: by mail-pl1-f202.google.com with SMTP id l16-20020a170902f69000b001865f863784so2381163plg.2 for ; Fri, 21 Oct 2022 15:33:17 -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=Fhq9+ubrffUDOgK8gNyGgNPDHRU1+55DMZbYHuijl2E=; b=Y177hO7earZyQ0NgvX45x7cQ+QQcbkSCyGj10syjwEY+O+MT0crQAgP7c53piVwCRR E8jqObD43Mw/CAVnzfeH/GKucD9VnR+8zjWBqsJQy++OPzQeluqj7uJzJW2wIgXRZuZW B90bxgjZzBp0Ejc6Dk1FwOwuZ791xd8fBCSz5ZW5mYRDkzPjmV8WYLNDpyBN4dzzHtdR WdcpYlF2n4uGjVgp4DC75k42aqHMZ8gJE3Mvl9TC5mlAJCnVDYy9uWQ+FPL3ezl6gR1U 6euz62GLoGPc3CVoJ4AR6MOWamjFuCeIQsVifzdQkdls34lXwUSWmvtAaxcmCT3cNWnN KtFA== 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=Fhq9+ubrffUDOgK8gNyGgNPDHRU1+55DMZbYHuijl2E=; b=JKOI2enSApCY7mDzabFzX1D3MU3xjRtGnPQPsXdIWozQQGFWpf9dR8NtJFlMJpoxJU bM84/l2HRQ4v+PlBnxJISVvGKc1dceGKT78BZ0x1YIJ4xkVE92sD9yLPKAmXiAK9urES vAIn+x2mPn1hqUF1tdRh6Aa9winXf4qdeZKTAJTWj1KSw1z0HsKV2irqf6NrEWIZT2Uc /hvwrZrNZS4P8XnUJJBa57X2RUnv4owQMKXWrKYIG9nJoD0YCh2oSLxy5+z7B9VOZDWm /ApUy/slQFmb/d5CfeBM0P+OrT4nrrcUv6F16WSJtmpk360Xw0kvruZFGLnqfCx2EUjR yVZg== X-Gm-Message-State: ACrzQf2zujuK34sQdve1RhmRbsyvdMtU/WLBs1h/jKVCD6eKf//F9o4V 3aOaKOtiCTArwNTJWZQdTSafgy5UnySh X-Google-Smtp-Source: AMsMyM5tDeCjjt4bJTgjV2UIJ2FL/zqgZQGgoBq56Gw08dtgmaViPv5SnsyL/cVsZ8cXHGFFFaWGnL3Im69q X-Received: from zokeefe3.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1b6]) (user=zokeefe job=sendgmr) by 2002:a17:902:e742:b0:17f:6a44:ee4a with SMTP id p2-20020a170902e74200b0017f6a44ee4amr21719351plf.103.1666391596561; Fri, 21 Oct 2022 15:33:16 -0700 (PDT) Date: Fri, 21 Oct 2022 15:33:00 -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-5-zokeefe@google.com> Subject: [PATCH man-pages v3 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, "Zach O'Keefe" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666391597; a=rsa-sha256; cv=none; b=ZK9VM1AsgzZoBynb0oFj+yHbegz2a8/srS0h8vH94sVNzklanTBOyh54YrKfXrOVO1i0De rcaG2QrVhRiV7sIjTsgYEpztF/TeSk7VYgALajYjWIMvhIBfpHuVeaf4GazL+W4sU9qbMW xx3I1Dje2p3UPzX+uWLDffPEv/3MisE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Y177hO7e; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3LB5TYwcKCNUQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3LB5TYwcKCNUQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666391597; 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=Fhq9+ubrffUDOgK8gNyGgNPDHRU1+55DMZbYHuijl2E=; b=d3Ay7DvbizfI1PjRWBLPgzpnBrQfPLUl7zcjHRFiNT/AQYXgrFTCOHZiooxbUjUSuAG6bp UuN/3v5PB8w2BO4DWOOSmnVUlGaBWghH/57EiTKmd2Yu6k6xQvGYyXuE7LSEwycNRzd1jN TSPOnZyMPoGlc8I3iF/Ns/2Ar1tDb9o= Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Y177hO7e; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3LB5TYwcKCNUQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com designates 209.85.214.202 as permitted sender) smtp.mailfrom=3LB5TYwcKCNUQFB55657FF7C5.3FDC9ELO-DDBM13B.FI7@flex--zokeefe.bounces.google.com X-Rspamd-Server: rspam04 X-Rspam-User: X-Stat-Signature: gux475ifc9zp7dut37d83rizxxqj6j4t X-Rspamd-Queue-Id: 7F4DE180019 X-HE-Tag: 1666391597-394568 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 | 90 +++++++++++++++++++++++++++++++++++++++++- man2/process_madvise.2 | 10 +++++ 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/man2/madvise.2 b/man2/madvise.2 index df3413cc8..b03fc731d 100644 --- a/man2/madvise.2 +++ b/man2/madvise.2 @@ -385,9 +385,10 @@ set (see .BR prctl (2) ). .IP The -.B MADV_HUGEPAGE +.BR MADV_HUGEPAGE , +.BR MADV_NOHUGEPAGE , and -.B MADV_NOHUGEPAGE +.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 @@ -400,6 +401,81 @@ 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 pages, +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 @@ -619,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 @@ -716,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 44d3b94e8..8b0ddccdd 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). @@ -173,6 +177,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