1 #ifndef LINUX_QUICKLIST_H
2 #define LINUX_QUICKLIST_H
4 * Fast allocations and disposal of pages. Pages must be in the condition
5 * as needed after allocation when they are freed. Per cpu lists of pages
6 * are kept that only contain node local pages.
8 * (C) 2007, SGI. Christoph Lameter <clameter@sgi.com>
10 #include <linux/kernel.h>
11 #include <linux/gfp.h>
12 #include <linux/percpu.h>
14 #ifdef CONFIG_QUICKLIST
21 DECLARE_PER_CPU(struct quicklist
, quicklist
)[CONFIG_NR_QUICK
];
24 * The two key functions quicklist_alloc and quicklist_free are inline so
25 * that they may be custom compiled for the platform.
26 * Specifying a NULL ctor can remove constructor support. Specifying
27 * a constant quicklist allows the determination of the exact address
28 * in the per cpu area.
30 * The fast patch in quicklist_alloc touched only a per cpu cacheline and
31 * the first cacheline of the page itself. There is minmal overhead involved.
33 static inline void *quicklist_alloc(int nr
, gfp_t flags
, void (*ctor
)(void *))
38 q
=&get_cpu_var(quicklist
)[nr
];
45 put_cpu_var(quicklist
);
49 p
= (void *)__get_free_page(flags
| __GFP_ZERO
);
55 static inline void __quicklist_free(int nr
, void (*dtor
)(void *), void *p
,
59 int nid
= page_to_nid(page
);
61 if (unlikely(nid
!= numa_node_id())) {
68 q
= &get_cpu_var(quicklist
)[nr
];
69 *(void **)p
= q
->page
;
72 put_cpu_var(quicklist
);
75 static inline void quicklist_free(int nr
, void (*dtor
)(void *), void *pp
)
77 __quicklist_free(nr
, dtor
, pp
, virt_to_page(pp
));
80 static inline void quicklist_free_page(int nr
, void (*dtor
)(void *),
83 __quicklist_free(nr
, dtor
, page_address(page
), page
);
86 void quicklist_trim(int nr
, void (*dtor
)(void *),
87 unsigned long min_pages
, unsigned long max_free
);
89 unsigned long quicklist_total_size(void);
93 #endif /* LINUX_QUICKLIST_H */