From patchwork Wed Jul 17 21:59:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11048273 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 E5F58138B for ; Wed, 17 Jul 2019 21:59:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5DEE2872E for ; Wed, 17 Jul 2019 21:59:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C94B228751; Wed, 17 Jul 2019 21:59:59 +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,UNPARSEABLE_RELAY 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 2F43B2872E for ; Wed, 17 Jul 2019 21:59:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B0146B0007; Wed, 17 Jul 2019 17:59:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4394A6B000A; Wed, 17 Jul 2019 17:59:58 -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 2DB2A8E0001; Wed, 17 Jul 2019 17:59:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id EAA756B0007 for ; Wed, 17 Jul 2019 17:59:57 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id t18so5445191pgu.20 for ; Wed, 17 Jul 2019 14:59:57 -0700 (PDT) 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; bh=0q3n2ME2A0WBx2Hhy0HNQT8g5UQwULlqyspL3BepubM=; b=dxn0QOCtSAH5ahe6R7IsiGvI+9Xf0dzWiFCdj62wmhZ8pD3z1Vk2sao8yffIcwETbS vqT49ojRlRw9puz9oeJ6OsbJiTnqgKLdpwjzES0GmxFqj7CNEzDbHXPTzUQN6MvFi43+ 51F+WOThWMudPwN23qOWnzZb7pXdytreSxd5v+Bxfu1eY9Wn048/8hM0WM0wiGQUXuxp T2YwGDZfx9N7KvilrHcg8aBTYxB3mYR7beWGbqmjjzjCBrr/UkB8yMdkl1L0pGuAn2Bm dbCQhQCUL+r89runDBRBXUOqb7qBRHoXyev2Yk9PAOv6DHP6LBuDYpJdUDUt/ChuBOo3 +KHw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: APjAAAW3T6IvvmqBFHBmSiRHyPTLjCSbN2kWdiNgtQqK9puczDLwtNvf JCbwKJc2u3TQLu3hpe9ofMJ+k28TsqGmqaRSgGxYIdH/Woo2NU5HuwoGt5pWy57AJko8UHhpE8i iIbkBhJRFUn5O58iErFDdRVjQLc3/33rJzFE8JypAza3TLncFu40sC+OI2IduOUJWTA== X-Received: by 2002:a17:90a:8984:: with SMTP id v4mr46619207pjn.133.1563400797628; Wed, 17 Jul 2019 14:59:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAbx/kpLoSZQkE4+P3fQlRNHKbt3KD09aftcu2lSZqJYIY7lkq+4jf6wkfcLb2VrM/QoX4 X-Received: by 2002:a17:90a:8984:: with SMTP id v4mr46619124pjn.133.1563400796499; Wed, 17 Jul 2019 14:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563400796; cv=none; d=google.com; s=arc-20160816; b=JVOPPBhH2e1JHogmvUMUGV/N9d4oqixjtkUYjlwZtYdDtOmmD5+t7A52TOOFdxrpRw +QlrBg98lxlMCPt6FvprD3NfydUZlsKJWzX8pPuJakZoIzd0NvRjYl6R3n9CZ4J3B3SQ CLci9NXWkarTficJDarZ6R1QFBcxYTBZScwcz6VZJJ6m+oSVHhxRVvC1VtHJCZp9duVp m9988b6D1watzmHvOPWdnCjQt9nQKTI56lKQFuF1XEoGCwAId0dUjJD1PUqwZ4CJLTvJ S6vm7xFleDdhF2fBo/WPlYl55MxDW3kr0XelbwW4jqv+C0WjYPCOC5L/6hJnQO/DbrYU V8cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=0q3n2ME2A0WBx2Hhy0HNQT8g5UQwULlqyspL3BepubM=; b=u9AHCU6T+RzOijs2i0/XuO8EZeEp65NDuVhZzQ9N8RWHfwBBQOj2Vx6Cv9JDrnrLkk XO7gNctOBlDmm327UbUBvuHHjzC5gP0dAjUOLwDcaXAidZBdSaPH5NZyFlRY3cTfSQTN zeKk4mdx3n8EeqGkZ8Uc0KhX80FZHKMNrXDOlM0kDXz0LFJrAvZsI7vB0U5W/Xp/KBmZ hkugrGuLHiIZkDjZB/F1VjOUPymfFDwclHQ4QWBvSsmKVWvviP74ATx/du8kh9d1paSM VxCrs8HNw51EXa3yTtp7l7RKb53lfcKWvfTiTPtTRF+Vfu4cS35yCcsxKPvSB+hLXjLR EVyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com. [47.88.44.36]) by mx.google.com with ESMTPS id n20si23465473plp.395.2019.07.17.14.59.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jul 2019 14:59:56 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) client-ip=47.88.44.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R631e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04446;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0TX9KWw9_1563400771; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TX9KWw9_1563400771) by smtp.aliyun-inc.com(127.0.0.1); Thu, 18 Jul 2019 05:59:38 +0800 From: Yang Shi To: hughd@google.com, kirill.shutemov@linux.intel.com, mhocko@suse.com, vbabka@suse.cz, rientjes@google.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v4 PATCH 1/2] mm: thp: make transhuge_vma_suitable available for anonymous THP Date: Thu, 18 Jul 2019 05:59:17 +0800 Message-Id: <1563400758-124759-2-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1563400758-124759-1-git-send-email-yang.shi@linux.alibaba.com> References: <1563400758-124759-1-git-send-email-yang.shi@linux.alibaba.com> 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 The transhuge_vma_suitable() was only available for shmem THP, but anonymous THP has the same check except pgoff check. And, it will be used for THP eligible check in the later patch, so make it available for all kind of THPs. This also helps reduce code duplication slightly. Since anonymous THP doesn't have to check pgoff, so make pgoff check shmem vma only. And regroup some functions in include/linux/mm.h to solve compile issue since transhuge_vma_suitable() needs call vma_is_anonymous() which was defined after huge_mm.h is included. Cc: Hugh Dickins Cc: Kirill A. Shutemov Cc: Michal Hocko Cc: Vlastimil Babka Cc: David Rientjes Signed-off-by: Yang Shi Acked-by: Hugh Dickins --- include/linux/huge_mm.h | 23 +++++++++++++++++++++++ include/linux/mm.h | 34 +++++++++++++++++----------------- mm/huge_memory.c | 2 +- mm/memory.c | 13 ------------- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 7cd5c15..45ede62 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -121,6 +121,23 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) bool transparent_hugepage_enabled(struct vm_area_struct *vma); +#define HPAGE_CACHE_INDEX_MASK (HPAGE_PMD_NR - 1) + +static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, + unsigned long haddr) +{ + /* Don't have to check pgoff for anonymous vma */ + if (!vma_is_anonymous(vma)) { + if (((vma->vm_start >> PAGE_SHIFT) & HPAGE_CACHE_INDEX_MASK) != + (vma->vm_pgoff & HPAGE_CACHE_INDEX_MASK)) + return false; + } + + if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end) + return false; + return true; +} + #define transparent_hugepage_use_zero_page() \ (transparent_hugepage_flags & \ (1<vm_ops = NULL; } +static inline bool vma_is_anonymous(struct vm_area_struct *vma) +{ + return !vma->vm_ops; +} + +#ifdef CONFIG_SHMEM +/* + * The vma_is_shmem is not inline because it is used only by slow + * paths in userfault. + */ +bool vma_is_shmem(struct vm_area_struct *vma); +#else +static inline bool vma_is_shmem(struct vm_area_struct *vma) { return false; } +#endif + +int vma_is_stack_for_current(struct vm_area_struct *vma); + /* flush_tlb_range() takes a vma, not a mm, and can care about flags */ #define TLB_FLUSH_VMA(mm,flags) { .vm_mm = (mm), .vm_flags = (flags) } @@ -1629,23 +1646,6 @@ static inline void cancel_dirty_page(struct page *page) int get_cmdline(struct task_struct *task, char *buffer, int buflen); -static inline bool vma_is_anonymous(struct vm_area_struct *vma) -{ - return !vma->vm_ops; -} - -#ifdef CONFIG_SHMEM -/* - * The vma_is_shmem is not inline because it is used only by slow - * paths in userfault. - */ -bool vma_is_shmem(struct vm_area_struct *vma); -#else -static inline bool vma_is_shmem(struct vm_area_struct *vma) { return false; } -#endif - -int vma_is_stack_for_current(struct vm_area_struct *vma); - extern unsigned long move_page_tables(struct vm_area_struct *vma, unsigned long old_addr, struct vm_area_struct *new_vma, unsigned long new_addr, unsigned long len, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 885642c..782dd14 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -689,7 +689,7 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf) struct page *page; unsigned long haddr = vmf->address & HPAGE_PMD_MASK; - if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end) + if (!transhuge_vma_suitable(vma, haddr)) return VM_FAULT_FALLBACK; if (unlikely(anon_vma_prepare(vma))) return VM_FAULT_OOM; diff --git a/mm/memory.c b/mm/memory.c index 89325f9..e2bb51b 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3162,19 +3162,6 @@ static vm_fault_t pte_alloc_one_map(struct vm_fault *vmf) } #ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE - -#define HPAGE_CACHE_INDEX_MASK (HPAGE_PMD_NR - 1) -static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, - unsigned long haddr) -{ - if (((vma->vm_start >> PAGE_SHIFT) & HPAGE_CACHE_INDEX_MASK) != - (vma->vm_pgoff & HPAGE_CACHE_INDEX_MASK)) - return false; - if (haddr < vma->vm_start || haddr + HPAGE_PMD_SIZE > vma->vm_end) - return false; - return true; -} - static void deposit_prealloc_pte(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; From patchwork Wed Jul 17 21:59:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11048269 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 1C36D14DB for ; Wed, 17 Jul 2019 21:59:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09CDC2872E for ; Wed, 17 Jul 2019 21:59:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF65728787; Wed, 17 Jul 2019 21:59:54 +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,UNPARSEABLE_RELAY 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 732142872E for ; Wed, 17 Jul 2019 21:59:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9451E6B0005; Wed, 17 Jul 2019 17:59:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8CE946B0006; Wed, 17 Jul 2019 17:59:42 -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 7959C8E0001; Wed, 17 Jul 2019 17:59:42 -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 3F2B56B0005 for ; Wed, 17 Jul 2019 17:59:42 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id n9so12000727pgq.4 for ; Wed, 17 Jul 2019 14:59:42 -0700 (PDT) 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; bh=NXJtoxitHhlDQoPNi265FByj0rrIqDH/87FnzCF7KHo=; b=OCehrEU+jYwb73XW3TDiZFhZk1wQwglyHdxcHIHL62Wg0UssP6nHa1m/tF3FMQHvFn 7V4s4VmpB/+2anvPMuTcVOZhUA4tOZ0KGuAuCOGXpCU5zam0xMAXXLczjq/BHNtKRe71 0lDi7C9bnbh++eIhBE3qHAaB+Dw01c7PJo0ilzxGeXhHF4tvJRbGvH5GHjt1ajybtK+e lEfKwjaTg/8YvgL3bdWI8Za0kxO87r+auPxyYm91dJ6sMWFiAbcqFR6/OoeZZRV00DCC UI9bhy3m/k+0jJRpB7dwK/1Xzx32crCco9kb43KDdFzoXMlCi2BqrcoaNTtij2EK1i3c Od+w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: APjAAAXzQ9tpRRg6Kebe4uQdKjXVqG63tBQm/C4j0BlkN9kzavbT22L4 Xhp4k577rXfawrPUDZLaoRoSDo+Ylj89BpzpU1dlxs8KrxlACybUqUHdbFhNxqgFH075IOt9rZ6 usNcEcPuQPcDZ2zH0mlKAsPJAgooajfQB6aFu8sDrZySHHpp8NMZumotflyVajcRpHg== X-Received: by 2002:a17:90a:bf02:: with SMTP id c2mr47072437pjs.73.1563400781925; Wed, 17 Jul 2019 14:59:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwX3y4GUfNviJYyMwf78MLFeD8HeE0S9q34laOEt6+fP/buiy3ND0FXqrwb4cI6+RNw9i7M X-Received: by 2002:a17:90a:bf02:: with SMTP id c2mr47072386pjs.73.1563400781001; Wed, 17 Jul 2019 14:59:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563400780; cv=none; d=google.com; s=arc-20160816; b=LuLVUFJ2qZE9LMFYyeRpjOB8ualwvyapb4hbZvKNmFnS1xSNWHz0gg6Av3eiop0apk BrhirylnKWawM+lVFIcNc1Eev1WjupgqDTLTfuXOksjgk4Etkc0WXJsaBcfTgTykHMXO wl/p+odlfryFEk5BTi8HlXv24K+9nNZAiUGoE0OvtshCTXqpEP++2OTkzXsHxtmiAap4 vz0Br4zDjl8JU9EquJGiJjBRWub8VOOYlBpeMJrGyPnqH6L4Bt0m6/8wdqGI04JlV2KN 9shrjjkr9I7gk2zdsHLgGSyB1gNw36OLixsVYt6BKCQzhMB24VF1aYSHNZu6lFGq24E9 dW9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=NXJtoxitHhlDQoPNi265FByj0rrIqDH/87FnzCF7KHo=; b=FcS3z9Wh5uVzE3zvNP0hgjUj6FmIbu3hhMEBLELXEJUsevwOQqisuNoV8YhCpJTekx oiEJHJ5GBMWb+f1mO9B+GTYniVIrfAiBwrdB7D4LFbHwtBJDlF63rqiwC0u2kW0a4irc yVvFgkWOLQ8JziaHCNGOufEEgwD0/M7zoUybgQzSuCumSdsepa+tVwSoNPEQdZ8YGu7M LwaSSG3r/w7BsCSWL+SxmiY7iOBr+GgIytT8NVyArha+JhcQpBFH7+pxA4f/bmDNpXUz XYJ79xWT2COWBxXihYHyKRCUQrXng/65uSaVYcdpVEXMjmHwJM6B7Xqbfm4uLY7fWhnD jF0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com. [115.124.30.130]) by mx.google.com with ESMTPS id q12si1752294pgt.447.2019.07.17.14.59.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jul 2019 14:59:40 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.130 as permitted sender) client-ip=115.124.30.130; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R471e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04391;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0TX9KWw9_1563400771; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TX9KWw9_1563400771) by smtp.aliyun-inc.com(127.0.0.1); Thu, 18 Jul 2019 05:59:38 +0800 From: Yang Shi To: hughd@google.com, kirill.shutemov@linux.intel.com, mhocko@suse.com, vbabka@suse.cz, rientjes@google.com, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v4 PATCH 2/2] mm: thp: fix false negative of shmem vma's THP eligibility Date: Thu, 18 Jul 2019 05:59:18 +0800 Message-Id: <1563400758-124759-3-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1563400758-124759-1-git-send-email-yang.shi@linux.alibaba.com> References: <1563400758-124759-1-git-send-email-yang.shi@linux.alibaba.com> 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 The commit 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma, __transparent_hugepage_enabled() is called to override the result from shmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show: 7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764 /dev/shm/test Size: 4096 kB ... [snip] ... ShmemPmdMapped: 4096 kB ... [snip] ... THPeligible: 0 And, /proc/meminfo does show THP allocated and PMD mapped too: ShmemHugePages: 4096 kB ShmemPmdMapped: 4096 kB This doesn't make too much sense. The shmem objects should be treated separately from anonymous THP. Calling shmem_huge_enabled() with checking MMF_DISABLE_THP sounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already. Also check if vma is suitable for THP by calling transhuge_vma_suitable(). And minor fix to smaps output format and documentation. Fixes: 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma") Acked-by: Hugh Dickins Cc: Kirill A. Shutemov Cc: Michal Hocko Cc: Vlastimil Babka Cc: David Rientjes Signed-off-by: Yang Shi --- Documentation/filesystems/proc.txt | 4 ++-- fs/proc/task_mmu.c | 3 ++- mm/huge_memory.c | 9 +++++++-- mm/shmem.c | 3 +++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Documentation/filesystems/proc.txt b/Documentation/filesystems/proc.txt index fb4735f..99ca040 100644 --- a/Documentation/filesystems/proc.txt +++ b/Documentation/filesystems/proc.txt @@ -486,8 +486,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. +"THPeligible" indicates whether the mapping is eligible for allocating THP +pages - 1 if true, 0 otherwise. It just shows the current status. "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 818cedb..731642e 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -832,7 +832,8 @@ static int show_smap(struct seq_file *m, void *v) __show_smap(m, &mss, false); - seq_printf(m, "THPeligible: %d\n", transparent_hugepage_enabled(vma)); + seq_printf(m, "THPeligible: %d\n", + transparent_hugepage_enabled(vma)); if (arch_pkeys_enabled()) seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 782dd14..1334ede 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -63,10 +63,15 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) { + /* The addr is used to check if the vma size fits */ + unsigned long addr = (vma->vm_end & HPAGE_PMD_MASK) - HPAGE_PMD_SIZE; + + if (!transhuge_vma_suitable(vma, addr)) + return false; if (vma_is_anonymous(vma)) return __transparent_hugepage_enabled(vma); - if (vma_is_shmem(vma) && shmem_huge_enabled(vma)) - return __transparent_hugepage_enabled(vma); + if (vma_is_shmem(vma)) + return shmem_huge_enabled(vma); return false; } diff --git a/mm/shmem.c b/mm/shmem.c index f4dce9c..64e5d59 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3872,6 +3872,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma) loff_t i_size; pgoff_t off; + if ((vma->vm_flags & VM_NOHUGEPAGE) || + test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) + return false; if (shmem_huge == SHMEM_HUGE_FORCE) return true; if (shmem_huge == SHMEM_HUGE_DENY)