[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 34/34] mm: add swap_bio_new common bio helper



Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@xxxxxxx>
---
 mm/page_io.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 7579485ccb5e..cc30c9a0b0a7 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -287,6 +287,17 @@ static void bio_associate_blkg_from_page(struct bio *bio, 
struct page *page)
 #define bio_associate_blkg_from_page(bio, page)                do { } while (0)
 #endif /* CONFIG_MEMCG && CONFIG_BLK_CGROUP */
 
+static inline struct bio *swap_bio_new(struct block_device *dev,
+               unsigned op, unsigned opf, gfp_t gfp, struct page *p,
+               bio_end_io_t *end_io)
+{
+       struct bio *bio = bio_new(dev, swap_page_sector(p), op, opf, 1, gfp);
+
+       bio->bi_end_io = end_io;
+       bio_add_page(bio, p, thp_size(p), 0);
+       return bio;
+}
+
 int __swap_writepage(struct page *page, struct writeback_control *wbc,
                bio_end_io_t end_write_func)
 {
@@ -342,11 +353,9 @@ int __swap_writepage(struct page *page, struct 
writeback_control *wbc,
                return 0;
        }
 
-       bio = bio_new(sis->bdev, swap_page_sector(page), REQ_OP_WRITE,
-                       REQ_SWAP | wbc_to_write_flags(wbc), 1, GFP_NOIO);
-       bio->bi_end_io = end_write_func;
-       bio_add_page(bio, page, thp_size(page), 0);
-
+       bio = swap_bio_new(sis->bdev, REQ_OP_WRITE,
+                       REQ_SWAP | wbc_to_write_flags(wbc), GFP_KERNEL,
+                       page, end_write_func);
        bio_associate_blkg_from_page(bio, page);
        count_swpout_vm_event(page);
        set_page_writeback(page);
@@ -406,11 +415,8 @@ int swap_readpage(struct page *page, bool synchronous)
        }
 
        ret = 0;
-       bio = bio_new(sis->bdev, swap_page_sector(page), REQ_OP_READ, 0, 1,
-                       GFP_KERNEL);
-       bio->bi_end_io = end_swap_bio_read;
-       bio_add_page(bio, page, thp_size(page), 0);
-
+       bio = swap_bio_new(sis->bdev, REQ_OP_READ, 0, GFP_KERNEL, page,
+                       end_swap_bio_read);
        disk = bio->bi_bdev->bd_disk;
        /*
         * Keep this task valid during swap readpage because the oom killer may
-- 
2.22.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.