This source file includes following definitions.
- show_swap_cache_info
- add_to_swap_cache
- init_swap_cache
- swap_duplicate
1
2
3
4
5
6
7
8 #include <linux/mm.h>
9 #include <linux/sched.h>
10 #include <linux/head.h>
11 #include <linux/kernel.h>
12 #include <linux/kernel_stat.h>
13 #include <linux/errno.h>
14 #include <linux/string.h>
15 #include <linux/stat.h>
16 #include <linux/swap.h>
17 #include <linux/fs.h>
18 #include <linux/swapctl.h>
19
20 #include <asm/dma.h>
21 #include <asm/system.h>
22 #include <asm/segment.h>
23 #include <asm/bitops.h>
24 #include <asm/pgtable.h>
25
26
27
28
29
30
31
32
33 unsigned long *swap_cache;
34
35 #ifdef SWAP_CACHE_INFO
36 unsigned long swap_cache_add_total = 0;
37 unsigned long swap_cache_add_success = 0;
38 unsigned long swap_cache_del_total = 0;
39 unsigned long swap_cache_del_success = 0;
40 unsigned long swap_cache_find_total = 0;
41 unsigned long swap_cache_find_success = 0;
42
43 void show_swap_cache_info(void)
44 {
45 printk("Swap cache: add %ld/%ld, delete %ld/%ld, find %ld/%ld\n",
46 swap_cache_add_total, swap_cache_add_success,
47 swap_cache_del_total, swap_cache_del_success,
48 swap_cache_find_total, swap_cache_find_success);
49 }
50 #endif
51
52 int add_to_swap_cache(unsigned long index, unsigned long entry)
53 {
54 struct swap_info_struct * p = &swap_info[SWP_TYPE(entry)];
55
56 #ifdef SWAP_CACHE_INFO
57 swap_cache_add_total++;
58 #endif
59 if ((p->flags & SWP_WRITEOK) == SWP_WRITEOK) {
60 entry = xchg(swap_cache + index, entry);
61 if (entry) {
62 printk("swap_cache: replacing non-NULL entry\n");
63 }
64 #ifdef SWAP_CACHE_INFO
65 swap_cache_add_success++;
66 #endif
67 return 1;
68 }
69 return 0;
70 }
71
72 unsigned long init_swap_cache(unsigned long mem_start,
73 unsigned long mem_end)
74 {
75 unsigned long swap_cache_size;
76
77 mem_start = (mem_start + 15) & ~15;
78 swap_cache = (unsigned long *) mem_start;
79 swap_cache_size = MAP_NR(mem_end);
80 memset(swap_cache, 0, swap_cache_size * sizeof (unsigned long));
81 return (unsigned long) (swap_cache + swap_cache_size);
82 }
83
84 void swap_duplicate(unsigned long entry)
85 {
86 struct swap_info_struct * p;
87 unsigned long offset, type;
88
89 if (!entry)
90 return;
91 offset = SWP_OFFSET(entry);
92 type = SWP_TYPE(entry);
93 if (type & SHM_SWP_TYPE)
94 return;
95 if (type >= nr_swapfiles) {
96 printk("Trying to duplicate nonexistent swap-page\n");
97 return;
98 }
99 p = type + swap_info;
100 if (offset >= p->max) {
101 printk("swap_duplicate: weirdness\n");
102 return;
103 }
104 if (!p->swap_map[offset]) {
105 printk("swap_duplicate: trying to duplicate unused page\n");
106 return;
107 }
108 p->swap_map[offset]++;
109 return;
110 }
111