Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3796134yba; Tue, 23 Apr 2019 09:44:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvA8k8hPlknf0PYWC/mfpPg1Nok7IUnkgHWPyIh6IJUm5BTgq2WPpFGhjKisFDCK3ONdzz X-Received: by 2002:a17:902:2a6a:: with SMTP id i97mr27275428plb.273.1556037875846; Tue, 23 Apr 2019 09:44:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556037875; cv=none; d=google.com; s=arc-20160816; b=aORCJfhuDR3OFsXg2lyLC5jDx6lLMGPkd5qzxdgR4qV/hS1GzgVu+Btpi2blygyziE o8qwKHV4QqEkFCu3dAhGF7ZZ+7fXZ16sSZkqaoBmfwhlwToe0w2D/qkuHU8cWFpo+q2l EHy525fOMJ1TnS9kI9H4AF1F/bHkgs0hGOiULw7tHonOTKaWbBNi3H4zU4T0dtgmH/gy LgNn81lxjceH7Mr29YrgVMVgVM7ucvteJVqNpjxMY4PpzpZVFtpg/cAeIBg7X3rnE6FG r0L6o9hKpURTzbVY4a/c0oE2L9Ku7XQmbStlti0seQU8AhUvMqHGQo360L7bO2szg2zR 0mEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=st9ctL0bwQXPnG+ZDcH92e0dsG3UcS5ETD78Lf3mweQ=; b=ln50em/qdW6KClRJTREcWfpJi/FRHMI5bBalkh6Yfr/5XMA17cuB53kgF2wqLk6JaJ 2uJMuux2onrWliiyhP858KMrJiMf9h1uM4B9nUrJJEWlNmi8ovXsEzd3Fj2FP1kFJ74x J4w6+UzEQgBAtfO6qF6SnD9ljuJUDfWpuanPxbCoI875WBYmigMxJIMRq+iXdD/X5mpR Nm8Tf5L7q6OQq/71S9A0ZERxKQoQBXt34kqchbi0LsWZtpcU6fL3D6ZBeAJs2qAwJYkI hTBXbpWC2VW+9rVt7kY3o8Q3tRp+n9Ic07xt/t734MKxzq9by7kCttl1kfqC5/rR8ccd +NyQ== 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 c13si2449403pfp.48.2019.04.23.09.44.20; Tue, 23 Apr 2019 09:44:35 -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 S1729109AbfDWQn1 (ORCPT + 99 others); Tue, 23 Apr 2019 12:43:27 -0400 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:40429 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727656AbfDWQn1 (ORCPT ); Tue, 23 Apr 2019 12:43:27 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0TQ4.3kP_1556037781; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TQ4.3kP_1556037781) by smtp.aliyun-inc.com(127.0.0.1); Wed, 24 Apr 2019 00:43:15 +0800 From: Yang Shi To: mhocko@suse.com, vbabka@suse.cz, rientjes@google.com, kirill@shutemov.name, akpm@linux-foundation.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH] mm: thp: fix false negative of shmem vma's THP eligibility Date: Wed, 24 Apr 2019 00:43:01 +0800 Message-Id: <1556037781-57869-1-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; if (shmem_huge == SHMEM_HUGE_FORCE) return true; if (shmem_huge == SHMEM_HUGE_DENY) -- 1.8.3.1