Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp913752ybi; Fri, 7 Jun 2019 21:32:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWrvHSczN/XDCumH0exgEyKx5MWFzjA04tHnRk4Bg1H6Tphzk5oGnXH53P9/KrOYkLpuPB X-Received: by 2002:a63:6b07:: with SMTP id g7mr6153411pgc.325.1559968342145; Fri, 07 Jun 2019 21:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559968342; cv=none; d=google.com; s=arc-20160816; b=n1MKHNXs6rG44QQVQbB1HtZNDW+9vZXbWQ5/U0Qqbui3L7Q+rYWaEi/199LOx+U4VY b+geix8De1A9vDHEywNH0lwRZDehQtfC67RUKXZEjjwazYqfpmoL9h7uIvHNsgNlaN07 lfjjGTzOr+V/2p9T+sjXmuOMAVLsTURPE/vcwaW8RKe1kNMcFgVMpbFauSVrNz8XA8Jc 5TY/zv/ihNKCJf31c/LXxMzoi9sxH2/pUQniZPsgyRmGEL/a/xr42pLgRfij3We1hQ/C GbuSgKZGKYoSKGDs5lwhUWX4FQnTl1v5Y8muZ18dpeaH6B5fiA/3/GbJ2i3k4wPTXmI1 z+WA== 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=vtwv/19e9tggX3cqe5qv1DLU/M+NFvqtXR4KfTiH/nA=; b=qKtLDwTkaSxdltcpUhsPnus3dJTzx/NZYtNqMPM19V8Ho9E7/wI9QKSL7WB4/gCxY3 cUjuPwg6LND94RnKEDBRQfIQiYDs7CIzRvZ93CKdPC1WRQL63/38R6HfofmR9Bpx3YGU t/UhAT5+tVh/SKC/Y8h5Z+NvVhQK1DcMG7iGkYNylf5C5sCqc0LDZ3HmdLWQknQ8z3HM pj79/Q5KY/9Vqx9GgsexUAeUAmnvJL0idfeyTBbCr0cAyl1Qyg9crQmT2bnCcPzBOK/v o7iTh4hIV/bR9qnGPMxLEGRUdHkab9W8T6+s8YVr5ley4D2LM3a39ABrHoWA1edTiyTD 1OLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oSTMOOMg; 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 x21si3734824pfa.48.2019.06.07.21.32.03; Fri, 07 Jun 2019 21:32:22 -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=oSTMOOMg; 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 S1731049AbfFHD7U (ORCPT + 99 others); Fri, 7 Jun 2019 23:59:20 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44903 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730056AbfFHD7U (ORCPT ); Fri, 7 Jun 2019 23:59:20 -0400 Received: by mail-pf1-f195.google.com with SMTP id t16so2218951pfe.11 for ; Fri, 07 Jun 2019 20:59:19 -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=vtwv/19e9tggX3cqe5qv1DLU/M+NFvqtXR4KfTiH/nA=; b=oSTMOOMgUDPwm9v3S0xQOC94eI7B+uLlRaPeDAiJhY7G5hwqhlqXib84eocSO4Or4Q s0x7m/OWbYvbr05AqgrpysSsialSnP2IO4KBRUcSw5nHDJJ9VT1JXgbFuODL+a03Z4CY fxnjowQ4yxOMJfuRyI+LlO2yB9we3efobS6TYwIsiOjfMo8b6WZBTJaU+YBh9SaZBOnG 1j7mVIMwXLBa194ga11kGZm/58Txn50vJjPDmAixIt8kjjFoTSLMs5mEJ3EPCvSbcwcY fqcr4O0WM6f0WWVmK93XA17IO7PqzDpr6Ih0imbGmw18zRp/e/84OdJn/GrOWuqMl0mQ +Jgw== 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=vtwv/19e9tggX3cqe5qv1DLU/M+NFvqtXR4KfTiH/nA=; b=X81thOrm9hM5a8GJ9FQOZ4YQpQ8Rnj7Fc0e8dnd7NqnMo/62Oj4DDPQD2BeQN/IbGN Gqq97zXcrvN5Vi6TRr3CeKNgJsK3dKv0WeT0k2fOZXyqPCo1+BNVaIt2HjTbqY1/Cf7a qMGSpl7f0Fi+QYGdl6w41vt6hMi0z63bwNJBWH9cYrnvqfEw+4b1qjrADyIsO7ropSVK ZJecI3CsY6u3lQd4yMLxg8ONGtI7UTl6vbAkjlSqqJ2WnB010vlR9yqxmqSvp4Qx4JtV XI/MLVGxLGrqqeGzsQgf0ACL+JOKeFN4zGuLEzPqc4QpTQrVqsUQztzGjfvlcvaBIsBc hexA== X-Gm-Message-State: APjAAAWi91LNibqO1ilgG2ZpbMeYbbsB1Siqt3pnzhSVJ/PIRRaeKilE Htgm94zb87MQhsu9+14MiBA9TQ== X-Received: by 2002:a63:e645:: with SMTP id p5mr5903986pgj.4.1559966358366; Fri, 07 Jun 2019 20:59:18 -0700 (PDT) Received: from [100.112.83.253] ([104.133.9.109]) by smtp.gmail.com with ESMTPSA id n2sm6068531pgp.27.2019.06.07.20.59.17 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Jun 2019 20:59:17 -0700 (PDT) Date: Fri, 7 Jun 2019 20:58:56 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Yang Shi cc: mhocko@suse.com, vbabka@suse.cz, rientjes@google.com, kirill@shutemov.name, kirill.shutemov@linux.intel.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [v2 PATCH] mm: thp: fix false negative of shmem vma's THP eligibility In-Reply-To: <1556037781-57869-1-git-send-email-yang.shi@linux.alibaba.com> Message-ID: References: <1556037781-57869-1-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 Wed, 24 Apr 2019, Yang Shi wrote: > 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 anonymous THP flag should not > intervene shmem 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. > > Fixes: 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma") > Cc: Michal Hocko > Cc: Vlastimil Babka > Cc: David Rientjes > Cc: Kirill A. Shutemov > Signed-off-by: Yang Shi > --- > v2: Check VM_NOHUGEPAGE per Michal Hocko > > mm/huge_memory.c | 4 ++-- > mm/shmem.c | 3 +++ > 2 files changed, 5 insertions(+), 2 deletions(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 165ea46..5881e82 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) > { > 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 2275a0f..6f09a31 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -3873,6 +3873,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; Yes, that is correct; and correctly placed. But a little more is needed: see how mm/memory.c's transhuge_vma_suitable() will only allow a pmd to be used instead of a pte if the vma offset and size permit. smaps should not report a shmem vma as THPeligible if its offset or size prevent it. And I see that should also be fixed on anon vmas: at present smaps reports even a 4kB anon vma as THPeligible, which is not right. Maybe a test like transhuge_vma_suitable() can be added into transparent_hugepage_enabled(), to handle anon and shmem together. I say "like transhuge_vma_suitable()", because that function needs an address, which here you don't have. The anon offset situation is interesting: usually anon vm_pgoff is initialized to fit with its vm_start, so the anon offset check passes; but I wonder what happens after mremap to a different address - does transhuge_vma_suitable() then prevent the use of pmds where they could actually be used? Not a Number#1 priority to investigate or fix here! but a curiosity someone might want to look into. > if (shmem_huge == SHMEM_HUGE_FORCE) > return true; > if (shmem_huge == SHMEM_HUGE_DENY) > -- > 1.8.3.1 Even with your changes ShmemPmdMapped: 4096 kB THPeligible: 0 will easily be seen: THPeligible reflects whether a huge page can be allocated and mapped by pmd in that vma; but if something else already allocated the huge page earlier, it will be mapped by pmd in this vma if offset and size allow, whatever THPeligible says. We could change transhuge_vma_suitable() to force ptes in that case, but it would be a silly change, just to make what smaps shows easier to explain. Hugh