From patchwork Mon Feb 28 23:57:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12763900 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 A881FC433EF for ; Mon, 28 Feb 2022 23:58:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39FD88D0003; Mon, 28 Feb 2022 18:58:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 34FED8D0001; Mon, 28 Feb 2022 18:58:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EFDE8D0003; Mon, 28 Feb 2022 18:58:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0172.hostedemail.com [216.40.44.172]) by kanga.kvack.org (Postfix) with ESMTP id 0FAEC8D0001 for ; Mon, 28 Feb 2022 18:58:06 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C215C9A274 for ; Mon, 28 Feb 2022 23:58:05 +0000 (UTC) X-FDA: 79193854530.30.9C915F5 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf28.hostedemail.com (Postfix) with ESMTP id 558FBC0004 for ; Mon, 28 Feb 2022 23:58:05 +0000 (UTC) Received: by mail-pj1-f43.google.com with SMTP id bx9-20020a17090af48900b001bc64ee7d3cso652678pjb.4 for ; Mon, 28 Feb 2022 15:58:05 -0800 (PST) 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=7qVTXgEk7jDbNe3RIcGVI67pez+4LMoxn8Ha8tkNEVM=; b=I/uneKQYRfBvvU1QYfMRxA9cdeOKNDx/GA80yQj/Vii5WOYT8JOLzKQ39OtDsLJu0e w68+trSpW+r3e+66nPqchuDl41VrZKCXAQGBhtvqKIYb9WYtGnPkgetwDILXcx3Ufnm6 qMBAVb3txy8flmueV6alKq9spfgtUhlVfk7krxGlnlerA9XBBtqiWGZLBz96Yoa74hLj Od7jXKzhB8UI9wQQeuJYi4wYkOq19NjFPBQEOFDqXYdIwIKiaAZkzknKapA4y0+lcBGv J2k+NZJFmd7jy+8HFikciV61Djwz36lqySOqaLUGqMA7vNp0f/ai6ZRZpZv18TqYZ8j0 EYOQ== 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=7qVTXgEk7jDbNe3RIcGVI67pez+4LMoxn8Ha8tkNEVM=; b=LETJEJp9sIqfo9OICrThHGTjG7QutnvGGIMMM6c7G8IcXq2A6dxdHfE309WluaZmU7 XthK5qaz6HeUbbm1R46aZN+kstk54GAF+3miqjzVFoT4e9wmYMtQKWYXdjdzJw7cHPMv vDkVjgCp1lqy+kooHNqA0di+oW3U7k1VvEO6w9ihNiEOincT3ny1Q6NyLh+sCvURIQCC m4igGhkiEJ6oqElewMgSz71Z7lOY7C6Fte+jd/jC7lfAj/Y4Mb4dUA2246YB4sIdy62d yIaDJJiC1UND2Z0oGbCzcWeFE76bO5HBCWvgV5f8bilai7FbarBf4CGGBtNMf+bEJ8LV ydUQ== X-Gm-Message-State: AOAM530UEXWfFn8Aeadra0qKYq0EaCXoqooQc0+GXc6Qvpi3uOhslMM5 om1L3a0GNcHYSZ+RCs2KwbY= X-Google-Smtp-Source: ABdhPJwS2d/mQvKUD9RT9YRNebvue4fyV0w7v+iF01ewR6eZtUfak47eHHmfgpbarwiWX2HhFS9nLA== X-Received: by 2002:a17:902:b204:b0:14d:a8c8:af37 with SMTP id t4-20020a170902b20400b0014da8c8af37mr23074869plr.108.1646092684471; Mon, 28 Feb 2022 15:58:04 -0800 (PST) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id on15-20020a17090b1d0f00b001b9d1b5f901sm396963pjb.47.2022.02.28.15.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 15:58:04 -0800 (PST) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, songliubraving@fb.com, linmiaohe@huawei.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: 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: [PATCH 1/8] sched: coredump.h: clarify the use of MMF_VM_HUGEPAGE Date: Mon, 28 Feb 2022 15:57:34 -0800 Message-Id: <20220228235741.102941-2-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220228235741.102941-1-shy828301@gmail.com> References: <20220228235741.102941-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 558FBC0004 X-Stat-Signature: 746gn3ywfm4jtgpotrpx4ikzu9awewjg Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="I/uneKQY"; spf=pass (imf28.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.43 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1646092685-971841 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: MMF_VM_HUGEPAGE is set as long as the mm is available for khugepaged by khugepaged_enter(), not only when VM_HUGEPAGE is set on vma. Correct the comment to avoid confusion. Signed-off-by: Yang Shi Reviewed-by: Miaohe Lin --- include/linux/sched/coredump.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h index 4d9e3a656875..4d0a5be28b70 100644 --- a/include/linux/sched/coredump.h +++ b/include/linux/sched/coredump.h @@ -57,7 +57,8 @@ static inline int get_dumpable(struct mm_struct *mm) #endif /* leave room for more dump flags */ #define MMF_VM_MERGEABLE 16 /* KSM may merge identical pages */ -#define MMF_VM_HUGEPAGE 17 /* set when VM_HUGEPAGE is set on vma */ +#define MMF_VM_HUGEPAGE 17 /* set when mm is available for + khugepaged */ /* * This one-shot flag is dropped due to necessity of changing exe once again * on NFS restore From patchwork Mon Feb 28 23:57:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12763901 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 A2290C433F5 for ; Mon, 28 Feb 2022 23:58:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C7F38D0005; Mon, 28 Feb 2022 18:58:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3770B8D0001; Mon, 28 Feb 2022 18:58:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 265D88D0005; Mon, 28 Feb 2022 18:58:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id 18A328D0001 for ; Mon, 28 Feb 2022 18:58:10 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C658E181C34FB for ; Mon, 28 Feb 2022 23:58:09 +0000 (UTC) X-FDA: 79193854698.25.27A56B7 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf07.hostedemail.com (Postfix) with ESMTP id 49F1540006 for ; Mon, 28 Feb 2022 23:58:09 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id 27so12921331pgk.10 for ; Mon, 28 Feb 2022 15:58:09 -0800 (PST) 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=+7utIe6zwoBoauJ2NDcsB651FtDL3xoIf2xpV9Lf8S0=; b=qXcrsfxt+hvAbzaB5ZB/MyAxUI9xoo6HoxydYwNc3CkF77+DBqZC8T5imRGPWrcRAA esh99RrRkr7bWkbYvpNi9XG4kEFjKk26aEuhEQ/J2Iu8zksxCUbIAmUrNU7+waOfM9lM yfphxzALZU1B1wD/dqWHXYoL+DYtJ8io1U1jAf70r+taKnzydII+k6v084eL8SSkYMue c/qRxVY6MuheK7tBR1u/mxmKUtMTqzKqdCy1Qp/R2wVHpWQUGVniSyRZBa5c6c6fO0A3 5mVx8u6UxkZ+0YSiav8lTwmXy40ZD5wmo7tyzS5539mlw0GPSZRBGbghOu2hFqm0mI1y vrbw== 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=+7utIe6zwoBoauJ2NDcsB651FtDL3xoIf2xpV9Lf8S0=; b=xd28NUm6DMPzUhIkXqgKDvPUEf8K4gA3B8M7yZGDnEV3J3nsieWoJbO4ZOgAEWd9VC zPtyAh+bRMQDQJfjovsvdB1REIdacaK1OwXmjOATeD8ij48FlBF6UyUxm1z+Xmds436R u3is0mp5pq7NhJwVnvgvNwqSf3a8JZ/3BTeaqb2ktQ6AF0MweYw+RDDv8BcySoxT+C4+ 2QpOEG8fqIVWS9t28Y+J4m4k4hNT6wtsZ4VpOzISmUxfLlm5+p6KgrXIMez+FQtjytLf Eg4omz1NggZfuChxuY25xnz060NbYzyPkJdxyj5m7paD0R+FJMMHpv5AH7WOgYYrUK0s yNTQ== X-Gm-Message-State: AOAM533MI1s4Gp0/eNxhVDb0PS4zGRL980cTBa8yVZiLkOp4fU4N1krL 8U0XGi+R1l3qqoUdUMj7+J0= X-Google-Smtp-Source: ABdhPJyUkJBFxZjHIgqTERZs6mkUNDMkgNt9kOSA3xlCm6y1IkyOi4wDqhot8eXP8IdFiudmtbtypw== X-Received: by 2002:a65:63d6:0:b0:375:7cc6:2b63 with SMTP id n22-20020a6563d6000000b003757cc62b63mr19289215pgv.598.1646092688435; Mon, 28 Feb 2022 15:58:08 -0800 (PST) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id on15-20020a17090b1d0f00b001b9d1b5f901sm396963pjb.47.2022.02.28.15.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 15:58:07 -0800 (PST) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, songliubraving@fb.com, linmiaohe@huawei.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: 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: [PATCH 2/8] mm: khugepaged: remove redundant check for VM_NO_KHUGEPAGED Date: Mon, 28 Feb 2022 15:57:35 -0800 Message-Id: <20220228235741.102941-3-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220228235741.102941-1-shy828301@gmail.com> References: <20220228235741.102941-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 49F1540006 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=qXcrsfxt; spf=pass (imf07.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: pcm5a1cha6jidpejhbpak3s8r8kz6aqc X-HE-Tag: 1646092689-21700 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000065, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The hugepage_vma_check() called by khugepaged_enter_vma_merge() does check VM_NO_KHUGEPAGED. Remove the check from caller and move the check in hugepage_vma_check() up. More checks may be run for VM_NO_KHUGEPAGED vmas, but MADV_HUGEPAGE is definitely not a hot path, so cleaner code does outweigh. Signed-off-by: Yang Shi Reviewed-by: Miaohe Lin --- mm/khugepaged.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 131492fd1148..82c71c6da9ce 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -366,8 +366,7 @@ int hugepage_madvise(struct vm_area_struct *vma, * register it here without waiting a page fault that * may not happen any time soon. */ - if (!(*vm_flags & VM_NO_KHUGEPAGED) && - khugepaged_enter_vma_merge(vma, *vm_flags)) + if (khugepaged_enter_vma_merge(vma, *vm_flags)) return -ENOMEM; break; case MADV_NOHUGEPAGE: @@ -446,6 +445,9 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, if (!transhuge_vma_enabled(vma, vm_flags)) return false; + if (vm_flags & VM_NO_KHUGEPAGED) + return false; + if (vma->vm_file && !IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, HPAGE_PMD_NR)) return false; @@ -471,7 +473,8 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, return false; if (vma_is_temporary_stack(vma)) return false; - return !(vm_flags & VM_NO_KHUGEPAGED); + + return true; } int __khugepaged_enter(struct mm_struct *mm) From patchwork Mon Feb 28 23:57:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12763902 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 D4A45C433FE for ; Mon, 28 Feb 2022 23:58:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 74AA68D0006; Mon, 28 Feb 2022 18:58:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FA748D0001; Mon, 28 Feb 2022 18:58:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C1918D0006; Mon, 28 Feb 2022 18:58:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id 4D2758D0001 for ; Mon, 28 Feb 2022 18:58:13 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 09FF9181C34FB for ; Mon, 28 Feb 2022 23:58:13 +0000 (UTC) X-FDA: 79193854866.21.CB40697 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf01.hostedemail.com (Postfix) with ESMTP id A036940002 for ; Mon, 28 Feb 2022 23:58:12 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id ge19-20020a17090b0e1300b001bcca16e2e7so587793pjb.3 for ; Mon, 28 Feb 2022 15:58:12 -0800 (PST) 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=p8kDVzZeSF/gSse0fUjCfu4T2T1nlW4Umj0Wis3mUpc=; b=DtcxAF2YbSTtBa+NYkVVk8WdqZzc0TXAiOomstKNeYxOjPsnsVSIu8Trep2mjqdb6T jsLDhrJA39R4NAIZbYdTbTIhrI4ckIyWNXGzkPBt2C2niwCCOqSUV7wFrB3ISqJma8WL htd5qRu9kgUvXHxzxeL7RODzYPXvqmG8BHkIMbvDSsLcpnzN+/2htnU3Og2Ef9JsANgl bS7M1W3T7vOnGTGO8nKSku88gdZaBDVo3ZaM1qM46mlyzTnZ9+cq/oxfZiiTxklUgr4G f7BSoTKxcbhMlNvaPOPR6IDGpuEXv3DD54YgtamAD8PHO+GleKkbydY1IgzpNBF6ZjgM DHYg== 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=p8kDVzZeSF/gSse0fUjCfu4T2T1nlW4Umj0Wis3mUpc=; b=UHygDQk4F1BY3C2wxZrO/OWzJwbE2qWtjARaPC5Et80C1VbqW+zYeVCEsmBQumHeyn mnORMuoX0k+XWGMwASZCnBPqNi5Rx1vPNlTnZkevEzVgDw9yAjrJOIj7q1hiXzzxqi5C 1j75vV1B1kmjCvUddkX73lAlna0/c0O38J9jJYP9PIQ7afbmte2/sTg55Xf6uqOZRrrk pU9UE+bOipTd1VFcCI9S2BOEEnWwvdy3tn55vrV38xXs13WE60F1BFvtgIFINp+XwxlV VFqnSEBu1gYT+ZCiEkAeGy2tTHi7USZ9f5eN1RZCz0sDD4/PmQrw12+2Lz/T1NxVCWpS LiDw== X-Gm-Message-State: AOAM532t1uflS+gimDxCyE8HJPscbgIhZfBoIXjMy7bGq1Yl+2XXW7N9 dPu5LbCqgFzaChjJMfL4QkE= X-Google-Smtp-Source: ABdhPJyF4X1yuiU1rNjzj1hH5DMaMGbsoU0rLs4bppVSjZZfontbcTs0n4CH4W0cRbWUzlx+TYRyaA== X-Received: by 2002:a17:902:a60d:b0:14f:b781:ccd7 with SMTP id u13-20020a170902a60d00b0014fb781ccd7mr23252925plq.2.1646092691740; Mon, 28 Feb 2022 15:58:11 -0800 (PST) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id on15-20020a17090b1d0f00b001b9d1b5f901sm396963pjb.47.2022.02.28.15.58.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 15:58:11 -0800 (PST) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, songliubraving@fb.com, linmiaohe@huawei.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: 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: [PATCH 3/8] mm: khugepaged: skip DAX vma Date: Mon, 28 Feb 2022 15:57:36 -0800 Message-Id: <20220228235741.102941-4-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220228235741.102941-1-shy828301@gmail.com> References: <20220228235741.102941-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A036940002 X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DtcxAF2Y; spf=pass (imf01.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: csttwwxeyuqibmgqhypdia87y57wjzxn X-HE-Tag: 1646092692-866594 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 DAX vma may be seen by khugepaged when the mm has other khugepaged suitable vmas. So khugepaged may try to collapse THP for DAX vma, but it will fail due to page sanity check, for example, page is not on LRU. So it is not harmful, but it is definitely pointless to run khugepaged against DAX vma, so skip it in early check. Signed-off-by: Yang Shi Reviewed-by: Miaohe Lin --- mm/khugepaged.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 82c71c6da9ce..a0e4fa33660e 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -448,6 +448,10 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, 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; From patchwork Mon Feb 28 23:57:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12763903 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 5D327C433EF for ; Mon, 28 Feb 2022 23:58:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFFD48D0007; Mon, 28 Feb 2022 18:58:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DAFEB8D0001; Mon, 28 Feb 2022 18:58:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C52EE8D0007; Mon, 28 Feb 2022 18:58:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id B74AF8D0001 for ; Mon, 28 Feb 2022 18:58:16 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 86CB723627 for ; Mon, 28 Feb 2022 23:58:16 +0000 (UTC) X-FDA: 79193854992.15.2F159D1 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf30.hostedemail.com (Postfix) with ESMTP id 0F0C780003 for ; Mon, 28 Feb 2022 23:58:15 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id a5so11707961pfv.9 for ; Mon, 28 Feb 2022 15:58:15 -0800 (PST) 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=pVRCwJsnXRapubfoKiJlcGvRUl3JFnCz5Si7tbrZLpI=; b=LPc9yKE7q4GUZk+StLd67GP4m3Wy74Y/4FO2wtG0pHgA9+i6BhG5pSo3LIXwy+kN/2 ytsJ6UjvwHuhTIhaUSwtm/andOpYZtnta0CknadHD4T+bAQrLhYKdm9hkDohw/HLl10e KhtiWm7dDcIOVueaxOvjjmPsnJPw8OOZo88af1mNJs5GRMHwajphoBIii3bb2fB8cJAl Tiu9j4DsmPyFLindLKcapatb/57mYkm/H6uwcJl3cIqzjUppbP48jpVh1g259tXyB3vg 8fh0mI+AYeim7dcwv/oESfglqvrA2KeXw5J7SspnPhAILjJ+opx+IOzlH+kLgJhEuOTE TWmg== 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=pVRCwJsnXRapubfoKiJlcGvRUl3JFnCz5Si7tbrZLpI=; b=EggKRPhEhPUoOXeOMjnGKAoU0gMUnMHUvOaKsfGaomfDThQYDgikk3kvw23pV+ag0h 9UsG5oYBBo6HGsjwa9fgzlK87uM68Bo+G/N0pkHAA0O0egpRvraGrdwXT/fTWa+3Se1F upfSyf78Lh52LH2Dk6/vBTciZtjo52pmdX1QdjZa8Y7vJal5aN3z60xFkgzURwRDoEQQ CskYwu8fiT0V1RDR52UpBoVT0xtgVB0T/l9kuBSwxduyEnhunrVemdnxmCLeQAjVyUud xzTInRkrUrRpa+K9dz8+VYw0hpU4CqtryUyuGVoNFZJcZ+V1yO32z9GIIUXtIezMLttf ZfnQ== X-Gm-Message-State: AOAM53376BvVDHKPZFtoa8AI/rhT0ZrEPGtrW17fCaouort08k40JOx4 zgOrbZKryNffOktYJmmdf98= X-Google-Smtp-Source: ABdhPJyuOTDdsUnt1yb7WW+NRJmeVFGOWeL67LCaX3vde5vYx61mSkUMtKzLTWNpTwg6F1RLu5vGwA== X-Received: by 2002:a05:6a00:134c:b0:4e1:75b:ca4b with SMTP id k12-20020a056a00134c00b004e1075bca4bmr24166481pfu.37.1646092695126; Mon, 28 Feb 2022 15:58:15 -0800 (PST) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id on15-20020a17090b1d0f00b001b9d1b5f901sm396963pjb.47.2022.02.28.15.58.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 15:58:14 -0800 (PST) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, songliubraving@fb.com, linmiaohe@huawei.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: 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: [PATCH 4/8] mm: thp: only regular file could be THP eligible Date: Mon, 28 Feb 2022 15:57:37 -0800 Message-Id: <20220228235741.102941-5-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220228235741.102941-1-shy828301@gmail.com> References: <20220228235741.102941-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0F0C780003 X-Stat-Signature: a9h5heffruqzriak4cfr3mooffjzd3io Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LPc9yKE7; spf=pass (imf30.hostedemail.com: domain of shy828301@gmail.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1646092695-934963 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: Since commit a4aeaa06d45e ("mm: khugepaged: skip huge page collapse for special files"), khugepaged just collapses THP for regular file which is the intended usecase for readonly fs THP. Only show regular file as THP eligible accordingly. And make file_thp_enabled() available for khugepaged too in order to remove duplicate code. Signed-off-by: Yang Shi Reported-by: kernel test robot Reported-by: Dan Carpenter --- include/linux/huge_mm.h | 9 +++++++++ mm/huge_memory.c | 11 ++--------- mm/khugepaged.c | 9 ++------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index e4c18ba8d3bf..e6d867f72458 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -172,6 +172,15 @@ static inline bool __transparent_hugepage_enabled(struct vm_area_struct *vma) return false; } +static inline bool file_thp_enabled(struct vm_area_struct *vma) +{ + struct inode *inode = vma->vm_file->f_inode; + + return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) && vma->vm_file && + (vma->vm_flags & VM_EXEC) && + !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode); +} + bool transparent_hugepage_active(struct vm_area_struct *vma); #define transparent_hugepage_use_zero_page() \ diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 406a3c28c026..a87b3df63209 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -64,13 +64,6 @@ static atomic_t huge_zero_refcount; struct page *huge_zero_page __read_mostly; unsigned long huge_zero_pfn __read_mostly = ~0UL; -static inline bool file_thp_enabled(struct vm_area_struct *vma) -{ - return transhuge_vma_enabled(vma, vma->vm_flags) && vma->vm_file && - !inode_is_open_for_write(vma->vm_file->f_inode) && - (vma->vm_flags & VM_EXEC); -} - bool transparent_hugepage_active(struct vm_area_struct *vma) { /* The addr is used to check if the vma size fits */ @@ -82,8 +75,8 @@ bool transparent_hugepage_active(struct vm_area_struct *vma) return __transparent_hugepage_enabled(vma); if (vma_is_shmem(vma)) return shmem_huge_enabled(vma); - if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) - return file_thp_enabled(vma); + if (transhuge_vma_enabled(vma, vma->vm_flags) && file_thp_enabled(vma)) + return true; return false; } diff --git a/mm/khugepaged.c b/mm/khugepaged.c index a0e4fa33660e..3dbac3e23f43 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -465,13 +465,8 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, return false; /* Only regular file is valid */ - if (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && vma->vm_file && - (vm_flags & VM_EXEC)) { - struct inode *inode = vma->vm_file->f_inode; - - return !inode_is_open_for_write(inode) && - S_ISREG(inode->i_mode); - } + if (file_thp_enabled(vma)) + return true; if (!vma->anon_vma || vma->vm_ops) return false; From patchwork Mon Feb 28 23:57:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12763904 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 49B65C433EF for ; Mon, 28 Feb 2022 23:58:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB3CF8D0008; Mon, 28 Feb 2022 18:58:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D621E8D0001; Mon, 28 Feb 2022 18:58:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDB778D0008; Mon, 28 Feb 2022 18:58:20 -0500 (EST) 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 AF62D8D0001 for ; Mon, 28 Feb 2022 18:58:20 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 87B5C8186C for ; Mon, 28 Feb 2022 23:58:20 +0000 (UTC) X-FDA: 79193855160.11.F638F06 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf14.hostedemail.com (Postfix) with ESMTP id F38E8100006 for ; Mon, 28 Feb 2022 23:58:19 +0000 (UTC) Received: by mail-pj1-f49.google.com with SMTP id iq13-20020a17090afb4d00b001bc4437df2cso655910pjb.2 for ; Mon, 28 Feb 2022 15:58:19 -0800 (PST) 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=PYzHG/r/zQJfX7Jqdvp+ttkJo6GETokQfZcD3GwLWs8=; b=SwTpvGt1o++d9q/YF6TkggxExOdqLIPnW6LotUSHwj+vou9wxNG/ApPWwYoJlBAb2L m2PII6WBUyNjfhBbIzPYAWKG+RWhIFep0dOuKK3KGRr5OWmi8bQrANDC7tFYVCXdyVOI jsiCyJg7Ryf02RqlLKWSWCnL8nqqg3b0obMQ6iibCh+FOGbuleLru+hTqPity+EQ2na9 WVhYXH+dzGnZqQRqFuhwN5wV152RMgWgc31oOZd/DneDkFd//MADonXge+HZkWl+OSlW 5ou5ygKDfNQz9WjWHxhdNO71sz4DZ/jSF2kgDEm5SHDE+Nc4qj9hjEDB6+4GQlaNtG+i KI/w== 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=PYzHG/r/zQJfX7Jqdvp+ttkJo6GETokQfZcD3GwLWs8=; b=VDbBVNxpaitqXXf4Koe2E1H+XZ4yVJrnQRDfcni6n3QroFXUMhBEdm+ZjMkI0HRGy4 QbIuNw3xf/jOoFfJhkqbtjRBhU37dypZa+Z1esa3QiXuRvZpErfaWWf+AkhceV7Wvq/0 BHVpWGN5dYkkxBf1KLDa+0RJArjneD3y7qtvfbaYKfLBjyRfhU8mvH7l75zm1BPm+Fzv EYYEM+5NbZldayz26UVOyc+Md1/+Uw3nekF/Fr98EXS0KjTM9Z6D9YBLPOF2DPr0Pt9S AUd5vVgAXPwZl9O/INtlKXUXgYn3O+6wY2gZat/uW4IvgAg7P/eDrmvgjaBx0DRwMUHx tBLg== X-Gm-Message-State: AOAM533p9/8Um7PDbF8qGRWkCrAKCkqOGhjPQNsACLimpgTbVkugg1Og xKZteK8rg8bsYzRLRnkD1QQ= X-Google-Smtp-Source: ABdhPJyurHvAr5zzgjNeHZWTfLVrv7GL1aHUSkClbjW1FEdxYfjL1nZKILiili3ESpSsU8yJM0MUTQ== X-Received: by 2002:a17:902:7296:b0:14f:2a67:b400 with SMTP id d22-20020a170902729600b0014f2a67b400mr23297170pll.172.1646092698866; Mon, 28 Feb 2022 15:58:18 -0800 (PST) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id on15-20020a17090b1d0f00b001b9d1b5f901sm396963pjb.47.2022.02.28.15.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 15:58:18 -0800 (PST) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, songliubraving@fb.com, linmiaohe@huawei.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: 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: [PATCH 5/8] mm: khugepaged: make khugepaged_enter() void function Date: Mon, 28 Feb 2022 15:57:38 -0800 Message-Id: <20220228235741.102941-6-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220228235741.102941-1-shy828301@gmail.com> References: <20220228235741.102941-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: F38E8100006 X-Stat-Signature: q3i9iz3xdpa9qtirtj5k6h57ihy74jhg X-Rspam-User: Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SwTpvGt1; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf14.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=shy828301@gmail.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646092699-378222 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 most callers of khugepaged_enter() don't care about the return value. Only dup_mmap(), anonymous THP page fault and MADV_HUGEPAGE handle the error by returning -ENOMEM. Actually it is not harmful for them to ignore the error case either. It also sounds overkilling to fail fork() and page fault early due to khugepaged_enter() error, and MADV_HUGEPAGE does set VM_HUGEPAGE flag regardless of the error. Signed-off-by: Yang Shi --- include/linux/khugepaged.h | 30 ++++++++++++------------------ kernel/fork.c | 4 +--- mm/huge_memory.c | 4 ++-- mm/khugepaged.c | 18 +++++++----------- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h index 2fcc01891b47..0423d3619f26 100644 --- a/include/linux/khugepaged.h +++ b/include/linux/khugepaged.h @@ -12,10 +12,10 @@ extern struct attribute_group khugepaged_attr_group; extern int khugepaged_init(void); extern void khugepaged_destroy(void); extern int start_stop_khugepaged(void); -extern int __khugepaged_enter(struct mm_struct *mm); +extern void __khugepaged_enter(struct mm_struct *mm); extern void __khugepaged_exit(struct mm_struct *mm); -extern int khugepaged_enter_vma_merge(struct vm_area_struct *vma, - unsigned long vm_flags); +extern void khugepaged_enter_vma_merge(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); @@ -40,11 +40,10 @@ static inline void collapse_pte_mapped_thp(struct mm_struct *mm, (transparent_hugepage_flags & \ (1<flags)) - return __khugepaged_enter(mm); - return 0; + __khugepaged_enter(mm); } static inline void khugepaged_exit(struct mm_struct *mm) @@ -53,7 +52,7 @@ static inline void khugepaged_exit(struct mm_struct *mm) __khugepaged_exit(mm); } -static inline int khugepaged_enter(struct vm_area_struct *vma, +static inline void khugepaged_enter(struct vm_area_struct *vma, unsigned long vm_flags) { if (!test_bit(MMF_VM_HUGEPAGE, &vma->vm_mm->flags)) @@ -62,27 +61,22 @@ static inline int khugepaged_enter(struct vm_area_struct *vma, (khugepaged_req_madv() && (vm_flags & VM_HUGEPAGE))) && !(vm_flags & VM_NOHUGEPAGE) && !test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) - if (__khugepaged_enter(vma->vm_mm)) - return -ENOMEM; - return 0; + __khugepaged_enter(vma->vm_mm); } #else /* CONFIG_TRANSPARENT_HUGEPAGE */ -static inline int khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) +static inline void khugepaged_fork(struct mm_struct *mm, struct mm_struct *oldmm) { - return 0; } static inline void khugepaged_exit(struct mm_struct *mm) { } -static inline int khugepaged_enter(struct vm_area_struct *vma, - unsigned long vm_flags) +static inline void khugepaged_enter(struct vm_area_struct *vma, + unsigned long vm_flags) { - return 0; } -static inline int khugepaged_enter_vma_merge(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) { - return 0; } static inline void collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr) diff --git a/kernel/fork.c b/kernel/fork.c index a024bf6254df..dc85418c426a 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -523,9 +523,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, retval = ksm_fork(mm, oldmm); if (retval) goto out; - retval = khugepaged_fork(mm, oldmm); - if (retval) - goto out; + khugepaged_fork(mm, oldmm); prev = NULL; for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) { diff --git a/mm/huge_memory.c b/mm/huge_memory.c index a87b3df63209..ec2490d6af09 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -725,8 +725,8 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf) return VM_FAULT_FALLBACK; if (unlikely(anon_vma_prepare(vma))) return VM_FAULT_OOM; - if (unlikely(khugepaged_enter(vma, vma->vm_flags))) - return VM_FAULT_OOM; + khugepaged_enter(vma, vma->vm_flags); + if (!(vmf->flags & FAULT_FLAG_WRITE) && !mm_forbids_zeropage(vma->vm_mm) && transparent_hugepage_use_zero_page()) { diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 3dbac3e23f43..b87af297e652 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -366,8 +366,7 @@ int hugepage_madvise(struct vm_area_struct *vma, * register it here without waiting a page fault that * may not happen any time soon. */ - if (khugepaged_enter_vma_merge(vma, *vm_flags)) - return -ENOMEM; + khugepaged_enter_vma_merge(vma, *vm_flags); break; case MADV_NOHUGEPAGE: *vm_flags &= ~VM_HUGEPAGE; @@ -476,20 +475,20 @@ static bool hugepage_vma_check(struct vm_area_struct *vma, return true; } -int __khugepaged_enter(struct mm_struct *mm) +void __khugepaged_enter(struct mm_struct *mm) { struct mm_slot *mm_slot; int wakeup; mm_slot = alloc_mm_slot(); if (!mm_slot) - return -ENOMEM; + return; /* __khugepaged_exit() must not run from under us */ VM_BUG_ON_MM(khugepaged_test_exit(mm), mm); if (unlikely(test_and_set_bit(MMF_VM_HUGEPAGE, &mm->flags))) { free_mm_slot(mm_slot); - return 0; + return; } spin_lock(&khugepaged_mm_lock); @@ -505,11 +504,9 @@ int __khugepaged_enter(struct mm_struct *mm) mmgrab(mm); if (wakeup) wake_up_interruptible(&khugepaged_wait); - - return 0; } -int khugepaged_enter_vma_merge(struct vm_area_struct *vma, +void khugepaged_enter_vma_merge(struct vm_area_struct *vma, unsigned long vm_flags) { unsigned long hstart, hend; @@ -520,13 +517,12 @@ int khugepaged_enter_vma_merge(struct vm_area_struct *vma, * file-private shmem THP is not supported. */ if (!hugepage_vma_check(vma, vm_flags)) - return 0; + return; hstart = (vma->vm_start + ~HPAGE_PMD_MASK) & HPAGE_PMD_MASK; hend = vma->vm_end & HPAGE_PMD_MASK; if (hstart < hend) - return khugepaged_enter(vma, vm_flags); - return 0; + khugepaged_enter(vma, vm_flags); } void __khugepaged_exit(struct mm_struct *mm) From patchwork Mon Feb 28 23:57:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12763905 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 47EC0C433F5 for ; Mon, 28 Feb 2022 23:58:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D66188D0009; Mon, 28 Feb 2022 18:58:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CED368D0001; Mon, 28 Feb 2022 18:58:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8D0E8D0009; Mon, 28 Feb 2022 18:58:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id A9C468D0001 for ; Mon, 28 Feb 2022 18:58:24 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8607B235D1 for ; Mon, 28 Feb 2022 23:58:24 +0000 (UTC) X-FDA: 79193855328.13.E429392 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf12.hostedemail.com (Postfix) with ESMTP id 2044B40005 for ; Mon, 28 Feb 2022 23:58:23 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id 132so12947161pga.5 for ; Mon, 28 Feb 2022 15:58:23 -0800 (PST) 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=g+Z88nKMaMfnoSMNb28nSkaCjqMBUKAv77UuVBn2dOA=; b=Y/eAj4zOI32uQO07S2u9fw4pyH5VUHMWjTICZaR2LXS1QNnXSUZWy8gwZObI0JlAuT eV7p0ri47A+rjBcmwwR0YL1tP8tc7DgO9DSTYR3BFkxLcKOec3g/0ZKKLLrLHbLuSTDJ 1t3XLM3wv3r6DoCOg4FiXvLqtLPe8epceOXb7JXhjc2NQ9H14MlP/qxYUVORZzEsy0vc PxP/F2Uslq/UxPlOvY9swJgpq7Easigg3RYr0FLqZ4wHbLvFMQMaiQbEIwmCazkhxHUp AyEhW8Shpi8rx1XYpm/lisIWpPZQpD1WPyXPU8sLHszlNGHtFo+kWUoz7BuMO94Uy5WG PIzA== 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=g+Z88nKMaMfnoSMNb28nSkaCjqMBUKAv77UuVBn2dOA=; b=Do6wXq9t/KOb6esJYJF/TBeuv8YDqtUdlhr9wGhtpMuHFGyo1Gb1Sa2aSQIMk50MeK XlqdEGupTtOW5uC+7YCBf04lYsO3+nb5YFsTrj37Dxi17EIYdTB1GE+bIo6IijkigPIX fVZ8zZYI3u7MYpJeGz9qF+qoM1CXCdYnkiY4i2Cc0uwdQxIvc9KKZtumJep/K1YigzUb UggQ4d5S+ElKS1fHyeyib+gfS+6FXiTqApiz5wk4EYsk/eoLQqFR5QO80UTCRqDBDPvx xrD0hrqohkEpcKkSW6h3YHAN+BMsqEH7QMUcAALK7T2LEnrJkBPOKW8EMe3AsvE/GREM itMg== X-Gm-Message-State: AOAM532+fKzRjDndm59Q1uc8FVoVK6dvLF3QLyX3dkEtsIuLx7D8K0X2 aRoqkKIAi6ajDfaZ9iJwEpw= X-Google-Smtp-Source: ABdhPJxBLejg9ODYXcpvvGlLqL7Xi68l/FsoGoG/EIgU1d8hoBFNE9JpZGiFHfRFdlAWUyzpUpx/8Q== X-Received: by 2002:a63:790d:0:b0:373:cc0b:5b6a with SMTP id u13-20020a63790d000000b00373cc0b5b6amr19448962pgc.119.1646092703220; Mon, 28 Feb 2022 15:58:23 -0800 (PST) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id on15-20020a17090b1d0f00b001b9d1b5f901sm396963pjb.47.2022.02.28.15.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 15:58:22 -0800 (PST) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, songliubraving@fb.com, linmiaohe@huawei.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: 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: [PATCH 6/8] mm: khugepaged: move some khugepaged_* functions to khugepaged.c Date: Mon, 28 Feb 2022 15:57:39 -0800 Message-Id: <20220228235741.102941-7-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220228235741.102941-1-shy828301@gmail.com> References: <20220228235741.102941-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2044B40005 X-Stat-Signature: 6u9ghecnr9ir1cbyga9rctgyg9jnehqy Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Y/eAj4zO"; spf=pass (imf12.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-HE-Tag: 1646092703-961860 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: This move also makes the following patches easier. The following patches will call khugepaged_enter() for regular filesystems to make readonly FS THP collapse more consistent. They need to use some macros defined in huge_mm.h, for example, HPAGE_PMD_*, but it seems not preferred to polute filesystems code with including unnecessary header files. With this move the filesystems code just need include khugepaged.h, which is quite small and the use is quite specific, to call khugepaged_enter() to hook mm with khugepaged. 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. This also helps to reuse hugepage_vma_check() for khugepaged_enter() so that we could remove some duplicate checks. Signed-off-by: Yang Shi --- include/linux/khugepaged.h | 33 ++++++--------------------------- mm/khugepaged.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/include/linux/khugepaged.h b/include/linux/khugepaged.h index 0423d3619f26..54e169116d49 100644 --- a/include/linux/khugepaged.h +++ b/include/linux/khugepaged.h @@ -16,6 +16,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 +39,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 b87af297e652..4cb4379ecf25 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -557,6 +557,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), From patchwork Mon Feb 28 23:57:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12763906 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 5D4ECC433F5 for ; Mon, 28 Feb 2022 23:58:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB18F8D000A; Mon, 28 Feb 2022 18:58:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D615C8D0001; Mon, 28 Feb 2022 18:58:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C29158D000A; Mon, 28 Feb 2022 18:58:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id B59EC8D0001 for ; Mon, 28 Feb 2022 18:58:27 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 943BE6118C for ; Mon, 28 Feb 2022 23:58:27 +0000 (UTC) X-FDA: 79193855454.06.89D1569 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf19.hostedemail.com (Postfix) with ESMTP id 1F0F21A000F for ; Mon, 28 Feb 2022 23:58:26 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id ev16-20020a17090aead000b001bc3835fea8so679402pjb.0 for ; Mon, 28 Feb 2022 15:58:26 -0800 (PST) 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=LcgiviPPtKQf+Yoyq7Ym1LQh5IjQuQxUzZMQnQbNObkY79MjvEU+0kT6e2d2QOYJ28 tmpc48fdX2xECAAqffdE8n4vm5kr12od2ZdR6uC5+gf7A48Ht9EdyR+1YOjiyugwFLrm 5W4ivZBBhe+WR1ochAVmnUXIQZqGo592s0Kc6Pojz1QdmoYvfgESOIMeu/AgXzb0B7Ao VUCwG/TqnODlUmhIKslMesq9l8MNCzhovKjS1Nd0KBgSbVc8TAjwo4zmQa5io6BrNT2+ NT+4fl2mPyYMgZXW3z5h8oE3c+Ds5tKm+K7yegxLhKtChJShB9U7Gs7AAco/a80ERQgu ES0Q== 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=ODMOrE7gOENWbeUBzE2edY8iK9RWsXNL+aO3fBpv1k31QGq9F/srQoN6AaLypAiBj2 NuSC+z720bmwuy0I3pR78lEZ5u2v6heM7QPgEnzw/bIdS0Zr1LnwGbjlMKMOuUELXo4L d6ZVGSqKmE4zAZSFLu9skxAN6B66wTOnGOzzi+EDw5r79i/EX5Y/HyA8vN9Pc11mvScI rVEHusTKkDMOwhxCeJwO45Nb2P/snkZyNEz1UafWGu/vopjbipIh/MqR/KcnlNDxAYe/ CxK8iFI7L2XTs/4VoLEUQIIrvNAGG0KV46QzbHsf8V1Td1s/k64EFMqNb9GNSs2bnr3v 1Ijg== X-Gm-Message-State: AOAM531GCZJmuNE/kAdgdAx15WbFzPbz5GXB501SsplR314LlqowG9Gd VtXog/Jduz53gfwaGmfIq28= X-Google-Smtp-Source: ABdhPJyFc6bKerDrlYwteOuLB48KU0sCJ2MnBiYTLqL/dBe2GXiIupe81JUUbwoTRmj9GFlCEYKzlQ== X-Received: by 2002:a17:90b:3b4d:b0:1bc:a5a7:b389 with SMTP id ot13-20020a17090b3b4d00b001bca5a7b389mr18923376pjb.148.1646092706213; Mon, 28 Feb 2022 15:58:26 -0800 (PST) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id on15-20020a17090b1d0f00b001b9d1b5f901sm396963pjb.47.2022.02.28.15.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 15:58:25 -0800 (PST) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, songliubraving@fb.com, linmiaohe@huawei.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: 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: [PATCH 7/8] mm: khugepaged: introduce khugepaged_enter_file() helper Date: Mon, 28 Feb 2022 15:57:40 -0800 Message-Id: <20220228235741.102941-8-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220228235741.102941-1-shy828301@gmail.com> References: <20220228235741.102941-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1F0F21A000F X-Stat-Signature: xomte8ccnh65y3maj55kakqpphmhahy6 X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LcgiviPP; spf=pass (imf19.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam07 X-HE-Tag: 1646092706-928179 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; } From patchwork Mon Feb 28 23:57:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12763907 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 27CB1C433F5 for ; Mon, 28 Feb 2022 23:58:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B41A38D000B; Mon, 28 Feb 2022 18:58:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AF0278D0001; Mon, 28 Feb 2022 18:58:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DF328D000B; Mon, 28 Feb 2022 18:58:32 -0500 (EST) 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 8FCB98D0001 for ; Mon, 28 Feb 2022 18:58:32 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 593C4235D1 for ; Mon, 28 Feb 2022 23:58:32 +0000 (UTC) X-FDA: 79193855664.15.B9DC909 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf13.hostedemail.com (Postfix) with ESMTP id D8ADF20008 for ; Mon, 28 Feb 2022 23:58:31 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id 195so12947384pgc.6 for ; Mon, 28 Feb 2022 15:58:31 -0800 (PST) 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=lpJtQjEfn/J2FKfZSO5FEN5nDVRpWWfEH9M+CcSvJbU=; b=VLRQXiy3wvMknW7AOO7IVvKT7MqkbdlU3FLw3ClWWTqHa1MhRB+cT54O6woccfVv23 bPVM9qXq6z9fQnsc1ZNinyshivIpU9XgnlE6GxxVR1pVJGieloj7NEL4/9Y56UqfEefA nt0ayjMOUb9cb5rL/nilpAkiprwoLdMwikh2BzDI0fmBq2RU3iHJb5syWs73VxIvmf8s vaJN5zmC0ipjUwAO6ioaulNabDVSklq6nQ0EHwtl1muE1bO4Tn2al5xuHpb3H/mVmLqH zt4VDKst1elD4wKiZ07Ed36eOtFfAxmYtn6WW6JoTyUtsIPpcErbDYEt5qorV2Crwkr8 TRUw== 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=lpJtQjEfn/J2FKfZSO5FEN5nDVRpWWfEH9M+CcSvJbU=; b=OQ7g8ng5VLwqE0xX3bsrDirpDmdItNZ1syO2x+SukjzhnigRZgJVhSs8aJAmkf64eI X0+t+tgAq0Kplrzrnp9HCHGlwUfPxFtnK2vvQg5KNhJi7cPb06L2FyFqXx+5u/mA71ui dmeQ5mB8vtGtVzs6NPGQUjsoicQYGXG+RQcIxRJ3CaV06MNIpxNn5gSoPGOGxs/We+xf CQdJ1jPrfP87c/UJ8hu7tQ5vQJyjVRqjbySTVXqUIn7a105rbs7kJOq3OFYxtHqcSf2z HH7Qynp1Ur5w0OZgqm4R3nb/br2LWj/EA99/JoVSF4AljXn7yfYVGo0+MOj/LquqUNmr oqag== X-Gm-Message-State: AOAM533zgkTb6E1kR7d4EKKvzKnnUslWjnjY50/YoidghAdWooAqBt+s 6P0xkgpGCWt8f/RK3/7R9b4= X-Google-Smtp-Source: ABdhPJzyv0UQbz9tZczy02j/XLMhXWEhyZDVPmYSr4FxI3UgPBCDu42TpFtDCT4zx3Gb1O0sASg6pA== X-Received: by 2002:a05:6a00:22d3:b0:4f3:d439:7189 with SMTP id f19-20020a056a0022d300b004f3d4397189mr18780779pfj.79.1646092711038; Mon, 28 Feb 2022 15:58:31 -0800 (PST) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id on15-20020a17090b1d0f00b001b9d1b5f901sm396963pjb.47.2022.02.28.15.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 15:58:30 -0800 (PST) From: Yang Shi To: vbabka@suse.cz, kirill.shutemov@linux.intel.com, songliubraving@fb.com, linmiaohe@huawei.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: 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: [PATCH 8/8] fs: register suitable readonly vmas for khugepaged Date: Mon, 28 Feb 2022 15:57:41 -0800 Message-Id: <20220228235741.102941-9-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20220228235741.102941-1-shy828301@gmail.com> References: <20220228235741.102941-1-shy828301@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: zk6znc7abq5iozqu8io96dkhfhbezt7f Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=VLRQXiy3; spf=pass (imf13.hostedemail.com: domain of shy828301@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Queue-Id: D8ADF20008 X-HE-Tag: 1646092711-350817 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 readonly FS THP relies on khugepaged to collapse THP for suitable vmas. But it is kind of "random luck" for khugepaged to see the readonly FS vmas (https://lore.kernel.org/linux-mm/00f195d4-d039-3cf2-d3a1-a2c88de397a0@suse.cz/) since currently the vmas are registered to khugepaged when: - Anon huge pmd page fault - VMA merge - MADV_HUGEPAGE - Shmem mmap If the above conditions are not met, even though khugepaged is enabled it won't see readonly FS vmas at all. MADV_HUGEPAGE could be specified explicitly to tell khugepaged to collapse this area, but when khugepaged mode is "always" it should scan suitable vmas as long as VM_NOHUGEPAGE is not set. So make sure readonly FS vmas are registered to khugepaged to make the behavior more consistent. Registering the vmas in mmap path seems more preferred from performance point of view since page fault path is definitely hot path. Reported-by: Vlastimil Babka Signed-off-by: Yang Shi --- fs/ext4/file.c | 4 ++++ fs/xfs/xfs_file.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 8cc11715518a..b894cd5aff44 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "ext4.h" #include "ext4_jbd2.h" #include "xattr.h" @@ -782,6 +783,9 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma) } else { vma->vm_ops = &ext4_file_vm_ops; } + + khugepaged_enter_file(vma, vma->vm_flags); + return 0; } diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 5bddb1e9e0b3..d94144b1fb0f 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -30,6 +30,7 @@ #include #include #include +#include static const struct vm_operations_struct xfs_file_vm_ops; @@ -1407,6 +1408,9 @@ xfs_file_mmap( vma->vm_ops = &xfs_file_vm_ops; if (IS_DAX(inode)) vma->vm_flags |= VM_HUGEPAGE; + + khugepaged_enter_file(vma, vma->vm_flags); + return 0; }