Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/core: pass migrate_dests to damos_commit_dests()

damos_commit_dests() receives 'struct damos' pointers, while it uses only
their ->migrate_dests fields. This makes code unnecessarily difficult to
read. It also makes unit tests writing complicated. Refactor the
function to receive pointers to the ->migrate_dests fields.

Link: https://lkml.kernel.org/r/20251111184415.141757-9-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>

authored by

SeongJae Park and committed by
Andrew Morton
c1cefda7 11bb980d

+17 -21
+17 -21
mm/damon/core.c
··· 1000 1000 damos_filters_default_reject(&s->ops_filters); 1001 1001 } 1002 1002 1003 - static int damos_commit_dests(struct damos *dst, struct damos *src) 1003 + static int damos_commit_dests(struct damos_migrate_dests *dst, 1004 + struct damos_migrate_dests *src) 1004 1005 { 1005 - struct damos_migrate_dests *dst_dests, *src_dests; 1006 + if (dst->nr_dests != src->nr_dests) { 1007 + kfree(dst->node_id_arr); 1008 + kfree(dst->weight_arr); 1006 1009 1007 - dst_dests = &dst->migrate_dests; 1008 - src_dests = &src->migrate_dests; 1009 - 1010 - if (dst_dests->nr_dests != src_dests->nr_dests) { 1011 - kfree(dst_dests->node_id_arr); 1012 - kfree(dst_dests->weight_arr); 1013 - 1014 - dst_dests->node_id_arr = kmalloc_array(src_dests->nr_dests, 1015 - sizeof(*dst_dests->node_id_arr), GFP_KERNEL); 1016 - if (!dst_dests->node_id_arr) { 1017 - dst_dests->weight_arr = NULL; 1010 + dst->node_id_arr = kmalloc_array(src->nr_dests, 1011 + sizeof(*dst->node_id_arr), GFP_KERNEL); 1012 + if (!dst->node_id_arr) { 1013 + dst->weight_arr = NULL; 1018 1014 return -ENOMEM; 1019 1015 } 1020 1016 1021 - dst_dests->weight_arr = kmalloc_array(src_dests->nr_dests, 1022 - sizeof(*dst_dests->weight_arr), GFP_KERNEL); 1023 - if (!dst_dests->weight_arr) { 1017 + dst->weight_arr = kmalloc_array(src->nr_dests, 1018 + sizeof(*dst->weight_arr), GFP_KERNEL); 1019 + if (!dst->weight_arr) { 1024 1020 /* ->node_id_arr will be freed by scheme destruction */ 1025 1021 return -ENOMEM; 1026 1022 } 1027 1023 } 1028 1024 1029 - dst_dests->nr_dests = src_dests->nr_dests; 1030 - for (int i = 0; i < src_dests->nr_dests; i++) { 1031 - dst_dests->node_id_arr[i] = src_dests->node_id_arr[i]; 1032 - dst_dests->weight_arr[i] = src_dests->weight_arr[i]; 1025 + dst->nr_dests = src->nr_dests; 1026 + for (int i = 0; i < src->nr_dests; i++) { 1027 + dst->node_id_arr[i] = src->node_id_arr[i]; 1028 + dst->weight_arr[i] = src->weight_arr[i]; 1033 1029 } 1034 1030 1035 1031 return 0; ··· 1072 1076 dst->wmarks = src->wmarks; 1073 1077 dst->target_nid = src->target_nid; 1074 1078 1075 - err = damos_commit_dests(dst, src); 1079 + err = damos_commit_dests(&dst->migrate_dests, &src->migrate_dests); 1076 1080 if (err) 1077 1081 return err; 1078 1082