| .. | .. |
|---|
| 33 | 33 | #include <linux/sysfs.h> |
|---|
| 34 | 34 | #include <linux/debugfs.h> |
|---|
| 35 | 35 | #include <linux/cpuhotplug.h> |
|---|
| 36 | +#include <linux/part_stat.h> |
|---|
| 36 | 37 | |
|---|
| 37 | 38 | #include "zram_drv.h" |
|---|
| 38 | 39 | |
|---|
| .. | .. |
|---|
| 41 | 42 | static DEFINE_MUTEX(zram_index_mutex); |
|---|
| 42 | 43 | |
|---|
| 43 | 44 | static int zram_major; |
|---|
| 44 | | -static const char *default_compressor = "lzo"; |
|---|
| 45 | +static const char *default_compressor = "lzo-rle"; |
|---|
| 45 | 46 | |
|---|
| 46 | 47 | /* Module params (documentation at end) */ |
|---|
| 47 | 48 | static unsigned int num_devices = 1; |
|---|
| .. | .. |
|---|
| 51 | 52 | */ |
|---|
| 52 | 53 | static size_t huge_class_size; |
|---|
| 53 | 54 | |
|---|
| 55 | +static const struct block_device_operations zram_devops; |
|---|
| 56 | +static const struct block_device_operations zram_wb_devops; |
|---|
| 57 | + |
|---|
| 54 | 58 | static void zram_free_page(struct zram *zram, size_t index); |
|---|
| 55 | 59 | static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, |
|---|
| 56 | 60 | u32 index, int offset, struct bio *bio); |
|---|
| 57 | 61 | |
|---|
| 62 | +#ifdef CONFIG_PREEMPT_RT |
|---|
| 63 | +static void zram_meta_init_table_locks(struct zram *zram, size_t num_pages) |
|---|
| 64 | +{ |
|---|
| 65 | + size_t index; |
|---|
| 66 | + |
|---|
| 67 | + for (index = 0; index < num_pages; index++) |
|---|
| 68 | + spin_lock_init(&zram->table[index].lock); |
|---|
| 69 | +} |
|---|
| 70 | + |
|---|
| 71 | +static int zram_slot_trylock(struct zram *zram, u32 index) |
|---|
| 72 | +{ |
|---|
| 73 | + int ret; |
|---|
| 74 | + |
|---|
| 75 | + ret = spin_trylock(&zram->table[index].lock); |
|---|
| 76 | + if (ret) |
|---|
| 77 | + __set_bit(ZRAM_LOCK, &zram->table[index].flags); |
|---|
| 78 | + return ret; |
|---|
| 79 | +} |
|---|
| 80 | + |
|---|
| 81 | +static void zram_slot_lock(struct zram *zram, u32 index) |
|---|
| 82 | +{ |
|---|
| 83 | + spin_lock(&zram->table[index].lock); |
|---|
| 84 | + __set_bit(ZRAM_LOCK, &zram->table[index].flags); |
|---|
| 85 | +} |
|---|
| 86 | + |
|---|
| 87 | +static void zram_slot_unlock(struct zram *zram, u32 index) |
|---|
| 88 | +{ |
|---|
| 89 | + __clear_bit(ZRAM_LOCK, &zram->table[index].flags); |
|---|
| 90 | + spin_unlock(&zram->table[index].lock); |
|---|
| 91 | +} |
|---|
| 92 | + |
|---|
| 93 | +#else |
|---|
| 94 | + |
|---|
| 95 | +static void zram_meta_init_table_locks(struct zram *zram, size_t num_pages) { } |
|---|
| 58 | 96 | |
|---|
| 59 | 97 | static int zram_slot_trylock(struct zram *zram, u32 index) |
|---|
| 60 | 98 | { |
|---|
| .. | .. |
|---|
| 70 | 108 | { |
|---|
| 71 | 109 | bit_spin_unlock(ZRAM_LOCK, &zram->table[index].flags); |
|---|
| 72 | 110 | } |
|---|
| 111 | +#endif |
|---|
| 73 | 112 | |
|---|
| 74 | 113 | static inline bool init_done(struct zram *zram) |
|---|
| 75 | 114 | { |
|---|
| .. | .. |
|---|
| 207 | 246 | |
|---|
| 208 | 247 | static bool page_same_filled(void *ptr, unsigned long *element) |
|---|
| 209 | 248 | { |
|---|
| 210 | | - unsigned int pos; |
|---|
| 211 | 249 | unsigned long *page; |
|---|
| 212 | 250 | unsigned long val; |
|---|
| 251 | + unsigned int pos, last_pos = PAGE_SIZE / sizeof(*page) - 1; |
|---|
| 213 | 252 | |
|---|
| 214 | 253 | page = (unsigned long *)ptr; |
|---|
| 215 | 254 | val = page[0]; |
|---|
| 216 | 255 | |
|---|
| 217 | | - for (pos = 1; pos < PAGE_SIZE / sizeof(*page); pos++) { |
|---|
| 256 | + if (val != page[last_pos]) |
|---|
| 257 | + return false; |
|---|
| 258 | + |
|---|
| 259 | + for (pos = 1; pos < last_pos; pos++) { |
|---|
| 218 | 260 | if (val != page[pos]) |
|---|
| 219 | 261 | return false; |
|---|
| 220 | 262 | } |
|---|
| .. | .. |
|---|
| 290 | 332 | struct zram *zram = dev_to_zram(dev); |
|---|
| 291 | 333 | unsigned long nr_pages = zram->disksize >> PAGE_SHIFT; |
|---|
| 292 | 334 | int index; |
|---|
| 293 | | - char mode_buf[8]; |
|---|
| 294 | | - ssize_t sz; |
|---|
| 295 | 335 | |
|---|
| 296 | | - sz = strscpy(mode_buf, buf, sizeof(mode_buf)); |
|---|
| 297 | | - if (sz <= 0) |
|---|
| 298 | | - return -EINVAL; |
|---|
| 299 | | - |
|---|
| 300 | | - /* ignore trailing new line */ |
|---|
| 301 | | - if (mode_buf[sz - 1] == '\n') |
|---|
| 302 | | - mode_buf[sz - 1] = 0x00; |
|---|
| 303 | | - |
|---|
| 304 | | - if (strcmp(mode_buf, "all")) |
|---|
| 336 | + if (!sysfs_streq(buf, "all")) |
|---|
| 305 | 337 | return -EINVAL; |
|---|
| 306 | 338 | |
|---|
| 307 | 339 | down_read(&zram->init_lock); |
|---|
| .. | .. |
|---|
| 414 | 446 | zram->backing_dev = NULL; |
|---|
| 415 | 447 | zram->old_block_size = 0; |
|---|
| 416 | 448 | zram->bdev = NULL; |
|---|
| 417 | | - zram->disk->queue->backing_dev_info->capabilities |= |
|---|
| 418 | | - BDI_CAP_SYNCHRONOUS_IO; |
|---|
| 449 | + zram->disk->fops = &zram_devops; |
|---|
| 419 | 450 | kvfree(zram->bitmap); |
|---|
| 420 | 451 | zram->bitmap = NULL; |
|---|
| 421 | 452 | } |
|---|
| .. | .. |
|---|
| 481 | 512 | if (sz > 0 && file_name[sz - 1] == '\n') |
|---|
| 482 | 513 | file_name[sz - 1] = 0x00; |
|---|
| 483 | 514 | |
|---|
| 484 | | - backing_dev = filp_open(file_name, O_RDWR|O_LARGEFILE, 0); |
|---|
| 515 | + backing_dev = filp_open_block(file_name, O_RDWR|O_LARGEFILE, 0); |
|---|
| 485 | 516 | if (IS_ERR(backing_dev)) { |
|---|
| 486 | 517 | err = PTR_ERR(backing_dev); |
|---|
| 487 | 518 | backing_dev = NULL; |
|---|
| .. | .. |
|---|
| 497 | 528 | goto out; |
|---|
| 498 | 529 | } |
|---|
| 499 | 530 | |
|---|
| 500 | | - bdev = bdgrab(I_BDEV(inode)); |
|---|
| 501 | | - err = blkdev_get(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL, zram); |
|---|
| 502 | | - if (err < 0) { |
|---|
| 531 | + bdev = blkdev_get_by_dev(inode->i_rdev, |
|---|
| 532 | + FMODE_READ | FMODE_WRITE | FMODE_EXCL, zram); |
|---|
| 533 | + if (IS_ERR(bdev)) { |
|---|
| 534 | + err = PTR_ERR(bdev); |
|---|
| 503 | 535 | bdev = NULL; |
|---|
| 504 | 536 | goto out; |
|---|
| 505 | 537 | } |
|---|
| .. | .. |
|---|
| 534 | 566 | * freely but in fact, IO is going on so finally could cause |
|---|
| 535 | 567 | * use-after-free when the IO is really done. |
|---|
| 536 | 568 | */ |
|---|
| 537 | | - zram->disk->queue->backing_dev_info->capabilities &= |
|---|
| 538 | | - ~BDI_CAP_SYNCHRONOUS_IO; |
|---|
| 569 | + zram->disk->fops = &zram_wb_devops; |
|---|
| 539 | 570 | up_write(&zram->init_lock); |
|---|
| 540 | 571 | |
|---|
| 541 | 572 | pr_info("setup backing device %s\n", file_name); |
|---|
| .. | .. |
|---|
| 624 | 655 | return 1; |
|---|
| 625 | 656 | } |
|---|
| 626 | 657 | |
|---|
| 658 | +#define PAGE_WB_SIG "page_index=" |
|---|
| 659 | + |
|---|
| 660 | +#define PAGE_WRITEBACK 0 |
|---|
| 627 | 661 | #define HUGE_WRITEBACK 1 |
|---|
| 628 | 662 | #define IDLE_WRITEBACK 2 |
|---|
| 663 | + |
|---|
| 629 | 664 | |
|---|
| 630 | 665 | static ssize_t writeback_store(struct device *dev, |
|---|
| 631 | 666 | struct device_attribute *attr, const char *buf, size_t len) |
|---|
| 632 | 667 | { |
|---|
| 633 | 668 | struct zram *zram = dev_to_zram(dev); |
|---|
| 634 | 669 | unsigned long nr_pages = zram->disksize >> PAGE_SHIFT; |
|---|
| 635 | | - unsigned long index; |
|---|
| 670 | + unsigned long index = 0; |
|---|
| 636 | 671 | struct bio bio; |
|---|
| 637 | 672 | struct bio_vec bio_vec; |
|---|
| 638 | 673 | struct page *page; |
|---|
| 639 | | - ssize_t ret, sz; |
|---|
| 640 | | - char mode_buf[8]; |
|---|
| 641 | | - int mode = -1; |
|---|
| 674 | + ssize_t ret = len; |
|---|
| 675 | + int mode, err; |
|---|
| 642 | 676 | unsigned long blk_idx = 0; |
|---|
| 643 | 677 | |
|---|
| 644 | | - sz = strscpy(mode_buf, buf, sizeof(mode_buf)); |
|---|
| 645 | | - if (sz <= 0) |
|---|
| 646 | | - return -EINVAL; |
|---|
| 647 | | - |
|---|
| 648 | | - /* ignore trailing newline */ |
|---|
| 649 | | - if (mode_buf[sz - 1] == '\n') |
|---|
| 650 | | - mode_buf[sz - 1] = 0x00; |
|---|
| 651 | | - |
|---|
| 652 | | - if (!strcmp(mode_buf, "idle")) |
|---|
| 678 | + if (sysfs_streq(buf, "idle")) |
|---|
| 653 | 679 | mode = IDLE_WRITEBACK; |
|---|
| 654 | | - else if (!strcmp(mode_buf, "huge")) |
|---|
| 680 | + else if (sysfs_streq(buf, "huge")) |
|---|
| 655 | 681 | mode = HUGE_WRITEBACK; |
|---|
| 682 | + else { |
|---|
| 683 | + if (strncmp(buf, PAGE_WB_SIG, sizeof(PAGE_WB_SIG) - 1)) |
|---|
| 684 | + return -EINVAL; |
|---|
| 656 | 685 | |
|---|
| 657 | | - if (mode == -1) |
|---|
| 658 | | - return -EINVAL; |
|---|
| 686 | + if (kstrtol(buf + sizeof(PAGE_WB_SIG) - 1, 10, &index) || |
|---|
| 687 | + index >= nr_pages) |
|---|
| 688 | + return -EINVAL; |
|---|
| 689 | + |
|---|
| 690 | + nr_pages = 1; |
|---|
| 691 | + mode = PAGE_WRITEBACK; |
|---|
| 692 | + } |
|---|
| 659 | 693 | |
|---|
| 660 | 694 | down_read(&zram->init_lock); |
|---|
| 661 | 695 | if (!init_done(zram)) { |
|---|
| .. | .. |
|---|
| 674 | 708 | goto release_init_lock; |
|---|
| 675 | 709 | } |
|---|
| 676 | 710 | |
|---|
| 677 | | - for (index = 0; index < nr_pages; index++) { |
|---|
| 711 | + for (; nr_pages != 0; index++, nr_pages--) { |
|---|
| 678 | 712 | struct bio_vec bvec; |
|---|
| 679 | 713 | |
|---|
| 680 | 714 | bvec.bv_page = page; |
|---|
| .. | .. |
|---|
| 739 | 773 | * XXX: A single page IO would be inefficient for write |
|---|
| 740 | 774 | * but it would be not bad as starter. |
|---|
| 741 | 775 | */ |
|---|
| 742 | | - ret = submit_bio_wait(&bio); |
|---|
| 743 | | - if (ret) { |
|---|
| 776 | + err = submit_bio_wait(&bio); |
|---|
| 777 | + if (err) { |
|---|
| 744 | 778 | zram_slot_lock(zram, index); |
|---|
| 745 | 779 | zram_clear_flag(zram, index, ZRAM_UNDER_WB); |
|---|
| 746 | 780 | zram_clear_flag(zram, index, ZRAM_IDLE); |
|---|
| 747 | 781 | zram_slot_unlock(zram, index); |
|---|
| 782 | + /* |
|---|
| 783 | + * Return last IO error unless every IO were |
|---|
| 784 | + * not suceeded. |
|---|
| 785 | + */ |
|---|
| 786 | + ret = err; |
|---|
| 748 | 787 | continue; |
|---|
| 749 | 788 | } |
|---|
| 750 | 789 | |
|---|
| .. | .. |
|---|
| 782 | 821 | |
|---|
| 783 | 822 | if (blk_idx) |
|---|
| 784 | 823 | free_block_bdev(zram, blk_idx); |
|---|
| 785 | | - ret = len; |
|---|
| 786 | 824 | __free_page(page); |
|---|
| 787 | 825 | release_init_lock: |
|---|
| 788 | 826 | up_read(&zram->init_lock); |
|---|
| .. | .. |
|---|
| 810 | 848 | } |
|---|
| 811 | 849 | |
|---|
| 812 | 850 | /* |
|---|
| 813 | | - * Block layer want one ->make_request_fn to be active at a time |
|---|
| 814 | | - * so if we use chained IO with parent IO in same context, |
|---|
| 815 | | - * it's a deadlock. To avoid, it, it uses worker thread context. |
|---|
| 851 | + * Block layer want one ->submit_bio to be active at a time, so if we use |
|---|
| 852 | + * chained IO with parent IO in same context, it's a deadlock. To avoid that, |
|---|
| 853 | + * use a worker thread context. |
|---|
| 816 | 854 | */ |
|---|
| 817 | 855 | static int read_from_bdev_sync(struct zram *zram, struct bio_vec *bvec, |
|---|
| 818 | 856 | unsigned long entry, struct bio *bio) |
|---|
| .. | .. |
|---|
| 1175 | 1213 | |
|---|
| 1176 | 1214 | if (!huge_class_size) |
|---|
| 1177 | 1215 | huge_class_size = zs_huge_class_size(zram->mem_pool); |
|---|
| 1216 | + zram_meta_init_table_locks(zram, num_pages); |
|---|
| 1178 | 1217 | return true; |
|---|
| 1179 | 1218 | } |
|---|
| 1180 | 1219 | |
|---|
| .. | .. |
|---|
| 1233 | 1272 | static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index, |
|---|
| 1234 | 1273 | struct bio *bio, bool partial_io) |
|---|
| 1235 | 1274 | { |
|---|
| 1236 | | - int ret; |
|---|
| 1275 | + struct zcomp_strm *zstrm; |
|---|
| 1237 | 1276 | unsigned long handle; |
|---|
| 1238 | 1277 | unsigned int size; |
|---|
| 1239 | 1278 | void *src, *dst; |
|---|
| 1279 | + int ret; |
|---|
| 1240 | 1280 | |
|---|
| 1241 | 1281 | zram_slot_lock(zram, index); |
|---|
| 1242 | 1282 | if (zram_test_flag(zram, index, ZRAM_WB)) { |
|---|
| .. | .. |
|---|
| 1267 | 1307 | |
|---|
| 1268 | 1308 | size = zram_get_obj_size(zram, index); |
|---|
| 1269 | 1309 | |
|---|
| 1310 | + if (size != PAGE_SIZE) |
|---|
| 1311 | + zstrm = zcomp_stream_get(zram->comp); |
|---|
| 1312 | + |
|---|
| 1270 | 1313 | src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); |
|---|
| 1271 | 1314 | if (size == PAGE_SIZE) { |
|---|
| 1272 | 1315 | dst = kmap_atomic(page); |
|---|
| .. | .. |
|---|
| 1274 | 1317 | kunmap_atomic(dst); |
|---|
| 1275 | 1318 | ret = 0; |
|---|
| 1276 | 1319 | } else { |
|---|
| 1277 | | - struct zcomp_strm *zstrm = zcomp_stream_get(zram->comp); |
|---|
| 1278 | | - |
|---|
| 1279 | 1320 | dst = kmap_atomic(page); |
|---|
| 1280 | 1321 | ret = zcomp_decompress(zstrm, src, size, dst); |
|---|
| 1281 | 1322 | kunmap_atomic(dst); |
|---|
| .. | .. |
|---|
| 1285 | 1326 | zram_slot_unlock(zram, index); |
|---|
| 1286 | 1327 | |
|---|
| 1287 | 1328 | /* Should NEVER happen. Return bio error if it does. */ |
|---|
| 1288 | | - if (unlikely(ret)) |
|---|
| 1329 | + if (WARN_ON(ret)) |
|---|
| 1289 | 1330 | pr_err("Decompression failed! err=%d, page=%u\n", ret, index); |
|---|
| 1290 | 1331 | |
|---|
| 1291 | 1332 | return ret; |
|---|
| .. | .. |
|---|
| 1380 | 1421 | __GFP_KSWAPD_RECLAIM | |
|---|
| 1381 | 1422 | __GFP_NOWARN | |
|---|
| 1382 | 1423 | __GFP_HIGHMEM | |
|---|
| 1383 | | - __GFP_MOVABLE); |
|---|
| 1424 | + __GFP_MOVABLE | |
|---|
| 1425 | + __GFP_CMA); |
|---|
| 1384 | 1426 | if (!handle) { |
|---|
| 1385 | 1427 | zcomp_stream_put(zram->comp); |
|---|
| 1386 | 1428 | atomic64_inc(&zram->stats.writestall); |
|---|
| 1387 | 1429 | handle = zs_malloc(zram->mem_pool, comp_len, |
|---|
| 1388 | 1430 | GFP_NOIO | __GFP_HIGHMEM | |
|---|
| 1389 | | - __GFP_MOVABLE); |
|---|
| 1431 | + __GFP_MOVABLE | __GFP_CMA); |
|---|
| 1390 | 1432 | if (handle) |
|---|
| 1391 | 1433 | goto compress_again; |
|---|
| 1392 | 1434 | return -ENOMEM; |
|---|
| .. | .. |
|---|
| 1527 | 1569 | static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index, |
|---|
| 1528 | 1570 | int offset, unsigned int op, struct bio *bio) |
|---|
| 1529 | 1571 | { |
|---|
| 1530 | | - unsigned long start_time = jiffies; |
|---|
| 1531 | | - struct request_queue *q = zram->disk->queue; |
|---|
| 1532 | 1572 | int ret; |
|---|
| 1533 | | - |
|---|
| 1534 | | - generic_start_io_acct(q, op, bvec->bv_len >> SECTOR_SHIFT, |
|---|
| 1535 | | - &zram->disk->part0); |
|---|
| 1536 | 1573 | |
|---|
| 1537 | 1574 | if (!op_is_write(op)) { |
|---|
| 1538 | 1575 | atomic64_inc(&zram->stats.num_reads); |
|---|
| .. | .. |
|---|
| 1542 | 1579 | atomic64_inc(&zram->stats.num_writes); |
|---|
| 1543 | 1580 | ret = zram_bvec_write(zram, bvec, index, offset, bio); |
|---|
| 1544 | 1581 | } |
|---|
| 1545 | | - |
|---|
| 1546 | | - generic_end_io_acct(q, op, &zram->disk->part0, start_time); |
|---|
| 1547 | 1582 | |
|---|
| 1548 | 1583 | zram_slot_lock(zram, index); |
|---|
| 1549 | 1584 | zram_accessed(zram, index); |
|---|
| .. | .. |
|---|
| 1565 | 1600 | u32 index; |
|---|
| 1566 | 1601 | struct bio_vec bvec; |
|---|
| 1567 | 1602 | struct bvec_iter iter; |
|---|
| 1603 | + unsigned long start_time; |
|---|
| 1568 | 1604 | |
|---|
| 1569 | 1605 | index = bio->bi_iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; |
|---|
| 1570 | 1606 | offset = (bio->bi_iter.bi_sector & |
|---|
| .. | .. |
|---|
| 1580 | 1616 | break; |
|---|
| 1581 | 1617 | } |
|---|
| 1582 | 1618 | |
|---|
| 1619 | + start_time = bio_start_io_acct(bio); |
|---|
| 1583 | 1620 | bio_for_each_segment(bvec, bio, iter) { |
|---|
| 1584 | 1621 | struct bio_vec bv = bvec; |
|---|
| 1585 | 1622 | unsigned int unwritten = bvec.bv_len; |
|---|
| .. | .. |
|---|
| 1588 | 1625 | bv.bv_len = min_t(unsigned int, PAGE_SIZE - offset, |
|---|
| 1589 | 1626 | unwritten); |
|---|
| 1590 | 1627 | if (zram_bvec_rw(zram, &bv, index, offset, |
|---|
| 1591 | | - bio_op(bio), bio) < 0) |
|---|
| 1592 | | - goto out; |
|---|
| 1628 | + bio_op(bio), bio) < 0) { |
|---|
| 1629 | + bio->bi_status = BLK_STS_IOERR; |
|---|
| 1630 | + break; |
|---|
| 1631 | + } |
|---|
| 1593 | 1632 | |
|---|
| 1594 | 1633 | bv.bv_offset += bv.bv_len; |
|---|
| 1595 | 1634 | unwritten -= bv.bv_len; |
|---|
| .. | .. |
|---|
| 1597 | 1636 | update_position(&index, &offset, &bv); |
|---|
| 1598 | 1637 | } while (unwritten); |
|---|
| 1599 | 1638 | } |
|---|
| 1600 | | - |
|---|
| 1639 | + bio_end_io_acct(bio, start_time); |
|---|
| 1601 | 1640 | bio_endio(bio); |
|---|
| 1602 | | - return; |
|---|
| 1603 | | - |
|---|
| 1604 | | -out: |
|---|
| 1605 | | - bio_io_error(bio); |
|---|
| 1606 | 1641 | } |
|---|
| 1607 | 1642 | |
|---|
| 1608 | 1643 | /* |
|---|
| 1609 | 1644 | * Handler function for all zram I/O requests. |
|---|
| 1610 | 1645 | */ |
|---|
| 1611 | | -static blk_qc_t zram_make_request(struct request_queue *queue, struct bio *bio) |
|---|
| 1646 | +static blk_qc_t zram_submit_bio(struct bio *bio) |
|---|
| 1612 | 1647 | { |
|---|
| 1613 | | - struct zram *zram = queue->queuedata; |
|---|
| 1648 | + struct zram *zram = bio->bi_disk->private_data; |
|---|
| 1614 | 1649 | |
|---|
| 1615 | 1650 | if (!valid_io_request(zram, bio->bi_iter.bi_sector, |
|---|
| 1616 | 1651 | bio->bi_iter.bi_size)) { |
|---|
| .. | .. |
|---|
| 1650 | 1685 | u32 index; |
|---|
| 1651 | 1686 | struct zram *zram; |
|---|
| 1652 | 1687 | struct bio_vec bv; |
|---|
| 1688 | + unsigned long start_time; |
|---|
| 1653 | 1689 | |
|---|
| 1654 | 1690 | if (PageTransHuge(page)) |
|---|
| 1655 | 1691 | return -ENOTSUPP; |
|---|
| .. | .. |
|---|
| 1668 | 1704 | bv.bv_len = PAGE_SIZE; |
|---|
| 1669 | 1705 | bv.bv_offset = 0; |
|---|
| 1670 | 1706 | |
|---|
| 1707 | + start_time = disk_start_io_acct(bdev->bd_disk, SECTORS_PER_PAGE, op); |
|---|
| 1671 | 1708 | ret = zram_bvec_rw(zram, &bv, index, offset, op, NULL); |
|---|
| 1709 | + disk_end_io_acct(bdev->bd_disk, op, start_time); |
|---|
| 1672 | 1710 | out: |
|---|
| 1673 | 1711 | /* |
|---|
| 1674 | 1712 | * If I/O fails, just return error(ie, non-zero) without |
|---|
| .. | .. |
|---|
| 1760 | 1798 | zram->disksize = disksize; |
|---|
| 1761 | 1799 | set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); |
|---|
| 1762 | 1800 | |
|---|
| 1763 | | - revalidate_disk(zram->disk); |
|---|
| 1801 | + revalidate_disk_size(zram->disk, true); |
|---|
| 1764 | 1802 | up_write(&zram->init_lock); |
|---|
| 1765 | 1803 | |
|---|
| 1766 | 1804 | return len; |
|---|
| .. | .. |
|---|
| 1807 | 1845 | /* Make sure all the pending I/O are finished */ |
|---|
| 1808 | 1846 | fsync_bdev(bdev); |
|---|
| 1809 | 1847 | zram_reset_device(zram); |
|---|
| 1810 | | - revalidate_disk(zram->disk); |
|---|
| 1848 | + revalidate_disk_size(zram->disk, true); |
|---|
| 1811 | 1849 | bdput(bdev); |
|---|
| 1812 | 1850 | |
|---|
| 1813 | 1851 | mutex_lock(&bdev->bd_mutex); |
|---|
| .. | .. |
|---|
| 1834 | 1872 | |
|---|
| 1835 | 1873 | static const struct block_device_operations zram_devops = { |
|---|
| 1836 | 1874 | .open = zram_open, |
|---|
| 1875 | + .submit_bio = zram_submit_bio, |
|---|
| 1837 | 1876 | .swap_slot_free_notify = zram_slot_free_notify, |
|---|
| 1838 | 1877 | .rw_page = zram_rw_page, |
|---|
| 1878 | + .owner = THIS_MODULE |
|---|
| 1879 | +}; |
|---|
| 1880 | + |
|---|
| 1881 | +static const struct block_device_operations zram_wb_devops = { |
|---|
| 1882 | + .open = zram_open, |
|---|
| 1883 | + .submit_bio = zram_submit_bio, |
|---|
| 1884 | + .swap_slot_free_notify = zram_slot_free_notify, |
|---|
| 1839 | 1885 | .owner = THIS_MODULE |
|---|
| 1840 | 1886 | }; |
|---|
| 1841 | 1887 | |
|---|
| .. | .. |
|---|
| 1912 | 1958 | #ifdef CONFIG_ZRAM_WRITEBACK |
|---|
| 1913 | 1959 | spin_lock_init(&zram->wb_limit_lock); |
|---|
| 1914 | 1960 | #endif |
|---|
| 1915 | | - queue = blk_alloc_queue(GFP_KERNEL); |
|---|
| 1961 | + queue = blk_alloc_queue(NUMA_NO_NODE); |
|---|
| 1916 | 1962 | if (!queue) { |
|---|
| 1917 | 1963 | pr_err("Error allocating disk queue for device %d\n", |
|---|
| 1918 | 1964 | device_id); |
|---|
| 1919 | 1965 | ret = -ENOMEM; |
|---|
| 1920 | 1966 | goto out_free_idr; |
|---|
| 1921 | 1967 | } |
|---|
| 1922 | | - |
|---|
| 1923 | | - blk_queue_make_request(queue, zram_make_request); |
|---|
| 1924 | 1968 | |
|---|
| 1925 | 1969 | /* gendisk structure */ |
|---|
| 1926 | 1970 | zram->disk = alloc_disk(1); |
|---|
| .. | .. |
|---|
| 1935 | 1979 | zram->disk->first_minor = device_id; |
|---|
| 1936 | 1980 | zram->disk->fops = &zram_devops; |
|---|
| 1937 | 1981 | zram->disk->queue = queue; |
|---|
| 1938 | | - zram->disk->queue->queuedata = zram; |
|---|
| 1939 | 1982 | zram->disk->private_data = zram; |
|---|
| 1940 | 1983 | snprintf(zram->disk->disk_name, 16, "zram%d", device_id); |
|---|
| 1941 | 1984 | |
|---|
| .. | .. |
|---|
| 1969 | 2012 | if (ZRAM_LOGICAL_BLOCK_SIZE == PAGE_SIZE) |
|---|
| 1970 | 2013 | blk_queue_max_write_zeroes_sectors(zram->disk->queue, UINT_MAX); |
|---|
| 1971 | 2014 | |
|---|
| 1972 | | - zram->disk->queue->backing_dev_info->capabilities |= |
|---|
| 1973 | | - (BDI_CAP_STABLE_WRITES | BDI_CAP_SYNCHRONOUS_IO); |
|---|
| 1974 | | - disk_to_dev(zram->disk)->groups = zram_disk_attr_groups; |
|---|
| 1975 | | - add_disk(zram->disk); |
|---|
| 2015 | + blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, zram->disk->queue); |
|---|
| 2016 | + device_add_disk(NULL, zram->disk, zram_disk_attr_groups); |
|---|
| 1976 | 2017 | |
|---|
| 1977 | 2018 | strlcpy(zram->compressor, default_compressor, sizeof(zram->compressor)); |
|---|
| 1978 | 2019 | |
|---|
| .. | .. |
|---|
| 2008 | 2049 | mutex_unlock(&bdev->bd_mutex); |
|---|
| 2009 | 2050 | |
|---|
| 2010 | 2051 | zram_debugfs_unregister(zram); |
|---|
| 2052 | + |
|---|
| 2011 | 2053 | /* Make sure all the pending I/O are finished */ |
|---|
| 2012 | 2054 | fsync_bdev(bdev); |
|---|
| 2013 | 2055 | zram_reset_device(zram); |
|---|