shrinker.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. * Note that 'shrink' will be passed nr_to_scan == 0 when the VM is
  11. * querying the cache size, so a fastpath for that case is appropriate.
  12. */
  13. struct shrink_control {
  14. gfp_t gfp_mask;
  15. /* How many slab objects shrinker() should scan and try to reclaim */
  16. unsigned long nr_to_scan;
  17. /* shrink from these nodes */
  18. nodemask_t nodes_to_scan;
  19. /* current node being shrunk (for NUMA aware shrinkers) */
  20. int nid;
  21. };
  22. #define SHRINK_STOP (~0UL)
  23. /*
  24. * A callback you can register to apply pressure to ageable caches.
  25. *
  26. * @shrink() should look through the least-recently-used 'nr_to_scan' entries
  27. * and attempt to free them up. It should return the number of objects which
  28. * remain in the cache. If it returns -1, it means it cannot do any scanning at
  29. * this time (eg. there is a risk of deadlock).
  30. *
  31. * @count_objects should return the number of freeable items in the cache. If
  32. * there are no objects to free or the number of freeable items cannot be
  33. * determined, it should return 0. No deadlock checks should be done during the
  34. * count callback - the shrinker relies on aggregating scan counts that couldn't
  35. * be executed due to potential deadlocks to be run at a later call when the
  36. * deadlock condition is no longer pending.
  37. *
  38. * @scan_objects will only be called if @count_objects returned a non-zero
  39. * value for the number of freeable objects. The callout should scan the cache
  40. * and attempt to free items from the cache. It should then return the number
  41. * of objects freed during the scan, or SHRINK_STOP if progress cannot be made
  42. * due to potential deadlocks. If SHRINK_STOP is returned, then no further
  43. * attempts to call the @scan_objects will be made from the current reclaim
  44. * context.
  45. *
  46. * @flags determine the shrinker abilities, like numa awareness
  47. */
  48. struct shrinker {
  49. int (*shrink)(struct shrinker *, struct shrink_control *sc);
  50. unsigned long (*count_objects)(struct shrinker *,
  51. struct shrink_control *sc);
  52. unsigned long (*scan_objects)(struct shrinker *,
  53. struct shrink_control *sc);
  54. int seeks; /* seeks to recreate an obj */
  55. long batch; /* reclaim batch size, 0 = default */
  56. unsigned long flags;
  57. /* These are for internal use */
  58. struct list_head list;
  59. /* objs pending delete, per node */
  60. atomic_long_t *nr_deferred;
  61. };
  62. #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
  63. /* Flags */
  64. #define SHRINKER_NUMA_AWARE (1 << 0)
  65. extern int register_shrinker(struct shrinker *);
  66. extern void unregister_shrinker(struct shrinker *);
  67. #endif