diff options
Diffstat (limited to 'mm/swapfile.c')
-rw-r--r-- | mm/swapfile.c | 46 |
1 files changed, 6 insertions, 40 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c index aafcf3611b31..8c6b3ce38f09 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c | |||
@@ -95,39 +95,6 @@ __try_to_reclaim_swap(struct swap_info_struct *si, unsigned long offset) | |||
95 | } | 95 | } |
96 | 96 | ||
97 | /* | 97 | /* |
98 | * We need this because the bdev->unplug_fn can sleep and we cannot | ||
99 | * hold swap_lock while calling the unplug_fn. And swap_lock | ||
100 | * cannot be turned into a mutex. | ||
101 | */ | ||
102 | static DECLARE_RWSEM(swap_unplug_sem); | ||
103 | |||
104 | void swap_unplug_io_fn(struct backing_dev_info *unused_bdi, struct page *page) | ||
105 | { | ||
106 | swp_entry_t entry; | ||
107 | |||
108 | down_read(&swap_unplug_sem); | ||
109 | entry.val = page_private(page); | ||
110 | if (PageSwapCache(page)) { | ||
111 | struct block_device *bdev = swap_info[swp_type(entry)]->bdev; | ||
112 | struct backing_dev_info *bdi; | ||
113 | |||
114 | /* | ||
115 | * If the page is removed from swapcache from under us (with a | ||
116 | * racy try_to_unuse/swapoff) we need an additional reference | ||
117 | * count to avoid reading garbage from page_private(page) above. | ||
118 | * If the WARN_ON triggers during a swapoff it maybe the race | ||
119 | * condition and it's harmless. However if it triggers without | ||
120 | * swapoff it signals a problem. | ||
121 | */ | ||
122 | WARN_ON(page_count(page) <= 1); | ||
123 | |||
124 | bdi = bdev->bd_inode->i_mapping->backing_dev_info; | ||
125 | blk_run_backing_dev(bdi, page); | ||
126 | } | ||
127 | up_read(&swap_unplug_sem); | ||
128 | } | ||
129 | |||
130 | /* | ||
131 | * swapon tell device that all the old swap contents can be discarded, | 98 | * swapon tell device that all the old swap contents can be discarded, |
132 | * to allow the swap device to optimize its wear-levelling. | 99 | * to allow the swap device to optimize its wear-levelling. |
133 | */ | 100 | */ |
@@ -880,7 +847,7 @@ unsigned int count_swap_pages(int type, int free) | |||
880 | static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, | 847 | static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, |
881 | unsigned long addr, swp_entry_t entry, struct page *page) | 848 | unsigned long addr, swp_entry_t entry, struct page *page) |
882 | { | 849 | { |
883 | struct mem_cgroup *ptr = NULL; | 850 | struct mem_cgroup *ptr; |
884 | spinlock_t *ptl; | 851 | spinlock_t *ptl; |
885 | pte_t *pte; | 852 | pte_t *pte; |
886 | int ret = 1; | 853 | int ret = 1; |
@@ -1662,10 +1629,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) | |||
1662 | goto out_dput; | 1629 | goto out_dput; |
1663 | } | 1630 | } |
1664 | 1631 | ||
1665 | /* wait for any unplug function to finish */ | ||
1666 | down_write(&swap_unplug_sem); | ||
1667 | up_write(&swap_unplug_sem); | ||
1668 | |||
1669 | destroy_swap_extents(p); | 1632 | destroy_swap_extents(p); |
1670 | if (p->flags & SWP_CONTINUED) | 1633 | if (p->flags & SWP_CONTINUED) |
1671 | free_swap_count_continuations(p); | 1634 | free_swap_count_continuations(p); |
@@ -2088,7 +2051,6 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) | |||
2088 | 2051 | ||
2089 | p->swap_file = swap_file; | 2052 | p->swap_file = swap_file; |
2090 | mapping = swap_file->f_mapping; | 2053 | mapping = swap_file->f_mapping; |
2091 | inode = mapping->host; | ||
2092 | 2054 | ||
2093 | for (i = 0; i < nr_swapfiles; i++) { | 2055 | for (i = 0; i < nr_swapfiles; i++) { |
2094 | struct swap_info_struct *q = swap_info[i]; | 2056 | struct swap_info_struct *q = swap_info[i]; |
@@ -2101,6 +2063,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) | |||
2101 | } | 2063 | } |
2102 | } | 2064 | } |
2103 | 2065 | ||
2066 | inode = mapping->host; | ||
2067 | /* If S_ISREG(inode->i_mode) will do mutex_lock(&inode->i_mutex); */ | ||
2104 | error = claim_swapfile(p, inode); | 2068 | error = claim_swapfile(p, inode); |
2105 | if (unlikely(error)) | 2069 | if (unlikely(error)) |
2106 | goto bad_swap; | 2070 | goto bad_swap; |
@@ -2187,8 +2151,10 @@ bad_swap: | |||
2187 | spin_unlock(&swap_lock); | 2151 | spin_unlock(&swap_lock); |
2188 | vfree(swap_map); | 2152 | vfree(swap_map); |
2189 | if (swap_file) { | 2153 | if (swap_file) { |
2190 | if (inode && S_ISREG(inode->i_mode)) | 2154 | if (inode && S_ISREG(inode->i_mode)) { |
2191 | mutex_unlock(&inode->i_mutex); | 2155 | mutex_unlock(&inode->i_mutex); |
2156 | inode = NULL; | ||
2157 | } | ||
2192 | filp_close(swap_file, NULL); | 2158 | filp_close(swap_file, NULL); |
2193 | } | 2159 | } |
2194 | out: | 2160 | out: |