From patchwork Mon Apr 4 20:02:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12800667 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 A08DDC433F5 for ; Mon, 4 Apr 2022 20:06:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C1E18D0007; Mon, 4 Apr 2022 16:03:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 971638D0001; Mon, 4 Apr 2022 16:03:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 811558D0007; Mon, 4 Apr 2022 16:03:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 74ADF8D0001 for ; Mon, 4 Apr 2022 16:03:23 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 53E8F24529 for ; Mon, 4 Apr 2022 20:03:13 +0000 (UTC) X-FDA: 79320270666.10.7A8B711 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf25.hostedemail.com (Postfix) with ESMTP id C0FEFA0006 for ; Mon, 4 Apr 2022 20:03:12 +0000 (UTC) Received: by mail-pf1-f174.google.com with SMTP id x31so9969069pfh.9 for ; Mon, 04 Apr 2022 13:03:12 -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=299dhLN8fZQaqsT9OGmphjyBEYT6w3EQIbst3RvXrxI=; b=pNHjfPkGU3nk4TyLoHEURVpFplmDQJP/QKBA1MTf9iPA+5O96M5KmGbjPNHgH3kGdo PB8MP/4BFQMW8iZUT0rXAvH6ICgHnflXm0yZiIGUM7ObvsZjlYZ1kOzxdSYTQ8oKUlcD cyxjX9o+hs4GHpbvU7N2kQhZtmPKCBsWlLx0CuJIf+mTLae52Gt2eRcr7K83q0NUB28Y 5ztyPyaLXwKf5AcFHDFb/wXTRVMhRIA5p7kNnRPfO85xZkwHO/SKyosZrLqhwLQsDT8W hNrKMR2Ofm3nfe4E6BIpLMjFYbX0PQryTsa8GkPDukq569Dkfw3xpXh7ltx8WWQNiRp9 ND+A== 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=299dhLN8fZQaqsT9OGmphjyBEYT6w3EQIbst3RvXrxI=; b=OntTUST6SeyzD1lSNzBfOliar2Z7sb+22pTDoOsvl/t22h3haD/n0BOyuLTeRGmZHR TnGh5+IFGapQGK78LhUyGSgjmr+ZCoR+AYi2B37i29wNUL/KsSTSznYGbftMKkW0vnLj BRIklQbxpS6mEmUd63i9QO+24x5hEKeiipkqBL9vUn8uzVAv2Htvc7tyPhhOubhrWkXT DT9eX8dzRL6iLg+IHgfy2IMCAx9ULeZJiSJAzcjyr/UHNvFuoW/rnZYjso3iDYGhNWkK dCwSA5HzAZ2MuH21bV5/+ixlkCImq9Unlo+KYIK1D1NLMAX6rMZM/bI/PBmZOgeFMOTe 5o5A== X-Gm-Message-State: AOAM533KH9nDY/RppDYolsOMD4NKxvwuri62BrY8jGk3BPg+0diP4KVl c9yEzJmwtaeJ5+qIjsfI71Y= X-Google-Smtp-Source: ABdhPJznJU9yE4ofpoTqB4D8WgSLsYOq7fqnscvbG/DJjVa+BvOJgo1PB6ZgI+8pMnraeasjO3kvtg== X-Received: by 2002:a63:4a5d:0:b0:399:5cd:1589 with SMTP id j29-20020a634a5d000000b0039905cd1589mr1293015pgl.22.1649102591800; Mon, 04 Apr 2022 13:03:11 -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 bw17-20020a056a00409100b004fadad3b93esm12779295pfb.142.2022.04.04.13.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 13:03:11 -0700 (PDT) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, linmiaohe@huawei.com, songliubraving@fb.com, riel@surriel.com, willy@infradead.org, ziy@nvidia.com, tytso@mit.edu, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 6/8] mm: khugepaged: move some khugepaged_* functions to khugepaged.c Date: Mon, 4 Apr 2022 13:02:48 -0700 Message-Id: <20220404200250.321455-7-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220404200250.321455-1-shy828301@gmail.com> References: <20220404200250.321455-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: oo87c3z4apz5fncg5iu5od9ga3erwgtd Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=pNHjfPkG; spf=pass (imf25.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C0FEFA0006 X-HE-Tag: 1649102592-546110 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: To reuse hugepage_vma_check() for khugepaged_enter() so that we could remove some duplicate code. But moving hugepage_vma_check() to khugepaged.h needs to include huge_mm.h in it, it seems not optimal to bloat khugepaged.h. And the khugepaged_* functions actually are wrappers for some non-inline functions, so it seems the benefits are not too much to keep them inline. So move the khugepaged_* functions to khugepaged.c, any callers just need to include khugepaged.h which is quite small. For example, the following patches will call khugepaged_enter() in filemap page fault path for regular filesystems to make readonly FS THP collapse more consistent. The filemap.c just needs to include khugepaged.h. Acked-by: Song Liu Signed-off-by: Yang Shi --- include/linux/khugepaged.h | 37 ++++++------------------------------- mm/khugepaged.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h index 0423d3619f26..6acf9701151e 100644 --- a/include/linux/khugepaged.h +++ b/include/linux/khugepaged.h @@ -2,10 +2,6 @@ #ifndef _LINUX_KHUGEPAGED_H #define _LINUX_KHUGEPAGED_H -#include /* MMF_VM_HUGEPAGE */ -#include - - #ifdef CONFIG_TRANSPARENT_HUGEPAGE extern struct attribute_group khugepaged_attr_group; @@ -16,6 +12,12 @@ extern void __khugepaged_enter(struct mm_struct *mm); extern void __khugepaged_exit(struct mm_struct *mm); extern void khugepaged_enter_vma_merge(struct vm_area_struct *vma, unsigned long vm_flags); +extern void khugepaged_fork(struct mm_struct *mm, + struct mm_struct *oldmm); +extern void khugepaged_exit(struct mm_struct *mm); +extern void khugepaged_enter(struct vm_area_struct *vma, + unsigned long vm_flags); + extern void khugepaged_min_free_kbytes_update(void); #ifdef CONFIG_SHMEM extern void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr); @@ -33,36 +35,9 @@ static inline void collapse_pte_mapped_thp(struct mm_struct *mm, #define khugepaged_always() \ (transparent_hugepage_flags & \ (1<flags)) - __khugepaged_enter(mm); -} - -static inline void khugepaged_exit(struct mm_struct *mm) -{ - if (test_bit(MMF_VM_HUGEPAGE, &mm->flags)) - __khugepaged_exit(mm); -} - -static inline void khugepaged_enter(struct vm_area_struct *vma, - unsigned long vm_flags) -{ - 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)) - __khugepaged_enter(vma->vm_mm); -} #else /* CONFIG_TRANSPARENT_HUGEPAGE */ static inline void khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) { diff --git a/mm/khugepaged.c b/mm/khugepaged.c index b69eda934d70..ec5b0a691d87 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -556,6 +556,26 @@ void __khugepaged_exit(struct mm_struct *mm) } } +void khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) +{ + if (test_bit(MMF_VM_HUGEPAGE, &oldmm->flags)) + __khugepaged_enter(mm); +} + +void khugepaged_exit(struct mm_struct *mm) +{ + if (test_bit(MMF_VM_HUGEPAGE, &mm->flags)) + __khugepaged_exit(mm); +} + +void khugepaged_enter(struct vm_area_struct *vma, unsigned long vm_flags) +{ + if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && + khugepaged_enabled()) + if (hugepage_vma_check(vma, vm_flags)) + __khugepaged_enter(vma->vm_mm); +} + static void release_pte_page(struct page *page) { mod_node_page_state(page_pgdat(page),