1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include <linux/kernel.h>
16
17#include <linux/mm.h>
18#include <linux/mmzone.h>
19#include <linux/module.h>
20#include <linux/quicklist.h>
21
22DEFINE_PER_CPU(struct quicklist, quicklist)[CONFIG_NR_QUICK];
23
24#define FRACTION_OF_NODE_MEM 16
25
26static unsigned long max_pages(unsigned long min_pages)
27{
28 unsigned long node_free_pages, max;
29
30 node_free_pages = node_page_state(numa_node_id(),
31 NR_FREE_PAGES);
32 max = node_free_pages / FRACTION_OF_NODE_MEM;
33 return max(max, min_pages);
34}
35
36static long min_pages_to_free(struct quicklist *q,
37 unsigned long min_pages, long max_free)
38{
39 long pages_to_free;
40
41 pages_to_free = q->nr_pages - max_pages(min_pages);
42
43 return min(pages_to_free, max_free);
44}
45
46
47
48
49void quicklist_trim(int nr, void (*dtor)(void *),
50 unsigned long min_pages, unsigned long max_free)
51{
52 long pages_to_free;
53 struct quicklist *q;
54
55 q = &get_cpu_var(quicklist)[nr];
56 if (q->nr_pages > min_pages) {
57 pages_to_free = min_pages_to_free(q, min_pages, max_free);
58
59 while (pages_to_free > 0) {
60
61
62
63
64 void *p = quicklist_alloc(nr, 0, NULL);
65
66 if (dtor)
67 dtor(p);
68 free_page((unsigned long)p);
69 pages_to_free--;
70 }
71 }
72 put_cpu_var(quicklist);
73}
74
75unsigned long quicklist_total_size(void)
76{
77 unsigned long count = 0;
78 int cpu;
79 struct quicklist *ql, *q;
80
81 for_each_online_cpu(cpu) {
82 ql = per_cpu(quicklist, cpu);
83 for (q = ql; q < ql + CONFIG_NR_QUICK; q++)
84 count += q->nr_pages;
85 }
86 return count;
87}
88
89