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