shrinker.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. };
  21. #define SHRINK_STOP (~0UL)
  22. /*
  23. * A callback you can register to apply pressure to ageable caches.
  24. *
  25. * @count_objects should return the number of freeable items in the cache. If
  26. * there are no objects to free or the number of freeable items cannot be
  27. * determined, it should return 0. No deadlock checks should be done during the
  28. * count callback - the shrinker relies on aggregating scan counts that couldn't
  29. * be executed due to potential deadlocks to be run at a later call when the
  30. * deadlock condition is no longer pending.
  31. *
  32. * @scan_objects will only be called if @count_objects returned a non-zero
  33. * value for the number of freeable objects. The callout should scan the cache
  34. * and attempt to free items from the cache. It should then return the number
  35. * of objects freed during the scan, or SHRINK_STOP if progress cannot be made
  36. * due to potential deadlocks. If SHRINK_STOP is returned, then no further
  37. * attempts to call the @scan_objects will be made from the current reclaim
  38. * context.
  39. *
  40. * @flags determine the shrinker abilities, like numa awareness
  41. */
  42. struct shrinker {
  43. unsigned long (*count_objects)(struct shrinker *,
  44. struct shrink_control *sc);
  45. unsigned long (*scan_objects)(struct shrinker *,
  46. struct shrink_control *sc);
  47. int seeks; /* seeks to recreate an obj */
  48. long batch; /* reclaim batch size, 0 = default */
  49. unsigned long flags;
  50. /* These are for internal use */
  51. struct list_head list;
  52. /* objs pending delete, per node */
  53. atomic_long_t *nr_deferred;
  54. };
  55. #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
  56. /* Flags */
  57. #define SHRINKER_NUMA_AWARE (1 << 0)
  58. extern int register_shrinker(struct shrinker *);
  59. extern void unregister_shrinker(struct shrinker *);
  60. #endif