]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/damon/tests/core-kunit: add damos_commit_quota_goal() test
authorSeongJae Park <sj@kernel.org>
Tue, 11 Nov 2025 18:44:04 +0000 (10:44 -0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 20 Nov 2025 21:44:00 +0000 (13:44 -0800)
Add a new unit test for damos_commit_quota_goal().

Link: https://lkml.kernel.org/r/20251111184415.141757-6-sj@kernel.org
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Gow <davidgow@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/tests/core-kunit.h

index 2770972b0a393bda00421d6f77e231915cec88c4..0fdf9c7eedc3484508a819b6f6565707c6418ad6 100644 (file)
@@ -497,6 +497,89 @@ static void damos_test_new_filter(struct kunit *test)
        damos_destroy_filter(filter);
 }
 
+static void damos_test_commit_quota_goal_for(struct kunit *test,
+               struct damos_quota_goal *dst,
+               struct damos_quota_goal *src)
+{
+       u64 dst_last_psi_total = 0;
+
+       if (dst->metric == DAMOS_QUOTA_SOME_MEM_PSI_US)
+               dst_last_psi_total = dst->last_psi_total;
+       damos_commit_quota_goal(dst, src);
+
+       KUNIT_EXPECT_EQ(test, dst->metric, src->metric);
+       KUNIT_EXPECT_EQ(test, dst->target_value, src->target_value);
+       if (src->metric == DAMOS_QUOTA_USER_INPUT)
+               KUNIT_EXPECT_EQ(test, dst->current_value, src->current_value);
+       if (dst_last_psi_total && src->metric == DAMOS_QUOTA_SOME_MEM_PSI_US)
+               KUNIT_EXPECT_EQ(test, dst->last_psi_total, dst_last_psi_total);
+       switch (dst->metric) {
+       case DAMOS_QUOTA_NODE_MEM_USED_BP:
+       case DAMOS_QUOTA_NODE_MEM_FREE_BP:
+               KUNIT_EXPECT_EQ(test, dst->nid, src->nid);
+               break;
+       case DAMOS_QUOTA_NODE_MEMCG_USED_BP:
+       case DAMOS_QUOTA_NODE_MEMCG_FREE_BP:
+               KUNIT_EXPECT_EQ(test, dst->nid, src->nid);
+               KUNIT_EXPECT_EQ(test, dst->memcg_id, src->memcg_id);
+               break;
+       default:
+               break;
+       }
+}
+
+static void damos_test_commit_quota_goal(struct kunit *test)
+{
+       struct damos_quota_goal dst = {
+               .metric = DAMOS_QUOTA_SOME_MEM_PSI_US,
+               .target_value = 1000,
+               .current_value = 123,
+               .last_psi_total = 456,
+       };
+
+       damos_test_commit_quota_goal_for(test, &dst,
+                       &(struct damos_quota_goal){
+                       .metric = DAMOS_QUOTA_USER_INPUT,
+                       .target_value = 789,
+                       .current_value = 12});
+       damos_test_commit_quota_goal_for(test, &dst,
+                       &(struct damos_quota_goal){
+                       .metric = DAMOS_QUOTA_NODE_MEM_FREE_BP,
+                       .target_value = 345,
+                       .current_value = 678,
+                       .nid = 9,
+                       });
+       damos_test_commit_quota_goal_for(test, &dst,
+                       &(struct damos_quota_goal){
+                       .metric = DAMOS_QUOTA_NODE_MEM_USED_BP,
+                       .target_value = 12,
+                       .current_value = 345,
+                       .nid = 6,
+                       });
+       damos_test_commit_quota_goal_for(test, &dst,
+                       &(struct damos_quota_goal){
+                       .metric = DAMOS_QUOTA_NODE_MEMCG_USED_BP,
+                       .target_value = 456,
+                       .current_value = 567,
+                       .nid = 6,
+                       .memcg_id = 7,
+                       });
+       damos_test_commit_quota_goal_for(test, &dst,
+                       &(struct damos_quota_goal){
+                       .metric = DAMOS_QUOTA_NODE_MEMCG_FREE_BP,
+                       .target_value = 890,
+                       .current_value = 901,
+                       .nid = 10,
+                       .memcg_id = 1,
+                       });
+       damos_test_commit_quota_goal_for(test, &dst,
+                       &(struct damos_quota_goal) {
+                       .metric = DAMOS_QUOTA_USER_INPUT,
+                       .target_value = 789,
+                       .current_value = 12,
+                       });
+}
+
 static void damos_test_commit_filter_for(struct kunit *test,
                struct damos_filter *dst, struct damos_filter *src)
 {
@@ -782,6 +865,7 @@ static struct kunit_case damon_test_cases[] = {
        KUNIT_CASE(damon_test_set_attrs),
        KUNIT_CASE(damon_test_moving_sum),
        KUNIT_CASE(damos_test_new_filter),
+       KUNIT_CASE(damos_test_commit_quota_goal),
        KUNIT_CASE(damos_test_commit_filter),
        KUNIT_CASE(damos_test_filter_out),
        KUNIT_CASE(damon_test_feed_loop_next_input),