From patchwork Tue May 10 20:32:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12845501 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 61E4EC433F5 for ; Tue, 10 May 2022 20:32:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C08028D0008; Tue, 10 May 2022 16:32:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8FA78D0002; Tue, 10 May 2022 16:32:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E1C98D0008; Tue, 10 May 2022 16:32:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8DEB88D0002 for ; Tue, 10 May 2022 16:32:48 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 6B094619E1 for ; Tue, 10 May 2022 20:32:48 +0000 (UTC) X-FDA: 79450982016.08.D02125F Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf01.hostedemail.com (Postfix) with ESMTP id 69991400A9 for ; Tue, 10 May 2022 20:32:36 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id x18so17792775plg.6 for ; Tue, 10 May 2022 13:32:47 -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=qd2V4gYzSQy9/AY2gyoqLCp31tKNiHFMo2KNXlpicIc=; b=nnkjdEyWUoaYouv5dBAoGcvMsB87vwqUX748f2MsldAO7yY2nJU4YYvQv7c2KBgswg tJs67T7a9GYnD6yfXc0BrOiQvzpX93PsvRUnk8L1FLg5mOY7so3PMu9dNQsBnjcJh8gQ NG9gh/QcWXwoeOubR/w9wI+JMA/K/3/iyv3UvszSqPTEJa9KwXDp8zde+LXoHI7yvoid Xu6TP07Fpxw1KtaX8FkDQqbO68QHiWqxZsAuHuU0Pn2Uxs7VtX7L46oPgndAYLcHGX+R EV2ssx29fWm6xMW65GB6Pm3lXH1BFltML328WqhU0glpcmuAog2eLaj6KdLUSWgT9lGh P90g== 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=qd2V4gYzSQy9/AY2gyoqLCp31tKNiHFMo2KNXlpicIc=; b=FGLICPKujOrub9nDzdkDqXxVB/B4AHzN4Wkw01JzvhzLnXoXzM1xUgXPcbpzXFI3gz TEB00J8KYgTl32AMLa/EBqC+u1DNTzHXNtocOEvWFpqQ6Txr3KydhbCkP2U3ftXtkOrE hlSx0JHgUJt2hPCYuJ0Ys7Q79BYq8U8V1ERhhBsOS06Z9J16/x5dki+YhwjQf7U6HYu7 eA1XBK8ZsyDvD886dIRaUsxRgeERaB74zEgXvO250XINjNgHPrZXuW7VAxcJxZKQ8WY7 x7ogS0/q+/RQU8CcDe8zQ6w+47CAURV3j0Zt75k73ssJZmGBCOlcqJuGYUPuuXT8NsBN S8/w== X-Gm-Message-State: AOAM533wXmvpVyRp1HGHkRB+Zu7wD+/vrZq5tb1GInRqGz/AUoC1v9ac FUw5YV62wDrFN6JBD/zDMzc= X-Google-Smtp-Source: ABdhPJyJfGQKpSGT3s9qaPsV4W+cAXWw7gFsDEedVDpmC7IxU3X+gl0uNVAXM3FDMXRcdZNwCPJvkw== X-Received: by 2002:a17:90b:4a03:b0:1dc:756a:2463 with SMTP id kk3-20020a17090b4a0300b001dc756a2463mr1673723pjb.68.1652214767036; Tue, 10 May 2022 13:32:47 -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 v17-20020a1709028d9100b0015e8d4eb1d4sm58898plo.30.2022.05.10.13.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 13:32:46 -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: [v4 PATCH 6/8] mm: khugepaged: make hugepage_vma_check() non-static Date: Tue, 10 May 2022 13:32:20 -0700 Message-Id: <20220510203222.24246-7-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220510203222.24246-1-shy828301@gmail.com> References: <20220510203222.24246-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 69991400A9 X-Stat-Signature: m48swczy5ucwpkkb5uciff3bwnmte8mr Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=nnkjdEyW; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of shy828301@gmail.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspam-User: X-HE-Tag: 1652214756-852906 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 hugepage_vma_check() could be reused by khugepaged_enter() and khugepaged_enter_vma_merge(), but it is static in khugepaged.c. Make it non-static and declare it in khugepaged.h. Suggested-by: Vlastimil Babka Signed-off-by: Yang Shi --- include/linux/khugepaged.h | 14 ++++++-------- mm/khugepaged.c | 25 +++++++++---------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h index 0423d3619f26..c340f6bb39d6 100644 --- a/include/linux/khugepaged.h +++ b/include/linux/khugepaged.h @@ -3,8 +3,6 @@ #define _LINUX_KHUGEPAGED_H #include /* MMF_VM_HUGEPAGE */ -#include - #ifdef CONFIG_TRANSPARENT_HUGEPAGE extern struct attribute_group khugepaged_attr_group; @@ -12,6 +10,8 @@ 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_merge(struct vm_area_struct *vma, @@ -55,13 +55,11 @@ static inline void khugepaged_exit(struct mm_struct *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)) + if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && + khugepaged_enabled()) { + if (hugepage_vma_check(vma, vm_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 7815218ab960..dec449339964 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -437,8 +437,8 @@ static inline int khugepaged_test_exit(struct mm_struct *mm) return atomic_read(&mm->mm_users) == 0; } -static bool hugepage_vma_check(struct vm_area_struct *vma, - unsigned long vm_flags) +bool hugepage_vma_check(struct vm_area_struct *vma, + unsigned long vm_flags) { if (!transhuge_vma_enabled(vma, vm_flags)) return false; @@ -508,20 +508,13 @@ void __khugepaged_enter(struct mm_struct *mm) void khugepaged_enter_vma_merge(struct vm_area_struct *vma, unsigned long vm_flags) { - unsigned long hstart, hend; - - /* - * khugepaged only supports read-only files for non-shmem files. - * khugepaged does not yet work on special mappings. And - * file-private shmem THP is not supported. - */ - if (!hugepage_vma_check(vma, vm_flags)) - return; - - hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; - hend = vma->vm_end & HPAGE_PMD_MASK; - if (hstart < hend) - khugepaged_enter(vma, vm_flags); + if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags) && + khugepaged_enabled() && + (((vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK) < + (vma->vm_end & HPAGE_PMD_MASK))) { + if (hugepage_vma_check(vma, vm_flags)) + __khugepaged_enter(vma->vm_mm); + } } void __khugepaged_exit(struct mm_struct *mm)