deferred-free-helper.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef DEFERRED_FREE_HELPER_H
  3. #define DEFERRED_FREE_HELPER_H
  4. /**
  5. * df_reason - enum for reason why item was freed
  6. *
  7. * This provides a reason for why the free function was called
  8. * on the item. This is useful when deferred_free is used in
  9. * combination with a pagepool, so under pressure the page can
  10. * be immediately freed.
  11. *
  12. * DF_NORMAL: Normal deferred free
  13. *
  14. * DF_UNDER_PRESSURE: Free was called because the system
  15. * is under memory pressure. Usually
  16. * from a shrinker. Avoid allocating
  17. * memory in the free call, as it may
  18. * fail.
  19. */
  20. enum df_reason {
  21. DF_NORMAL,
  22. DF_UNDER_PRESSURE,
  23. };
  24. /**
  25. * deferred_freelist_item - item structure for deferred freelist
  26. *
  27. * This is to be added to the structure for whatever you want to
  28. * defer freeing on.
  29. *
  30. * @nr_pages: number of pages used by item to be freed
  31. * @free: function pointer to be called when freeing the item
  32. * @list: list entry for the deferred list
  33. */
  34. struct deferred_freelist_item {
  35. size_t nr_pages;
  36. void (*free)(struct deferred_freelist_item *i,
  37. enum df_reason reason);
  38. struct list_head list;
  39. };
  40. /**
  41. * deferred_free - call to add item to the deferred free list
  42. *
  43. * @item: Pointer to deferred_freelist_item field of a structure
  44. * @free: Function pointer to the free call
  45. * @nr_pages: number of pages to be freed
  46. */
  47. void deferred_free(struct deferred_freelist_item *item,
  48. void (*free)(struct deferred_freelist_item *i,
  49. enum df_reason reason),
  50. size_t nr_pages);
  51. #endif