Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1295557ybi; Wed, 17 Jul 2019 12:44:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwArCgpsR6X0mKc584ZcPvz3rOZrDAYbuF+wzy6w8QIMWGK3f5ZGjObOfQIRX0AKoAXQYOr X-Received: by 2002:a17:902:fa2:: with SMTP id 31mr46071920plz.38.1563392665448; Wed, 17 Jul 2019 12:44:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563392665; cv=none; d=google.com; s=arc-20160816; b=fdKCjlGogAwf2c05qW660QJd9f6a/vXdeRha69FF3ApRpmRs7e2LnWN6EIMCc7idZ9 Jp4PYgrYRCysK9rYBhaMHoZUjzXntFVaVhUM0uxaz5gvN/ogbyTehveGLFfg+ZrBeX7+ sA980qEMz+3YOCbFDqQ8OB9X4z+mQoh33wTDdxm1/LpJIf84DUBdK3ndlcq4n/JZ+CDA 99/BAp/P8t99yhDTBaVNj8IwsCy4h08PKi0BMWgvATToszI3XSMBHRH/nDdLT5M3NweG gOgGKg+bLTOPmj0OOd5T0NlLxv3Hq4MwvwVXYsXbZLXdgU7JoDB2BXOrf3h7HNzjgQhz lfiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=B4KkASSByiIr8GwQ9SOJWtTimb9yBfYMRGwI3wSnBvU=; b=kR8Byf+DWblJgHsW2sF9oNvd0CT7zDuMZqzxxXthZM5prFNwq21qKWrQCeZ2fbfs+E OXGZmoS1EtaATiAAi3PrjZS64efubKWtfYb0PxjYjyWmZ3TmDXPgSARJUKPlBkK+/37V +KLrayPQDC372j9EJh+ya5fpExvlHBV8GnYhzz11dkUcGn33RI9stvNEOXA4yWe66Vtq Zu9RzxFpOkfYWupg0wbuj6Jq+eB4ttorfn4ce+AGPL7vO+SCdV6z7qaKjeCntFu4PaZw Xk/XBS7OsMbPxuSXYoI+pWbuUNiMzDYMEYPfdtoeElObDgAfG5aR2AnbfwLRr2lfprom wmIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pTU141rS; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y187si24288131pgd.66.2019.07.17.12.44.08; Wed, 17 Jul 2019 12:44:25 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=pTU141rS; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728363AbfGQTng (ORCPT + 99 others); Wed, 17 Jul 2019 15:43:36 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:33099 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727945AbfGQTng (ORCPT ); Wed, 17 Jul 2019 15:43:36 -0400 Received: by mail-pf1-f195.google.com with SMTP id g2so11356641pfq.0 for ; Wed, 17 Jul 2019 12:43:35 -0700 (PDT) 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=B4KkASSByiIr8GwQ9SOJWtTimb9yBfYMRGwI3wSnBvU=; b=pTU141rSxqpEpOL4UTml41bJC99Bbi08614VBV9iACXfdQBYQMGLsTxyZ5eWCJAsxp PkmS856N30EwaXjbhF/ogszdHLt5Y16oU9gI/Webo0Vzi3aLl7HBczJU2vNPyd+qTCEu Q3maXbuUy2yk1XlmTAlUbOmk1w6cqlSqw4Gt8BjP7ChFlly+n1AVNH7KVan6v6f2Elvx g4XUKTtvMIwVBZ0eeC13hoMhs+oVB4chrRXX80ycgTxXu0xYpRCAz4p4g4Z2ttJIctMO D5r4iEMm9pJU+QauaDTSBBFfvWV9kONhJqPiCSKskg6RibNRsS9fk61AKXSnuBtq18le smkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=B4KkASSByiIr8GwQ9SOJWtTimb9yBfYMRGwI3wSnBvU=; b=HKtYDpBNZ/koz0F5ZnZ/uzdKcSL7ARGQSfYsayWrCNsjm/gv3xd78xsWxEf2S7DMxK Eop4xvbEFF6gIhBE/f5QA2PQYs47dBoemQm5GUqNrOkpo9rVKpINf5KRTT9Dx7B4JSG9 6tqplhKmO0OudPLLcR5DXFpWXxdshgoYRfkqVxhZ8nKf7WIL/fBUO3YjiNquIYhQl8xU rm7zH3BpI6WrSDz8rAHnm2C7z7hyfFWbAF2EQBTyTlFuetIf1dTXdhvI9HQG0LZ6ADoA dpXiEXV11upN4OdOHXc0NuB0FhbiT2Jx3/4LPdiGzqw0Ugge4mIU6Ik7Rk0XX1ct+PNv F3bw== X-Gm-Message-State: APjAAAVjpRvWO/JWj+YKViFULUZITbE8O7qcUERpnIYFXOkPVjhHJV4o l65C+qwkYDP5p0beJMg7VyvrAg== X-Received: by 2002:a63:d944:: with SMTP id e4mr42815562pgj.261.1563392614248; Wed, 17 Jul 2019 12:43:34 -0700 (PDT) Received: from [100.112.64.100] ([104.133.8.100]) by smtp.gmail.com with ESMTPSA id r75sm27194536pfc.18.2019.07.17.12.43.33 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Jul 2019 12:43:33 -0700 (PDT) Date: Wed, 17 Jul 2019 12:43:16 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Yang Shi cc: hughd@google.com, kirill.shutemov@linux.intel.com, mhocko@suse.com, vbabka@suse.cz, rientjes@google.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [v3 PATCH 1/2] mm: thp: make transhuge_vma_suitable available for anonymous THP In-Reply-To: <1560401041-32207-2-git-send-email-yang.shi@linux.alibaba.com> Message-ID: References: <1560401041-32207-1-git-send-email-yang.shi@linux.alibaba.com> <1560401041-32207-2-git-send-email-yang.shi@linux.alibaba.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Jun 2019, Yang Shi wrote: > 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. Yes, I think you are right to avoid the pgoff check on anonymous. I had originally thought that it would work out okay even with the pgoff check on anonymous, and usually it would: but could give the wrong answer on an mremap-moved anonymous area. > > Cc: Hugh Dickins > Cc: Kirill A. Shutemov > Cc: Michal Hocko > Cc: Vlastimil Babka > Cc: David Rientjes > Signed-off-by: Yang Shi Almost Acked-by me, but there's one nit I'd much prefer to change: sorry for being such a late nuisance... > --- > mm/huge_memory.c | 2 +- > mm/internal.h | 25 +++++++++++++++++++++++++ > mm/memory.c | 13 ------------- > 3 files changed, 26 insertions(+), 14 deletions(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 9f8bce9..4bc2552 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -691,7 +691,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/internal.h b/mm/internal.h > index 9eeaf2b..7f096ba 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -555,4 +555,29 @@ static inline bool is_migrate_highatomic_page(struct page *page) > > void setup_zone_pageset(struct zone *zone); > extern struct page *alloc_new_node_page(struct page *page, unsigned long node); > + > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > +#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; > +} > +#else > +static inline bool transhuge_vma_suitable(struct vma_area_struct *vma, > + unsigned long haddr) > +{ > + return false; > +} > +#endif > + > #endif /* __MM_INTERNAL_H */ ... maybe I'm just not much of a fan of mm/internal.h (where at last you find odd bits and pieces which you had expected to find elsewhere), and maybe others will disagree: but I'd say transhuge_vma_suitable() surely belongs in include/linux/huge_mm.h, near __transparent_hugepage_enabled(). But then your correct use of vma_is_anonymous() gets more complicated: because that declaration is over in include/linux/mm.h; and although linux/mm.h includes linux/huge_mm.h, vma_is_anonymous() comes lower down. However... linux/mm.h's definition of vma_set_anonymous() comes higher up, and it would make perfect sense to move vma_is_anonymous up to just after vma_set_anonymous(), wouldn't it? Should vma_is_shmem() and vma_is_stack_for_current() declarations move with it? Probably yes: they make more sense near vma_is_anonymous() than where they were. Hugh > diff --git a/mm/memory.c b/mm/memory.c > index 96f1d47..2286424 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3205,19 +3205,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