2828static struct bio * get_swap_bio (gfp_t gfp_flags ,
2929 struct page * page , bio_end_io_t end_io )
3030{
31+ int i , nr = hpage_nr_pages (page );
3132 struct bio * bio ;
3233
33- bio = bio_alloc (gfp_flags , 1 );
34+ bio = bio_alloc (gfp_flags , nr );
3435 if (bio ) {
3536 bio -> bi_iter .bi_sector = map_swap_page (page , & bio -> bi_bdev );
3637 bio -> bi_iter .bi_sector <<= PAGE_SHIFT - 9 ;
3738 bio -> bi_end_io = end_io ;
3839
39- bio_add_page (bio , page , PAGE_SIZE , 0 );
40- BUG_ON (bio -> bi_iter .bi_size != PAGE_SIZE );
40+ for (i = 0 ; i < nr ; i ++ )
41+ bio_add_page (bio , page + i , PAGE_SIZE , 0 );
42+ VM_BUG_ON (bio -> bi_iter .bi_size != PAGE_SIZE * nr );
4143 }
4244 return bio ;
4345}
@@ -262,6 +264,15 @@ static sector_t swap_page_sector(struct page *page)
262264 return (sector_t )__page_file_index (page ) << (PAGE_SHIFT - 9 );
263265}
264266
267+ static inline void count_swpout_vm_event (struct page * page )
268+ {
269+ #ifdef CONFIG_TRANSPARENT_HUGEPAGE
270+ if (unlikely (PageTransHuge (page )))
271+ count_vm_event (THP_SWPOUT );
272+ #endif
273+ count_vm_events (PSWPOUT , hpage_nr_pages (page ));
274+ }
275+
265276int __swap_writepage (struct page * page , struct writeback_control * wbc ,
266277 bio_end_io_t end_write_func )
267278{
@@ -313,7 +324,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
313324
314325 ret = bdev_write_page (sis -> bdev , swap_page_sector (page ), page , wbc );
315326 if (!ret ) {
316- count_vm_event ( PSWPOUT );
327+ count_swpout_vm_event ( page );
317328 return 0 ;
318329 }
319330
@@ -326,7 +337,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
326337 goto out ;
327338 }
328339 bio -> bi_opf = REQ_OP_WRITE | wbc_to_write_flags (wbc );
329- count_vm_event ( PSWPOUT );
340+ count_swpout_vm_event ( page );
330341 set_page_writeback (page );
331342 unlock_page (page );
332343 submit_bio (bio );
0 commit comments