From patchwork Fri May 20 21:16:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12857453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69888C433F5 for ; Fri, 20 May 2022 21:16:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9ADA6B0078; Fri, 20 May 2022 17:16:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B4D0B6B007D; Fri, 20 May 2022 17:16:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D0226B007E; Fri, 20 May 2022 17:16:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 8EE886B0078 for ; Fri, 20 May 2022 17:16:21 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6F978735 for ; Fri, 20 May 2022 21:16:21 +0000 (UTC) X-FDA: 79487379762.11.128993B Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf15.hostedemail.com (Postfix) with ESMTP id C287CA0015 for ; Fri, 20 May 2022 21:16:03 +0000 (UTC) Received: by mail-pg1-f182.google.com with SMTP id 137so8739341pgb.5 for ; Fri, 20 May 2022 14:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uZ2MKo3NmwofqEpjSOVwGsJSdmq+ezPANYKqYBOCivQ=; b=GlUHTdvFzA+MiS/hUNdv6efIELq4i8AG5YNwOF3pCD/x8eHQ3mO/nO9rzy2mnR7XH1 ValbE4N4DtXGnshp8xRyTVvJzq2qACTDgi0ajm9hyH7DMsj5u4C2Jg8reA4QlehsVHbR be5ed75Yfa6fp38jcJq+/yfWqPbe2ETtPdPr+IVTBft67Os6XqydSX+tMIGtCeZUUOtp KiuB1bGfYS8zV6EUxtSrDxCoMRTFSmk3fUy67kQv2L/Eti7oN2DIRQTTx8mc0mLSl5Wg 2ppQD4KDMrosfKKb8KfPX1P4BH2GMZ9hcmKAcs2McyocWqVKB4rdSI04zdLEy3XJpuIN 76Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uZ2MKo3NmwofqEpjSOVwGsJSdmq+ezPANYKqYBOCivQ=; b=Mudv/Kg1BLg75xNEXN887B4Sz75z+BbsRGhnko2+9JP22soVH2iWKImxZ0PxeNaWcY ScoOQvM6NnaeW4keJbgBLstk+cnk4ADRheRhJKXlRY3CdYrkloXdwy6x8C0VaSesFCTm sR60W0AAMqeAIh7Bye7WQInFS1KRevWmyroKuNFEu8EODKohisPTjVevsKHdMkVzJTle 0ZEaX2u0r4VoKNxwSvRZbMjG0N/eil+9Gf6dE+0JjPQaHk71FR7WrG91V6OL741ZvlSF 7bMVcUdc0Jo1rv1mO0xdO2EqdqHr/MaqcMjdbSxfwC3N6L7jHIfaOmf2P6p0kKpFbe3T UObA== X-Gm-Message-State: AOAM531zEzbRpqPDYO4nRZKXTua9SNkUKNbzA0hPXxnZaOhwCt7rAiN6 /vfCtDZx2Ojrf1uJx2RZAFE= X-Google-Smtp-Source: ABdhPJxHWgmmuDTl0VVnULJFQSbEJPMKkPtl2dOD6vFWj6vfs9p9296+xsaK0tTFIq3fQZmISbfDAQ== X-Received: by 2002:a62:b515:0:b0:50a:3d51:671e with SMTP id y21-20020a62b515000000b0050a3d51671emr11785398pfe.48.1653081379866; Fri, 20 May 2022 14:16:19 -0700 (PDT) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id h1-20020a170902748100b0015e8d4eb2c2sm167620pll.268.2022.05.20.14.16.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 14:16:19 -0700 (PDT) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] mm: thp: kill transparent_hugepage_active() Date: Fri, 20 May 2022 14:16:03 -0700 Message-Id: <20220520211605.51473-6-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220520211605.51473-1-shy828301@gmail.com> References: <20220520211605.51473-1-shy828301@gmail.com> MIME-Version: 1.0 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GlUHTdvF; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: C287CA0015 X-Stat-Signature: mahwtqi5jhq1xfwjed4tu3eyrrsckcgb X-HE-Tag: 1653081363-469940 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The transparent_hugepage_active() was introduced to show THP eligibility bit in smaps in proc, smaps is the only user. But it actually does the similar check as hugepage_vma_check() which is used by khugepaged. We definitely don't have to maintain two similar checks, so kill transparent_hugepage_active(). Also move hugepage_vma_check() to huge_memory.c and huge_mm.h since it is not only for khugepaged anymore. Signed-off-by: Yang Shi --- fs/proc/task_mmu.c | 2 +- include/linux/huge_mm.h | 14 +++++++------ include/linux/khugepaged.h | 2 -- mm/huge_memory.c | 41 ++++++++++++++++++++++++++++++------ mm/khugepaged.c | 43 -------------------------------------- 5 files changed, 44 insertions(+), 58 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index f9c9abb50bb7..ab4849d07a1f 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -863,7 +863,7 @@ static int show_smap(struct seq_file *m, void *v) __show_smap(m, &mss, false); seq_printf(m, "THPeligible: %d\n", - transparent_hugepage_active(vma)); + hugepage_vma_check(vma, vma->vm_flags)); if (arch_pkeys_enabled()) seq_printf(m, "ProtectionKey: %8u\n", vma_pkey(vma)); diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 79d5919beb83..2da52ca8fd52 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -209,7 +209,8 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma) !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode); } -bool transparent_hugepage_active(struct vm_area_struct *vma); +extern bool hugepage_vma_check(struct vm_area_struct *vma, + unsigned long vm_flags); #define transparent_hugepage_use_zero_page() \ (transparent_hugepage_flags & \ @@ -358,11 +359,6 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) return false; } -static inline bool transparent_hugepage_active(struct vm_area_struct *vma) -{ - return false; -} - static inline bool transhuge_vma_size_ok(struct vm_area_struct *vma) { return false; @@ -380,6 +376,12 @@ static inline bool transhuge_vma_enabled(struct vm_area_struct *vma, return false; } +static inline bool hugepage_vma_check(struct vm_area_struct *vma, + unsigned long vm_flags) +{ + return false; +} + static inline void prep_transhuge_page(struct page *page) {} #define transparent_hugepage_flags 0UL diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h index 392d34c3c59a..795c8d2170b0 100644 --- a/include/linux/khugepaged.h +++ b/include/linux/khugepaged.h @@ -10,8 +10,6 @@ extern struct attribute_group khugepaged_attr_group; extern int khugepaged_init(void); extern void khugepaged_destroy(void); extern int start_stop_khugepaged(void); -extern bool hugepage_vma_check(struct vm_area_struct *vma, - unsigned long vm_flags); extern void __khugepaged_enter(struct mm_struct *mm); extern void __khugepaged_exit(struct mm_struct *mm); extern void khugepaged_enter_vma(struct vm_area_struct *vma, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index d633f97452c1..d9ec82892b05 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -69,18 +69,47 @@ static atomic_t huge_zero_refcount; struct page *huge_zero_page __read_mostly; unsigned long huge_zero_pfn __read_mostly = ~0UL; -bool transparent_hugepage_active(struct vm_area_struct *vma) +bool hugepage_vma_check(struct vm_area_struct *vma, + unsigned long vm_flags) { + if (!transhuge_vma_enabled(vma, vm_flags)) + return false; + + if (vm_flags & VM_NO_KHUGEPAGED) + return false; + + /* Don't run khugepaged against DAX vma */ + if (vma_is_dax(vma)) + return false; + + if (vma->vm_file && !IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - + vma->vm_pgoff, HPAGE_PMD_NR)) + return false; + if (!transhuge_vma_size_ok(vma)) return false; - if (vma_is_anonymous(vma)) - return __transparent_hugepage_enabled(vma); - if (vma_is_shmem(vma)) + + /* Enabled via shmem mount options or sysfs settings. */ + if (shmem_file(vma->vm_file)) return shmem_huge_enabled(vma); - if (transhuge_vma_enabled(vma, vma->vm_flags) && file_thp_enabled(vma)) + + if (!khugepaged_enabled()) + return false; + + /* THP settings require madvise. */ + if (!(vm_flags & VM_HUGEPAGE) && !khugepaged_always()) + return false; + + /* Only regular file is valid */ + if (file_thp_enabled(vma)) return true; - return false; + if (!vma->anon_vma || !vma_is_anonymous(vma)) + return false; + if (vma_is_temporary_stack(vma)) + return false; + + return true; } static bool get_huge_zero_page(void) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 51f0e6ea3977..a7ac1ae418f8 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -437,49 +437,6 @@ static inline int khugepaged_test_exit(struct mm_struct *mm) return atomic_read(&mm->mm_users) == 0; } -bool hugepage_vma_check(struct vm_area_struct *vma, - unsigned long vm_flags) -{ - if (!transhuge_vma_enabled(vma, vm_flags)) - return false; - - if (vm_flags & VM_NO_KHUGEPAGED) - return false; - - /* Don't run khugepaged against DAX vma */ - if (vma_is_dax(vma)) - return false; - - if (vma->vm_file && !IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - - vma->vm_pgoff, HPAGE_PMD_NR)) - return false; - - if (!transhuge_vma_size_ok(vma)) - return false; - - /* Enabled via shmem mount options or sysfs settings. */ - if (shmem_file(vma->vm_file)) - return shmem_huge_enabled(vma); - - if (!khugepaged_enabled()) - return false; - - /* THP settings require madvise. */ - if (!(vm_flags & VM_HUGEPAGE) && !khugepaged_always()) - return false; - - /* Only regular file is valid */ - if (file_thp_enabled(vma)) - return true; - - if (!vma->anon_vma || !vma_is_anonymous(vma)) - return false; - if (vma_is_temporary_stack(vma)) - return false; - - return true; -} - void __khugepaged_enter(struct mm_struct *mm) { struct mm_slot *mm_slot;