Skip to content

Commit 7a91e8d

Browse files
sjp38gregkh
authored andcommitted
mm/damon: rename min_sz_region of damon_ctx to min_region_sz
[ Upstream commit cc1db8d ] 'min_sz_region' field of 'struct damon_ctx' represents the minimum size of each DAMON region for the context. 'struct damos_access_pattern' has a field of the same name. It confuses readers and makes 'grep' less optimal for them. Rename it to 'min_region_sz'. Link: https://lkml.kernel.org/r/20260117175256.82826-9-sj@kernel.org Signed-off-by: SeongJae Park <sj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Stable-dep-of: c80f46a ("mm/damon/core: disallow non-power of two min_region_sz") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e4f13f7 commit 7a91e8d

6 files changed

Lines changed: 49 additions & 47 deletions

File tree

include/linux/damon.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ struct damon_attrs {
769769
*
770770
* @ops: Set of monitoring operations for given use cases.
771771
* @addr_unit: Scale factor for core to ops address conversion.
772-
* @min_sz_region: Minimum region size.
772+
* @min_region_sz: Minimum region size.
773773
* @adaptive_targets: Head of monitoring targets (&damon_target) list.
774774
* @schemes: Head of schemes (&damos) list.
775775
*/
@@ -812,7 +812,7 @@ struct damon_ctx {
812812

813813
struct damon_operations ops;
814814
unsigned long addr_unit;
815-
unsigned long min_sz_region;
815+
unsigned long min_region_sz;
816816

817817
struct list_head adaptive_targets;
818818
struct list_head schemes;
@@ -901,7 +901,7 @@ static inline void damon_insert_region(struct damon_region *r,
901901
void damon_add_region(struct damon_region *r, struct damon_target *t);
902902
void damon_destroy_region(struct damon_region *r, struct damon_target *t);
903903
int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges,
904-
unsigned int nr_ranges, unsigned long min_sz_region);
904+
unsigned int nr_ranges, unsigned long min_region_sz);
905905
void damon_update_region_access_rate(struct damon_region *r, bool accessed,
906906
struct damon_attrs *attrs);
907907

@@ -968,7 +968,7 @@ int damos_walk(struct damon_ctx *ctx, struct damos_walk_control *control);
968968

969969
int damon_set_region_biggest_system_ram_default(struct damon_target *t,
970970
unsigned long *start, unsigned long *end,
971-
unsigned long min_sz_region);
971+
unsigned long min_region_sz);
972972

973973
#endif /* CONFIG_DAMON */
974974

mm/damon/core.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,15 @@ static int damon_fill_regions_holes(struct damon_region *first,
197197
* @t: the given target.
198198
* @ranges: array of new monitoring target ranges.
199199
* @nr_ranges: length of @ranges.
200-
* @min_sz_region: minimum region size.
200+
* @min_region_sz: minimum region size.
201201
*
202202
* This function adds new regions to, or modify existing regions of a
203203
* monitoring target to fit in specific ranges.
204204
*
205205
* Return: 0 if success, or negative error code otherwise.
206206
*/
207207
int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges,
208-
unsigned int nr_ranges, unsigned long min_sz_region)
208+
unsigned int nr_ranges, unsigned long min_region_sz)
209209
{
210210
struct damon_region *r, *next;
211211
unsigned int i;
@@ -242,16 +242,16 @@ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges,
242242
/* no region intersects with this range */
243243
newr = damon_new_region(
244244
ALIGN_DOWN(range->start,
245-
min_sz_region),
246-
ALIGN(range->end, min_sz_region));
245+
min_region_sz),
246+
ALIGN(range->end, min_region_sz));
247247
if (!newr)
248248
return -ENOMEM;
249249
damon_insert_region(newr, damon_prev_region(r), r, t);
250250
} else {
251251
/* resize intersecting regions to fit in this range */
252252
first->ar.start = ALIGN_DOWN(range->start,
253-
min_sz_region);
254-
last->ar.end = ALIGN(range->end, min_sz_region);
253+
min_region_sz);
254+
last->ar.end = ALIGN(range->end, min_region_sz);
255255

