shrinker.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef _LINUX_SHRINKER_H
  2. #define _LINUX_SHRINKER_H
  3. /*
  4. * This struct is used to pass information from page reclaim to the shrinkers.
  5. * We consolidate the values for easier extention later.
  6. *
  7. * The 'gfpmask' refers to the allocation we are currently trying to
  8. * fulfil.
  9. */
  10. struct shrink_control {
  11. gfp_t gfp_mask;
  12. /*
  13. * How many objects scan_objects should scan and try to reclaim.
  14. * This is reset before every call, so it is safe for callees
  15. * to modify.
  16. */
  17. unsigned long nr_to_scan;
  18. /* current node being shrunk (for NUMA aware shrinkers) */
  19. int nid;
  20. /* current memcg being shrunk (for memcg aware shrinkers) */
  21. struct mem_cgroup *memcg;
  22. };
  23. #define SHRINK_STOP (~0UL)
  24. /*
  25. * A callback you can register to apply pressure to ageable caches.
  26. *
  27. * @count_objects should return the number of freeable items in the cache. If
  28. * there are no objects to free or the number of freeable items cannot be
  29. * determined, it should return 0. No deadlock checks should be done during the
  30. * count callback - the shrinker relies on aggregating scan counts that couldn't
  31. * be executed due to potential deadlocks to be run at a later call when the
  32. * deadlock condition is no longer pending.
  33. *
  34. * @scan_objects will only be called if @count_objects returned a non-zero
  35. * value for the number of freeable objects. The callout should scan the cache
  36. * and attempt to free items from the cache. It should then return the number
  37. * of objects freed during the scan, or SHRINK_STOP if progress cannot be made
  38. * due to potential deadlocks. If SHRINK_STOP is returned, then no further
  39. * attempts to call the @scan_objects will be made from the current reclaim
  40. * context.
  41. *
  42. * @flags determine the shrinker abilities, like numa awareness
  43. */
  44. struct shrinker {
  45. unsigned long (*count_objects)(struct shrinker *,
  46. struct shrink_control *sc);
  47. unsigned long (*scan_objects)(struct shrinker *,
  48. struct shrink_control *sc);
  49. int seeks; /* seeks to recreate an obj */
  50. long batch; /* reclaim batch size, 0 = default */
  51. unsigned long flags;
  52. /* These are for internal use */
  53. struct list_head list;
  54. /* objs pending delete, per node */
  55. atomic_long_t *nr_deferred;
  56. };
  57. #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
  58. /* Flags */
  59. #define SHRINKER_NUMA_AWARE (1 << 0)
  60. #define SHRINKER_MEMCG_AWARE (1 << 1)
  61. extern int register_shrinker(struct shrinker *);
  62. extern void unregister_shrinker(struct shrinker *);
  63. #endif