Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp698784pxu; Thu, 26 Nov 2020 09:21:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUo1KLnecAV3BRR96qTY+BrXJF8c00UFDwWkHD94yXUTOdY28tTvGgUWFLlnG8Fro4TEex X-Received: by 2002:a17:906:6947:: with SMTP id c7mr3647872ejs.512.1606411284629; Thu, 26 Nov 2020 09:21:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606411284; cv=none; d=google.com; s=arc-20160816; b=QQ6cbEe+xtOub+hpQwuc6WGXkC1jKn4DTv6UxCdCnM1w9mGQsYSpx4MleohK9BiZBy FtgdXrQrZcdFQQArVup2hC3SI9l17uPXtZTsPDNOT0nxohBhAMJc7P7nKkxrybIIPYLK 5zA/elNBzUafSVgwQVn7ezQPJznfDkGrR7T9MtUZ0d5j6F8GJ9qGtknLFebbLrrDJlVN Sbnkg6LkUPJcbPj5T3iTrYta0OWFLrkItyidfPlj7XsT0yT5LmGFs6Tsve0vlTbDyUC+ 4k/wvEFE8Kbtj9awFo8SpIcFHedln50WOUV5qHSYpGqCXgWFyKtNPUxDi5vIDWH9OfJy VILw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=TDq6WR+Dm/a2ekWx8DBvt1609ZsN/FMIOWHdfPPOjuk=; b=YHkuDv++ZnU+grM87j6z33i/CsaEgm8Nufz26kJZ0vCJzQihE1uy2HtSueVSSmg8ks UzyVkRy4dNiEfkZOOW1AbWFfWKzZnrxhmaghkzmPI0yVAVYkOmls2tktj4GUBAIyL5Wx LFdy7MeDYUdUxtH935XoK6PbYCeO1IorSVYPQVsPanyZEMWgg2z6KrroadXhAMrnWK18 JiMs77MUzeMOUHrxCKJdpUiBKT0RJr0D9qaRp40rekGPcDx/9NBQDaBwsyCPktQVQ+9m B5BDRBPVLB1X5odNOV9D6mvqSyNz/3C+WIFN5X4tmzaKF+Z2CoYjTfeGYkujFMBKUoaz eSpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u17si3458345edx.235.2020.11.26.09.21.01; Thu, 26 Nov 2020 09:21:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404224AbgKZRSf (ORCPT + 99 others); Thu, 26 Nov 2020 12:18:35 -0500 Received: from mx2.suse.de ([195.135.220.15]:53382 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391658AbgKZRSc (ORCPT ); Thu, 26 Nov 2020 12:18:32 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C9506AC2D; Thu, 26 Nov 2020 17:18:30 +0000 (UTC) Subject: Re: [PATCH 3/3] mm,thp,shmem: make khugepaged obey tmpfs mount flags To: Rik van Riel , hughd@google.com Cc: xuyu@linux.alibaba.com, akpm@linux-foundation.org, mgorman@suse.de, aarcange@redhat.com, willy@infradead.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, linux-mm@kvack.org, mhocko@suse.com References: <20201124194925.623931-1-riel@surriel.com> <20201124194925.623931-4-riel@surriel.com> From: Vlastimil Babka Message-ID: Date: Thu, 26 Nov 2020 18:18:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20201124194925.623931-4-riel@surriel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/24/20 8:49 PM, Rik van Riel wrote: > Currently if thp enabled=[madvise], mounting a tmpfs filesystem > with huge=always and mmapping files from that tmpfs does not > result in khugepaged collapsing those mappings, despite the > mount flag indicating that it should. > > Fix that by breaking up the blocks of tests in hugepage_vma_check > a little bit, and testing things in the correct order. > > Signed-off-by: Rik van Riel > Fixes: c2231020ea7b ("mm: thp: register mm for khugepaged when merging vma for shmem") Looks ok. But, it we have sysfs thp enabled=never, and shmem mount explicitly thp enabled, then shmem mount overrides the global sysfs setting and thp's will be allocated there, right? However, khugepaged_enabled() will be false and thus khugepaged won't run at all? So a similar situation than what you're fixing here. > --- > include/linux/khugepaged.h | 2 ++ > mm/khugepaged.c | 22 ++++++++++++++++------ > 2 files changed, 18 insertions(+), 6 deletions(-) > > diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h > index c941b7377321..2fcc01891b47 100644 > --- a/include/linux/khugepaged.h > +++ b/include/linux/khugepaged.h > @@ -3,6 +3,7 @@ > #define _LINUX_KHUGEPAGED_H > > #include /* MMF_VM_HUGEPAGE */ > +#include > > > #ifdef CONFIG_TRANSPARENT_HUGEPAGE > @@ -57,6 +58,7 @@ static inline int khugepaged_enter(struct vm_area_struct *vma, > { > if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags)) > if ((khugepaged_always() || > + (shmem_file(vma->vm_file) && shmem_huge_enabled(vma)) || > (khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) && > !(vm_flags & VM_NOHUGEPAGE) && > !test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 4e3dff13eb70..abab394c4206 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -440,18 +440,28 @@ static inline int khugepaged_test_exit(struct mm_struct *mm) > static bool hugepage_vma_check(struct vm_area_struct *vma, > unsigned long vm_flags) > { > - if ((!(vm_flags & VM_HUGEPAGE) && !khugepaged_always()) || > - (vm_flags & VM_NOHUGEPAGE) || > + /* Explicitly disabled through madvise. */ > + if ((vm_flags & VM_NOHUGEPAGE) || > test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) > return false; > > - if (shmem_file(vma->vm_file) || > - (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && > - vma->vm_file && > - (vm_flags & VM_DENYWRITE))) { > + /* Enabled via shmem mount options or sysfs settings. */ > + if (shmem_file(vma->vm_file) && shmem_huge_enabled(vma)) { > return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, > HPAGE_PMD_NR); > } > + > + /* THP settings require madvise. */ > + if (!(vm_flags & VM_HUGEPAGE) && !khugepaged_always()) > + return false; > + > + /* Read-only file mappings need to be aligned for THP to work. */ > + if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file && > + (vm_flags & VM_DENYWRITE)) { > + return IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, > + HPAGE_PMD_NR); > + } > + > if (!vma->anon_vma || vma->vm_ops) > return false; > if (vma_is_temporary_stack(vma)) >