From patchwork Tue Sep 25 21:50:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Rientjes X-Patchwork-Id: 10614849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC5D1161F for ; Tue, 25 Sep 2018 21:50:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B49A288D2 for ; Tue, 25 Sep 2018 21:50:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D0652AD35; Tue, 25 Sep 2018 21:50:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 097FB288D2 for ; Tue, 25 Sep 2018 21:50:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A3568E00C7; Tue, 25 Sep 2018 17:50:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0500D8E00A4; Tue, 25 Sep 2018 17:50:55 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4AAE8E00C7; Tue, 25 Sep 2018 17:50:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id A211E8E00A4 for ; Tue, 25 Sep 2018 17:50:55 -0400 (EDT) Received: by mail-pf1-f198.google.com with SMTP id v9-v6so13308527pff.4 for ; Tue, 25 Sep 2018 14:50:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :in-reply-to:message-id:references:user-agent:mime-version; bh=0Ce3odqB1qLWdsb9KwAtrrneVWS1aumo0hFHF3fNi7g=; b=dSKgr5dgy3uql0oOcn/TjDYzYtgBa610YbJYNeuG8TTfQSQCwTR/xladZa31lvZQwg QFGOriAgYf/b3He+fiuBH3OYttOzLtJNJxUJMRTBODr1V0BrfaQjB34bJBXyN+Js7paT ZtnD00359h6rI85vYXb0d1nob9y8nqKXuCxo4R0SiC0WXJPihNlimO//aa7wy0aljsoz LkUoLY9W2wTkFfpT10f1wNVDgVdcv+/jdDX7Sxt2iuGrSAJR9pjAoQQYbXQsKq9q3lR/ 5YSIzVs7B+8HkVLpG9r+ljC1tR753aINuti5x6zBZUeZ1nYf8nzFAzEq6d+8nsN09JZn CdwQ== X-Gm-Message-State: ABuFfohs0X2GnBVQRyoZBTTla/0UTq6kNYViRbMs9GhMTBjM7CnB8tJf YpZf8TTNvXQXakocT87Ohb/2Cz6pPM/DDSFUoYPVGH523X2KX2Yxcredy50XRViWfVUEfrjwOv1 u6LV8rg6l+IdAjLNOQVqzbpPA2ZzL5l4osO6qLWmMVK7g4jK0HJ82U0y6bcgsSiJfj5jSoe+y3e jgcLGkkVJ+kUmeVO8lRy4Ton5qA5kaEjzg7KhUWBiW3mOtLzmp02kJciDr/pWHUqBIR4GIqHd/Y +GL+lM9r2xAX3oeDMV6Dhm83d3hfHsUYJlvB4KvPmn54xm1l6dY8k33x3kN4XESnfFYP2JRZ8hX Bg8nXsSGKd5V/VM/DzlKh88KQ8S3WZ6XFW4oQToIbprSY5h2W0bNT9h+DyjbqdPwAx88NVuyscW S X-Received: by 2002:a62:bd4:: with SMTP id 81-v6mr3054682pfl.67.1537912255299; Tue, 25 Sep 2018 14:50:55 -0700 (PDT) X-Received: by 2002:a62:bd4:: with SMTP id 81-v6mr3054640pfl.67.1537912254361; Tue, 25 Sep 2018 14:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537912254; cv=none; d=google.com; s=arc-20160816; b=di3ctXM544OZqB/KIRv3DqqBy+jVUl7p55XcH/kOkZ4ZxR/gtU4O/gGj6UO0L1YE+u zKNB6VhEo0j5pyAszwX0CLQwbBwWCD2+PxBT6PtOhSHBoXO1nNqo+g3b4eeQ0zHebDVU aLP3R9IQode/dQ8N076QpSFHtGSbsvg0g4qWIXYPN6ueCyxHrT6qP0jO9167dNMR6ZsF JWoh78mTuDraSY2soXAWAg8iYAzj6107USQxLfykQKr9TjimBsLyacI13o8GV3N4DSnJ OqseM1jjI0t0DKAjQjG2d0fddLcN/RF6C1xEhHrKrNshRp1kNYIz5QfPe2l2greCDhS/ +3ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:dkim-signature; bh=0Ce3odqB1qLWdsb9KwAtrrneVWS1aumo0hFHF3fNi7g=; b=eZM3m3R0TGtzRg1MZo7+Bu1GVqqR+gf0myitdvkFBVzWkepBsO4F78MGU+pznfN3/v yjGFzIbJreLshu/5VZu2f1v/BFiB66Q1a/F7zR5XhfzKyGT14kzH8Wb0aA0NkWSam0EB HaBRr5mOvFka64YN7b0OY0DG23RewwDtOyCx5DL0I/b9zsgIOBRRKw8zqIiGYiO+93/f 1C+KjBtsKQnQ5Ikrjnq6LJD753nB8tLkGpkyFNAq1Mn9q3HKq5AaaNQzvX7/dmlLHLxq F/vLA/iEtFHepDxVEUvbcu7/zltETrLnz+uxNewye9MprtamOCFiXIxH3464rBx5kLmI ZRSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gSUR43+h; spf=pass (google.com: domain of rientjes@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=rientjes@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h3-v6sor706241plb.4.2018.09.25.14.50.54 for (Google Transport Security); Tue, 25 Sep 2018 14:50:54 -0700 (PDT) Received-SPF: pass (google.com: domain of rientjes@google.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gSUR43+h; spf=pass (google.com: domain of rientjes@google.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=rientjes@google.com; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=0Ce3odqB1qLWdsb9KwAtrrneVWS1aumo0hFHF3fNi7g=; b=gSUR43+h76jAdTnpQeXIJ2ffj5rNknYEG5mO5zgIaKOziDQVZdZWYnb7t5XN+s0mAZ 700yPJYax2GX5nQvqnfN2J0mEfQ9dPgV496JpmNSvu4n7CqiKSFeTxuWG1byOEeqCeO1 0hqx9Rxnw8FtdgMIX9Z58V6Eu9Kut/C3W0rWCvMXdfVqn9j0ttdueE7M0OhpbDrvieet BT2ch5WqEmAF7PYLH0jfNjpsisz3fjqSwgFCbASAcX2WlqktDPl4GnreT6SjmD0BdiRw dV/H3eDs4f4GWZZ/78pv0uQ70Qxoy53AgEeKPqx6MyANOEwEr3wvf/1nJ3m82IJcjI1T B6XA== X-Google-Smtp-Source: ACcGV63yYeJuidmH63czgnB0+bv01MSVrw030BquVl8L3phrN2qG9KZSQ2OuuJxigfIdtd7R6R2s9Q== X-Received: by 2002:a17:902:784a:: with SMTP id e10-v6mr2955073pln.197.1537912253865; Tue, 25 Sep 2018 14:50:53 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id v83-v6sm8986667pfa.103.2018.09.25.14.50.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Sep 2018 14:50:53 -0700 (PDT) Date: Tue, 25 Sep 2018 14:50:52 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Andrew Morton , Vlastimil Babka cc: Michal Hocko , Alexey Dobriyan , "Kirill A. Shutemov" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org Subject: [patch v3] mm, thp: always specify disabled vmas as nh in smaps In-Reply-To: Message-ID: References: <20180924195603.GJ18685@dhcp22.suse.cz> <20180924200258.GK18685@dhcp22.suse.cz> <0aa3eb55-82c0-eba3-b12c-2ba22e052a8e@suse.cz> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP Commit 1860033237d4 ("mm: make PR_SET_THP_DISABLE immediately active") introduced a regression in that userspace cannot always determine the set of vmas where thp is disabled. Userspace relies on the "nh" flag being emitted as part of /proc/pid/smaps to determine if a vma has been disabled from being backed by hugepages. Previous to this commit, prctl(PR_SET_THP_DISABLE, 1) would cause thp to be disabled and emit "nh" as a flag for the corresponding vmas as part of /proc/pid/smaps. After the commit, thp is disabled by means of an mm flag and "nh" is not emitted. This causes smaps parsing libraries to assume a vma is enabled for thp and ends up puzzling the user on why its memory is not backed by thp. This also clears the "hg" flag to make the behavior of MADV_HUGEPAGE and PR_SET_THP_DISABLE definitive. Fixes: 1860033237d4 ("mm: make PR_SET_THP_DISABLE immediately active") Signed-off-by: David Rientjes --- v3: - reword Documentation/filesystems/proc.txt for eligibility v2: - clear VM_HUGEPAGE per Vlastimil - update Documentation/filesystems/proc.txt to be explicit Documentation/filesystems/proc.txt | 7 ++++++- fs/proc/task_mmu.c | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt --- a/Documentation/filesystems/proc.txt +++ b/Documentation/filesystems/proc.txt @@ -491,9 +491,14 @@ manner. The codes are the following: sd - soft-dirty flag mm - mixed map area hg - huge page advise flag - nh - no-huge page advise flag + nh - no-huge page advise flag [*] mg - mergable advise flag + [*] A process mapping may be advised to not be backed by transparent hugepages + by either madvise(MADV_NOHUGEPAGE) or prctl(PR_SET_THP_DISABLE). See + Documentation/admin-guide/mm/transhuge.rst for system-wide and process + mapping policies. + Note that there is no guarantee that every flag and associated mnemonic will be present in all further kernel releases. Things get changed, the flags may be vanished or the reverse -- new added. diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -653,13 +653,25 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) #endif #endif /* CONFIG_ARCH_HAS_PKEYS */ }; + unsigned long flags = vma->vm_flags; size_t i; + /* + * Disabling thp is possible through both MADV_NOHUGEPAGE and + * PR_SET_THP_DISABLE. Both historically used VM_NOHUGEPAGE. Since + * the introduction of MMF_DISABLE_THP, however, userspace needs the + * ability to detect vmas where thp is not eligible in the same manner. + */ + if (vma->vm_mm && test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) { + flags &= ~VM_HUGEPAGE; + flags |= VM_NOHUGEPAGE; + } + seq_puts(m, "VmFlags: "); for (i = 0; i < BITS_PER_LONG; i++) { if (!mnemonics[i][0]) continue; - if (vma->vm_flags & (1UL << i)) { + if (flags & (1UL << i)) { seq_putc(m, mnemonics[i][0]); seq_putc(m, mnemonics[i][1]); seq_putc(m, ' ');