diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-05 19:41:23 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-05 19:41:23 -0400 |
commit | 8c27cb3566762613a23c080e3db7d0501af9a787 (patch) | |
tree | 32b2752e320b6cb3ecf289dd00b5145a6de947e6 /fs/btrfs/compression.c | |
parent | 7114f51fcb979f167ab5f625ac74059dcb1afc28 (diff) | |
parent | 848c23b78fafdcd3270b06a30737f8dbd70c347f (diff) |
Merge branch 'for-4.13-part1' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs updates from David Sterba:
"The core updates improve error handling (mostly related to bios), with
the usual incremental work on the GFP_NOFS (mis)use removal,
refactoring or cleanups. Except the two top patches, all have been in
for-next for an extensive amount of time.
User visible changes:
- statx support
- quota override tunable
- improved compression thresholds
- obsoleted mount option alloc_start
Core updates:
- bio-related updates:
- faster bio cloning
- no allocation failures
- preallocated flush bios
- more kvzalloc use, memalloc_nofs protections, GFP_NOFS updates
- prep work for btree_inode removal
- dir-item validation
- qgoup fixes and updates
- cleanups:
- removed unused struct members, unused code, refactoring
- argument refactoring (fs_info/root, caller -> callee sink)
- SEARCH_TREE ioctl docs"
* 'for-4.13-part1' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: (115 commits)
btrfs: Remove false alert when fiemap range is smaller than on-disk extent
btrfs: Don't clear SGID when inheriting ACLs
btrfs: fix integer overflow in calc_reclaim_items_nr
btrfs: scrub: fix target device intialization while setting up scrub context
btrfs: qgroup: Fix qgroup reserved space underflow by only freeing reserved ranges
btrfs: qgroup: Introduce extent changeset for qgroup reserve functions
btrfs: qgroup: Fix qgroup reserved space underflow caused by buffered write and quotas being enabled
btrfs: qgroup: Return actually freed bytes for qgroup release or free data
btrfs: qgroup: Cleanup btrfs_qgroup_prepare_account_extents function
btrfs: qgroup: Add quick exit for non-fs extents
Btrfs: rework delayed ref total_bytes_pinned accounting
Btrfs: return old and new total ref mods when adding delayed refs
Btrfs: always account pinned bytes when dropping a tree block ref
Btrfs: update total_bytes_pinned when pinning down extents
Btrfs: make BUG_ON() in add_pinned_bytes() an ASSERT()
Btrfs: make add_pinned_bytes() take an s64 num_bytes instead of u64
btrfs: fix validation of XATTR_ITEM dir items
btrfs: Verify dir_item in iterate_object_props
btrfs: Check name_len before in btrfs_del_root_ref
btrfs: Check name_len before reading btrfs_get_name
...
Diffstat (limited to 'fs/btrfs/compression.c')
-rw-r--r-- | fs/btrfs/compression.c | 94 |
1 files changed, 21 insertions, 73 deletions
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index a2fad39f79ba..2c0b7b57fcd5 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/writeback.h> | 32 | #include <linux/writeback.h> |
33 | #include <linux/bit_spinlock.h> | 33 | #include <linux/bit_spinlock.h> |
34 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/sched/mm.h> | ||
35 | #include "ctree.h" | 36 | #include "ctree.h" |
36 | #include "disk-io.h" | 37 | #include "disk-io.h" |
37 | #include "transaction.h" | 38 | #include "transaction.h" |
@@ -42,48 +43,7 @@ | |||
42 | #include "extent_io.h" | 43 | #include "extent_io.h" |
43 | #include "extent_map.h" | 44 | #include "extent_map.h" |
44 | 45 | ||
45 | struct compressed_bio { | 46 | static int btrfs_decompress_bio(struct compressed_bio *cb); |
46 | /* number of bios pending for this compressed extent */ | ||
47 | refcount_t pending_bios; | ||
48 | |||
49 | /* the pages with the compressed data on them */ | ||
50 | struct page **compressed_pages; | ||
51 | |||
52 | /* inode that owns this data */ | ||
53 | struct inode *inode; | ||
54 | |||
55 | /* starting offset in the inode for our pages */ | ||
56 | u64 start; | ||
57 | |||
58 | /* number of bytes in the inode we're working on */ | ||
59 | unsigned long len; | ||
60 | |||
61 | /* number of bytes on disk */ | ||
62 | unsigned long compressed_len; | ||
63 | |||
64 | /* the compression algorithm for this bio */ | ||
65 | int compress_type; | ||
66 | |||
67 | /* number of compressed pages in the array */ | ||
68 | unsigned long nr_pages; | ||
69 | |||
70 | /* IO errors */ | ||
71 | int errors; | ||
72 | int mirror_num; | ||
73 | |||
74 | /* for reads, this is the bio we are copying the data into */ | ||
75 | struct bio *orig_bio; | ||
76 | |||
77 | /* | ||
78 | * the start of a variable length array of checksums only | ||
79 | * used by reads | ||
80 | */ | ||
81 | u32 sums; | ||
82 | }; | ||
83 | |||
84 | static int btrfs_decompress_bio(int type, struct page **pages_in, | ||
85 | u64 disk_start, struct bio *orig_bio, | ||
86 | size_t srclen); | ||
87 | 47 | ||
88 | static inline int compressed_bio_size(struct btrfs_fs_info *fs_info, | 48 | static inline int compressed_bio_size(struct btrfs_fs_info *fs_info, |
89 | unsigned long disk_size) | 49 | unsigned long disk_size) |
@@ -94,12 +54,6 @@ static inline int compressed_bio_size(struct btrfs_fs_info *fs_info, | |||
94 | (DIV_ROUND_UP(disk_size, fs_info->sectorsize)) * csum_size; | 54 | (DIV_ROUND_UP(disk_size, fs_info->sectorsize)) * csum_size; |
95 | } | 55 | } |
96 | 56 | ||
97 | static struct bio *compressed_bio_alloc(struct block_device *bdev, | ||
98 | u64 first_byte, gfp_t gfp_flags) | ||
99 | { | ||
100 | return btrfs_bio_alloc(bdev, first_byte >> 9, BIO_MAX_PAGES, gfp_flags); | ||
101 | } | ||
102 | |||
103 | static int check_compressed_csum(struct btrfs_inode *inode, | 57 | static int check_compressed_csum(struct btrfs_inode *inode, |
104 | struct compressed_bio *cb, | 58 | struct compressed_bio *cb, |
105 | u64 disk_start) | 59 | u64 disk_start) |
@@ -173,11 +127,8 @@ static void end_compressed_bio_read(struct bio *bio) | |||
173 | /* ok, we're the last bio for this extent, lets start | 127 | /* ok, we're the last bio for this extent, lets start |
174 | * the decompression. | 128 | * the decompression. |
175 | */ | 129 | */ |
176 | ret = btrfs_decompress_bio(cb->compress_type, | 130 | ret = btrfs_decompress_bio(cb); |
177 | cb->compressed_pages, | 131 | |
178 | cb->start, | ||
179 | cb->orig_bio, | ||
180 | cb->compressed_len); | ||
181 | csum_failed: | 132 | csum_failed: |
182 | if (ret) | 133 | if (ret) |
183 | cb->errors = 1; | 134 | cb->errors = 1; |
@@ -355,11 +306,7 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start, | |||
355 | 306 | ||
356 | bdev = fs_info->fs_devices->latest_bdev; | 307 | bdev = fs_info->fs_devices->latest_bdev; |
357 | 308 | ||
358 | bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS); | 309 | bio = btrfs_bio_alloc(bdev, first_byte); |
359 | if (!bio) { | ||
360 | kfree(cb); | ||
361 | return BLK_STS_RESOURCE; | ||
362 | } | ||
363 | bio_set_op_attrs(bio, REQ_OP_WRITE, 0); | 310 | bio_set_op_attrs(bio, REQ_OP_WRITE, 0); |
364 | bio->bi_private = cb; | 311 | bio->bi_private = cb; |
365 | bio->bi_end_io = end_compressed_bio_write; | 312 | bio->bi_end_io = end_compressed_bio_write; |
@@ -406,8 +353,7 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start, | |||
406 | 353 | ||
407 | bio_put(bio); | 354 | bio_put(bio); |
408 | 355 | ||
409 | bio = compressed_bio_alloc(bdev, first_byte, GFP_NOFS); | 356 | bio = btrfs_bio_alloc(bdev, first_byte); |
410 | BUG_ON(!bio); | ||
411 | bio_set_op_attrs(bio, REQ_OP_WRITE, 0); | 357 | bio_set_op_attrs(bio, REQ_OP_WRITE, 0); |
412 | bio->bi_private = cb; | 358 | bio->bi_private = cb; |
413 | bio->bi_end_io = end_compressed_bio_write; | 359 | bio->bi_end_io = end_compressed_bio_write; |
@@ -650,9 +596,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | |||
650 | /* include any pages we added in add_ra-bio_pages */ | 596 | /* include any pages we added in add_ra-bio_pages */ |
651 | cb->len = bio->bi_iter.bi_size; | 597 | cb->len = bio->bi_iter.bi_size; |
652 | 598 | ||
653 | comp_bio = compressed_bio_alloc(bdev, cur_disk_byte, GFP_NOFS); | 599 | comp_bio = btrfs_bio_alloc(bdev, cur_disk_byte); |
654 | if (!comp_bio) | ||
655 | goto fail2; | ||
656 | bio_set_op_attrs (comp_bio, REQ_OP_READ, 0); | 600 | bio_set_op_attrs (comp_bio, REQ_OP_READ, 0); |
657 | comp_bio->bi_private = cb; | 601 | comp_bio->bi_private = cb; |
658 | comp_bio->bi_end_io = end_compressed_bio_read; | 602 | comp_bio->bi_end_io = end_compressed_bio_read; |
@@ -703,9 +647,7 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, | |||
703 | 647 | ||
704 | bio_put(comp_bio); | 648 | bio_put(comp_bio); |
705 | 649 | ||
706 | comp_bio = compressed_bio_alloc(bdev, cur_disk_byte, | 650 | comp_bio = btrfs_bio_alloc(bdev, cur_disk_byte); |
707 | GFP_NOFS); | ||
708 | BUG_ON(!comp_bio); | ||
709 | bio_set_op_attrs(comp_bio, REQ_OP_READ, 0); | 651 | bio_set_op_attrs(comp_bio, REQ_OP_READ, 0); |
710 | comp_bio->bi_private = cb; | 652 | comp_bio->bi_private = cb; |
711 | comp_bio->bi_end_io = end_compressed_bio_read; | 653 | comp_bio->bi_end_io = end_compressed_bio_read; |
@@ -801,6 +743,7 @@ static struct list_head *find_workspace(int type) | |||
801 | struct list_head *workspace; | 743 | struct list_head *workspace; |
802 | int cpus = num_online_cpus(); | 744 | int cpus = num_online_cpus(); |
803 | int idx = type - 1; | 745 | int idx = type - 1; |
746 | unsigned nofs_flag; | ||
804 | 747 | ||
805 | struct list_head *idle_ws = &btrfs_comp_ws[idx].idle_ws; | 748 | struct list_head *idle_ws = &btrfs_comp_ws[idx].idle_ws; |
806 | spinlock_t *ws_lock = &btrfs_comp_ws[idx].ws_lock; | 749 | spinlock_t *ws_lock = &btrfs_comp_ws[idx].ws_lock; |
@@ -830,7 +773,15 @@ again: | |||
830 | atomic_inc(total_ws); | 773 | atomic_inc(total_ws); |
831 | spin_unlock(ws_lock); | 774 | spin_unlock(ws_lock); |
832 | 775 | ||
776 | /* | ||
777 | * Allocation helpers call vmalloc that can't use GFP_NOFS, so we have | ||
778 | * to turn it off here because we might get called from the restricted | ||
779 | * context of btrfs_compress_bio/btrfs_compress_pages | ||
780 | */ | ||
781 | nofs_flag = memalloc_nofs_save(); | ||
833 | workspace = btrfs_compress_op[idx]->alloc_workspace(); | 782 | workspace = btrfs_compress_op[idx]->alloc_workspace(); |
783 | memalloc_nofs_restore(nofs_flag); | ||
784 | |||
834 | if (IS_ERR(workspace)) { | 785 | if (IS_ERR(workspace)) { |
835 | atomic_dec(total_ws); | 786 | atomic_dec(total_ws); |
836 | wake_up(ws_wait); | 787 | wake_up(ws_wait); |
@@ -961,19 +912,16 @@ int btrfs_compress_pages(int type, struct address_space *mapping, | |||
961 | * be contiguous. They all correspond to the range of bytes covered by | 912 | * be contiguous. They all correspond to the range of bytes covered by |
962 | * the compressed extent. | 913 | * the compressed extent. |
963 | */ | 914 | */ |
964 | static int btrfs_decompress_bio(int type, struct page **pages_in, | 915 | static int btrfs_decompress_bio(struct compressed_bio *cb) |
965 | u64 disk_start, struct bio *orig_bio, | ||
966 | size_t srclen) | ||
967 | { | 916 | { |
968 | struct list_head *workspace; | 917 | struct list_head *workspace; |
969 | int ret; | 918 | int ret; |
919 | int type = cb->compress_type; | ||
970 | 920 | ||
971 | workspace = find_workspace(type); | 921 | workspace = find_workspace(type); |
972 | 922 | ret = btrfs_compress_op[type - 1]->decompress_bio(workspace, cb); | |
973 | ret = btrfs_compress_op[type-1]->decompress_bio(workspace, pages_in, | ||
974 | disk_start, orig_bio, | ||
975 | srclen); | ||
976 | free_workspace(type, workspace); | 923 | free_workspace(type, workspace); |
924 | |||
977 | return ret; | 925 | return ret; |
978 | } | 926 | } |
979 | 927 | ||