aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/frontswap.h6
-rw-r--r--mm/frontswap.c31
-rw-r--r--mm/swapfile.c17
3 files changed, 35 insertions, 19 deletions
diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
index 6c49e1eba552..8293262401de 100644
--- a/include/linux/frontswap.h
+++ b/include/linux/frontswap.h
@@ -23,7 +23,7 @@ extern void frontswap_writethrough(bool);
23extern void frontswap_tmem_exclusive_gets(bool); 23extern void frontswap_tmem_exclusive_gets(bool);
24 24
25extern bool __frontswap_test(struct swap_info_struct *, pgoff_t); 25extern bool __frontswap_test(struct swap_info_struct *, pgoff_t);
26extern void __frontswap_init(unsigned type); 26extern void __frontswap_init(unsigned type, unsigned long *map);
27extern int __frontswap_store(struct page *page); 27extern int __frontswap_store(struct page *page);
28extern int __frontswap_load(struct page *page); 28extern int __frontswap_load(struct page *page);
29extern void __frontswap_invalidate_page(unsigned, pgoff_t); 29extern void __frontswap_invalidate_page(unsigned, pgoff_t);
@@ -98,10 +98,10 @@ static inline void frontswap_invalidate_area(unsigned type)
98 __frontswap_invalidate_area(type); 98 __frontswap_invalidate_area(type);
99} 99}
100 100
101static inline void frontswap_init(unsigned type) 101static inline void frontswap_init(unsigned type, unsigned long *map)
102{ 102{
103 if (frontswap_enabled) 103 if (frontswap_enabled)
104 __frontswap_init(type); 104 __frontswap_init(type, map);
105} 105}
106 106
107#endif /* _LINUX_FRONTSWAP_H */ 107#endif /* _LINUX_FRONTSWAP_H */
diff --git a/mm/frontswap.c b/mm/frontswap.c
index 2760b0f98822..538367ef1372 100644
--- a/mm/frontswap.c
+++ b/mm/frontswap.c
@@ -121,8 +121,13 @@ struct frontswap_ops *frontswap_register_ops(struct frontswap_ops *ops)
121 int i; 121 int i;
122 122
123 for (i = 0; i < MAX_SWAPFILES; i++) { 123 for (i = 0; i < MAX_SWAPFILES; i++) {
124 if (test_and_clear_bit(i, need_init)) 124 if (test_and_clear_bit(i, need_init)) {
125 struct swap_info_struct *sis = swap_info[i];
126 /* __frontswap_init _should_ have set it! */
127 if (!sis->frontswap_map)
128 return ERR_PTR(-EINVAL);
125 ops->init(i); 129 ops->init(i);
130 }
126 } 131 }
127 /* 132 /*
128 * We MUST have frontswap_ops set _after_ the frontswap_init's 133 * We MUST have frontswap_ops set _after_ the frontswap_init's
@@ -156,20 +161,30 @@ EXPORT_SYMBOL(frontswap_tmem_exclusive_gets);
156/* 161/*
157 * Called when a swap device is swapon'd. 162 * Called when a swap device is swapon'd.
158 */ 163 */
159void __frontswap_init(unsigned type) 164void __frontswap_init(unsigned type, unsigned long *map)
160{ 165{
161 struct swap_info_struct *sis = swap_info[type]; 166 struct swap_info_struct *sis = swap_info[type];
162 167
163 if (frontswap_ops) { 168 BUG_ON(sis == NULL);
164 BUG_ON(sis == NULL); 169
165 if (sis->frontswap_map == NULL) 170 /*
166 return; 171 * p->frontswap is a bitmap that we MUST have to figure out which page
172 * has gone in frontswap. Without it there is no point of continuing.
173 */
174 if (WARN_ON(!map))
175 return;
176 /*
177 * Irregardless of whether the frontswap backend has been loaded
178 * before this function or it will be later, we _MUST_ have the
179 * p->frontswap set to something valid to work properly.
180 */
181 frontswap_map_set(sis, map);
182 if (frontswap_ops)
167 frontswap_ops->init(type); 183 frontswap_ops->init(type);
168 } else { 184 else {
169 BUG_ON(type > MAX_SWAPFILES); 185 BUG_ON(type > MAX_SWAPFILES);
170 set_bit(type, need_init); 186 set_bit(type, need_init);
171 } 187 }
172
173} 188}
174EXPORT_SYMBOL(__frontswap_init); 189EXPORT_SYMBOL(__frontswap_init);
175 190
diff --git a/mm/swapfile.c b/mm/swapfile.c
index d417efddfe74..6c340d908b27 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1509,8 +1509,7 @@ static int setup_swap_extents(struct swap_info_struct *sis, sector_t *span)
1509} 1509}
1510 1510
1511static void _enable_swap_info(struct swap_info_struct *p, int prio, 1511static void _enable_swap_info(struct swap_info_struct *p, int prio,
1512 unsigned char *swap_map, 1512 unsigned char *swap_map)
1513 unsigned long *frontswap_map)
1514{ 1513{
1515 int i, prev; 1514 int i, prev;
1516 1515
@@ -1519,7 +1518,6 @@ static void _enable_swap_info(struct swap_info_struct *p, int prio,
1519 else 1518 else
1520 p->prio = --least_priority; 1519 p->prio = --least_priority;
1521 p->swap_map = swap_map; 1520 p->swap_map = swap_map;
1522 frontswap_map_set(p, frontswap_map);
1523 p->flags |= SWP_WRITEOK; 1521 p->flags |= SWP_WRITEOK;
1524 atomic_long_add(p->pages, &nr_swap_pages); 1522 atomic_long_add(p->pages, &nr_swap_pages);
1525 total_swap_pages += p->pages; 1523 total_swap_pages += p->pages;
@@ -1542,10 +1540,10 @@ static void enable_swap_info(struct swap_info_struct *p, int prio,
1542 unsigned char *swap_map, 1540 unsigned char *swap_map,
1543 unsigned long *frontswap_map) 1541 unsigned long *frontswap_map)
1544{ 1542{
1543 frontswap_init(p->type, frontswap_map);
1545 spin_lock(&swap_lock); 1544 spin_lock(&swap_lock);
1546 spin_lock(&p->lock); 1545 spin_lock(&p->lock);
1547 _enable_swap_info(p, prio, swap_map, frontswap_map); 1546 _enable_swap_info(p, prio, swap_map);
1548 frontswap_init(p->type);
1549 spin_unlock(&p->lock); 1547 spin_unlock(&p->lock);
1550 spin_unlock(&swap_lock); 1548 spin_unlock(&swap_lock);
1551} 1549}
@@ -1554,7 +1552,7 @@ static void reinsert_swap_info(struct swap_info_struct *p)
1554{ 1552{
1555 spin_lock(&swap_lock); 1553 spin_lock(&swap_lock);
1556 spin_lock(&p->lock); 1554 spin_lock(&p->lock);
1557 _enable_swap_info(p, p->prio, p->swap_map, frontswap_map_get(p)); 1555 _enable_swap_info(p, p->prio, p->swap_map);
1558 spin_unlock(&p->lock); 1556 spin_unlock(&p->lock);
1559 spin_unlock(&swap_lock); 1557 spin_unlock(&swap_lock);
1560} 1558}
@@ -1563,6 +1561,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
1563{ 1561{
1564 struct swap_info_struct *p = NULL; 1562 struct swap_info_struct *p = NULL;
1565 unsigned char *swap_map; 1563 unsigned char *swap_map;
1564 unsigned long *frontswap_map;
1566 struct file *swap_file, *victim; 1565 struct file *swap_file, *victim;
1567 struct address_space *mapping; 1566 struct address_space *mapping;
1568 struct inode *inode; 1567 struct inode *inode;
@@ -1662,12 +1661,14 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
1662 swap_map = p->swap_map; 1661 swap_map = p->swap_map;
1663 p->swap_map = NULL; 1662 p->swap_map = NULL;
1664 p->flags = 0; 1663 p->flags = 0;
1665 frontswap_invalidate_area(type); 1664 frontswap_map = frontswap_map_get(p);
1665 frontswap_map_set(p, NULL);
1666 spin_unlock(&p->lock); 1666 spin_unlock(&p->lock);
1667 spin_unlock(&swap_lock); 1667 spin_unlock(&swap_lock);
1668 frontswap_invalidate_area(type);
1668 mutex_unlock(&swapon_mutex); 1669 mutex_unlock(&swapon_mutex);
1669 vfree(swap_map); 1670 vfree(swap_map);
1670 vfree(frontswap_map_get(p)); 1671 vfree(frontswap_map);
1671 /* Destroy swap account informatin */ 1672 /* Destroy swap account informatin */
1672 swap_cgroup_swapoff(type); 1673 swap_cgroup_swapoff(type);
1673 1674