@@ -113,6 +113,113 @@ static struct kobj_type damon_sysfs_ul_range_ktype = {
113
113
.default_groups = damon_sysfs_ul_range_groups ,
114
114
};
115
115
116
+ /*
117
+ * quotas directory
118
+ */
119
+
120
+ struct damon_sysfs_quotas {
121
+ struct kobject kobj ;
122
+ unsigned long ms ;
123
+ unsigned long sz ;
124
+ unsigned long reset_interval_ms ;
125
+ };
126
+
127
+ static struct damon_sysfs_quotas * damon_sysfs_quotas_alloc (void )
128
+ {
129
+ return kzalloc (sizeof (struct damon_sysfs_quotas ), GFP_KERNEL );
130
+ }
131
+
132
+ static ssize_t ms_show (struct kobject * kobj , struct kobj_attribute * attr ,
133
+ char * buf )
134
+ {
135
+ struct damon_sysfs_quotas * quotas = container_of (kobj ,
136
+ struct damon_sysfs_quotas , kobj );
137
+
138
+ return sysfs_emit (buf , "%lu\n" , quotas -> ms );
139
+ }
140
+
141
+ static ssize_t ms_store (struct kobject * kobj , struct kobj_attribute * attr ,
142
+ const char * buf , size_t count )
143
+ {
144
+ struct damon_sysfs_quotas * quotas = container_of (kobj ,
145
+ struct damon_sysfs_quotas , kobj );
146
+ int err = kstrtoul (buf , 0 , & quotas -> ms );
147
+
148
+ if (err )
149
+ return - EINVAL ;
150
+ return count ;
151
+ }
152
+
153
+ static ssize_t bytes_show (struct kobject * kobj , struct kobj_attribute * attr ,
154
+ char * buf )
155
+ {
156
+ struct damon_sysfs_quotas * quotas = container_of (kobj ,
157
+ struct damon_sysfs_quotas , kobj );
158
+
159
+ return sysfs_emit (buf , "%lu\n" , quotas -> sz );
160
+ }
161
+
162
+ static ssize_t bytes_store (struct kobject * kobj ,
163
+ struct kobj_attribute * attr , const char * buf , size_t count )
164
+ {
165
+ struct damon_sysfs_quotas * quotas = container_of (kobj ,
166
+ struct damon_sysfs_quotas , kobj );
167
+ int err = kstrtoul (buf , 0 , & quotas -> sz );
168
+
169
+ if (err )
170
+ return - EINVAL ;
171
+ return count ;
172
+ }
173
+
174
+ static ssize_t reset_interval_ms_show (struct kobject * kobj ,
175
+ struct kobj_attribute * attr , char * buf )
176
+ {
177
+ struct damon_sysfs_quotas * quotas = container_of (kobj ,
178
+ struct damon_sysfs_quotas , kobj );
179
+
180
+ return sysfs_emit (buf , "%lu\n" , quotas -> reset_interval_ms );
181
+ }
182
+
183
+ static ssize_t reset_interval_ms_store (struct kobject * kobj ,
184
+ struct kobj_attribute * attr , const char * buf , size_t count )
185
+ {
186
+ struct damon_sysfs_quotas * quotas = container_of (kobj ,
187
+ struct damon_sysfs_quotas , kobj );
188
+ int err = kstrtoul (buf , 0 , & quotas -> reset_interval_ms );
189
+
190
+ if (err )
191
+ return - EINVAL ;
192
+ return count ;
193
+ }
194
+
195
+ static void damon_sysfs_quotas_release (struct kobject * kobj )
196
+ {
197
+ kfree (container_of (kobj , struct damon_sysfs_quotas , kobj ));
198
+ }
199
+
200
+ static struct kobj_attribute damon_sysfs_quotas_ms_attr =
201
+ __ATTR_RW_MODE (ms , 0600 );
202
+
203
+ static struct kobj_attribute damon_sysfs_quotas_sz_attr =
204
+ __ATTR_RW_MODE (bytes , 0600 );
205
+
206
+ static struct kobj_attribute damon_sysfs_quotas_reset_interval_ms_attr =
207
+ __ATTR_RW_MODE (reset_interval_ms , 0600 );
208
+
209
+ static struct attribute * damon_sysfs_quotas_attrs [] = {
210
+ & damon_sysfs_quotas_ms_attr .attr ,
211
+ & damon_sysfs_quotas_sz_attr .attr ,
212
+ & damon_sysfs_quotas_reset_interval_ms_attr .attr ,
213
+ NULL ,
214
+ };
215
+ ATTRIBUTE_GROUPS (damon_sysfs_quotas );
216
+
217
+ static struct kobj_type damon_sysfs_quotas_ktype = {
218
+ .release = damon_sysfs_quotas_release ,
219
+ .sysfs_ops = & kobj_sysfs_ops ,
220
+ .default_groups = damon_sysfs_quotas_groups ,
221
+ };
222
+
116
223
/*
117
224
* access_pattern directory
118
225
*/
@@ -220,6 +327,7 @@ struct damon_sysfs_scheme {
220
327
struct kobject kobj ;
221
328
enum damos_action action ;
222
329
struct damon_sysfs_access_pattern * access_pattern ;
330
+ struct damon_sysfs_quotas * quotas ;
223
331
};
224
332
225
333
/* This should match with enum damos_action */
@@ -270,20 +378,48 @@ static int damon_sysfs_scheme_set_access_pattern(
270
378
return err ;
271
379
}
272
380
381
+ static int damon_sysfs_scheme_set_quotas (struct damon_sysfs_scheme * scheme )
382
+ {
383
+ struct damon_sysfs_quotas * quotas = damon_sysfs_quotas_alloc ();
384
+ int err ;
385
+
386
+ if (!quotas )
387
+ return - ENOMEM ;
388
+ err = kobject_init_and_add (& quotas -> kobj , & damon_sysfs_quotas_ktype ,
389
+ & scheme -> kobj , "quotas" );
390
+ if (err )
391
+ goto out ;
392
+ scheme -> quotas = quotas ;
393
+ return 0 ;
394
+
395
+ out :
396
+ kobject_put (& quotas -> kobj );
397
+ return err ;
398
+ }
399
+
273
400
static int damon_sysfs_scheme_add_dirs (struct damon_sysfs_scheme * scheme )
274
401
{
275
402
int err ;
276
403
277
404
err = damon_sysfs_scheme_set_access_pattern (scheme );
278
405
if (err )
279
406
return err ;
407
+ err = damon_sysfs_scheme_set_quotas (scheme );
408
+ if (err )
409
+ goto put_access_pattern_out ;
280
410
return 0 ;
411
+
412
+ put_access_pattern_out :
413
+ kobject_put (& scheme -> access_pattern -> kobj );
414
+ scheme -> access_pattern = NULL ;
415
+ return err ;
281
416
}
282
417
283
418
static void damon_sysfs_scheme_rm_dirs (struct damon_sysfs_scheme * scheme )
284
419
{
285
420
damon_sysfs_access_pattern_rm_dirs (scheme -> access_pattern );
286
421
kobject_put (& scheme -> access_pattern -> kobj );
422
+ kobject_put (& scheme -> quotas -> kobj );
287
423
}
288
424
289
425
static ssize_t action_show (struct kobject * kobj , struct kobj_attribute * attr ,
@@ -1522,7 +1658,15 @@ static struct damos *damon_sysfs_mk_scheme(
1522
1658
{
1523
1659
struct damon_sysfs_access_pattern * pattern =
1524
1660
sysfs_scheme -> access_pattern ;
1525
- struct damos_quota quota = (struct damos_quota ){};
1661
+ struct damon_sysfs_quotas * sysfs_quotas = sysfs_scheme -> quotas ;
1662
+ struct damos_quota quota = {
1663
+ .ms = sysfs_quotas -> ms ,
1664
+ .sz = sysfs_quotas -> sz ,
1665
+ .reset_interval = sysfs_quotas -> reset_interval_ms ,
1666
+ .weight_sz = 1000 ,
1667
+ .weight_nr_accesses = 1000 ,
1668
+ .weight_age = 1000 ,
1669
+ };
1526
1670
struct damos_watermarks wmarks = {
1527
1671
.metric = DAMOS_WMARK_NONE ,
1528
1672
.interval = 0 ,
0 commit comments