256256
/* fill possible holes in the range */
257257
err = damon_fill_regions_holes(first, last, t);
@@ -546,7 +546,7 @@ struct damon_ctx *damon_new_ctx(void)
546546
ctx->attrs.max_nr_regions = 1000;
547547

548548
ctx->addr_unit = 1;
549-
ctx->min_sz_region = DAMON_MIN_REGION_SZ;
549+
ctx->min_region_sz = DAMON_MIN_REGION_SZ;
550550

551551
INIT_LIST_HEAD(&ctx->adaptive_targets);
552552
INIT_LIST_HEAD(&ctx->schemes);
@@ -1131,7 +1131,7 @@ static struct damon_target *damon_nth_target(int n, struct damon_ctx *ctx)
11311131
* If @src has no region, @dst keeps current regions.
11321132
*/
11331133
static int damon_commit_target_regions(struct damon_target *dst,
1134-
struct damon_target *src, unsigned long src_min_sz_region)
1134+
struct damon_target *src, unsigned long src_min_region_sz)
11351135
{
11361136
struct damon_region *src_region;
11371137
struct damon_addr_range *ranges;
@@ -1148,19 +1148,19 @@ static int damon_commit_target_regions(struct damon_target *dst,
11481148
i = 0;
11491149
damon_for_each_region(src_region, src)
11501150
ranges[i++] = src_region->ar;
1151-
err = damon_set_regions(dst, ranges, i, src_min_sz_region);
1151+
err = damon_set_regions(dst, ranges, i, src_min_region_sz);
11521152
kfree(ranges);
11531153
return err;
11541154
}
11551155

11561156
static int damon_commit_target(
11571157
struct damon_target *dst, bool dst_has_pid,
11581158
struct damon_target *src, bool src_has_pid,
1159-
unsigned long src_min_sz_region)
1159+
unsigned long src_min_region_sz)
11601160
{
11611161
int err;
11621162

1163-
err = damon_commit_target_regions(dst, src, src_min_sz_region);
1163+
err = damon_commit_target_regions(dst, src, src_min_region_sz);
11641164
if (err)
11651165
return err;
11661166
if (dst_has_pid)
@@ -1187,7 +1187,7 @@ static int damon_commit_targets(
11871187
err = damon_commit_target(
11881188
dst_target, damon_target_has_pid(dst),
11891189
src_target, damon_target_has_pid(src),
1190-
src->min_sz_region);
1190+
src->min_region_sz);
11911191
if (err)
11921192
return err;
11931193
} else {
@@ -1214,7 +1214,7 @@ static int damon_commit_targets(
12141214
return -ENOMEM;
12151215
err = damon_commit_target(new_target, false,
12161216
src_target, damon_target_has_pid(src),
1217-
src->min_sz_region);
1217+
src->min_region_sz);
12181218
if (err) {
12191219
damon_destroy_target(new_target, NULL);
12201220
return err;
@@ -1261,7 +1261,7 @@ int damon_commit_ctx(struct damon_ctx *dst, struct damon_ctx *src)
12611261
}
12621262
dst->ops = src->ops;
12631263
dst->addr_unit = src->addr_unit;
1264-
dst->min_sz_region = src->min_sz_region;
1264+
dst->min_region_sz = src->min_region_sz;
12651265

12661266
return 0;
12671267
}
@@ -1294,8 +1294,8 @@ static unsigned long damon_region_sz_limit(struct damon_ctx *ctx)
12941294

12951295
if (ctx->attrs.min_nr_regions)
12961296
sz /= ctx->attrs.min_nr_regions;
1297-
if (sz < ctx->min_sz_region)
1298-
sz = ctx->min_sz_region;
1297+
if (sz < ctx->min_region_sz)
1298+
sz = ctx->min_region_sz;
12991299

