From patchwork Mon Sep 24 19:30:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Rientjes X-Patchwork-Id: 10612821 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 8998E14BD for ; Mon, 24 Sep 2018 19:30:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D0B62A54E for ; Mon, 24 Sep 2018 19:30:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 702E42A563; Mon, 24 Sep 2018 19:30:15 +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 DEBD72A54E for ; Mon, 24 Sep 2018 19:30:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D314F8E0043; Mon, 24 Sep 2018 15:30:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CE1388E0041; Mon, 24 Sep 2018 15:30:13 -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 BD2128E0043; Mon, 24 Sep 2018 15:30:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 76C638E0041 for ; Mon, 24 Sep 2018 15:30:13 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id r20-v6so8155999pgv.20 for ; Mon, 24 Sep 2018 12:30:13 -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=y3/6bU7rADT46TOcEOr8FsIuUf9WoWa/vu2klU9m74I=; b=rELLUXNq5UmwoQGzDUSBjwjRqqaGDVkEPdmNB8y3ocOCVv0S55Acl75M1gBX1esRrN HT6B1pThvHqVIWdmmcAm6+VnrB37LrD6Rhn+u1o+1/uOyjWRdGRD+0EBqWKj902apsQa UTpfvA/6kszEW6Uyelh/COLPDMCSlQSHapFHo5jFVoG4sNogyXJRllfV7MUGlELBIbQ+ Qcat5D2Og+9Gh7LpRVjBTx7gLN0aRNOGgk5vXaMJf7FSbOQ/LH2J3c8iKeTI7kORmb+d nPsVjP2roVAkbvbGKmQyKmDtZiKOK1bdPSW/6C6PYxgIvZZjGa6vzkY9NvfbcfwN4gY0 2IsA== X-Gm-Message-State: ABuFfojLh1Sd3zwMPWRiQrmPx7CTQi603Itfi18zS73rsKGsDsDLlawO Sgcg5xM6V1ojg4tO3CA3haYi7afTkH8aO2Jb41TZfE+uAExqr+4ZkPj7yovVCHCpJfm5v8++0dr sEEttmnW1l0XnTFrfTTorqXdkgIZHgUZONsXy92f6KUPQGAbjUtTUPZiZDsD/z2U/4ObusSgTc8 SzVFTaLXpXSkuzE9ENd5ZIDYMXfo20KLaDQdeF9iweWJL8Ye8N7E+G5USqcDM6DAwOsAz0DeL2g 87i8SIifMX+hb0qAv5G+SlSeUgMckjo5XwqFvyXcT8gyffS4RVWgHRJNphhy6iicU4ahDA6MwBV 2bw+Y5CcVx4uiwOHfkiJZgP2hyQqci1a2uiySfjZJ9TPusDy1kv642ZgP0GiR2YdBZF5vjo1HFK 5 X-Received: by 2002:a17:902:9b98:: with SMTP id y24-v6mr209962plp.239.1537817413147; Mon, 24 Sep 2018 12:30:13 -0700 (PDT) X-Received: by 2002:a17:902:9b98:: with SMTP id y24-v6mr209908plp.239.1537817412021; Mon, 24 Sep 2018 12:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537817411; cv=none; d=google.com; s=arc-20160816; b=k/2GIgatmSJ13nQuDsmJENh4F4jevujwNmgb1+qOVlbJLnNPDhi0J1lqI4EHy4exBm lWPsaN91PVA/vl0PL8HAcYCCjQWD3nOOvsEi0XfhquaE153r3wBnt0HYMlMmdbfbBchB EykbfQzkzkUSxClfKIgeUhZVwA2MP1RZJBSyAitItCEBj6pUghe55X7/lgReIx1UsH+7 JC6lAYwtHnFJY+YkPMTI/zD6B7vm5+Wa30tueIZBTr97/+0HDndJ36VFNw4TtgCamVjt jNwuXD8Zc6hctNa4uCD2bn649NJDxp77q3HRyK3wmgit2jDdVsmLEqdsSoWWbGHGhgqS k8yQ== 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=y3/6bU7rADT46TOcEOr8FsIuUf9WoWa/vu2klU9m74I=; b=E9HS56rsalUo7luKNVYNDFotp+OQxgGzNRrqzG/kybuHzb9WzLi3rtQwH3Kqkbq0Wf ZgbWgSfwRq5gTvf0n5CgD3iUaV80SveHWIHWeqKXH0trf11aepnnefOHCUj2JFI8axoA LL2Q4uagHBKa/F1tztviudUWOJwlbKpUUXNmFGlO+sCZNRk5SHkVbJX2hEWrLZhOjugR e3R9MFeewtRzyHvJMZ/BZUj8XBJTA/mh92HvhHEmn0iLE5BdmCnWEK8QTOvFOslj7H9E qlwTO3k82Qw6k2AV3f+jXwLSXiWT4BkpqaFbA1/XQNq7HC+ku2Nll2QB4FTjitpmhZT1 hf6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cQer5cp8; 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 1-v6sor36548plj.42.2018.09.24.12.30.11 for (Google Transport Security); Mon, 24 Sep 2018 12:30:11 -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=cQer5cp8; 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=y3/6bU7rADT46TOcEOr8FsIuUf9WoWa/vu2klU9m74I=; b=cQer5cp88AmIRKyJ0UbSg3YLRV0/+mfA/oNmukzdcJSng9fsvVqph1vwD5wfqlDX2S DK93+7zdTTdDgwj9ygjnnAviWMUkR/Mw6BbxSrSATc53L3YqhcCxJKoSQL28HJA3HM/9 rreDtVPpdlgDc2sNiyPTLeWFLEtJYrFOKFTJGH2P1Fx4Wn7uuKO89AibeYe827urjySq JN/+0OcZY4TBMfaxqUJ+6fVpaJjph/v7O17q0q5Do9T6ycAIJ+6XXB2Y3wkHHXqGBNEP odddco1M09Uz/2yGCzCpWp8iY/bU2VUuAQe9PusTfjuKB4MaFUxHPamQ5PpIALQ/g0vF kMRA== X-Google-Smtp-Source: ACcGV63MuqL6FRd4MqKm+ZD7TdPATSAEoGIr+2t+Z3GOdWrm8AdCKB4xKCsELZfrBb3W5dvyWUb7Zg== X-Received: by 2002:a17:902:7e0d:: with SMTP id b13-v6mr249066plm.230.1537817411233; Mon, 24 Sep 2018 12:30:11 -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 w23-v6sm139896pgi.18.2018.09.24.12.30.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Sep 2018 12:30:10 -0700 (PDT) Date: Mon, 24 Sep 2018 12:30:07 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Andrew Morton , Vlastimil Babka cc: Alexey Dobriyan , "Kirill A. Shutemov" , Michal Hocko , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org Subject: [patch v2] mm, thp: always specify ineligible vmas as nh in smaps In-Reply-To: Message-ID: References: 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 ineligible. Userspace relies on the "nh" flag being emitted as part of /proc/pid/smaps to determine if a vma is eligible to be 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 eligible 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 --- v2: - clear VM_HUGEPAGE per Vlastimil - update Documentation/filesystems/proc.txt to be explicit Documentation/filesystems/proc.txt | 12 ++++++++++-- fs/proc/task_mmu.c | 14 +++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt --- a/Documentation/filesystems/proc.txt +++ b/Documentation/filesystems/proc.txt @@ -490,10 +490,18 @@ manner. The codes are the following: dd - do not include area into core dump sd - soft-dirty flag mm - mixed map area - hg - huge page advise flag - nh - no-huge page advise flag + hg - eligible for transparent hugepages [*] + nh - not eligible for transparent hugepages [*] mg - mergable advise flag + [*] A process mapping is eligible to be backed by transparent hugepages (thp) + depending on system-wide settings and the mapping itself. See + Documentation/admin-guide/mm/transhuge.rst for default behavior. If a + mapping has a flag of "nh", it is not eligible to be backed by hugepages + in any condition, either because of prctl(PR_SET_THP_DISABLE) or + madvise(MADV_NOHUGEPAGE). PR_SET_THP_DISABLE takes precedence over any + MADV_HUGEPAGE. + 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, ' ');