From patchwork Thu Mar 17 23:48:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12784681 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 CB094C43217 for ; Thu, 17 Mar 2022 23:48:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1B6D8D000B; Thu, 17 Mar 2022 19:48:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC8BA8D0001; Thu, 17 Mar 2022 19:48:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF46E8D000B; Thu, 17 Mar 2022 19:48:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id BF9C68D0001 for ; Thu, 17 Mar 2022 19:48:49 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9CEA761BA6 for ; Thu, 17 Mar 2022 23:48:49 +0000 (UTC) X-FDA: 79255520778.10.C829FFB Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf29.hostedemail.com (Postfix) with ESMTP id 2AF2B120007 for ; Thu, 17 Mar 2022 23:48:48 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id q13so5721401plk.12 for ; Thu, 17 Mar 2022 16:48:48 -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=e8qThGmR6qWWYZNQEqh4yIj3Ne/feg2xUmJaASesT2M=; b=Q8u/tgbEZte1l+GJAkZCMz3Ct5k4Nu5o8GV+SvDdYg7FPjhtRQ4S6BthMj0tx6333x CNQuCEPSL3r1/gAm7gZ3BvPAHQu/VIQhP548H716jpthOj1bvkeHftkCgd+iir4u5Wb/ 7QWlt6efJHKZJatCDSMMLkYyCk9YWhoclsbWlJP04Q93Yvxe/B9AG86U35LbVlxuTZE8 JutmKy2dyY9KA51e5m6N3o9gH6/XfzVlA1lI7LRdNn53bxGlRH/u9FhrTAbji6rxuDGq mZTT1gAywfZuHm247vqURRsIUcEa6NOKt+fnFQgEGI4oP4xEGbtL/qCbZSEg+FiUurEh Ei7Q== 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=e8qThGmR6qWWYZNQEqh4yIj3Ne/feg2xUmJaASesT2M=; b=wEC1V1YU4XO8eZRQTIqqBqCCexMBXih4nAykEyMVVZMppOAg91kIJXtm/BYXlE24is nOP9EaXzlZFytd4RoAKKViyPEFMZyNUlXWIIBDZh5GBBRoafd4WuQ+1XOoAAcmaMqL/v 0ddcvGbFlFxtLxW4OnNqECsFTiln5uG5wN3kdpKhBF3gEZ7ahEk8yll/mBQPLPPHdH3L MPH60UvKUM0tHBoms7TFt0zwBurMf0QWhgeWZwdBbb7n+vXJ4aOmL664sn6AinYq10xm TUSwdM8yRn6b3NnPLtoD9Yta+BsMVxSv8zFeCAVikoywDV+5dGHiK8ATO6iWINz42TjN P+dg== X-Gm-Message-State: AOAM533hhvNjLcX1WFHx8LrlrUVA1y//ZtnQd5C4LKeqx/ddW6x8t0E0 3YZrtjc37HWVXbNIPpq0LmM= X-Google-Smtp-Source: ABdhPJyp8fZ/A0uESg9v+zKNEb0Mpr9NlB5MF0RbJ0fvxFGMYc0TTPAaDF54pFiTc/DyCZMv8jCtSg== X-Received: by 2002:a17:902:dad2:b0:151:f895:9c31 with SMTP id q18-20020a170902dad200b00151f8959c31mr7666608plx.93.1647560928254; Thu, 17 Mar 2022 16:48:48 -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 o7-20020aa79787000000b004f8e44a02e2sm8581329pfp.45.2022.03.17.16.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 16:48:47 -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, akpm@linux-foundation.org, tytso@mit.edu, adilger.kernel@dilger.ca, darrick.wong@oracle.com Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH 7/8] mm: khugepaged: introduce khugepaged_enter_file() helper Date: Thu, 17 Mar 2022 16:48:26 -0700 Message-Id: <20220317234827.447799-8-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220317234827.447799-1-shy828301@gmail.com> References: <20220317234827.447799-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2AF2B120007 X-Stat-Signature: 7bni3zith38ekikpyaw4ycu57zdu5dj1 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Q8u/tgbE"; spf=pass (imf29.hostedemail.com: domain of shy828301@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-HE-Tag: 1647560928-527236 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 following patch will have filesystems code call khugepaged_enter() to make readonly FS THP collapse more consistent. Extract the current implementation used by shmem in khugepaged_enter_file() helper so that it could be reused by other filesystems and export the symbol for modules. Signed-off-by: Yang Shi --- include/linux/khugepaged.h | 6 ++++++ mm/khugepaged.c | 11 +++++++++++ mm/shmem.c | 14 ++++---------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h index 54e169116d49..06464e9a1f91 100644 --- a/include/linux/khugepaged.h +++ b/include/linux/khugepaged.h @@ -21,6 +21,8 @@ extern void khugepaged_fork(struct mm_struct *mm, extern void khugepaged_exit(struct mm_struct *mm); extern void khugepaged_enter(struct vm_area_struct *vma, unsigned long vm_flags); +extern void khugepaged_enter_file(struct vm_area_struct *vma, + unsigned long vm_flags); extern void khugepaged_min_free_kbytes_update(void); #ifdef CONFIG_SHMEM @@ -53,6 +55,10 @@ static inline void khugepaged_enter(struct vm_area_struct *vma, unsigned long vm_flags) { } +static inline void khugepaged_enter_file(struct vm_area_struct *vma, + unsigned long vm_flags) +{ +} static inline void khugepaged_enter_vma_merge(struct vm_area_struct *vma, unsigned long vm_flags) { diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 4cb4379ecf25..93c9072983e2 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -577,6 +577,17 @@ void khugepaged_enter(struct vm_area_struct *vma, unsigned long vm_flags) __khugepaged_enter(vma->vm_mm); } +void khugepaged_enter_file(struct vm_area_struct *vma, unsigned long 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); +} +EXPORT_SYMBOL_GPL(khugepaged_enter_file); + static void release_pte_page(struct page *page) { mod_node_page_state(page_pgdat(page), diff --git a/mm/shmem.c b/mm/shmem.c index a09b29ec2b45..c2346e5d2b24 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2233,11 +2233,9 @@ static int shmem_mmap(struct file *file, struct vm_area_struct *vma) file_accessed(file); vma->vm_ops = &shmem_vm_ops; - if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && - ((vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK) < - (vma->vm_end & HPAGE_PMD_MASK)) { - khugepaged_enter(vma, vma->vm_flags); - } + + khugepaged_enter_file(vma, vma->vm_flags); + return 0; } @@ -4132,11 +4130,7 @@ int shmem_zero_setup(struct vm_area_struct *vma) vma->vm_file = file; vma->vm_ops = &shmem_vm_ops; - if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && - ((vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK) < - (vma->vm_end & HPAGE_PMD_MASK)) { - khugepaged_enter(vma, vma->vm_flags); - } + khugepaged_enter_file(vma, vma->vm_flags); return 0; }