* [PATCH 1/4] mm/damon/reclaim: enable and disable synchronously
2022-10-25 17:36 [PATCH 0/4] mm/damon/reclaim,lru_sort: enable/disable synchronously SeongJae Park
@ 2022-10-25 17:36 ` SeongJae Park
2022-10-25 17:36 ` [PATCH 2/4] selftests/damon: add tests for DAMON_RECLAIM's enabled parameter SeongJae Park
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2022-10-25 17:36 UTC (permalink / raw)
To: Andrew Morton; +Cc: damon, linux-mm, linux-kernel, SeongJae Park
Writing a value to DAMON_RECLAIM's 'enabled' parameter turns on or off
DAMON in an ansychronous way. This means the parameter cannot be used
to read the current status of DAMON_RECLAIM. 'kdamond_pid' parameter
should be used instead for the purpose. The documentation is easy to be
read as it works in a synchronous way, so it is a little bit confusing.
It also makes the user space tooling dirty.
There's no real reason to have the asynchronous behavior, though.
Simply make the parameter works synchronously, rather than updating the
document.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/reclaim.c | 53 ++++++++++++++++++++--------------------------
1 file changed, 23 insertions(+), 30 deletions(-)
diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c
index e14eb30c01f4..e57604bec06d 100644
--- a/mm/damon/reclaim.c
+++ b/mm/damon/reclaim.c
@@ -9,7 +9,6 @@
#include <linux/damon.h>
#include <linux/module.h>
-#include <linux/workqueue.h>
#include "modules-common.h"
@@ -181,38 +180,31 @@ static int damon_reclaim_turn(bool on)
return 0;
}
-static struct delayed_work damon_reclaim_timer;
-static void damon_reclaim_timer_fn(struct work_struct *work)
-{
- static bool last_enabled;
- bool now_enabled;
-
- now_enabled = enabled;
- if (last_enabled != now_enabled) {
- if (!damon_reclaim_turn(now_enabled))
- last_enabled = now_enabled;
- else
- enabled = last_enabled;
- }
-}
-static DECLARE_DELAYED_WORK(damon_reclaim_timer, damon_reclaim_timer_fn);
-
-static bool damon_reclaim_initialized;
-
static int damon_reclaim_enabled_store(const char *val,
const struct kernel_param *kp)
{
- int rc = param_set_bool(val, kp);
+ bool is_enabled = enabled;
+ bool enable;
+ int err;
- if (rc < 0)
- return rc;
+ err = strtobool(val, &enable);
+ if (err)
+ return err;
- /* system_wq might not initialized yet */
- if (!damon_reclaim_initialized)
- return rc;
+ if (is_enabled == enable)
+ return 0;
- schedule_delayed_work(&damon_reclaim_timer, 0);
- return 0;
+ /* Called before init function. The function will handle this. */
+ if (!ctx)
+ goto set_param_out;
+
+ err = damon_reclaim_turn(enable);
+ if (err)
+ return err;
+
+set_param_out:
+ enabled = enable;
+ return err;
}
static const struct kernel_param_ops enabled_param_ops = {
@@ -262,10 +254,11 @@ static int __init damon_reclaim_init(void)
ctx->callback.after_wmarks_check = damon_reclaim_after_wmarks_check;
ctx->callback.after_aggregation = damon_reclaim_after_aggregation;
- schedule_delayed_work(&damon_reclaim_timer, 0);
+ /* 'enabled' has set before this function, probably via command line */
+ if (enabled)
+ err = damon_reclaim_turn(true);
- damon_reclaim_initialized = true;
- return 0;
+ return err;
}
module_init(damon_reclaim_init);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/4] selftests/damon: add tests for DAMON_RECLAIM's enabled parameter
2022-10-25 17:36 [PATCH 0/4] mm/damon/reclaim,lru_sort: enable/disable synchronously SeongJae Park
2022-10-25 17:36 ` [PATCH 1/4] mm/damon/reclaim: enable and disable synchronously SeongJae Park
@ 2022-10-25 17:36 ` SeongJae Park
2022-10-25 17:36 ` [PATCH 3/4] mm/damon/lru_sort: enable and disable synchronously SeongJae Park
2022-10-25 17:36 ` [PATCH 4/4] selftests/damon: add tests for DAMON_LRU_SORT's enabled parameter SeongJae Park
3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2022-10-25 17:36 UTC (permalink / raw)
To: Andrew Morton
Cc: Shuah Khan, linux-kernel, damon, linux-mm, linux-kselftest,
SeongJae Park
Adds simple test cases for DAMON_RECLAIM's 'enabled' parameter. Those
tests are focusing on the synchronous behavior of DAMON_RECLAIM enabling
and disabling.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/Makefile | 1 +
tools/testing/selftests/damon/reclaim.sh | 42 ++++++++++++++++++++++++
2 files changed, 43 insertions(+)
create mode 100755 tools/testing/selftests/damon/reclaim.sh
diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile
index a1fa2eff8192..dbbf18cb3e6b 100644
--- a/tools/testing/selftests/damon/Makefile
+++ b/tools/testing/selftests/damon/Makefile
@@ -8,5 +8,6 @@ TEST_PROGS = debugfs_attrs.sh debugfs_schemes.sh debugfs_target_ids.sh
TEST_PROGS += debugfs_empty_targets.sh debugfs_huge_count_read_write.sh
TEST_PROGS += debugfs_duplicate_context_creation.sh
TEST_PROGS += sysfs.sh
+TEST_PROGS += reclaim.sh
include ../lib.mk
diff --git a/tools/testing/selftests/damon/reclaim.sh b/tools/testing/selftests/damon/reclaim.sh
new file mode 100755
index 000000000000..78dbc2334cbe
--- /dev/null
+++ b/tools/testing/selftests/damon/reclaim.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+
+if [ $EUID -ne 0 ]
+then
+ echo "Run as root"
+ exit $ksft_skip
+fi
+
+damon_reclaim_enabled="/sys/module/damon_reclaim/parameters/enabled"
+if [ ! -f "$damon_reclaim_enabled" ]
+then
+ echo "No 'enabled' file. Maybe DAMON_RECLAIM not built"
+ exit $ksft_skip
+fi
+
+nr_kdamonds=$(pgrep kdamond | wc -l)
+if [ "$nr_kdamonds" -ne 0 ]
+then
+ echo "Another kdamond is running"
+ exit $ksft_skip
+fi
+
+echo Y > "$damon_reclaim_enabled"
+
+nr_kdamonds=$(pgrep kdamond | wc -l)
+if [ "$nr_kdamonds" -ne 1 ]
+then
+ echo "kdamond is not turned on"
+ exit 1
+fi
+
+echo N > "$damon_reclaim_enabled"
+nr_kdamonds=$(pgrep kdamond | wc -l)
+if [ "$nr_kdamonds" -ne 0 ]
+then
+ echo "kdamond is not turned off"
+ exit 1
+fi
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] mm/damon/lru_sort: enable and disable synchronously
2022-10-25 17:36 [PATCH 0/4] mm/damon/reclaim,lru_sort: enable/disable synchronously SeongJae Park
2022-10-25 17:36 ` [PATCH 1/4] mm/damon/reclaim: enable and disable synchronously SeongJae Park
2022-10-25 17:36 ` [PATCH 2/4] selftests/damon: add tests for DAMON_RECLAIM's enabled parameter SeongJae Park
@ 2022-10-25 17:36 ` SeongJae Park
2022-10-25 17:36 ` [PATCH 4/4] selftests/damon: add tests for DAMON_LRU_SORT's enabled parameter SeongJae Park
3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2022-10-25 17:36 UTC (permalink / raw)
To: Andrew Morton; +Cc: damon, linux-mm, linux-kernel, SeongJae Park
Writing a value to DAMON_RECLAIM's 'enabled' parameter turns on or off
DAMON in an ansychronous way. This means the parameter cannot be used
to read the current status of DAMON_RECLAIM. 'kdamond_pid' parameter
should be used instead for the purpose. The documentation is easy to be
read as it works in a synchronous way, so it is a little bit confusing.
It also makes the user space tooling dirty.
There's no real reason to have the asynchronous behavior, though.
Simply make the parameter works synchronously, rather than updating the
document.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/lru_sort.c | 51 +++++++++++++++++++--------------------------
1 file changed, 22 insertions(+), 29 deletions(-)
diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index 5c60163e556c..2a532e3983df 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -9,7 +9,6 @@
#include <linux/damon.h>
#include <linux/module.h>
-#include <linux/workqueue.h>
#include "modules-common.h"
@@ -235,38 +234,31 @@ static int damon_lru_sort_turn(bool on)
return 0;
}
-static struct delayed_work damon_lru_sort_timer;
-static void damon_lru_sort_timer_fn(struct work_struct *work)
-{
- static bool last_enabled;
- bool now_enabled;
-
- now_enabled = enabled;
- if (last_enabled != now_enabled) {
- if (!damon_lru_sort_turn(now_enabled))
- last_enabled = now_enabled;
- else
- enabled = last_enabled;
- }
-}
-static DECLARE_DELAYED_WORK(damon_lru_sort_timer, damon_lru_sort_timer_fn);
-
-static bool damon_lru_sort_initialized;
-
static int damon_lru_sort_enabled_store(const char *val,
const struct kernel_param *kp)
{
- int rc = param_set_bool(val, kp);
+ bool is_enabled = enabled;
+ bool enable;
+ int err;
+
+ err = strtobool(val, &enable);
+ if (err)
+ return err;
- if (rc < 0)
- return rc;
+ if (is_enabled == enable)
+ return 0;
- if (!damon_lru_sort_initialized)
- return rc;
+ /* Called before init function. The function will handle this. */
+ if (!ctx)
+ goto set_param_out;
- schedule_delayed_work(&damon_lru_sort_timer, 0);
+ err = damon_lru_sort_turn(enable);
+ if (err)
+ return err;
- return 0;
+set_param_out:
+ enabled = enable;
+ return err;
}
static const struct kernel_param_ops enabled_param_ops = {
@@ -320,10 +312,11 @@ static int __init damon_lru_sort_init(void)
ctx->callback.after_wmarks_check = damon_lru_sort_after_wmarks_check;
ctx->callback.after_aggregation = damon_lru_sort_after_aggregation;
- schedule_delayed_work(&damon_lru_sort_timer, 0);
+ /* 'enabled' has set before this function, probably via command line */
+ if (enabled)
+ err = damon_lru_sort_turn(true);
- damon_lru_sort_initialized = true;
- return 0;
+ return err;
}
module_init(damon_lru_sort_init);
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 4/4] selftests/damon: add tests for DAMON_LRU_SORT's enabled parameter
2022-10-25 17:36 [PATCH 0/4] mm/damon/reclaim,lru_sort: enable/disable synchronously SeongJae Park
` (2 preceding siblings ...)
2022-10-25 17:36 ` [PATCH 3/4] mm/damon/lru_sort: enable and disable synchronously SeongJae Park
@ 2022-10-25 17:36 ` SeongJae Park
3 siblings, 0 replies; 5+ messages in thread
From: SeongJae Park @ 2022-10-25 17:36 UTC (permalink / raw)
To: Andrew Morton
Cc: Shuah Khan, linux-kernel, damon, linux-mm, linux-kselftest,
SeongJae Park
Adds simple test cases for DAMON_LRU_SORT's 'enabled' parameter. Those
tests are focusing on the synchronous behavior of DAMON_RECLAIM enabling
and disabling.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
tools/testing/selftests/damon/Makefile | 2 +-
tools/testing/selftests/damon/lru_sort.sh | 41 +++++++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
create mode 100755 tools/testing/selftests/damon/lru_sort.sh
diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile
index dbbf18cb3e6b..af490acc5348 100644
--- a/tools/testing/selftests/damon/Makefile
+++ b/tools/testing/selftests/damon/Makefile
@@ -8,6 +8,6 @@ TEST_PROGS = debugfs_attrs.sh debugfs_schemes.sh debugfs_target_ids.sh
TEST_PROGS += debugfs_empty_targets.sh debugfs_huge_count_read_write.sh
TEST_PROGS += debugfs_duplicate_context_creation.sh
TEST_PROGS += sysfs.sh
-TEST_PROGS += reclaim.sh
+TEST_PROGS += reclaim.sh lru_sort.sh
include ../lib.mk
diff --git a/tools/testing/selftests/damon/lru_sort.sh b/tools/testing/selftests/damon/lru_sort.sh
new file mode 100755
index 000000000000..61b80197c896
--- /dev/null
+++ b/tools/testing/selftests/damon/lru_sort.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# Kselftest framework requirement - SKIP code is 4.
+ksft_skip=4
+
+if [ $EUID -ne 0 ]
+then
+ echo "Run as root"
+ exit $ksft_skip
+fi
+
+damon_lru_sort_enabled="/sys/module/damon_lru_sort/parameters/enabled"
+if [ ! -f "$damon_lru_sort_enabled" ]
+then
+ echo "No 'enabled' file. Maybe DAMON_LRU_SORT not built"
+ exit $ksft_skip
+fi
+
+nr_kdamonds=$(pgrep kdamond | wc -l)
+if [ "$nr_kdamonds" -ne 0 ]
+then
+ echo "Another kdamond is running"
+ exit $ksft_skip
+fi
+
+echo Y > "$damon_lru_sort_enabled"
+nr_kdamonds=$(pgrep kdamond | wc -l)
+if [ "$nr_kdamonds" -ne 1 ]
+then
+ echo "kdamond is not turned on"
+ exit 1
+fi
+
+echo N > "$damon_lru_sort_enabled"
+nr_kdamonds=$(pgrep kdamond | wc -l)
+if [ "$nr_kdamonds" -ne 0 ]
+then
+ echo "kdamond is not turned off"
+ exit 1
+fi
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread