dm-cache-background-tracker.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2017 Red Hat. All rights reserved.
  4. *
  5. * This file is released under the GPL.
  6. */
  7. #ifndef DM_CACHE_BACKGROUND_WORK_H
  8. #define DM_CACHE_BACKGROUND_WORK_H
  9. #include <linux/vmalloc.h>
  10. #include "dm-cache-policy.h"
  11. /*----------------------------------------------------------------*/
  12. /*
  13. * The cache policy decides what background work should be performed,
  14. * such as promotions, demotions and writebacks. The core cache target
  15. * is in charge of performing the work, and does so when it sees fit.
  16. *
  17. * The background_tracker acts as a go between. Keeping track of future
  18. * work that the policy has decided upon, and handing (issuing) it to
  19. * the core target when requested.
  20. *
  21. * There is no locking in this, so calls will probably need to be
  22. * protected with a spinlock.
  23. */
  24. struct bt_work {
  25. struct list_head list;
  26. struct rb_node node;
  27. struct policy_work work;
  28. };
  29. extern struct kmem_cache *btracker_work_cache;
  30. struct background_work;
  31. struct background_tracker;
  32. /*
  33. * Create a new tracker, it will not be able to queue more than
  34. * 'max_work' entries.
  35. */
  36. struct background_tracker *btracker_create(unsigned int max_work);
  37. /*
  38. * Destroy the tracker. No issued, but not complete, work should
  39. * exist when this is called. It is fine to have queued but unissued
  40. * work.
  41. */
  42. void btracker_destroy(struct background_tracker *b);
  43. unsigned int btracker_nr_demotions_queued(struct background_tracker *b);
  44. /*
  45. * Queue some work within the tracker. 'work' should point to the work
  46. * to queue, this will be copied (ownership doesn't pass). If pwork
  47. * is not NULL then it will be set to point to the tracker's internal
  48. * copy of the work.
  49. *
  50. * returns -EINVAL iff the work is already queued. -ENOMEM if the work
  51. * couldn't be queued for another reason.
  52. */
  53. int btracker_queue(struct background_tracker *b,
  54. struct policy_work *work,
  55. struct policy_work **pwork);
  56. /*
  57. * Hands out the next piece of work to be performed.
  58. * Returns -ENODATA if there's no work.
  59. */
  60. int btracker_issue(struct background_tracker *b, struct policy_work **work);
  61. /*
  62. * Informs the tracker that the work has been completed and it may forget
  63. * about it.
  64. */
  65. void btracker_complete(struct background_tracker *b, struct policy_work *op);
  66. /*
  67. * Predicate to see if an origin block is already scheduled for promotion.
  68. */
  69. bool btracker_promotion_already_present(struct background_tracker *b,
  70. dm_oblock_t oblock);
  71. /*----------------------------------------------------------------*/
  72. #endif