From patchwork Tue Nov 20 10:35:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 10690207 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 1E88F15A7 for ; Tue, 20 Nov 2018 10:35:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 111B52A87C for ; Tue, 20 Nov 2018 10:35:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 058402A881; Tue, 20 Nov 2018 10:35:39 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE 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 543FF2A87C for ; Tue, 20 Nov 2018 10:35:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5CB1B6B1FCD; Tue, 20 Nov 2018 05:35:34 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 57AD56B1FCE; Tue, 20 Nov 2018 05:35:34 -0500 (EST) 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 41C7C6B1FCF; Tue, 20 Nov 2018 05:35:34 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id DBE676B1FCD for ; Tue, 20 Nov 2018 05:35:33 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id w15so1041231edl.21 for ; Tue, 20 Nov 2018 02:35:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=QWerdv5NokFZCG7auzm1OEN/qgY42YRYuNB88bkmlcY=; b=uI9K8p/iOpqcLU6Cq9ZDheUDQcHLTmxaqUoFot0JG65TqKnqtimK+UKUel3OuGL6JH g8ta3PRYpRflD7eYJUhjYOrSKFxqjVF579pQYwCF6fa5cpHdd3Q+qeocCkoknuec/JND i5cCjg2SzE6D/ka2aqUM2vLwP/PnznEw7ErAZWDgqulaDd3YFfzJHooeWMdeQtXouo5o LKN08YpvfCeGKREE341zUAAjFl0lCDbUabHe1NuVF0/5VCNoHh25k5NkvPj3+TrIacQp h3PDHM6Phn9yNdXwMtJd6NERFaKiAK13rB/qWIl6xtz6nZPvVw+5vWim17S0gLnFSu9+ VB5A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Gm-Message-State: AA+aEWa+NELIL8ewKH7SgXV+kWcWA3Z8Ema37SzX8OEtzT3VCm6zoM0m dNmYP1hA6npHp8u2Yv9eJGmCqgv8KIPsmu67lvr+91nX3N5H+YQlEDQ+jPkhiNh4vmzpPfXyd0F MyaiD/qxRMeMfZD5SvoX7XiMbfVi2F5fR6RmriupHiK+Qaqf4sjlp5kWnqcADq1IBxaBlywFOtA 6CHjoURmAQg9gSgav9RrMPY3tDrK4C5A0LMmIyxBjJOe/Eb68F+4IL0/vOEdlhk3xR3w/H+FXyR UHSzY46HqJ60HJShx8z3Gyr2d6Im1KpTAxPisqVbPA21Je496V5Gx+UVH5f+DH/MH5DzP4eko31 u081jHxfNPlbbtH65d8mMth8XOSFPo756J/qnsOFgz1Q4T2Z+KFiDNYr70vlo2VPq1k6FJNFkA= = X-Received: by 2002:a50:f5af:: with SMTP id u44mr1870385edm.172.1542710133348; Tue, 20 Nov 2018 02:35:33 -0800 (PST) X-Received: by 2002:a50:f5af:: with SMTP id u44mr1870334edm.172.1542710132298; Tue, 20 Nov 2018 02:35:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542710132; cv=none; d=google.com; s=arc-20160816; b=eWKWRaOLZ2xzhtpKrv1O0CIpT9ghPuLQLf1Q69z0HKNtC6mNHTKI9RNsr84VSBZIeI 3+eytSpV5mYAtdlIdETs1RKc+DVo78aeREfT+4isXLJy2Ag+26wWAgC3ZUVFzCnLmFQu XhJohId10cr0LG8nXtWTEsy5CShX0B2tgj/BFfrRr0NvT9bWS72ZF8+SpBEUAIMPWpjp K58AJ/xX8jUonmlIDMxhwF9HD9zPl8nRuDLWed1osaMZdiE8qlv1EQOEMTs3Ny47d42e IQLYjK1KGItqHtJCt7xoz63Ko6NOmMhjsQIuQheldQre8KdNrlIXwWK2d/nUxE5lmunj PY/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=QWerdv5NokFZCG7auzm1OEN/qgY42YRYuNB88bkmlcY=; b=iBFtzekS7Lys6OWz9288kXUYefSm4Iu5/kjJLk/ZINJymx811TEBZFoZ9zc0sMfLGt +UZXcBNjClmMcTOWtZ7H0P4e1FL8loKh6utxJ09LYkt3C+uXqSAyl4Y2EUj58MG6qTEk kLfkt/etq1QzvzEXZ6e35newHirhNdsgBBBQdjLVND/7FDF/SoQnnZGX4lUHz20g7zuz maZ4MxNEnbCiy+cS6HxW0QY3AIPeNYUcNi0S/aBrLfiLC2d6tU4lEZpVNjddc3U453Ji RvXDd0Gn/xzjryb8z46CjXyCVYxtYszMdBzey1slDLi5FnCbI1NreWX1Z4oV7v862sVf Kr+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f47sor8782037edb.4.2018.11.20.02.35.32 for (Google Transport Security); Tue, 20 Nov 2018 02:35:32 -0800 (PST) Received-SPF: pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Google-Smtp-Source: AFSGD/U8yv77zjPMMDkFdhuOBD/tAZDxskV5Ravx718ZFAdo8bVLSrpGjbCwriOcV5GVV4qvNOllvg== X-Received: by 2002:a50:e045:: with SMTP id g5mr1862061edl.152.1542710131793; Tue, 20 Nov 2018 02:35:31 -0800 (PST) Received: from tiehlicka.suse.cz (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id a15-v6sm5967233ejj.5.2018.11.20.02.35.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 02:35:31 -0800 (PST) From: Michal Hocko To: linux-api@vger.kernel.org Cc: Andrew Morton , Alexey Dobriyan , , LKML , Michal Hocko Subject: [RFC PATCH 2/3] mm, thp, proc: report THP eligibility for each vma Date: Tue, 20 Nov 2018 11:35:14 +0100 Message-Id: <20181120103515.25280-3-mhocko@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181120103515.25280-1-mhocko@kernel.org> References: <20181120103515.25280-1-mhocko@kernel.org> 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 From: Michal Hocko Userspace falls short when trying to find out whether a specific memory range is eligible for THP. There are usecases that would like to know that http://lkml.kernel.org/r/alpine.DEB.2.21.1809251248450.50347@chino.kir.corp.google.com : This is used to identify heap mappings that should be able to fault thp : but do not, and they normally point to a low-on-memory or fragmentation : issue. The only way to deduce this now is to query for hg resp. nh flags and confronting the state with the global setting. Except that there is also PR_SET_THP_DISABLE that might change the picture. So the final logic is not trivial. Moreover the eligibility of the vma depends on the type of VMA as well. In the past we have supported only anononymous memory VMAs but things have changed and shmem based vmas are supported as well these days and the query logic gets even more complicated because the eligibility depends on the mount option and another global configuration knob. Simplify the current state and report the THP eligibility in /proc//smaps for each existing vma. Reuse transparent_hugepage_enabled for this purpose. The original implementation of this function assumes that the caller knows that the vma itself is supported for THP so make the core checks into __transparent_hugepage_enabled and use it for existing callers. __show_smap just use the new transparent_hugepage_enabled which also checks the vma support status (please note that this one has to be out of line due to include dependency issues). Signed-off-by: Michal Hocko Acked-by: Vlastimil Babka --- Documentation/filesystems/proc.txt | 3 +++ fs/proc/task_mmu.c | 2 ++ include/linux/huge_mm.h | 13 ++++++++++++- mm/huge_memory.c | 12 +++++++++++- mm/memory.c | 4 ++-- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt index b1fda309f067..06562bab509a 100644 --- a/Documentation/filesystems/proc.txt +++ b/Documentation/filesystems/proc.txt @@ -425,6 +425,7 @@ SwapPss: 0 kB KernelPageSize: 4 kB MMUPageSize: 4 kB Locked: 0 kB +THPeligible: 0 VmFlags: rd ex mr mw me dw the first of these lines shows the same information as is displayed for the @@ -462,6 +463,8 @@ replaced by copy-on-write) part of the underlying shmem object out on swap. "SwapPss" shows proportional swap share of this mapping. Unlike "Swap", this does not take into account swapped out page of underlying shmem objects. "Locked" indicates whether the mapping is locked in memory or not. +"THPeligible" indicates whether the mapping is eligible for THP pages - 1 if +true, 0 otherwise. "VmFlags" field deserves a separate description. This member represents the kernel flags associated with the particular virtual memory area in two letter encoded diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 47c3764c469b..c9f160eb9fbc 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -790,6 +790,8 @@ static int show_smap(struct seq_file *m, void *v) __show_smap(m, &mss); + seq_printf(m, "THPeligible: %d\n", transparent_hugepage_enabled(vma)); + if (arch_pkeys_enabled()) seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); show_smap_vma_flags(m, vma); diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 4663ee96cf59..381e872bfde0 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -93,7 +93,11 @@ extern bool is_vma_temporary_stack(struct vm_area_struct *vma); extern unsigned long transparent_hugepage_flags; -static inline bool transparent_hugepage_enabled(struct vm_area_struct *vma) +/* + * to be used on vmas which are known to support THP. + * Use transparent_hugepage_enabled otherwise + */ +static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) { if (vma->vm_flags & VM_NOHUGEPAGE) return false; @@ -117,6 +121,8 @@ static inline bool transparent_hugepage_enabled(struct vm_area_struct *vma) return false; } +bool transparent_hugepage_enabled(struct vm_area_struct *vma); + #define transparent_hugepage_use_zero_page() \ (transparent_hugepage_flags & \ (1<vm_file->f_mapping) && shmem_huge_enabled(vma)) + return __transparent_hugepage_enabled(vma); + + return false; +} + static struct page *get_huge_zero_page(void) { struct page *zero_page; @@ -1303,7 +1313,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd) get_page(page); spin_unlock(vmf->ptl); alloc: - if (transparent_hugepage_enabled(vma) && + if (__transparent_hugepage_enabled(vma) && !transparent_hugepage_debug_cow()) { huge_gfp = alloc_hugepage_direct_gfpmask(vma, haddr); new_page = alloc_pages_vma(huge_gfp, HPAGE_PMD_ORDER, vma, diff --git a/mm/memory.c b/mm/memory.c index 4ad2d293ddc2..3c2716ec7fbd 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3830,7 +3830,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, vmf.pud = pud_alloc(mm, p4d, address); if (!vmf.pud) return VM_FAULT_OOM; - if (pud_none(*vmf.pud) && transparent_hugepage_enabled(vma)) { + if (pud_none(*vmf.pud) && __transparent_hugepage_enabled(vma)) { ret = create_huge_pud(&vmf); if (!(ret & VM_FAULT_FALLBACK)) return ret; @@ -3856,7 +3856,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, vmf.pmd = pmd_alloc(mm, vmf.pud, address); if (!vmf.pmd) return VM_FAULT_OOM; - if (pmd_none(*vmf.pmd) && transparent_hugepage_enabled(vma)) { + if (pmd_none(*vmf.pmd) && __transparent_hugepage_enabled(vma)) { ret = create_huge_pmd(&vmf); if (!(ret & VM_FAULT_FALLBACK)) return ret;