Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1297572ybi; Wed, 17 Jul 2019 12:46:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+IhZtjHwpG0YLsPe7a4bGEKAVYlhG1RCOsmcpbBExtF2otLkf/6IaKjpituK8d9iHzdMd X-Received: by 2002:a17:902:b608:: with SMTP id b8mr45955473pls.303.1563392788691; Wed, 17 Jul 2019 12:46:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563392788; cv=none; d=google.com; s=arc-20160816; b=hCHug6WzHlUs6CafM9rolVKKDhfxWu9Cv6KqaMsT43mPoG0KsCd+Q4W4U+nRxAU2v6 RL5nRe+M7t+GaY+Cg+jZ7oynFjwKIAU0uSsURwTzSIahR+QUNkAQggncV2JYTDgoFSrI FZFJBxFqgfCA7epn/AwhgE7C8mE0UxQ3MvkfdoexjL/XNPJ8QhxhYHSXnakEmbp0D5Oh LQIk2s/sntfH5wrqeGN106/NzKUOtt3gXU6VsExgpI73KoJ1n7R31Dx53gwPRMZz/btk A+yIjIqMcZqlxXxGr/VwFTquefOTqCw0t/1eOef4h58/+k0HqjJkHCJDo7Rk06cBhMtf R/Bg== 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=gvjPZWoufoHncj5iyWeqiWRKnFrwf8zGjNBYtpZ6tKQ=; b=kgB5nE1qCl1vT6E9RppJWvpAEmmTt/uH9ZFEBjSA+RbC0ha5WLUUJSKi/xtMu3ktaU hXJ/hi8ni4FKW0JQeFiy5lbQCSx3vLImd8CtZzIfljCWzVGsfYC1TPw6P3VeWzFEgq9O Tk62LnnyCdbo2836/IPLmgO+VUdP7S8m3uo5WuIdasUb+yttW6Vhv4ZCUzO9MdsKeZhV T7auftiMdJ6JXroOBeiiMwaW759BUMb3Uy4Jnp3KUog8GwCuW1Iltc7vfzVfmNJtX/Np DlwyJCgxR2gpPy6bkBZxj0ZJ4FOBBayN1Hkkg/h850BE8NqPxtWYn+DpUbWUWT+THvnG IUfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=V+41nzxS; 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 v24si68665pgn.64.2019.07.17.12.46.12; Wed, 17 Jul 2019 12:46:28 -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=V+41nzxS; 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 S1729133AbfGQToe (ORCPT + 99 others); Wed, 17 Jul 2019 15:44:34 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:41582 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726598AbfGQToe (ORCPT ); Wed, 17 Jul 2019 15:44:34 -0400 Received: by mail-pl1-f193.google.com with SMTP id m9so12452024pls.8 for ; Wed, 17 Jul 2019 12:44:33 -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=gvjPZWoufoHncj5iyWeqiWRKnFrwf8zGjNBYtpZ6tKQ=; b=V+41nzxSMtHHtuKjjlYe2GfJUL8OkwTW54lqpP4dzM4zgY3shyyLaX0K65MjCbgkMA JbEoFVMktVLB3yjSnRHiCY/QGDeT/Ry1EtepMiiQZBtORT4LcsanPu+wmDHPU5A8ImJZ ldVpzOO2iZ7YzyDbWT2fLzrjfofjjisJtzT8oJ+LheNWez/iuEh8rIrXccIbc6wOmENU bymQc2QANDdpuvEugqEqUY33+9C5zNaq8aNQvWYnJfl2VIYp+NDrL1dmaf/yoMoe+wia PQa0y1K4sc3F7Xf58nEjx6tNNBQQWv75mlgYI1ha4k6Jhx5wCMoMPtZyRCR9AsEli8l9 8+aw== 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=gvjPZWoufoHncj5iyWeqiWRKnFrwf8zGjNBYtpZ6tKQ=; b=JTas0zq+PDTkv8X8qXf881rjYKIvKC95jEuHmDQPsnSaXSzab9FlGZpQAIXU30Jxqx LL9JNyZnRe77A5k8Hf+dDXUJSnzhIrRm5RlaxP8HicV3Ux7iqhiRKM7azpSQU20sVQ+F q99IOLbOxRjxT+ej5bVpmLMhhYBGG4GLMZBAjszK3jDyqud5xCNVc3LetTN861rURg3D 9ldka5jxc7kgSOch1qz1FQMuae1Q6n8j9jg4ppSJSOeTqbBDsDN6t7rT6brlLPM7fmzQ L1/u07A0VotsL3/3Ujmp+fOeHqo9r+Qg9HEBRuJ37sqLj1H6kBLMsjRCIp1o3p5BQJZZ LIRg== X-Gm-Message-State: APjAAAWWTjMwsidL/USsLb39hOGH+Yal716Vcs7JBBB+IuQC3esL2BDU 8UIuZO04upkqks9hbkEm2QYBfQ== X-Received: by 2002:a17:902:9041:: with SMTP id w1mr46275249plz.132.1563392672552; Wed, 17 Jul 2019 12:44:32 -0700 (PDT) Received: from [100.112.64.100] ([104.133.8.100]) by smtp.gmail.com with ESMTPSA id 14sm24016805pfy.40.2019.07.17.12.44.31 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Jul 2019 12:44:31 -0700 (PDT) Date: Wed, 17 Jul 2019 12:44:30 -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 2/2] mm: thp: fix false negative of shmem vma's THP eligibility In-Reply-To: <1560401041-32207-3-git-send-email-yang.shi@linux.alibaba.com> Message-ID: References: <1560401041-32207-1-git-send-email-yang.shi@linux.alibaba.com> <1560401041-32207-3-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 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") > Cc: Hugh Dickins Thanks, 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 66cad5c..b0ded06 100644 > --- a/Documentation/filesystems/proc.txt > +++ b/Documentation/filesystems/proc.txt > @@ -477,8 +477,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 01d4eb0..6a13882 100644 > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -796,7 +796,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)); > + 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 4bc2552..36f0225 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -65,10 +65,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 1bb3b8d..a807712 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) > -- > 1.8.3.1