Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp885992ybi; Wed, 19 Jun 2019 09:30:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaQRJpWDoHdbh77/oAsCAFGQ6T9cuiyCeTGMnVWg64EoXCTpTJB84Fvm2MdGFKQPA0Tv32 X-Received: by 2002:a63:4105:: with SMTP id o5mr8752616pga.308.1560961801673; Wed, 19 Jun 2019 09:30:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560961801; cv=none; d=google.com; s=arc-20160816; b=njl+CUNeD43avf+gBIcl/HHUHmIxVJJPXNZUkTVM0IFFpHQHr/IVbOkpK3ZE3S5MDR M5SQLwSCo2//+Lu8HVFLwrL/NJpmSxNzXzXVe/4PUfZyZ7SeYAqTSDMKtjw97CFd1qbH YEwhiV4Kbk9IMLa4LvFilmtzd2QKnMGyy12yawWTYdR4JXerb9f4x1jwP1u2ooMmbuBs /Y3dq/d405u+3H+/Xw/8Guo4QRn2KIq6MKuTRlKwAer3mrcYZl10OQS2FjvgdAwxQGzH 6BLm2DnttHIjOh8QZQpX0FOQpxfnDRiysR91Sa2RmXlRN2knmG69tLBPiClbewyHo1L5 2pxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=arYgjf8u/K6k4mBeFecJDAyvmeQXfup1Kljv1rw5lDc=; b=I2tnBqq7XorOEijOUGNKdAoCEKkJ+UeMKJk33fTdVv63nUeMHThMNzhuzpSdfsk0/W SbbbwbU4DeW+HFrI6O4k+EFqeQoeoJLXw1Ck6Wtc8jJQbqrSzTTE17yEx1mEaWApyGEt KUpFBj9BWviEs6SCFHiaTbronJn3YojlVDON7/leJR7fKl1J1yyBTF+wNB/PF/5sE78F CqZNmcjrtjrqahJsOamRxvc9a9XhdLOf+d8GX6hZ6DrXGsdVyg+YS7RgTS7BA6jAPjMP UQU5ySwbmej/Gzvo6vlBGVsNkZFmkU5ww/D9601s3kmg0Q6hrHrv7ALazMdITkYZ1jZi KumQ== 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 62si16021293pff.216.2019.06.19.09.29.46; Wed, 19 Jun 2019 09:30:01 -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 S1729681AbfFSQ3Z (ORCPT + 99 others); Wed, 19 Jun 2019 12:29:25 -0400 Received: from out30-54.freemail.mail.aliyun.com ([115.124.30.54]:40810 "EHLO out30-54.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726251AbfFSQ3Z (ORCPT ); Wed, 19 Jun 2019 12:29:25 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R991e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0TUccovW_1560961724; Received: from US-143344MP.local(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0TUccovW_1560961724) by smtp.aliyun-inc.com(127.0.0.1); Thu, 20 Jun 2019 00:28:47 +0800 Subject: Re: [v3 PATCH 2/2] mm: thp: fix false negative of shmem vma's THP eligibility To: Vlastimil Babka , hughd@google.com, kirill.shutemov@linux.intel.com, mhocko@suse.com, rientjes@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1560401041-32207-1-git-send-email-yang.shi@linux.alibaba.com> <1560401041-32207-3-git-send-email-yang.shi@linux.alibaba.com> <4a07a6b8-8ff2-419c-eac8-3e7dc17670df@suse.cz> From: Yang Shi Message-ID: <5dde4380-68b4-66ee-2c3c-9b9da0c243ca@linux.alibaba.com> Date: Wed, 19 Jun 2019 09:28:42 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <4a07a6b8-8ff2-419c-eac8-3e7dc17670df@suse.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/19/19 5:12 AM, Vlastimil Babka wrote: > On 6/13/19 6:44 AM, 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: > ... > >> 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; > Sorry for replying rather late, and not in the v2 thread, but unlike > Hugh I'm not convinced that we should include vma size/alignment in the > test for reporting THPeligible, which was supposed to reflect > administrative settings and madvise hints. I guess it's mostly a matter > of personal feeling. But one objective distinction is that the admin > settings and madvise do have an exact binary result for the whole VMA, > while this check is more fuzzy - only part of the VMA's span might be > properly sized+aligned, and THPeligible will be 1 for the whole VMA. I think THPeligible is used to tell us if the vma is suitable for allocating THP. Both anonymous and shmem THP checks vma size/alignment to decide to or not to allocate THP. And, if vma size/alignment is not checked, THPeligible may show "true" for even 4K mapping. This doesn't make too much sense either. > >> 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) >>