Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp467053pxf; Thu, 8 Apr 2021 06:51:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5rftzM6XOjswPZ58i0zUAyLOTAojIWm4qATRm3JzSfBbDZqnxcX8QuQDTEoRbZ9ybs65m X-Received: by 2002:a05:6402:430c:: with SMTP id m12mr11943795edc.138.1617889867482; Thu, 08 Apr 2021 06:51:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617889867; cv=none; d=google.com; s=arc-20160816; b=L/PzNvNB122hyXvcn21bcUQ6smJiu+2pR20mZBM2Q7OUgeZdphSAaGmExi2INcH9tz j34L3b+9DAUbeZ/3gK2epgJ5CpYJ0y686G3j+56q/JKr8dscKLnIDVKtAuk0KEU72eKZ /h84MrW3ob053L28DsO2vt5TDzyxEClLKfvPDW63qKxdX+Yjg8U9CAnkmj0XfTA5vhty 8H6w38pkicLuxDZjq2nklzkla71moUnPmb5whCqay8NlelzCkgjX00qkhiq+eSGUICRc apir3OI0vNe4vLXaKssftZnTWbaFDPVGBvYNE0zFf/zahJUUoUWxsxrNY61Vf7LKfd9Q 6yOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=87PKWiZvQRIIAr841agmMMnwG7Sfs9WVfkUdue6O4oE=; b=NBCmVigR70Lj22TnuzyrN94ZXyT594d3SZwERPn6xiA6puKolm9cVBvETNsRLOT0zZ 9MnTwk3bwgqiKw7hmeKQHLcW7xA6Ppz4U+WNwrk6w96EbEvjUICvi6A2hqwjf0kG6YvX crC+0qXGIzgrjUfTFtDO0lz92G0ctqT9rzR+8SvkanZ32T36wjrzcDRFucD+15v/o3d0 xz2wz8dMTierVxdcNgCeYwUPtvDY+JD6wMmhG1urvygyHH+i5CEsNmUGcnZPDaTeaU8f QYgrl66jMGA42XBO2YUMiIUKYPjnWFrq5gxi783scJWDLNxYI02eUQZo6BCo7Cr1RmiC Nd+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=unzXDrKZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kf14si4366546ejc.693.2021.04.08.06.50.40; Thu, 08 Apr 2021 06:51:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=unzXDrKZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231838AbhDHNts (ORCPT + 99 others); Thu, 8 Apr 2021 09:49:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231758AbhDHNtb (ORCPT ); Thu, 8 Apr 2021 09:49:31 -0400 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A159C061763; Thu, 8 Apr 2021 06:49:20 -0700 (PDT) Received: by mail-qv1-xf33.google.com with SMTP id x27so879977qvd.2; Thu, 08 Apr 2021 06:49:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=87PKWiZvQRIIAr841agmMMnwG7Sfs9WVfkUdue6O4oE=; b=unzXDrKZVRVNgdOWvT69zBNx43Wdw6oIbVPgMz7IfDwKl3hTrM5u61AV6I+qRT71+q ZxQhwb5Hw/Ae62zMpLYLyEmbU1bXVvE5qUT+LPbHTJsmR83P7wdQ8TSJ/e2O3DvLki+n pk4UglKI+Ab49FJM6VFUO4aQO/mfMJ7BaMJ9q6DR8zRPcAerBS7puLo2xndKnJzO8lz3 J4eXquDTCsAPhdCICXbdoRbyqBJm46H0UWmItWxEFTv8640oJ/2VlHnv2U6OwWdg44bV uGCevFD4Ytt/lmm/ttFYNxwRoDPHrec/zzPuwv6Zzf/Q2Ul8hTEnDtTYsNopwoopo9G2 zeow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=87PKWiZvQRIIAr841agmMMnwG7Sfs9WVfkUdue6O4oE=; b=kld2MqfGnarLU+qN0KKHSQO/dO8koqnLkhg7bEZBVBrSVeZWe8gdlyCIRmbVLMGSz+ dmyysWGhWwgbQDBJg/+Lti2/96s6z9BTd3BIMrSInJOmINhfcilfxrsKged8h8iQFKKd mArJ8ATimAnv54tTjqJu/MHmb7nwMEmHyp2iyeO/PDSjwm/iYv259CpuskntuQrXBFeA yMlcnvqBugnpkpZpWxmx4yBHZqK4D0N01cQLal0YPEJC5yIAh0G+OHD1SlUiPz2VtVWW U0Rc/wgS5xpu+vibXzJuVjt/FeLwBwQ3FNi4cHiOOnb+r3sa82eiYX6cG0bQmIUV2Vhe dU1g== X-Gm-Message-State: AOAM531SKNx8QE6GxOjM1DYSety9F7Edo1V37Xj9whtJUTWdX1acSl3/ 8By+BHCfLI5KN16W/Szb9qg= X-Received: by 2002:a0c:a0c6:: with SMTP id c64mr8689910qva.57.1617889759742; Thu, 08 Apr 2021 06:49:19 -0700 (PDT) Received: from localhost.localdomain (ec2-35-169-212-159.compute-1.amazonaws.com. [35.169.212.159]) by smtp.gmail.com with ESMTPSA id h16sm506094qkh.18.2021.04.08.06.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Apr 2021 06:49:19 -0700 (PDT) From: SeongJae Park To: akpm@linux-foundation.org Cc: SeongJae Park , Jonathan.Cameron@Huawei.com, acme@kernel.org, alexander.shishkin@linux.intel.com, amit@kernel.org, benh@kernel.crashing.org, brendanhiggins@google.com, corbet@lwn.net, david@redhat.com, dwmw@amazon.com, elver@google.com, fan.du@intel.com, foersleo@amazon.de, greg@kroah.com, gthelen@google.com, guoju.fgj@alibaba-inc.com, mgorman@suse.de, minchan@kernel.org, mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org, riel@surriel.com, rientjes@google.com, rostedt@goodmis.org, rppt@kernel.org, shakeelb@google.com, shuah@kernel.org, sj38.park@gmail.com, snu@amazon.de, vbabka@suse.cz, vdavydov.dev@gmail.com, zgf574564920@gmail.com, linux-damon@amazon.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v27 04/13] mm/idle_page_tracking: Make PG_idle reusable Date: Thu, 8 Apr 2021 13:48:45 +0000 Message-Id: <20210408134854.31625-5-sj38.park@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210408134854.31625-1-sj38.park@gmail.com> References: <20210408134854.31625-1-sj38.park@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: SeongJae Park PG_idle and PG_young allow the two PTE Accessed bit users, Idle Page Tracking and the reclaim logic concurrently work while don't interfere each other. That is, when they need to clear the Accessed bit, they set PG_young to represent the previous state of the bit, respectively. And when they need to read the bit, if the bit is cleared, they further read the PG_young to know whether the other has cleared the bit meanwhile or not. We could add another page flag and extend the mechanism to use the flag if we need to add another concurrent PTE Accessed bit user subsystem. However, the space is limited. Meanwhile, if the new subsystem is mutually exclusive with IDLE_PAGE_TRACKING or interfering with it is not a real problem, it would be ok to simply reuse the PG_idle flag. However, it's impossible because the flags are dependent on IDLE_PAGE_TRACKING. To allow such reuse of the flags, this commit separates the PG_young and PG_idle flag logic from IDLE_PAGE_TRACKING and introduces new kernel config, 'PAGE_IDLE_FLAG'. Hence, a new subsystem would be able to reuse PG_idle without depending on IDLE_PAGE_TRACKING. In the next commit, DAMON's reference implementation of the virtual memory address space monitoring primitives will use it. Signed-off-by: SeongJae Park Reviewed-by: Shakeel Butt --- include/linux/page-flags.h | 4 ++-- include/linux/page_ext.h | 2 +- include/linux/page_idle.h | 6 +++--- include/trace/events/mmflags.h | 2 +- mm/Kconfig | 8 ++++++++ mm/page_ext.c | 12 +++++++++++- mm/page_idle.c | 10 ---------- 7 files changed, 26 insertions(+), 18 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 04a34c08e0a6..6be2c1e2fb48 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -131,7 +131,7 @@ enum pageflags { #ifdef CONFIG_MEMORY_FAILURE PG_hwpoison, /* hardware poisoned page. Don't touch */ #endif -#if defined(CONFIG_IDLE_PAGE_TRACKING) && defined(CONFIG_64BIT) +#if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT) PG_young, PG_idle, #endif @@ -436,7 +436,7 @@ PAGEFLAG_FALSE(HWPoison) #define __PG_HWPOISON 0 #endif -#if defined(CONFIG_IDLE_PAGE_TRACKING) && defined(CONFIG_64BIT) +#if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT) TESTPAGEFLAG(Young, young, PF_ANY) SETPAGEFLAG(Young, young, PF_ANY) TESTCLEARFLAG(Young, young, PF_ANY) diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index aff81ba31bd8..fabb2e1e087f 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -19,7 +19,7 @@ struct page_ext_operations { enum page_ext_flags { PAGE_EXT_OWNER, PAGE_EXT_OWNER_ALLOCATED, -#if defined(CONFIG_IDLE_PAGE_TRACKING) && !defined(CONFIG_64BIT) +#if defined(CONFIG_PAGE_IDLE_FLAG) && !defined(CONFIG_64BIT) PAGE_EXT_YOUNG, PAGE_EXT_IDLE, #endif diff --git a/include/linux/page_idle.h b/include/linux/page_idle.h index 1e894d34bdce..d8a6aecf99cb 100644 --- a/include/linux/page_idle.h +++ b/include/linux/page_idle.h @@ -6,7 +6,7 @@ #include #include -#ifdef CONFIG_IDLE_PAGE_TRACKING +#ifdef CONFIG_PAGE_IDLE_FLAG #ifdef CONFIG_64BIT static inline bool page_is_young(struct page *page) @@ -106,7 +106,7 @@ static inline void clear_page_idle(struct page *page) } #endif /* CONFIG_64BIT */ -#else /* !CONFIG_IDLE_PAGE_TRACKING */ +#else /* !CONFIG_PAGE_IDLE_FLAG */ static inline bool page_is_young(struct page *page) { @@ -135,6 +135,6 @@ static inline void clear_page_idle(struct page *page) { } -#endif /* CONFIG_IDLE_PAGE_TRACKING */ +#endif /* CONFIG_PAGE_IDLE_FLAG */ #endif /* _LINUX_MM_PAGE_IDLE_H */ diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index 629c7a0eaff2..ea434bbc2d2b 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -73,7 +73,7 @@ #define IF_HAVE_PG_HWPOISON(flag,string) #endif -#if defined(CONFIG_IDLE_PAGE_TRACKING) && defined(CONFIG_64BIT) +#if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT) #define IF_HAVE_PG_IDLE(flag,string) ,{1UL << flag, string} #else #define IF_HAVE_PG_IDLE(flag,string) diff --git a/mm/Kconfig b/mm/Kconfig index 56bec147bdff..0616a8b1ff0b 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -771,10 +771,18 @@ config DEFERRED_STRUCT_PAGE_INIT lifetime of the system until these kthreads finish the initialisation. +config PAGE_IDLE_FLAG + bool "Add PG_idle and PG_young flags" + help + This feature adds PG_idle and PG_young flags in 'struct page'. PTE + Accessed bit writers can set the state of the bit in the flags to let + other PTE Accessed bit readers don't disturbed. + config IDLE_PAGE_TRACKING bool "Enable idle page tracking" depends on SYSFS && MMU select PAGE_EXTENSION if !64BIT + select PAGE_IDLE_FLAG help This feature allows to estimate the amount of user pages that have not been touched during a given period of time. This information can diff --git a/mm/page_ext.c b/mm/page_ext.c index df6f74aac8e1..8e59da0f4367 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -58,11 +58,21 @@ * can utilize this callback to initialize the state of it correctly. */ +#if defined(CONFIG_PAGE_IDLE_FLAG) && !defined(CONFIG_64BIT) +static bool need_page_idle(void) +{ + return true; +} +struct page_ext_operations page_idle_ops = { + .need = need_page_idle, +}; +#endif + static struct page_ext_operations *page_ext_ops[] = { #ifdef CONFIG_PAGE_OWNER &page_owner_ops, #endif -#if defined(CONFIG_IDLE_PAGE_TRACKING) && !defined(CONFIG_64BIT) +#if defined(CONFIG_PAGE_IDLE_FLAG) && !defined(CONFIG_64BIT) &page_idle_ops, #endif }; diff --git a/mm/page_idle.c b/mm/page_idle.c index 64e5344a992c..edead6a8a5f9 100644 --- a/mm/page_idle.c +++ b/mm/page_idle.c @@ -207,16 +207,6 @@ static const struct attribute_group page_idle_attr_group = { .name = "page_idle", }; -#ifndef CONFIG_64BIT -static bool need_page_idle(void) -{ - return true; -} -struct page_ext_operations page_idle_ops = { - .need = need_page_idle, -}; -#endif - static int __init page_idle_init(void) { int err; -- 2.17.1