23 #include <asm/pgtable.h>
25 static struct bio *get_swap_bio(
gfp_t gfp_flags,
26 struct page *
page, bio_end_io_t end_io)
30 bio = bio_alloc(gfp_flags, 1);
34 bio->bi_io_vec[0].bv_page =
page;
36 bio->bi_io_vec[0].bv_offset = 0;
40 bio->bi_end_io = end_io;
45 static void end_swap_bio_write(
struct bio *bio,
int err)
47 const int uptodate =
test_bit(BIO_UPTODATE, &bio->bi_flags);
48 struct page *page = bio->bi_io_vec[0].bv_page;
62 imajor(bio->bi_bdev->bd_inode),
63 iminor(bio->bi_bdev->bd_inode),
64 (
unsigned long long)bio->bi_sector);
65 ClearPageReclaim(page);
73 const int uptodate =
test_bit(BIO_UPTODATE, &bio->bi_flags);
74 struct page *page = bio->bi_io_vec[0].bv_page;
78 ClearPageUptodate(page);
80 imajor(bio->bi_bdev->bd_inode),
81 iminor(bio->bi_bdev->bd_inode),
82 (
unsigned long long)bio->bi_sector);
84 SetPageUptodate(page);
91 struct file *swap_file,
96 unsigned blocks_per_page;
97 unsigned long page_no;
115 last_block = i_size_read(inode) >> blkbits;
116 while ((probe_block + blocks_per_page) <= last_block &&
117 page_no < sis->
max) {
118 unsigned block_in_page;
121 first_block =
bmap(inode, probe_block);
122 if (first_block == 0)
128 if (first_block & (blocks_per_page - 1)) {
133 for (block_in_page = 1; block_in_page < blocks_per_page;
137 block =
bmap(inode, probe_block + block_in_page);
140 if (block != first_block + block_in_page) {
149 if (first_block < lowest_block)
150 lowest_block = first_block;
151 if (first_block > highest_block)
152 highest_block = first_block;
163 probe_block += blocks_per_page;
168 *span = 1 + highest_block - lowest_block;
172 sis->pages = page_no - 1;
173 sis->highest_bit = page_no - 1;
196 if (frontswap_store(page) == 0) {
197 set_page_writeback(page);
203 if (sis->flags & SWP_FILE) {
205 struct file *swap_file = sis->swap_file;
212 init_sync_kiocb(&kiocb, swap_file);
213 kiocb.
ki_pos = page_file_offset(page);
229 bio = get_swap_bio(
GFP_NOIO, page, end_swap_bio_write);
239 set_page_writeback(page);
254 if (frontswap_load(page) == 0) {
255 SetPageUptodate(page);
260 if (sis->flags & SWP_FILE) {
261 struct file *swap_file = sis->swap_file;
264 ret = mapping->
a_ops->readpage(swap_file, page);
286 if (sis->flags & SWP_FILE) {
288 return mapping->
a_ops->set_page_dirty(page);