[PATCH v22 08/18] mm/damon/primitives: Make coexistable with Idle Page Tracking

From: SeongJae Park
Date: Tue Oct 20 2020 - 05:04:10 EST


From: SeongJae Park <sjpark@xxxxxxxxx>

DAMON's reference 'primitives' internally use 'PG_Idle' flag. Because
the flag is also used by Idle Page Tracking but there was no way to
synchronize with it, the 'primitives' were configured to be exclusive
with Idle Page Tracking before. However, as we can now synchronize with
Idle Page Tracking using 'idle_page_lock', this commit makes the
primitives to do the synchronization and coexistable with Idle Page
Tracking.

Note that the 'primitives' only require the users to do the
synchronization by themselves.

Signed-off-by: SeongJae Park <sjpark@xxxxxxxxx>
---
include/linux/page_idle.h | 2 ++
mm/damon/Kconfig | 2 +-
mm/damon/primitives.c | 7 +++++++
mm/page_idle.c | 2 +-
4 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/linux/page_idle.h b/include/linux/page_idle.h
index d8a6aecf99cb..bcbb965b566c 100644
--- a/include/linux/page_idle.h
+++ b/include/linux/page_idle.h
@@ -8,6 +8,8 @@

#ifdef CONFIG_PAGE_IDLE_FLAG

+extern struct mutex page_idle_lock;
+
#ifdef CONFIG_64BIT
static inline bool page_is_young(struct page *page)
{
diff --git a/mm/damon/Kconfig b/mm/damon/Kconfig
index 0d2a18ddb9d8..63b9c905b548 100644
--- a/mm/damon/Kconfig
+++ b/mm/damon/Kconfig
@@ -14,7 +14,7 @@ config DAMON

config DAMON_PRIMITIVES
bool "Monitoring primitives for virtual address spaces monitoring"
- depends on DAMON && MMU && !IDLE_PAGE_TRACKING
+ depends on DAMON && MMU
select PAGE_EXTENSION if !64BIT
select PAGE_IDLE_FLAG
help
diff --git a/mm/damon/primitives.c b/mm/damon/primitives.c
index 9b603ac0077c..59f4de703413 100644
--- a/mm/damon/primitives.c
+++ b/mm/damon/primitives.c
@@ -15,6 +15,10 @@
#include <linux/sched/mm.h>
#include <linux/slab.h>

+#ifndef CONFIG_IDLE_PAGE_TRACKING
+DEFINE_MUTEX(page_idle_lock);
+#endif
+
/* Minimal region size. Every damon_region is aligned by this. */
#define MIN_REGION PAGE_SIZE

@@ -552,6 +556,9 @@ bool damon_va_target_valid(struct damon_target *t)
{
struct task_struct *task;

+ if (!mutex_is_locked(&page_idle_lock))
+ return false;
+
task = damon_get_task_struct(t);
if (task) {
put_task_struct(task);
diff --git a/mm/page_idle.c b/mm/page_idle.c
index 0aa45f848570..958dcc18f6cd 100644
--- a/mm/page_idle.c
+++ b/mm/page_idle.c
@@ -16,7 +16,7 @@
#define BITMAP_CHUNK_SIZE sizeof(u64)
#define BITMAP_CHUNK_BITS (BITMAP_CHUNK_SIZE * BITS_PER_BYTE)

-static DEFINE_MUTEX(page_idle_lock);
+DEFINE_MUTEX(page_idle_lock);

/*
* Idle page tracking only considers user memory pages, for other types of
--
2.17.1