From: Hyeongtak Ji <hyeongtak...@sk.com>

This patch introduces DAMOS_MIGRATE_HOT action, which is similar to
DAMOS_MIGRATE_COLD, but proritizes hot pages.

It migrates pages inside the given region to the 'target_nid' NUMA node
in the sysfs.

Here is one of the example usage of this 'migrate_hot' action.

  $ cd /sys/kernel/mm/damon/admin/kdamonds/<N>
  $ cat contexts/<N>/schemes/<N>/action
  migrate_hot
  $ echo 0 > contexts/<N>/schemes/<N>/target_nid
  $ echo commit > state
  $ numactl -p 2 ./hot_cold 500M 600M &
  $ numastat -c -p hot_cold

  Per-node process memory usage (in MBs)
  PID             Node 0 Node 1 Node 2 Total
  --------------  ------ ------ ------ -----
  701 (hot_cold)     501      0    601  1101

Signed-off-by: Hyeongtak Ji <hyeongtak...@sk.com>
Signed-off-by: Honggyu Kim <honggyu....@sk.com>
Signed-off-by: SeongJae Park <s...@kernel.org>
---
 include/linux/damon.h    | 2 ++
 mm/damon/paddr.c         | 3 +++
 mm/damon/sysfs-schemes.c | 1 +
 3 files changed, 6 insertions(+)

diff --git a/include/linux/damon.h b/include/linux/damon.h
index 56714b6eb0d7..3d62d98d6359 100644
--- a/include/linux/damon.h
+++ b/include/linux/damon.h
@@ -105,6 +105,7 @@ struct damon_target {
  * @DAMOS_NOHUGEPAGE:  Call ``madvise()`` for the region with MADV_NOHUGEPAGE.
  * @DAMOS_LRU_PRIO:    Prioritize the region on its LRU lists.
  * @DAMOS_LRU_DEPRIO:  Deprioritize the region on its LRU lists.
+ * @DAMOS_MIGRATE_HOT:  Migrate the regions prioritizing warmer regions.
  * @DAMOS_MIGRATE_COLD:        Migrate the regions prioritizing colder regions.
  * @DAMOS_STAT:                Do nothing but count the stat.
  * @NR_DAMOS_ACTIONS:  Total number of DAMOS actions
@@ -123,6 +124,7 @@ enum damos_action {
        DAMOS_NOHUGEPAGE,
        DAMOS_LRU_PRIO,
        DAMOS_LRU_DEPRIO,
+       DAMOS_MIGRATE_HOT,
        DAMOS_MIGRATE_COLD,
        DAMOS_STAT,             /* Do nothing but only record the stat */
        NR_DAMOS_ACTIONS,
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 882ae54af829..af6aac388a43 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -486,6 +486,7 @@ static unsigned long damon_pa_apply_scheme(struct damon_ctx 
*ctx,
                return damon_pa_mark_accessed(r, scheme);
        case DAMOS_LRU_DEPRIO:
                return damon_pa_deactivate_pages(r, scheme);
+       case DAMOS_MIGRATE_HOT:
        case DAMOS_MIGRATE_COLD:
                return damon_pa_migrate(r, scheme);
        case DAMOS_STAT:
@@ -508,6 +509,8 @@ static int damon_pa_scheme_score(struct damon_ctx *context,
                return damon_hot_score(context, r, scheme);
        case DAMOS_LRU_DEPRIO:
                return damon_cold_score(context, r, scheme);
+       case DAMOS_MIGRATE_HOT:
+               return damon_hot_score(context, r, scheme);
        case DAMOS_MIGRATE_COLD:
                return damon_cold_score(context, r, scheme);
        default:
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 880015d5b5ea..66fccfa776d7 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -1458,6 +1458,7 @@ static const char * const damon_sysfs_damos_action_strs[] 
= {
        "nohugepage",
        "lru_prio",
        "lru_deprio",
+       "migrate_hot",
        "migrate_cold",
        "stat",
 };
-- 
2.34.1


Reply via email to