damon.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * DAMON api
  4. *
  5. * Author: SeongJae Park <[email protected]>
  6. */
  7. #ifndef _DAMON_H_
  8. #define _DAMON_H_
  9. #include <linux/mutex.h>
  10. #include <linux/time64.h>
  11. #include <linux/types.h>
  12. #include <linux/random.h>
  13. /* Minimal region size. Every damon_region is aligned by this. */
  14. #define DAMON_MIN_REGION PAGE_SIZE
  15. /* Max priority score for DAMON-based operation schemes */
  16. #define DAMOS_MAX_SCORE (99)
  17. /* Get a random number in [l, r) */
  18. static inline unsigned long damon_rand(unsigned long l, unsigned long r)
  19. {
  20. return l + prandom_u32_max(r - l);
  21. }
  22. /**
  23. * struct damon_addr_range - Represents an address region of [@start, @end).
  24. * @start: Start address of the region (inclusive).
  25. * @end: End address of the region (exclusive).
  26. */
  27. struct damon_addr_range {
  28. unsigned long start;
  29. unsigned long end;
  30. };
  31. /**
  32. * struct damon_region - Represents a monitoring target region.
  33. * @ar: The address range of the region.
  34. * @sampling_addr: Address of the sample for the next access check.
  35. * @nr_accesses: Access frequency of this region.
  36. * @list: List head for siblings.
  37. * @age: Age of this region.
  38. *
  39. * @age is initially zero, increased for each aggregation interval, and reset
  40. * to zero again if the access frequency is significantly changed. If two
  41. * regions are merged into a new region, both @nr_accesses and @age of the new
  42. * region are set as region size-weighted average of those of the two regions.
  43. */
  44. struct damon_region {
  45. struct damon_addr_range ar;
  46. unsigned long sampling_addr;
  47. unsigned int nr_accesses;
  48. struct list_head list;
  49. unsigned int age;
  50. /* private: Internal value for age calculation. */
  51. unsigned int last_nr_accesses;
  52. };
  53. /**
  54. * struct damon_target - Represents a monitoring target.
  55. * @pid: The PID of the virtual address space to monitor.
  56. * @nr_regions: Number of monitoring target regions of this target.
  57. * @regions_list: Head of the monitoring target regions of this target.
  58. * @list: List head for siblings.
  59. *
  60. * Each monitoring context could have multiple targets. For example, a context
  61. * for virtual memory address spaces could have multiple target processes. The
  62. * @pid should be set for appropriate &struct damon_operations including the
  63. * virtual address spaces monitoring operations.
  64. */
  65. struct damon_target {
  66. struct pid *pid;
  67. unsigned int nr_regions;
  68. struct list_head regions_list;
  69. struct list_head list;
  70. };
  71. /**
  72. * enum damos_action - Represents an action of a Data Access Monitoring-based
  73. * Operation Scheme.
  74. *
  75. * @DAMOS_WILLNEED: Call ``madvise()`` for the region with MADV_WILLNEED.
  76. * @DAMOS_COLD: Call ``madvise()`` for the region with MADV_COLD.
  77. * @DAMOS_PAGEOUT: Call ``madvise()`` for the region with MADV_PAGEOUT.
  78. * @DAMOS_HUGEPAGE: Call ``madvise()`` for the region with MADV_HUGEPAGE.
  79. * @DAMOS_NOHUGEPAGE: Call ``madvise()`` for the region with MADV_NOHUGEPAGE.
  80. * @DAMOS_LRU_PRIO: Prioritize the region on its LRU lists.
  81. * @DAMOS_LRU_DEPRIO: Deprioritize the region on its LRU lists.
  82. * @DAMOS_STAT: Do nothing but count the stat.
  83. * @NR_DAMOS_ACTIONS: Total number of DAMOS actions
  84. */
  85. enum damos_action {
  86. DAMOS_WILLNEED,
  87. DAMOS_COLD,
  88. DAMOS_PAGEOUT,
  89. DAMOS_HUGEPAGE,
  90. DAMOS_NOHUGEPAGE,
  91. DAMOS_LRU_PRIO,
  92. DAMOS_LRU_DEPRIO,
  93. DAMOS_STAT, /* Do nothing but only record the stat */
  94. NR_DAMOS_ACTIONS,
  95. };
  96. /**
  97. * struct damos_quota - Controls the aggressiveness of the given scheme.
  98. * @ms: Maximum milliseconds that the scheme can use.
  99. * @sz: Maximum bytes of memory that the action can be applied.
  100. * @reset_interval: Charge reset interval in milliseconds.
  101. *
  102. * @weight_sz: Weight of the region's size for prioritization.
  103. * @weight_nr_accesses: Weight of the region's nr_accesses for prioritization.
  104. * @weight_age: Weight of the region's age for prioritization.
  105. *
  106. * To avoid consuming too much CPU time or IO resources for applying the
  107. * &struct damos->action to large memory, DAMON allows users to set time and/or
  108. * size quotas. The quotas can be set by writing non-zero values to &ms and
  109. * &sz, respectively. If the time quota is set, DAMON tries to use only up to
  110. * &ms milliseconds within &reset_interval for applying the action. If the
  111. * size quota is set, DAMON tries to apply the action only up to &sz bytes
  112. * within &reset_interval.
  113. *
  114. * Internally, the time quota is transformed to a size quota using estimated
  115. * throughput of the scheme's action. DAMON then compares it against &sz and
  116. * uses smaller one as the effective quota.
  117. *
  118. * For selecting regions within the quota, DAMON prioritizes current scheme's
  119. * target memory regions using the &struct damon_operations->get_scheme_score.
  120. * You could customize the prioritization logic by setting &weight_sz,
  121. * &weight_nr_accesses, and &weight_age, because monitoring operations are
  122. * encouraged to respect those.
  123. */
  124. struct damos_quota {
  125. unsigned long ms;
  126. unsigned long sz;
  127. unsigned long reset_interval;
  128. unsigned int weight_sz;
  129. unsigned int weight_nr_accesses;
  130. unsigned int weight_age;
  131. /* private: */
  132. /* For throughput estimation */
  133. unsigned long total_charged_sz;
  134. unsigned long total_charged_ns;
  135. unsigned long esz; /* Effective size quota in bytes */
  136. /* For charging the quota */
  137. unsigned long charged_sz;
  138. unsigned long charged_from;
  139. struct damon_target *charge_target_from;
  140. unsigned long charge_addr_from;
  141. /* For prioritization */
  142. unsigned long histogram[DAMOS_MAX_SCORE + 1];
  143. unsigned int min_score;
  144. };
  145. /**
  146. * enum damos_wmark_metric - Represents the watermark metric.
  147. *
  148. * @DAMOS_WMARK_NONE: Ignore the watermarks of the given scheme.
  149. * @DAMOS_WMARK_FREE_MEM_RATE: Free memory rate of the system in [0,1000].
  150. * @NR_DAMOS_WMARK_METRICS: Total number of DAMOS watermark metrics
  151. */
  152. enum damos_wmark_metric {
  153. DAMOS_WMARK_NONE,
  154. DAMOS_WMARK_FREE_MEM_RATE,
  155. NR_DAMOS_WMARK_METRICS,
  156. };
  157. /**
  158. * struct damos_watermarks - Controls when a given scheme should be activated.
  159. * @metric: Metric for the watermarks.
  160. * @interval: Watermarks check time interval in microseconds.
  161. * @high: High watermark.
  162. * @mid: Middle watermark.
  163. * @low: Low watermark.
  164. *
  165. * If &metric is &DAMOS_WMARK_NONE, the scheme is always active. Being active
  166. * means DAMON does monitoring and applying the action of the scheme to
  167. * appropriate memory regions. Else, DAMON checks &metric of the system for at
  168. * least every &interval microseconds and works as below.
  169. *
  170. * If &metric is higher than &high, the scheme is inactivated. If &metric is
  171. * between &mid and &low, the scheme is activated. If &metric is lower than
  172. * &low, the scheme is inactivated.
  173. */
  174. struct damos_watermarks {
  175. enum damos_wmark_metric metric;
  176. unsigned long interval;
  177. unsigned long high;
  178. unsigned long mid;
  179. unsigned long low;
  180. /* private: */
  181. bool activated;
  182. };
  183. /**
  184. * struct damos_stat - Statistics on a given scheme.
  185. * @nr_tried: Total number of regions that the scheme is tried to be applied.
  186. * @sz_tried: Total size of regions that the scheme is tried to be applied.
  187. * @nr_applied: Total number of regions that the scheme is applied.
  188. * @sz_applied: Total size of regions that the scheme is applied.
  189. * @qt_exceeds: Total number of times the quota of the scheme has exceeded.
  190. */
  191. struct damos_stat {
  192. unsigned long nr_tried;
  193. unsigned long sz_tried;
  194. unsigned long nr_applied;
  195. unsigned long sz_applied;
  196. unsigned long qt_exceeds;
  197. };
  198. /**
  199. * struct damos_access_pattern - Target access pattern of the given scheme.
  200. * @min_sz_region: Minimum size of target regions.
  201. * @max_sz_region: Maximum size of target regions.
  202. * @min_nr_accesses: Minimum ``->nr_accesses`` of target regions.
  203. * @max_nr_accesses: Maximum ``->nr_accesses`` of target regions.
  204. * @min_age_region: Minimum age of target regions.
  205. * @max_age_region: Maximum age of target regions.
  206. */
  207. struct damos_access_pattern {
  208. unsigned long min_sz_region;
  209. unsigned long max_sz_region;
  210. unsigned int min_nr_accesses;
  211. unsigned int max_nr_accesses;
  212. unsigned int min_age_region;
  213. unsigned int max_age_region;
  214. };
  215. /**
  216. * struct damos - Represents a Data Access Monitoring-based Operation Scheme.
  217. * @pattern: Access pattern of target regions.
  218. * @action: &damo_action to be applied to the target regions.
  219. * @quota: Control the aggressiveness of this scheme.
  220. * @wmarks: Watermarks for automated (in)activation of this scheme.
  221. * @stat: Statistics of this scheme.
  222. * @list: List head for siblings.
  223. *
  224. * For each aggregation interval, DAMON finds regions which fit in the
  225. * &pattern and applies &action to those. To avoid consuming too much
  226. * CPU time or IO resources for the &action, &quota is used.
  227. *
  228. * To do the work only when needed, schemes can be activated for specific
  229. * system situations using &wmarks. If all schemes that registered to the
  230. * monitoring context are inactive, DAMON stops monitoring either, and just
  231. * repeatedly checks the watermarks.
  232. *
  233. * If all schemes that registered to a &struct damon_ctx are inactive, DAMON
  234. * stops monitoring and just repeatedly checks the watermarks.
  235. *
  236. * After applying the &action to each region, &stat_count and &stat_sz is
  237. * updated to reflect the number of regions and total size of regions that the
  238. * &action is applied.
  239. */
  240. struct damos {
  241. struct damos_access_pattern pattern;
  242. enum damos_action action;
  243. struct damos_quota quota;
  244. struct damos_watermarks wmarks;
  245. struct damos_stat stat;
  246. struct list_head list;
  247. };
  248. /**
  249. * enum damon_ops_id - Identifier for each monitoring operations implementation
  250. *
  251. * @DAMON_OPS_VADDR: Monitoring operations for virtual address spaces
  252. * @DAMON_OPS_FVADDR: Monitoring operations for only fixed ranges of virtual
  253. * address spaces
  254. * @DAMON_OPS_PADDR: Monitoring operations for the physical address space
  255. * @NR_DAMON_OPS: Number of monitoring operations implementations
  256. */
  257. enum damon_ops_id {
  258. DAMON_OPS_VADDR,
  259. DAMON_OPS_FVADDR,
  260. DAMON_OPS_PADDR,
  261. NR_DAMON_OPS,
  262. };
  263. struct damon_ctx;
  264. /**
  265. * struct damon_operations - Monitoring operations for given use cases.
  266. *
  267. * @id: Identifier of this operations set.
  268. * @init: Initialize operations-related data structures.
  269. * @update: Update operations-related data structures.
  270. * @prepare_access_checks: Prepare next access check of target regions.
  271. * @check_accesses: Check the accesses to target regions.
  272. * @reset_aggregated: Reset aggregated accesses monitoring results.
  273. * @get_scheme_score: Get the score of a region for a scheme.
  274. * @apply_scheme: Apply a DAMON-based operation scheme.
  275. * @target_valid: Determine if the target is valid.
  276. * @cleanup: Clean up the context.
  277. *
  278. * DAMON can be extended for various address spaces and usages. For this,
  279. * users should register the low level operations for their target address
  280. * space and usecase via the &damon_ctx.ops. Then, the monitoring thread
  281. * (&damon_ctx.kdamond) calls @init and @prepare_access_checks before starting
  282. * the monitoring, @update after each &damon_ctx.ops_update_interval, and
  283. * @check_accesses, @target_valid and @prepare_access_checks after each
  284. * &damon_ctx.sample_interval. Finally, @reset_aggregated is called after each
  285. * &damon_ctx.aggr_interval.
  286. *
  287. * Each &struct damon_operations instance having valid @id can be registered
  288. * via damon_register_ops() and selected by damon_select_ops() later.
  289. * @init should initialize operations-related data structures. For example,
  290. * this could be used to construct proper monitoring target regions and link
  291. * those to @damon_ctx.adaptive_targets.
  292. * @update should update the operations-related data structures. For example,
  293. * this could be used to update monitoring target regions for current status.
  294. * @prepare_access_checks should manipulate the monitoring regions to be
  295. * prepared for the next access check.
  296. * @check_accesses should check the accesses to each region that made after the
  297. * last preparation and update the number of observed accesses of each region.
  298. * It should also return max number of observed accesses that made as a result
  299. * of its update. The value will be used for regions adjustment threshold.
  300. * @reset_aggregated should reset the access monitoring results that aggregated
  301. * by @check_accesses.
  302. * @get_scheme_score should return the priority score of a region for a scheme
  303. * as an integer in [0, &DAMOS_MAX_SCORE].
  304. * @apply_scheme is called from @kdamond when a region for user provided
  305. * DAMON-based operation scheme is found. It should apply the scheme's action
  306. * to the region and return bytes of the region that the action is successfully
  307. * applied.
  308. * @target_valid should check whether the target is still valid for the
  309. * monitoring.
  310. * @cleanup is called from @kdamond just before its termination.
  311. */
  312. struct damon_operations {
  313. enum damon_ops_id id;
  314. void (*init)(struct damon_ctx *context);
  315. void (*update)(struct damon_ctx *context);
  316. void (*prepare_access_checks)(struct damon_ctx *context);
  317. unsigned int (*check_accesses)(struct damon_ctx *context);
  318. void (*reset_aggregated)(struct damon_ctx *context);
  319. int (*get_scheme_score)(struct damon_ctx *context,
  320. struct damon_target *t, struct damon_region *r,
  321. struct damos *scheme);
  322. unsigned long (*apply_scheme)(struct damon_ctx *context,
  323. struct damon_target *t, struct damon_region *r,
  324. struct damos *scheme);
  325. bool (*target_valid)(struct damon_target *t);
  326. void (*cleanup)(struct damon_ctx *context);
  327. };
  328. /**
  329. * struct damon_callback - Monitoring events notification callbacks.
  330. *
  331. * @before_start: Called before starting the monitoring.
  332. * @after_wmarks_check: Called after each schemes' watermarks check.
  333. * @after_sampling: Called after each sampling.
  334. * @after_aggregation: Called after each aggregation.
  335. * @before_damos_apply: Called before applying DAMOS action.
  336. * @before_terminate: Called before terminating the monitoring.
  337. * @private: User private data.
  338. *
  339. * The monitoring thread (&damon_ctx.kdamond) calls @before_start and
  340. * @before_terminate just before starting and finishing the monitoring,
  341. * respectively. Therefore, those are good places for installing and cleaning
  342. * @private.
  343. *
  344. * The monitoring thread calls @after_wmarks_check after each DAMON-based
  345. * operation schemes' watermarks check. If users need to make changes to the
  346. * attributes of the monitoring context while it's deactivated due to the
  347. * watermarks, this is the good place to do.
  348. *
  349. * The monitoring thread calls @after_sampling and @after_aggregation for each
  350. * of the sampling intervals and aggregation intervals, respectively.
  351. * Therefore, users can safely access the monitoring results without additional
  352. * protection. For the reason, users are recommended to use these callback for
  353. * the accesses to the results.
  354. *
  355. * If any callback returns non-zero, monitoring stops.
  356. */
  357. struct damon_callback {
  358. void *private;
  359. int (*before_start)(struct damon_ctx *context);
  360. int (*after_wmarks_check)(struct damon_ctx *context);
  361. int (*after_sampling)(struct damon_ctx *context);
  362. int (*after_aggregation)(struct damon_ctx *context);
  363. int (*before_damos_apply)(struct damon_ctx *context,
  364. struct damon_target *target,
  365. struct damon_region *region,
  366. struct damos *scheme);
  367. void (*before_terminate)(struct damon_ctx *context);
  368. };
  369. /**
  370. * struct damon_attrs - Monitoring attributes for accuracy/overhead control.
  371. *
  372. * @sample_interval: The time between access samplings.
  373. * @aggr_interval: The time between monitor results aggregations.
  374. * @ops_update_interval: The time between monitoring operations updates.
  375. * @min_nr_regions: The minimum number of adaptive monitoring
  376. * regions.
  377. * @max_nr_regions: The maximum number of adaptive monitoring
  378. * regions.
  379. *
  380. * For each @sample_interval, DAMON checks whether each region is accessed or
  381. * not. It aggregates and keeps the access information (number of accesses to
  382. * each region) for @aggr_interval time. DAMON also checks whether the target
  383. * memory regions need update (e.g., by ``mmap()`` calls from the application,
  384. * in case of virtual memory monitoring) and applies the changes for each
  385. * @ops_update_interval. All time intervals are in micro-seconds.
  386. * Please refer to &struct damon_operations and &struct damon_callback for more
  387. * detail.
  388. */
  389. struct damon_attrs {
  390. unsigned long sample_interval;
  391. unsigned long aggr_interval;
  392. unsigned long ops_update_interval;
  393. unsigned long min_nr_regions;
  394. unsigned long max_nr_regions;
  395. };
  396. /**
  397. * struct damon_ctx - Represents a context for each monitoring. This is the
  398. * main interface that allows users to set the attributes and get the results
  399. * of the monitoring.
  400. *
  401. * @attrs: Monitoring attributes for accuracy/overhead control.
  402. * @kdamond: Kernel thread who does the monitoring.
  403. * @kdamond_lock: Mutex for the synchronizations with @kdamond.
  404. *
  405. * For each monitoring context, one kernel thread for the monitoring is
  406. * created. The pointer to the thread is stored in @kdamond.
  407. *
  408. * Once started, the monitoring thread runs until explicitly required to be
  409. * terminated or every monitoring target is invalid. The validity of the
  410. * targets is checked via the &damon_operations.target_valid of @ops. The
  411. * termination can also be explicitly requested by calling damon_stop().
  412. * The thread sets @kdamond to NULL when it terminates. Therefore, users can
  413. * know whether the monitoring is ongoing or terminated by reading @kdamond.
  414. * Reads and writes to @kdamond from outside of the monitoring thread must
  415. * be protected by @kdamond_lock.
  416. *
  417. * Note that the monitoring thread protects only @kdamond via @kdamond_lock.
  418. * Accesses to other fields must be protected by themselves.
  419. *
  420. * @ops: Set of monitoring operations for given use cases.
  421. * @callback: Set of callbacks for monitoring events notifications.
  422. *
  423. * @adaptive_targets: Head of monitoring targets (&damon_target) list.
  424. * @schemes: Head of schemes (&damos) list.
  425. */
  426. struct damon_ctx {
  427. struct damon_attrs attrs;
  428. /* private: internal use only */
  429. struct timespec64 last_aggregation;
  430. struct timespec64 last_ops_update;
  431. /* public: */
  432. struct task_struct *kdamond;
  433. struct mutex kdamond_lock;
  434. struct damon_operations ops;
  435. struct damon_callback callback;
  436. struct list_head adaptive_targets;
  437. struct list_head schemes;
  438. };
  439. static inline struct damon_region *damon_next_region(struct damon_region *r)
  440. {
  441. return container_of(r->list.next, struct damon_region, list);
  442. }
  443. static inline struct damon_region *damon_prev_region(struct damon_region *r)
  444. {
  445. return container_of(r->list.prev, struct damon_region, list);
  446. }
  447. static inline struct damon_region *damon_last_region(struct damon_target *t)
  448. {
  449. return list_last_entry(&t->regions_list, struct damon_region, list);
  450. }
  451. static inline struct damon_region *damon_first_region(struct damon_target *t)
  452. {
  453. return list_first_entry(&t->regions_list, struct damon_region, list);
  454. }
  455. static inline unsigned long damon_sz_region(struct damon_region *r)
  456. {
  457. return r->ar.end - r->ar.start;
  458. }
  459. #define damon_for_each_region(r, t) \
  460. list_for_each_entry(r, &t->regions_list, list)
  461. #define damon_for_each_region_from(r, t) \
  462. list_for_each_entry_from(r, &t->regions_list, list)
  463. #define damon_for_each_region_safe(r, next, t) \
  464. list_for_each_entry_safe(r, next, &t->regions_list, list)
  465. #define damon_for_each_target(t, ctx) \
  466. list_for_each_entry(t, &(ctx)->adaptive_targets, list)
  467. #define damon_for_each_target_safe(t, next, ctx) \
  468. list_for_each_entry_safe(t, next, &(ctx)->adaptive_targets, list)
  469. #define damon_for_each_scheme(s, ctx) \
  470. list_for_each_entry(s, &(ctx)->schemes, list)
  471. #define damon_for_each_scheme_safe(s, next, ctx) \
  472. list_for_each_entry_safe(s, next, &(ctx)->schemes, list)
  473. #ifdef CONFIG_DAMON
  474. struct damon_region *damon_new_region(unsigned long start, unsigned long end);
  475. /*
  476. * Add a region between two other regions
  477. */
  478. static inline void damon_insert_region(struct damon_region *r,
  479. struct damon_region *prev, struct damon_region *next,
  480. struct damon_target *t)
  481. {
  482. __list_add(&r->list, &prev->list, &next->list);
  483. t->nr_regions++;
  484. }
  485. void damon_add_region(struct damon_region *r, struct damon_target *t);
  486. void damon_destroy_region(struct damon_region *r, struct damon_target *t);
  487. int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges,
  488. unsigned int nr_ranges);
  489. struct damos *damon_new_scheme(struct damos_access_pattern *pattern,
  490. enum damos_action action, struct damos_quota *quota,
  491. struct damos_watermarks *wmarks);
  492. void damon_add_scheme(struct damon_ctx *ctx, struct damos *s);
  493. void damon_destroy_scheme(struct damos *s);
  494. struct damon_target *damon_new_target(void);
  495. void damon_add_target(struct damon_ctx *ctx, struct damon_target *t);
  496. bool damon_targets_empty(struct damon_ctx *ctx);
  497. void damon_free_target(struct damon_target *t);
  498. void damon_destroy_target(struct damon_target *t);
  499. unsigned int damon_nr_regions(struct damon_target *t);
  500. struct damon_ctx *damon_new_ctx(void);
  501. void damon_destroy_ctx(struct damon_ctx *ctx);
  502. int damon_set_attrs(struct damon_ctx *ctx, struct damon_attrs *attrs);
  503. void damon_set_schemes(struct damon_ctx *ctx,
  504. struct damos **schemes, ssize_t nr_schemes);
  505. int damon_nr_running_ctxs(void);
  506. bool damon_is_registered_ops(enum damon_ops_id id);
  507. int damon_register_ops(struct damon_operations *ops);
  508. int damon_select_ops(struct damon_ctx *ctx, enum damon_ops_id id);
  509. static inline bool damon_target_has_pid(const struct damon_ctx *ctx)
  510. {
  511. return ctx->ops.id == DAMON_OPS_VADDR || ctx->ops.id == DAMON_OPS_FVADDR;
  512. }
  513. static inline unsigned int damon_max_nr_accesses(const struct damon_attrs *attrs)
  514. {
  515. /* {aggr,sample}_interval are unsigned long, hence could overflow */
  516. return min(attrs->aggr_interval / attrs->sample_interval,
  517. (unsigned long)UINT_MAX);
  518. }
  519. int damon_start(struct damon_ctx **ctxs, int nr_ctxs, bool exclusive);
  520. int damon_stop(struct damon_ctx **ctxs, int nr_ctxs);
  521. int damon_set_region_biggest_system_ram_default(struct damon_target *t,
  522. unsigned long *start, unsigned long *end);
  523. #endif /* CONFIG_DAMON */
  524. #endif /* _DAMON_H */