shrinker.h 2.5 KB

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