1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef LINUX_QUICKLIST_H
3 #define LINUX_QUICKLIST_H
5 * Fast allocations and disposal of pages. Pages must be in the condition
6 * as needed after allocation when they are freed. Per cpu lists of pages
7 * are kept that only contain node local pages.
11 #include <linux/kernel.h>
12 #include <linux/gfp.h>
13 #include <linux/percpu.h>
15 #ifdef CONFIG_QUICKLIST
22 DECLARE_PER_CPU(struct quicklist, quicklist)[CONFIG_NR_QUICK];
25 * The two key functions quicklist_alloc and quicklist_free are inline so
26 * that they may be custom compiled for the platform.
27 * Specifying a NULL ctor can remove constructor support. Specifying
28 * a constant quicklist allows the determination of the exact address
29 * in the per cpu area.
31 * The fast patch in quicklist_alloc touched only a per cpu cacheline and
32 * the first cacheline of the page itself. There is minmal overhead involved.
34 static inline void *quicklist_alloc(int nr, gfp_t flags, void (*ctor)(void *))
39 q =&get_cpu_var(quicklist)[nr];
46 put_cpu_var(quicklist);
50 p = (void *)__get_free_page(flags | __GFP_ZERO);
56 static inline void __quicklist_free(int nr, void (*dtor)(void *), void *p,
61 q = &get_cpu_var(quicklist)[nr];
62 *(void **)p = q->page;
65 put_cpu_var(quicklist);
68 static inline void quicklist_free(int nr, void (*dtor)(void *), void *pp)
70 __quicklist_free(nr, dtor, pp, virt_to_page(pp));
73 static inline void quicklist_free_page(int nr, void (*dtor)(void *),
76 __quicklist_free(nr, dtor, page_address(page), page);
79 void quicklist_trim(int nr, void (*dtor)(void *),
80 unsigned long min_pages, unsigned long max_free);
82 unsigned long quicklist_total_size(void);
86 static inline unsigned long quicklist_total_size(void)
93 #endif /* LINUX_QUICKLIST_H */