shrinker.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. struct shrink_control {
  8. gfp_t gfp_mask;
  9. /* How many slab objects shrinker() should scan and try to reclaim */
  10. unsigned long nr_to_scan;
  11. };
  12. /*
  13. * A callback you can register to apply pressure to ageable caches.
  14. *
  15. * 'sc' is passed shrink_control which includes a count 'nr_to_scan'
  16. * and a 'gfpmask'. It should look through the least-recently-used
  17. * 'nr_to_scan' entries and attempt to free them up. It should return
  18. * the number of objects which remain in the cache. If it returns -1, it means
  19. * it cannot do any scanning at this time (eg. there is a risk of deadlock).
  20. * The callback must not return -1 if nr_to_scan is zero.
  21. *
  22. * The 'gfpmask' refers to the allocation we are currently trying to
  23. * fulfil.
  24. *
  25. * Note that 'shrink' will be passed nr_to_scan == 0 when the VM is
  26. * querying the cache size, so a fastpath for that case is appropriate.
  27. */
  28. struct shrinker {
  29. int (*shrink)(struct shrinker *, struct shrink_control *sc);
  30. int seeks; /* seeks to recreate an obj */
  31. long batch; /* reclaim batch size, 0 = default */
  32. /* These are for internal use */
  33. struct list_head list;
  34. atomic_long_t nr_in_batch; /* objs pending delete */
  35. };
  36. #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
  37. extern void register_shrinker(struct shrinker *);
  38. extern void unregister_shrinker(struct shrinker *);
  39. #endif