13001300
return sz;
13011301
}
@@ -1673,7 +1673,7 @@ static bool damos_valid_target(struct damon_ctx *c, struct damon_target *t,
16731673
* @t: The target of the region.
16741674
* @rp: The pointer to the region.
16751675
* @s: The scheme to be applied.
1676-
* @min_sz_region: minimum region size.
1676+
* @min_region_sz: minimum region size.
16771677
*
16781678
* If a quota of a scheme has exceeded in a quota charge window, the scheme's
16791679
* action would applied to only a part of the target access pattern fulfilling
@@ -1691,7 +1691,8 @@ static bool damos_valid_target(struct damon_ctx *c, struct damon_target *t,
16911691
* Return: true if the region should be entirely skipped, false otherwise.
16921692
*/
16931693
static bool damos_skip_charged_region(struct damon_target *t,
1694-
struct damon_region **rp, struct damos *s, unsigned long min_sz_region)
1694+
struct damon_region **rp, struct damos *s,
1695+
unsigned long min_region_sz)
16951696
{
16961697
struct damon_region *r = *rp;
16971698
struct damos_quota *quota = &s->quota;
@@ -1713,11 +1714,11 @@ static bool damos_skip_charged_region(struct damon_target *t,
17131714
if (quota->charge_addr_from && r->ar.start <
17141715
quota->charge_addr_from) {
17151716
sz_to_skip = ALIGN_DOWN(quota->charge_addr_from -
1716-
r->ar.start, min_sz_region);
1717+
r->ar.start, min_region_sz);
17171718
if (!sz_to_skip) {
1718-
if (damon_sz_region(r) <= min_sz_region)
1719+
if (damon_sz_region(r) <= min_region_sz)
17191720
return true;
1720-
sz_to_skip = min_sz_region;
1721+
sz_to_skip = min_region_sz;
17211722
}
17221723
damon_split_region_at(t, r, sz_to_skip);
17231724
r = damon_next_region(r);
@@ -1743,7 +1744,7 @@ static void damos_update_stat(struct damos *s,
17431744

17441745
static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t,
17451746
struct damon_region *r, struct damos_filter *filter,
1746-
unsigned long min_sz_region)
1747+
unsigned long min_region_sz)
17471748
{
17481749
bool matched = false;
17491750
struct damon_target *ti;
@@ -1760,8 +1761,8 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t,
17601761
matched = target_idx == filter->target_idx;
17611762
break;
17621763
case DAMOS_FILTER_TYPE_ADDR:
1763-
start = ALIGN_DOWN(filter->addr_range.start, min_sz_region);
1764-
end = ALIGN_DOWN(filter->addr_range.end, min_sz_region);
1764+
start = ALIGN_DOWN(filter->addr_range.start, min_region_sz);
1765+
end = ALIGN_DOWN(filter->addr_range.end, min_region_sz);
17651766

17661767
/* inside the range */
17671768
if (start <= r->ar.start && r->ar.end <= end) {
@@ -1797,7 +1798,7 @@ static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t,
17971798

17981799
s->core_filters_allowed = false;
17991800
damos_for_each_core_filter(filter, s) {
1800-
if (damos_filter_match(ctx, t, r, filter, ctx->min_sz_region)) {
1801+
if (damos_filter_match(ctx, t, r, filter, ctx->min_region_sz)) {
18011802
if (filter->allow)
18021803
s->core_filters_allowed = true;
18031804
return !filter->allow;
@@ -1932,7 +1933,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
19321933
if (c->ops.apply_scheme) {
19331934
if (quota->esz && quota->charged_sz + sz > quota->esz) {
19341935
sz = ALIGN_DOWN(quota->esz - quota->charged_sz,
1935-
c->min_sz_region);
1936+
c->min_region_sz);
19361937
if (!sz)
19371938
goto update_stat;
19381939
damon_split_region_at(t, r, sz);
@@ -1980,7 +1981,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c,
19801981
if (quota->esz && quota->charged_sz >= quota->esz)
19811982
continue;
19821983

1983-
if (damos_skip_charged_region(t, &r, s, c->min_sz_region))
1984+
if (damos_skip_charged_region(t, &r, s, c->min_region_sz))
19841985
continue;
19851986

19861987
if (!damos_valid_target(c, t, r, s))
@@ -2429,7 +2430,7 @@ static void damon_split_region_at(struct damon_target *t,
24292430

24302431
/* Split every region in the given target into 'nr_subs' regions */
24312432
static void damon_split_regions_of(struct damon_target *t, int nr_subs,
2432-
unsigned long min_sz_region)
2433+
unsigned long min_region_sz)
24332434
{
24342435
struct damon_region *r, *next;
24352436
unsigned long sz_region, sz_sub = 0;
@@ -2439,13 +2440,13 @@ static void damon_split_regions_of(struct damon_target *t, int nr_subs,
24392440
sz_region = damon_sz_region(r);
24402441

24412442
for (i = 0; i < nr_subs - 1 &&
2442-
sz_region > 2 * min_sz_region; i++) {
2443+
sz_region > 2 * min_region_sz; i++) {
24432444
/*
24442445
* Randomly select size of left sub-region to be at
24452446
* least 10 percent and at most 90% of original region
24462447
*/
24472448
sz_sub = ALIGN_DOWN(damon_rand(1, 10) *
2448-
sz_region / 10, min_sz_region);
2449+
sz_region / 10, min_region_sz);
24492450
/* Do not allow blank region */
24502451
if (sz_sub == 0 || sz_sub >= sz_region)
24512452
continue;
@@ -2485,7 +2486,7 @@ static void kdamond_split_regions(struct damon_ctx *ctx)
24852486
nr_subregions = 3;
24862487

24872488
damon_for_each_target(t, ctx)
2488-
damon_split_regions_of(t, nr_subregions, ctx->min_sz_region);
2489+
damon_split_regions_of(t, nr_subregions, ctx->min_region_sz);
24892490

24902491
last_nr_regions = nr_regions;
24912492
}
@@ -2855,7 +2856,7 @@ static bool damon_find_biggest_system_ram(unsigned long *start,
28552856
* @t: The monitoring target to set the region.
28562857
* @start: The pointer to the start address of the region.
28572858
* @end: The pointer to the end address of the region.
2858-
* @min_sz_region: Minimum region size.
2859+
* @min_region_sz: Minimum region size.
28592860
*
28602861
* This function sets the region of @t as requested by @start and @end. If the
28612862
* values of @start and @end are zero, however, this function finds the biggest
@@ -2867,7 +2868,7 @@ static bool damon_find_biggest_system_ram(unsigned long *start,
28672868
*/
28682869
int damon_set_region_biggest_system_ram_default(struct damon_target *t,
28692870
unsigned long *start, unsigned long *end,
2870-
unsigned long min_sz_region)
2871+
unsigned long min_region_sz)
28712872
{
28722873
struct damon_addr_range addr_range;
28732874

@@ -2880,7 +2881,7 @@ int damon_set_region_biggest_system_ram_default(struct damon_target *t,
28802881

28812882
addr_range.start = *start;
28822883
addr_range.end = *end;
2883-
return damon_set_regions(t, &addr_range, 1, min_sz_region);
2884+
return damon_set_regions(t, &addr_range, 1, min_region_sz);
28842885
}
28852886

28862887
/*

mm/damon/lru_sort.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static int damon_lru_sort_apply_parameters(void)
212212
if (!monitor_region_start && !monitor_region_end)
213213
addr_unit = 1;
214214
param_ctx->addr_unit = addr_unit;
215-
param_ctx->min_sz_region = max(DAMON_MIN_REGION_SZ / addr_unit, 1);
215+
param_ctx->min_region_sz = max(DAMON_MIN_REGION_SZ / addr_unit, 1);
216216

217217
if (!damon_lru_sort_mon_attrs.sample_interval) {
218218
err = -EINVAL;
@@ -243,7 +243,7 @@ static int damon_lru_sort_apply_parameters(void)
243243
err = damon_set_region_biggest_system_ram_default(param_target,
244244
&monitor_region_start,
245245
&monitor_region_end,
246-
param_ctx->min_sz_region);
246+
param_ctx->min_region_sz);
247247
if (err)
248248
goto out;
249249
err = damon_commit_ctx(ctx, param_ctx);

mm/damon/reclaim.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static int damon_reclaim_apply_parameters(void)
208208
if (!monitor_region_start && !monitor_region_end)
209209
addr_unit = 1;
210210
param_ctx->addr_unit = addr_unit;
211-
param_ctx->min_sz_region = max(DAMON_MIN_REGION_SZ / addr_unit, 1);
211+
param_ctx->min_region_sz = max(DAMON_MIN_REGION_SZ / addr_unit, 1);
212212

213213
if (!damon_reclaim_mon_attrs.aggr_interval) {
214214
err = -EINVAL;
@@ -251,7 +251,7 @@ static int damon_reclaim_apply_parameters(void)
251251
err = damon_set_region_biggest_system_ram_default(param_target,
252252
&monitor_region_start,
253253
&monitor_region_end,
254-
param_ctx->min_sz_region);
254+
param_ctx->min_region_sz);
255255
if (err)
256256
goto out;
257257
err = damon_commit_ctx(ctx, param_ctx);

mm/damon/stat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static struct damon_ctx *damon_stat_build_ctx(void)
189189
goto free_out;
190190
damon_add_target(ctx, target);
191191
if (damon_set_region_biggest_system_ram_default(target, &start, &end,
192-
ctx->min_sz_region))
192+
ctx->min_region_sz))
193193
goto free_out;
194194
return ctx;
195195
free_out:

mm/damon/sysfs.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ static int damon_sysfs_set_attrs(struct damon_ctx *ctx,
13651365

13661366
static int damon_sysfs_set_regions(struct damon_target *t,
13671367
struct damon_sysfs_regions *sysfs_regions,
1368-
unsigned long min_sz_region)
1368+
unsigned long min_region_sz)
13691369
{
13701370
struct damon_addr_range *ranges = kmalloc_array(sysfs_regions->nr,
13711371
sizeof(*ranges), GFP_KERNEL | __GFP_NOWARN);
@@ -1387,7 +1387,7 @@ static int damon_sysfs_set_regions(struct damon_target *t,
13871387
if (ranges[i - 1].end > ranges[i].start)
13881388
goto out;
13891389
}
1390-
err = damon_set_regions(t, ranges, sysfs_regions->nr, min_sz_region);
1390+
err = damon_set_regions(t, ranges, sysfs_regions->nr, min_region_sz);
13911391
out:
13921392
kfree(ranges);
13931393
return err;
@@ -1409,7 +1409,8 @@ static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target,
14091409
return -EINVAL;
14101410
}
14111411
t->obsolete = sys_target->obsolete;
1412-
return damon_sysfs_set_regions(t, sys_target->regions, ctx->min_sz_region);
1412+
return damon_sysfs_set_regions(t, sys_target->regions,
1413+
ctx->min_region_sz);
14131414
}
14141415

14151416
static int damon_sysfs_add_targets(struct damon_ctx *ctx,
@@ -1469,7 +1470,7 @@ static int damon_sysfs_apply_inputs(struct damon_ctx *ctx,
14691470
ctx->addr_unit = sys_ctx->addr_unit;
14701471
/* addr_unit is respected by only DAMON_OPS_PADDR */
14711472
if (sys_ctx->ops_id == DAMON_OPS_PADDR)
1472-
ctx->min_sz_region = max(
1473+
ctx->min_region_sz = max(
14731474
DAMON_MIN_REGION_SZ / sys_ctx->addr_unit, 1);
14741475
err = damon_sysfs_set_attrs(ctx, sys_ctx->attrs);
14751476
if (err)

0 commit comments

Comments
 (0)