Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1413899ybi; Wed, 17 Jul 2019 15:01:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqFVpIwRP4l1J0Eftqn+7diWumGoUsiqX/V0UYSE8PxtQGudHhOl8xKL+T0ZzEZcapprPr X-Received: by 2002:a17:90a:2ec1:: with SMTP id h1mr47167052pjs.119.1563400898402; Wed, 17 Jul 2019 15:01:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563400898; cv=none; d=google.com; s=arc-20160816; b=lgD4pkKUo/hz6CH0N4+DZFUGzqZOBkAUF/rTrCMWnDG/uYsNQBrw0yZgbBRY5vONxk KuyRe8bdvGzo2//fWXy8z0nV1L9DgXhd7FJrhb0EsrCRJB880o33MHLUlIMzJJPEO1Uc SG5UQuxtUjbRGsq5KargeByU5k9ud1UksjcWFxZcBepkPot1nybt4tS63fLteNWi9WOa +qiHLDoi3TFumZzbXX0HgLEjeI7rTGDxDsGDIJvUhQyfhiT4AjBNL3ftLIQ4MiNiZgNs pKx75dgPHsIe9P3BYXiZe7I2V5kl3bgGafji2YKpdQry4DgRwAu/l8hq3SPnjAmpbtXH 9iOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=0q3n2ME2A0WBx2Hhy0HNQT8g5UQwULlqyspL3BepubM=; b=QWiKLjKB9ynSJgL+bpqWwcFdW3NX+Yv91gDYYjqpbc03lSR6UrFeKMVFWRShBDwc18 pttiZ7fBq2BnprrDU2warCFAc1rN+QlolCHHRUPidR5lUCgBC2BMDD8evwIRBf5v7tjo p0pR3fEnD6xSG59MsX3zf4Zwemh/AAIJnvIQ2JB5D8p8YCp3CWReW9k4+cTbwNcelKeF FdfxMFORU1ejGM1TGpBmpf60RcHznT/1GnEYkDpvsKztQKCjxjaqjvZcWYwI2NQqdqrD 8bU8T9xCoDSCeKmpf9uj52JbMvDyJPN338YsBpYPTzONeXBZnHJFIHjbU214tCp02dDl 9o1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y8si317059plk.428.2019.07.17.15.01.22; Wed, 17 Jul 2019 15:01:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729208AbfGQV7l (ORCPT + 99 others); Wed, 17 Jul 2019 17:59:41 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:58363 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727543AbfGQV7k (ORCPT ); Wed, 17 Jul 2019 17:59:40 -0400 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; -- 1.8.3.1