Btrfs: Subpagesize-blocksize: Get rid of whole page I/O.
Subsystems (2)
v5 cover Btrfs: Subpagesize-blocksize: Get rid of whole page I/O.
This patchset continues with the work posted earlier at
https://www.mail-archive.com/[email protected]/msg35547.html.
Changes from V1:
1. Remove usage of bio_vec->bv_{len,offset} in end_bio_extent_readpage() and end_bio_extent_writepage().
Changes from V2:
1. Get __extent_writepage() to write only the dirty blocks of a page.
2. Fix "page private not zero on page" warning message which is printed when running xfstests.
Changes from V3:
1. Get "Hole punching" and "Extent preallocation" to work correctly in subpagesize-blocksize scenario.
2. Get btrfs_page_mkwrite() to reserve space in sectorsized units.
Changes from V4:
1. V2's "Btrfs: subpagesize-blocksize: Get rid of whole page reads" patch was incorrectly replaced with an older version when working on V3 patches. Fix this.
2. Fix btrfs_endio_direct_read() to compute checksums for all possible blocks in a page.
Xfstests' generic tests were run on an x86_64 machine with the patches applied. The Btrfs kernel module was compiled without ACL and quotas support and hence tests related to those were not run.
On multiple runs of the tests with 4k blocksize, 'umount' process would sometimes get blocked indefinitely causing 'hung task detector' to print the function call trace.
For 2k blocksize, the following xfstests' generic tests failed:
068, 075, 091, 112, 127, 224 and 274.
The following is a list of known TODO items which will be implemented in future revisions of this patchset:
1. The following command would cause a soft-lockup.
xfs_io -f -c "pwrite 0 6144" -c "sync_range 0 4096" -c "truncate 4095" file.bin
2. Re-base patchset on top of linux-btrfs/next branch to make use of immutable biovecs.
2. Remove PAGE_CACHE_SIZE delalloc reservation in btrfs_writepage_fixup_worker().
3. Create separate slab caches for 'extent buffer head' and 'extent buffer'.
4. Add 'leak list' tracking for 'extent buffer' instances.
5. Rename EXTENT_BUFFER_TREE_REF and EXTENT_BUFFER_IN_TREE to EXTENT_BUFFER_HEAD_TREE_REF and EXTENT_BUFFER_HEAD_IN_TREE respectively.
6. Get Xfstests' generic tests to successfully run on both 4k and 2k blocksizes.
Chandan Rajendra (10):
Btrfs: subpagesize-blocksize: Get rid of whole page reads.
Btrfs: subpagesize-blocksize: Get rid of whole page writes.
Btrfs: subpagesize-blocksize: __btrfs_buffered_write: Reserve/release
extents aligned to block size.
Btrfs: subpagesize-blocksize: Read tree blocks whose size is
<PAGE_CACHE_SIZE.
Btrfs: subpagesize-blocksize: Write only dirty extent buffers
belonging to a page
Btrfs: subpagesize-blocksize: Compute and look up csums based on
sectorsized blocks.
Btrfs: subpagesize-blocksize: __extent_writepage: Write only dirty
blocks of a page.
Btrfs: subpagesize-blocksize: fallocate: Work with sectorsized units.
Btrfs: subpagesize-blocksize: btrfs_page_mkwrite: Reserve space in
sectorsized units.
Btrfs: subpagesize-blocksize: Search for all ordered extents that
could span across a page.
Chandra Seetharaman (2):
Btrfs: subpagesize-blocksize: Define extent_buffer_head.
Btrfs: subpagesize-blocksize: Allow mounting filesystems where
sectorsize != PAGE_SIZE
fs/btrfs/backref.c | 2 +- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 8 +- fs/btrfs/disk-io.c | 117 +++-- fs/btrfs/disk-io.h | 3 + fs/btrfs/extent-tree.c | 6 +- fs/btrfs/extent_io.c | 1191 ++++++++++++++++++++++++++++-------------- fs/btrfs/extent_io.h | 48 +- fs/btrfs/file-item.c | 85 +-- fs/btrfs/file.c | 67 ++- fs/btrfs/inode.c | 184 ++++--- fs/btrfs/volumes.c | 2 +- fs/btrfs/volumes.h | 3 + include/trace/events/btrfs.h | 2 +- 14 files changed, 1124 insertions(+), 596 deletions(-)
Signature · 1 line
1.8.3.1
RFC PATCH v5 1/12 Btrfs: subpagesize-blocksize: Get rid of whole page reads.
Based on original patch from Aneesh Kumar K.V <[email protected]>
bio_vec->{bv_offset, bv_len} cannot be relied upon by the end bio functions to track the file offset range operated on by the bio. Hence this patch adds two new members to 'struct btrfs_io_bio' to track the file offset range.
This patch also brings back check_page_locked() to reliably unlock pages in readpage's end bio function.
--- fs/btrfs/extent_io.c | 200 ++++++++++++++++++++++----------------------------- fs/btrfs/volumes.h | 3 + 2 files changed, 90 insertions(+), 113 deletions(-)
fs/btrfs/extent_io.c +87 -113
@@ -1943,15 +1943,29 @@ int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,* helper function to set a given page up to date if all the * extents in the tree for that page are up to date */ -static void check_page_uptodate (struct extent_io_tree *tree,struct page *page) +static void check_page_uptodate (struct extent_io_tree *tree,struct page *page, +struct extent_state *cached) {u64 start =page_offset (page);u64 end = start +PAGE_CACHE_SIZE -1 ; -if (test_range_bit (tree, start, end,EXTENT_UPTODATE ,1 ,NULL )) +if (test_range_bit (tree, start, end,EXTENT_UPTODATE ,1 , cached))SetPageUptodate (page); }/* +* helper function to unlock a page if all the extents in the tree +* for that page are unlocked +*/ +static void check_page_locked (struct extent_io_tree *tree,struct page *page) +{ +u64 start =page_offset (page); +u64 end = start +PAGE_CACHE_SIZE -1 ; + +if (!test_range_bit (tree, start, end,EXTENT_LOCKED ,0 ,NULL )) { +unlock_page (page); + } +} + * When IO fails, either with EIO or csum verification fails, we * try other mirrors that might have a good copy of the data. This * io_failure_record is used to record state as we go through all the
@@ -2173,6 +2187,7 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset,struct bio *bio;struct btrfs_io_bio *btrfs_failed_bio;struct btrfs_io_bio *btrfs_bio; +int nr_sectors;int num_copies;int ret;int read_mode;
@@ -2267,7 +2282,8 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset,* a) deliver good data to the caller * b) correct the bad sectors on disk */ -if (failed_bio->bi_vcnt >1 ) { + nr_sectors =btrfs_io_bio (failed_bio)->len >> inode->i_sb->s_blocksize_bits; +if (nr_sectors >1 ) {/* * to fulfill b), we need to know the exact failing sectors, as * we don't want to rewrite any more than the failed ones. thus,
@@ -2314,6 +2330,8 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset, bio->bi_sector = failrec->logical >>9 ; bio->bi_bdev =BTRFS_I (inode)->root->fs_info->fs_devices->latest_bdev; bio->bi_size =0 ; +btrfs_io_bio (bio)->start_offset = start; +btrfs_io_bio (bio)->len = end - start +1 ; btrfs_failed_bio =btrfs_io_bio (failed_bio);if (btrfs_failed_bio->csum) {
@@ -2414,18 +2432,6 @@ static void end_bio_extent_writepage(struct bio *bio, int err)bio_put (bio); } -static void -endio_readpage_release_extent (struct extent_io_tree *tree,u64 start,u64 len, -int uptodate) -{ -struct extent_state *cached =NULL ; -u64 end = start + len -1 ; - -if (uptodate && tree->track_uptodate) -set_extent_uptodate (tree, start, end, &cached,GFP_ATOMIC ); -unlock_extent_cached (tree, start, end, &cached,GFP_ATOMIC ); -} -/* * after a readpage IO is done, we need to: * clear the uptodate bits on error
@@ -2440,76 +2446,50 @@ endio_readpage_release_extent(struct extent_io_tree *tree, u64 start, u64 len,static void end_bio_extent_readpage (struct bio *bio,int err) {int uptodate =test_bit (BIO_UPTODATE , &bio->bi_flags); -struct bio_vec *bvec_end = bio->bi_io_vec + bio->bi_vcnt -1 ; -struct bio_vec *bvec = bio->bi_io_vec;struct btrfs_io_bio *io_bio =btrfs_io_bio (bio); +struct bio_vec *bvec = bio->bi_io_vec; +struct bio_vec *bvec_end = bio->bi_io_vec + bio->bi_vcnt -1 ; +struct address_space *mapping; +struct extent_state *cached =NULL ;struct extent_io_tree *tree; -u64 offset =0 ; +struct btrfs_root *root; +struct inode *inode; +struct page *page;u64 start; -u64 end; +u64 offset =0 ;u64 len; -u64 extent_start =0 ; -u64 extent_len =0 ; +int nr_sectors;int mirror;int ret; -if (err) - uptodate =0 ; + mapping = bio->bi_io_vec->bv_page->mapping; + inode = mapping->host; + root =BTRFS_I (inode)->root; + tree = &BTRFS_I (inode)->io_tree; - do { - struct page *page = bvec->bv_page; - struct inode *inode = page->mapping->host; - - pr_debug("end_bio_extent_readpage: bi_sector=%llu, err=%d, " - "mirror=%lu\n", (u64)bio->bi_sector, err, - io_bio->mirror_num); - tree = &BTRFS_I(inode)->io_tree; - - /* We always issue full-page reads, but if some block - * in a page fails to read, blk_update_request() will - * advance bv_offset and adjust bv_len to compensate. - * Print a warning for nonzero offsets, and an error - * if they don't add up to a full page. */ - if (bvec->bv_offset || bvec->bv_len != PAGE_CACHE_SIZE) { - if (bvec->bv_offset + bvec->bv_len != PAGE_CACHE_SIZE) - btrfs_err(BTRFS_I(page->mapping->host)->root->fs_info, - "partial page read in btrfs with offset %u and length %u", - bvec->bv_offset, bvec->bv_len); - else - btrfs_info(BTRFS_I(page->mapping->host)->root->fs_info, - "incomplete page read in btrfs with offset %u and " - "length %u", - bvec->bv_offset, bvec->bv_len); - } + start =btrfs_io_bio (bio)->start_offset; + len =btrfs_io_bio (bio)->len; + mirror = io_bio->mirror_num; - start = page_offset(page); - end = start + bvec->bv_offset + bvec->bv_len - 1; - len = bvec->bv_len; + nr_sectors = len >> inode->i_sb->s_blocksize_bits; +BUG_ON (!nr_sectors); - if (++bvec <= bvec_end) - prefetchw(&bvec->bv_page->flags); + do { + BUG_ON(bvec > bvec_end); + page = bvec->bv_page; - mirror = io_bio->mirror_num; - if (likely(uptodate && tree->ops && - tree->ops->readpage_end_io_hook)) { + if (uptodate) { ret = tree->ops->readpage_end_io_hook(io_bio, offset, - page, start, end, - mirror); + page, start, + start + root->sectorsize - 1, + mirror); if (ret) uptodate = 0; else clean_io_failure(start, page); } - if (likely(uptodate)) - goto readpage_ok; - - if (tree->ops && tree->ops->readpage_io_failed_hook) { - ret = tree->ops->readpage_io_failed_hook(page, mirror); - if (!ret && !err && - test_bit(BIO_UPTODATE, &bio->bi_flags)) - uptodate = 1; - } else { + if (!uptodate) { /* * The generic bio_readpage_error handles errors the * following way: If possible, new read requests are
@@ -2520,63 +2500,38 @@ static void end_bio_extent_readpage(struct bio *bio, int err)* can't handle the error it will return -EIO and we * remain responsible for that page. */ - ret =bio_readpage_error (bio, offset, page, start, end, - mirror); + ret =bio_readpage_error (bio, offset, page, + start, start + root->sectorsize -1 , + mirror);if (ret ==0 ) { - uptodate = -test_bit (BIO_UPTODATE , &bio->bi_flags); + uptodate =test_bit (BIO_UPTODATE , &bio->bi_flags);if (err) uptodate =0 ; -continue ; + goto next_block; } } -readpage_ok: -if (likely (uptodate)) { -loff_t i_size =i_size_read (inode); -pgoff_t end_index = i_size >>PAGE_CACHE_SHIFT ; -unsigned offset; - -/* Zero out the end if this page straddles i_size */ - offset = i_size & (PAGE_CACHE_SIZE -1 ); -if (page->index == end_index && offset) -zero_user_segment (page, offset,PAGE_CACHE_SIZE ); -SetPageUptodate (page); + +if (uptodate) { +set_extent_uptodate (tree, start, + start + root->sectorsize -1 , + &cached,GFP_ATOMIC ); +check_page_uptodate (tree, page, cached); }else {ClearPageUptodate (page);SetPageError (page); } -unlock_page (page); - offset += len; - -if (unlikely (!uptodate)) { -if (extent_len) { -endio_readpage_release_extent (tree, - extent_start, - extent_len,1 ); - extent_start =0 ; - extent_len =0 ; - } -endio_readpage_release_extent (tree, start, - end - start +1 ,0 ); - }else if (!extent_len) { - extent_start = start; - extent_len = end +1 - start; - }else if (extent_start + extent_len == start) { - extent_len += end +1 - start; - }else { -endio_readpage_release_extent (tree, extent_start, - extent_len, uptodate); - extent_start = start; - extent_len = end +1 - start; - } - }while (bvec <= bvec_end); -if (extent_len) -endio_readpage_release_extent (tree, extent_start, extent_len, - uptodate); +unlock_extent (tree, start, start + root->sectorsize -1 ); +check_page_locked (tree, page); +next_block: + offset += root->sectorsize; + start += root->sectorsize; +if ((page_offset (page) +PAGE_CACHE_SIZE ) == start) + ++bvec; + }while (--nr_sectors); +if (io_bio->end_io) io_bio->end_io (io_bio, err); -bio_put (bio); }/*
@@ -2700,6 +2655,18 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree,else contig =bio_end_sector (bio) == sector; +if (contig) { +/* +* Check whether we are contig if file offsets. +* We should mostly be for readpage/readpages +* We need to do this because we use btrfs_io_bio +* start_offset and len to unlock in endio routines. +*/ +if ((page_offset (page) + offset) != + (btrfs_io_bio (bio)->start_offset + +btrfs_io_bio (bio)->len)) + contig =0 ; + }if (prev_bio_flags != bio_flags || !contig ||merge_bio (rw, tree, page, offset, page_size, bio, bio_flags) ||bio_add_page (bio, page, page_size, offset) < page_size) {
@@ -2709,6 +2676,11 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree,return ret; bio =NULL ; }else { +/* +* update btrfs_io_bio len. So that we can unlock +* correctly in end_io callback. +*/ +btrfs_io_bio (bio)->len += page_size;return 0 ; } }
@@ -2724,6 +2696,8 @@ static int submit_extent_page(int rw, struct extent_io_tree *tree,bio_add_page (bio, page, page_size, offset); bio->bi_end_io = end_io_func; bio->bi_private = tree; +btrfs_io_bio (bio)->start_offset =page_offset (page) + offset; +btrfs_io_bio (bio)->len = page_size;if (bio_ret) *bio_ret = bio;
@@ -2914,7 +2888,7 @@ static int __do_readpage(struct extent_io_tree *tree,/* the get_extent function already copied into the page */ if (test_range_bit (tree, cur, cur_end,EXTENT_UPTODATE ,1 ,NULL )) { -check_page_uptodate (tree, page); +check_page_uptodate (tree, page,NULL );if (!parent_locked)unlock_extent (tree, cur, cur + iosize -1 ); cur = cur + iosize;
fs/btrfs/volumes.h +3 -0
@@ -173,6 +173,9 @@ struct btrfs_io_bio {u8 csum_inline[BTRFS_BIO_INLINE_CSUM_SIZE ];u8 *csum_allocated;btrfs_io_bio_end_io_t *end_io; +/* Track file offset range operated on by the bio.*/ +u64 start_offset; +u64 len;struct bio bio; };
Signature · 1 line
1.8.3.1
RFC PATCH v5 2/12 Btrfs: subpagesize-blocksize: Get rid of whole page writes.
In reply to Chandan RajendraThis commit brings back functions that set/clear EXTENT_WRITEBACK bits. These are required to reliably clear PG_writeback page flag.
--- fs/btrfs/extent_io.c | 134 +++++++++++++++++++++++++++++++++------------------ fs/btrfs/extent_io.h | 2 +- fs/btrfs/inode.c | 47 +++++++++++++----- 3 files changed, 124 insertions(+), 59 deletions(-)
fs/btrfs/extent_io.c +88 -46
@@ -1293,6 +1293,20 @@ int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, cached_state, mask); } +static int set_extent_writeback (struct extent_io_tree *tree,u64 start,u64 end, +struct extent_state **cached_state,gfp_t mask) +{ +return set_extent_bit (tree, start, end,EXTENT_WRITEBACK ,NULL , + cached_state, mask); +} + +static int clear_extent_writeback (struct extent_io_tree *tree,u64 start,u64 end, +struct extent_state **cached_state,gfp_t mask) +{ +return clear_extent_bit (tree, start, end,EXTENT_WRITEBACK ,1 ,0 , + cached_state, mask); +} +/* * either insert or lock state struct between start and end use mask to tell * us if waiting is desired.
@@ -1399,6 +1413,7 @@ static int set_range_writeback(struct extent_io_tree *tree, u64 start, u64 end)page_cache_release (page); index++; } +set_extent_writeback (tree, start, end,NULL ,GFP_NOFS );return 0 ; }
@@ -1966,6 +1981,16 @@ static void check_page_locked(struct extent_io_tree *tree, struct page *page) } } +static void check_page_writeback (struct extent_io_tree *tree,struct page *page) +{ +u64 start =page_offset (page); +u64 end = start +PAGE_CACHE_SIZE -1 ; + +if (!test_range_bit (tree, start, end,EXTENT_WRITEBACK ,0 ,NULL )) +end_page_writeback (page); +} + +/* * When IO fails, either with EIO or csum verification fails, we * try other mirrors that might have a good copy of the data. This * io_failure_record is used to record state as we go through all the
@@ -2359,27 +2384,69 @@ static int bio_readpage_error(struct bio *failed_bio, u64 phy_offset, }/* lots and lots of room for performance fixes in the end_bio funcs */ - -int end_extent_writepage (struct page *page,int err,u64 start,u64 end) +void end_extents_write (struct inode *inode,int err,u64 start,u64 end) { +struct extent_io_tree *tree = &BTRFS_I (inode)->io_tree;int uptodate = (err ==0 ); -struct extent_io_tree *tree; +pgoff_t index, end_index; +u64 page_start, page_end; +struct page *page;int ret; - tree = &BTRFS_I (page->mapping->host)->io_tree; + index = start >>PAGE_CACHE_SHIFT ; + end_index = end >>PAGE_CACHE_SHIFT ; -if (tree->ops && tree->ops->writepage_end_io_hook) { - ret = tree->ops->writepage_end_io_hook (page, start, - end,NULL , uptodate); -if (ret) - uptodate =0 ; + page_start = start; + +while (index <= end_index) { + page =find_get_page (inode->i_mapping, index); +BUG_ON (!page); + + page_end =min_t (u64, end,page_offset (page) +PAGE_CACHE_SIZE -1 ); + +if (tree->ops && tree->ops->writepage_end_io_hook) { + ret = tree->ops->writepage_end_io_hook (page, + page_start, page_end, +NULL , uptodate); +if (ret) + uptodate =0 ; + } + + page_start = page_end +1 ; + + ++index; + +if (!uptodate) { +ClearPageUptodate (page); +SetPageError (page); + } + +page_cache_release (page); } +} -if (!uptodate) { -ClearPageUptodate (page); -SetPageError (page); +static void clear_extent_and_page_writeback (struct address_space *mapping, +struct extent_io_tree *tree, +struct btrfs_io_bio *io_bio) +{ +struct page *page; +pgoff_t index; +u64 offset, len; + + offset = io_bio->start_offset; + len = io_bio->len; + +clear_extent_writeback (tree, offset, offset + len -1 ,NULL , +GFP_ATOMIC ); + + index = offset >>PAGE_CACHE_SHIFT ; +while (offset < io_bio->start_offset + len) { + page =find_get_page (mapping, index); +check_page_writeback (tree, page); +page_cache_release (page); + index++; + offset +=page_offset (page) +PAGE_CACHE_SIZE - offset; } -return 0 ; }/*
@@ -2393,41 +2460,14 @@ int end_extent_writepage(struct page *page, int err, u64 start, u64 end)*/ static void end_bio_extent_writepage (struct bio *bio,int err) { -struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt -1 ; -u64 start; -u64 end; - -do { -struct page *page = bvec->bv_page; - -/* We always issue full-page reads, but if some block -* in a page fails to read, blk_update_request() will -* advance bv_offset and adjust bv_len to compensate. -* Print a warning for nonzero offsets, and an error -* if they don't add up to a full page. */ -if (bvec->bv_offset || bvec->bv_len !=PAGE_CACHE_SIZE ) { -if (bvec->bv_offset + bvec->bv_len !=PAGE_CACHE_SIZE ) -btrfs_err (BTRFS_I (page->mapping->host)->root->fs_info, -"partial page write in btrfs with offset %u and length %u" , - bvec->bv_offset, bvec->bv_len); -else -btrfs_info (BTRFS_I (page->mapping->host)->root->fs_info, -"incomplete page write in btrfs with offset %u and " -"length %u" , - bvec->bv_offset, bvec->bv_len); - } - - start =page_offset (page); - end = start + bvec->bv_offset + bvec->bv_len -1 ; - -if (--bvec >= bio->bi_io_vec) -prefetchw (&bvec->bv_page->flags); +struct address_space *mapping = bio->bi_io_vec->bv_page->mapping; +struct extent_io_tree *tree = &BTRFS_I (mapping->host)->io_tree; +struct btrfs_io_bio *io_bio =btrfs_io_bio (bio); -if (end_extent_writepage (page, err, start, end)) -continue ; +end_extents_write (mapping->host, err, io_bio->start_offset, + io_bio->start_offset + io_bio->len -1 ); -end_page_writeback (page); - }while (bvec >= bio->bi_io_vec); +clear_extent_and_page_writeback (mapping, tree, io_bio);bio_put (bio); }
@@ -3208,6 +3248,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, goto done_unlocked; } } +if (tree->ops && tree->ops->writepage_start_hook) { ret = tree->ops->writepage_start_hook (page, start, page_end);
@@ -3337,6 +3378,7 @@ done:set_page_writeback (page);end_page_writeback (page); } +unlock_page (page); done_unlocked:
fs/btrfs/extent_io.h +1 -1
@@ -341,7 +341,7 @@ struct btrfs_fs_info;int repair_io_failure (struct btrfs_fs_info *fs_info,u64 start,u64 length,u64 logical,struct page *page,int mirror_num); -int end_extent_writepage (struct page *page,int err,u64 start,u64 end); +void end_extents_write (struct inode *inode,int err,u64 start,u64 end);int repair_eb_io_failure (struct btrfs_root *root,struct extent_buffer *eb,int mirror_num);#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
fs/btrfs/inode.c +35 -12
72 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v5 3/12 Btrfs: subpagesize-blocksize: __btrfs_buffered_write: Reserve/release extents aligned to block size.
In reply to Chandan RajendraCurrently, the code reserves/releases extents in multiples of PAGE_CACHE_SIZE units. Fix this.
--- fs/btrfs/file.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
fs/btrfs/file.c +20 -12
@@ -1339,18 +1339,21 @@ fail: static noinline intlock_and_cleanup_extent_if_need (struct inode *inode,struct page **pages,size_t num_pages,loff_t pos, +size_t write_bytes,u64 *lockstart,u64 *lockend,struct extent_state **cached_state) { +struct btrfs_root *root =BTRFS_I (inode)->root;u64 start_pos;u64 last_pos;int i;int ret =0 ; - start_pos = pos & ~((u64 )PAGE_CACHE_SIZE -1 ); - last_pos = start_pos + ((u64 )num_pages <<PAGE_CACHE_SHIFT ) -1 ; + start_pos = pos & ~((u64 )root->sectorsize -1 ); + last_pos = start_pos + +ALIGN (pos + write_bytes - start_pos, root->sectorsize) -1 ; -if (start_pos < inode->i_size) { +if (start_pos < inode->i_size) {struct btrfs_ordered_extent *ordered;lock_extent_bits (&BTRFS_I (inode)->io_tree, start_pos, last_pos,0 , cached_state);
@@ -1468,6 +1471,7 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,while (iov_iter_count (i) >0 ) {size_t offset = pos & (PAGE_CACHE_SIZE -1 ); +size_t sector_offset;size_t write_bytes =min (iov_iter_count (i), nrptrs * (size_t )PAGE_CACHE_SIZE - offset);
@@ -1488,7 +1492,9 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,break ; } - reserve_bytes = num_pages <<PAGE_CACHE_SHIFT ; + sector_offset = pos & (root->sectorsize -1 ); + reserve_bytes =ALIGN (write_bytes + sector_offset, root->sectorsize); + ret =btrfs_check_data_free_space (inode, reserve_bytes); if (ret == -ENOSPC && (BTRFS_I(inode)->flags & (BTRFS_INODE_NODATACOW |
@@ -1503,7 +1509,9 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file, num_pages = (write_bytes + offset +PAGE_CACHE_SIZE -1 ) >>PAGE_CACHE_SHIFT ; - reserve_bytes = num_pages <<PAGE_CACHE_SHIFT ; + + reserve_bytes =ALIGN (write_bytes + sector_offset, + root->sectorsize); ret =0 ; }else { ret = -ENOSPC ;
@@ -1536,8 +1544,8 @@ again:break ; ret =lock_and_cleanup_extent_if_need (inode, pages, num_pages, - pos, &lockstart, &lockend, - &cached_state); + pos, write_bytes, &lockstart, &lockend, + &cached_state);if (ret <0 ) {if (ret == -EAGAIN ) goto again;
@@ -1574,9 +1582,9 @@ again:* we still have an outstanding extent for the chunk we actually * managed to copy. */ -if (num_pages > dirty_pages) { - release_bytes = (num_pages - dirty_pages) << -PAGE_CACHE_SHIFT ; +if (write_bytes > copied) { + release_bytes = (write_bytes - copied) + & ~((u64 )root->sectorsize -1 );if (copied >0 ) {spin_lock (&BTRFS_I (inode)->lock);BTRFS_I (inode)->outstanding_extents++;
@@ -1590,7 +1598,7 @@ again: release_bytes); } - release_bytes = dirty_pages <<PAGE_CACHE_SHIFT ; + release_bytes =ALIGN (copied + sector_offset, root->sectorsize);if (copied >0 ) ret = btrfs_dirty_pages(root, inode, pages,
@@ -1609,7 +1617,7 @@ again:if (only_release_metadata && copied >0 ) {u64 lockstart =round_down (pos, root->sectorsize);u64 lockend = lockstart + - (dirty_pages <<PAGE_CACHE_SHIFT ) -1 ; +ALIGN (copied, root->sectorsize) -1 ; set_extent_bit(&BTRFS_I(inode)->io_tree, lockstart, lockend, EXTENT_NORESERVE, NULL,
Signature · 1 line
1.8.3.1
RFC PATCH v5 4/12 Btrfs: subpagesize-blocksize: Define extent_buffer_head.
In reply to Chandan RajendraFrom: Chandra Seetharaman <[email protected]>
In order to handle multiple extent buffers per page, first we need to create a way to handle all the extent buffers that are attached to a page.
This patch creates a new data structure 'struct extent_buffer_head', and moves fields that are common to all extent buffers in a page from 'struct extent buffer' to 'struct extent_buffer_head'
Also, this patch moves EXTENT_BUFFER_TREE_REF, EXTENT_BUFFER_DUMMY and EXTENT_BUFFER_IN_TREE flags from extent_buffer->ebflags to extent_buffer_head->bflags.
--- fs/btrfs/backref.c | 2 +- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 6 +- fs/btrfs/disk-io.c | 46 ++++-- fs/btrfs/extent-tree.c | 6 +- fs/btrfs/extent_io.c | 372 +++++++++++++++++++++++++++++-------------- fs/btrfs/extent_io.h | 46 ++++-- fs/btrfs/volumes.c | 2 +- include/trace/events/btrfs.h | 2 +- 9 files changed, 326 insertions(+), 158 deletions(-)
fs/btrfs/backref.c +1 -1
@@ -1272,7 +1272,7 @@ char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path, eb = path->nodes[0 ];/* make sure we can use eb after releasing the path */ if (eb != eb_in) { -atomic_inc (&eb->refs); +atomic_inc (&eb_head (eb)->refs);btrfs_tree_read_lock (eb);btrfs_set_lock_blocking_rw (eb,BTRFS_READ_LOCK ); }
fs/btrfs/ctree.c +1 -1
@@ -169,7 +169,7 @@ struct extent_buffer *btrfs_root_node(struct btrfs_root *root)* the inc_not_zero dance and if it doesn't work then * synchronize_rcu and try again. */ -if (atomic_inc_not_zero (&eb->refs)) { +if (atomic_inc_not_zero (&eb_head (eb)->refs)) {rcu_read_unlock ();break ; }
fs/btrfs/ctree.h +4 -2
@@ -2138,14 +2138,16 @@ static inline void btrfs_set_token_##name(struct extent_buffer *eb, \#define BTRFS_SETGET_HEADER_FUNCS (name, type, member, bits) \ static inline u##bits btrfs_##name(struct extent_buffer *eb) \ { \ - type *p = page_address(eb->pages[0]); \ + type *p = page_address(eb_head(eb)->pages[0]) + \ + (eb->start & (PAGE_CACHE_SIZE -1)); \ u##bits res = le##bits##_to_cpu(p->member); \ return res; \ } \ static inline void btrfs_set_##name(struct extent_buffer *eb, \ u##bits val) \ { \ - type *p = page_address(eb->pages[0]); \ + type *p = page_address(eb_head(eb)->pages[0]) + \ + (eb->start & (PAGE_CACHE_SIZE -1)); \ p->member = cpu_to_le##bits(val); \ }
fs/btrfs/disk-io.c +30 -16
123 lines not on this page · raw message
fs/btrfs/extent-tree.c +3 -3
@@ -5984,7 +5984,7 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans, goto out; } -WARN_ON (test_bit (EXTENT_BUFFER_DIRTY , &buf->bflags)); +WARN_ON (test_bit (EXTENT_BUFFER_DIRTY , &buf->ebflags));btrfs_add_free_space (cache, buf->start, buf->len);btrfs_update_reserved_bytes (cache, buf->len,RESERVE_FREE );
@@ -6001,7 +6001,7 @@ out:* Deleting the buffer, clear the corrupt flag since it doesn't matter * anymore. */ -clear_bit (EXTENT_BUFFER_CORRUPT , &buf->bflags); +clear_bit (EXTENT_BUFFER_CORRUPT , &buf->ebflags);btrfs_put_block_group (cache); }
@@ -6887,7 +6887,7 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,btrfs_set_buffer_lockdep_class (root->root_key.objectid, buf, level);btrfs_tree_lock (buf);clean_tree_block (trans, root, buf); -clear_bit (EXTENT_BUFFER_STALE , &buf->bflags); +clear_bit (EXTENT_BUFFER_STALE , &buf->ebflags);btrfs_set_lock_blocking (buf);btrfs_set_buffer_uptodate (buf);
fs/btrfs/extent_io.c +252 -120
704 lines not on this page · raw message
fs/btrfs/extent_io.h +33 -13
86 lines not on this page · raw message
fs/btrfs/volumes.c +1 -1
@@ -5936,7 +5936,7 @@ int btrfs_read_sys_array(struct btrfs_root *root)* to silence the warning eg. on PowerPC 64. */ if (PAGE_CACHE_SIZE >BTRFS_SUPER_INFO_SIZE ) -SetPageUptodate (sb->pages[0 ]); +SetPageUptodate (eb_head (sb)->pages[0 ]);write_extent_buffer (sb, super_copy,0 ,BTRFS_SUPER_INFO_SIZE ); array_size =btrfs_super_sys_array_size (super_copy);
include/trace/events/btrfs.h +1 -1
@@ -695,7 +695,7 @@ TRACE_EVENT(btrfs_cow_block,TP_fast_assign ( __entry->root_objectid = root->root_key.objectid; __entry->buf_start = buf->start; - __entry->refs =atomic_read (&buf->refs); + __entry->refs =atomic_read (&eb_head (buf)->refs); __entry->cow_start = cow->start; __entry->buf_level =btrfs_header_level (buf); __entry->cow_level =btrfs_header_level (cow);
Signature · 1 line
1.8.3.1
RFC PATCH v5 5/12 Btrfs: subpagesize-blocksize: Read tree blocks whose size is <PAGE_CACHE_SIZE.
In reply to Chandan RajendraIn the case of subpagesize-blocksize, this patch makes it possible to read only a single metadata block from the disk instead of all the metadata blocks that map into a page.
--- fs/btrfs/disk-io.c | 45 ++++++++--------- fs/btrfs/disk-io.h | 3 ++ fs/btrfs/extent_io.c | 135 +++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 137 insertions(+), 46 deletions(-)
fs/btrfs/disk-io.c +19 -26
@@ -413,7 +413,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,int mirror_num =0 ;int failed_mirror =0 ; -clear_bit (EXTENT_BUFFER_CORRUPT , &eb->bflags); +clear_bit (EXTENT_BUFFER_CORRUPT , &eb->ebflags); io_tree = &BTRFS_I (root->fs_info->btree_inode)->io_tree;while (1 ) { ret = read_extent_buffer_pages(io_tree, eb, start,
@@ -432,7 +432,7 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,* there is no reason to read the other copies, they won't be * any less wrong. */ -if (test_bit (EXTENT_BUFFER_CORRUPT , &eb->bflags)) +if (test_bit (EXTENT_BUFFER_CORRUPT , &eb->ebflags))break ; num_copies = btrfs_num_copies(root->fs_info,
@@ -564,12 +564,13 @@ static noinline int check_leaf(struct btrfs_root *root,return 0 ; } -static int btree_readpage_end_io_hook (struct btrfs_io_bio *io_bio, -u64 phy_offset,struct page *page, -u64 start,u64 end,int mirror) +int verify_extent_buffer_read (struct btrfs_io_bio *io_bio, +struct page *page, +u64 start,u64 end,int mirror) {u64 found_start;int found_level; +struct extent_buffer_head *ebh;struct extent_buffer *eb;struct btrfs_root *root =BTRFS_I (page->mapping->host)->root;int ret =0 ;
@@ -579,18 +580,26 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, goto out; eb = (struct extent_buffer *)page->private; +do { +if ((eb->start <= start) && (eb->start + eb->len -1 > start)) +break ; + }while ((eb = eb->eb_next) !=NULL ); + +BUG_ON (!eb); + + ebh =eb_head (eb);/* the pending IO might have been the only thing that kept this buffer * in memory. Make sure we have a ref for all this other checks */ extent_buffer_get (eb); - reads_done =atomic_dec_and_test (&eb->io_pages); + reads_done =atomic_dec_and_test (&ebh->io_bvecs);if (!reads_done) goto err; eb->read_mirror = mirror; -if (test_bit (EXTENT_BUFFER_IOERR , &eb->bflags)) { +if (test_bit (EXTENT_BUFFER_IOERR , &eb->ebflags)) { ret = -EIO ; goto err; }
@@ -632,7 +641,7 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,* return -EIO. */ if (found_level ==0 &&check_leaf (root, eb)) { -set_bit (EXTENT_BUFFER_CORRUPT , &eb->bflags); +set_bit (EXTENT_BUFFER_CORRUPT , &eb->ebflags); ret = -EIO ; }
@@ -640,7 +649,7 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,set_extent_buffer_uptodate (eb); err:if (reads_done && -test_and_clear_bit (EXTENT_BUFFER_READAHEAD , &eb->bflags)) +test_and_clear_bit (EXTENT_BUFFER_READAHEAD , &eb->ebflags))btree_readahead_hook (root, eb, eb->start, ret);if (ret) {
@@ -649,7 +658,7 @@ err:* again, we have to make sure it has something * to decrement */ -atomic_inc (&eb->io_pages); +atomic_inc (&eb_head (eb)->io_bvecs);clear_extent_buffer_uptodate (eb); }free_extent_buffer (eb);
@@ -657,20 +666,6 @@ out:return ret; } -static int btree_io_failed_hook (struct page *page,int failed_mirror) -{ -struct extent_buffer *eb; -struct btrfs_root *root =BTRFS_I (page->mapping->host)->root; - - eb = (struct extent_buffer *)page->private; -set_bit (EXTENT_BUFFER_IOERR , &eb->bflags); - eb->read_mirror = failed_mirror; -atomic_dec (&eb->io_pages); -if (test_and_clear_bit (EXTENT_BUFFER_READAHEAD , &eb->bflags)) -btree_readahead_hook (root, eb, eb->start, -EIO ); -return -EIO ;/* we fixed nothing */ -} -static void end_workqueue_bio (struct bio *bio,int err) {struct end_io_wq *end_io_wq = bio->bi_private;
@@ -4109,8 +4104,6 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root) }static struct extent_io_ops btree_extent_io_ops = { - .readpage_end_io_hook = btree_readpage_end_io_hook, - .readpage_io_failed_hook = btree_io_failed_hook, .submit_bio_hook = btree_submit_bio_hook,/* note we're sharing with inode.c for the merge bio hook */ .merge_bio_hook = btrfs_merge_bio_hook,
fs/btrfs/disk-io.h +3 -0
@@ -110,6 +110,9 @@ static inline void btrfs_put_fs_root(struct btrfs_root *root)kfree (root); } +int verify_extent_buffer_read (struct btrfs_io_bio *io_bio, +struct page *page, +u64 start,u64 end,int mirror);void btrfs_mark_buffer_dirty (struct extent_buffer *buf);int btrfs_buffer_uptodate (struct extent_buffer *buf,u64 parent_transid,int atomic);
fs/btrfs/extent_io.c +115 -20
190 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v5 6/12 Btrfs: subpagesize-blocksize: Write only dirty extent buffers belonging to a page
In reply to Chandan RajendraFor the subpagesize-blocksize scenario, This patch adds the ability to write a single extent buffer to the disk.
--- fs/btrfs/disk-io.c | 20 ++-- fs/btrfs/extent_io.c | 279 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 244 insertions(+), 55 deletions(-)
fs/btrfs/disk-io.c +13 -7
@@ -466,17 +466,23 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,static int csum_dirty_buffer (struct btrfs_root *root,struct page *page) { -u64 start =page_offset (page); -u64 found_start;struct extent_buffer *eb; +u64 found_start; eb = (struct extent_buffer *)page->private; -if (page != eb->pages[0 ]) +if (page !=eb_head (eb)->pages[0 ])return 0 ; - found_start =btrfs_header_bytenr (eb); -if (WARN_ON (found_start != start || !PageUptodate (page))) -return 0 ; -csum_tree_block (root, eb,0 ); +do { +if (!test_bit (EXTENT_BUFFER_WRITEBACK , &eb->ebflags)) +continue ; +if (WARN_ON (!test_bit (EXTENT_BUFFER_UPTODATE , &eb->ebflags))) +continue ; + found_start =btrfs_header_bytenr (eb); +if (WARN_ON (found_start != eb->start)) +return 0 ; +csum_tree_block (root, eb,0 ); + }while ((eb = eb->eb_next) !=NULL ); +return 0 ; }
fs/btrfs/extent_io.c +231 -48
407 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v5 7/12 Btrfs: subpagesize-blocksize: Allow mounting filesystems where sectorsize != PAGE_SIZE
In reply to Chandan RajendraFrom: Chandra Seetharaman <[email protected]>
This patch allows mounting filesystems with blocksize smaller than the PAGE_SIZE.
--- fs/btrfs/disk-io.c | 6 ------ 1 file changed, 6 deletions(-)
fs/btrfs/disk-io.c +0 -6
@@ -2599,12 +2599,6 @@ int open_ctree(struct super_block *sb, goto fail_sb_buffer; } -if (sectorsize !=PAGE_SIZE ) { -printk (KERN_WARNING "BTRFS: Incompatible sector size(%lu) " -"found on %s\n" , (unsigned long )sectorsize, sb->s_id); - goto fail_sb_buffer; - } -mutex_lock (&fs_info->chunk_mutex); ret =btrfs_read_sys_array (tree_root);mutex_unlock (&fs_info->chunk_mutex);
Signature · 1 line
1.8.3.1
RFC PATCH v5 8/12 Btrfs: subpagesize-blocksize: Compute and look up csums based on sectorsized blocks.
In reply to Chandan RajendraChecksums are applicable to sectorsize units. The current code uses bio->bv_len units to compute and look up checksums. This works on machines where sectorsize == PAGE_CACHE_SIZE. This patch makes the checksum computation and look up code to work with sectorsize units.
--- fs/btrfs/file-item.c | 85 ++++++++++++++++++++++++++++++++-------------------- fs/btrfs/inode.c | 50 ++++++++++++++++++++----------- 2 files changed, 85 insertions(+), 50 deletions(-)
fs/btrfs/file-item.c +52 -33
@@ -172,6 +172,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,u64 item_start_offset =0 ;u64 item_last_offset =0 ;u64 disk_bytenr; +u64 page_bytes_left;u32 diff;int nblocks;int bio_index =0 ;
@@ -220,6 +221,8 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, disk_bytenr = (u64 )bio->bi_sector <<9 ;if (dio) offset = logical_offset; + + page_bytes_left = bvec->bv_len;while (bio_index < bio->bi_vcnt) {if (!dio) offset =page_offset (bvec->bv_page) + bvec->bv_offset;
@@ -243,7 +246,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,if (BTRFS_I (inode)->root->root_key.objectid ==BTRFS_DATA_RELOC_TREE_OBJECTID ) {set_extent_bits (io_tree, offset, - offset + bvec->bv_len -1 , + offset + root->sectorsize -1 ,EXTENT_NODATASUM ,GFP_NOFS ); }else { btrfs_info(BTRFS_I(inode)->root->fs_info,
@@ -281,11 +284,17 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, found: csum += count * csum_size; nblocks -= count; +while (count--) { - disk_bytenr += bvec->bv_len; - offset += bvec->bv_len; - bio_index++; - bvec++; + disk_bytenr += root->sectorsize; + offset += root->sectorsize; + page_bytes_left -= root->sectorsize; +if (!page_bytes_left) { + bio_index++; + bvec++; + page_bytes_left = bvec->bv_len; + } + } }btrfs_free_path (path);
@@ -442,6 +451,8 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,struct bio_vec *bvec = bio->bi_io_vec;int bio_index =0 ;int index; +int nr_sectors; +int i;unsigned long total_bytes =0 ;unsigned long this_sum_bytes =0 ;u64 offset;
@@ -468,41 +479,49 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,if (!contig) offset =page_offset (bvec->bv_page) + bvec->bv_offset; -if (offset >= ordered->file_offset + ordered->len || - offset < ordered->file_offset) { -unsigned long bytes_left; - sums->len = this_sum_bytes; - this_sum_bytes =0 ; -btrfs_add_ordered_sum (inode, ordered, sums); -btrfs_put_ordered_extent (ordered); + data =kmap_atomic (bvec->bv_page); - bytes_left = bio->bi_size - total_bytes; + nr_sectors = (bvec->bv_len + root->sectorsize -1 ) + >> root->fs_info->sb->s_blocksize_bits; + +for (i =0 ; i < nr_sectors; i++) { +if (offset >= ordered->file_offset + ordered->len || + offset < ordered->file_offset) { +unsigned long bytes_left; + sums->len = this_sum_bytes; + this_sum_bytes =0 ; +btrfs_add_ordered_sum (inode, ordered, sums); +btrfs_put_ordered_extent (ordered); + + bytes_left = bio->bi_size - total_bytes; + + sums =kzalloc (btrfs_ordered_sum_size (root, bytes_left), +GFP_NOFS ); +BUG_ON (!sums);/* -ENOMEM */ + sums->len = bytes_left; + ordered =btrfs_lookup_ordered_extent (inode, offset); +BUG_ON (!ordered);/* Logic error */ + sums->bytenr = ((u64 )bio->bi_sector <<9 ) + + total_bytes; + index =0 ; + } - sums =kzalloc (btrfs_ordered_sum_size (root, bytes_left), -GFP_NOFS ); -BUG_ON (!sums);/* -ENOMEM */ - sums->len = bytes_left; - ordered =btrfs_lookup_ordered_extent (inode, offset); -BUG_ON (!ordered);/* Logic error */ - sums->bytenr = ((u64 )bio->bi_sector <<9 ) + - total_bytes; - index =0 ; + sums->sums[index] = ~(u32 )0 ; + sums->sums[index] + =btrfs_csum_data (data + bvec->bv_offset + (i * root->sectorsize), + sums->sums[index], + root->sectorsize); +btrfs_csum_final (sums->sums[index], + (char *)(sums->sums + index)); + index++; + offset += root->sectorsize; + this_sum_bytes += root->sectorsize; + total_bytes += root->sectorsize; } - data =kmap_atomic (bvec->bv_page); - sums->sums[index] = ~(u32 )0 ; - sums->sums[index] =btrfs_csum_data (data + bvec->bv_offset, - sums->sums[index], - bvec->bv_len);kunmap_atomic (data); -btrfs_csum_final (sums->sums[index], - (char *)(sums->sums + index)); bio_index++; - index++; - total_bytes += bvec->bv_len; - this_sum_bytes += bvec->bv_len; - offset += bvec->bv_len; bvec++; } this_sum_bytes =0 ;
fs/btrfs/inode.c +33 -17
71 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v5 9/12 Btrfs: subpagesize-blocksize: __extent_writepage: Write only dirty blocks of a page.
In reply to Chandan RajendraThe code now loops across 'ordered extents' instead of 'extent maps' to figure out the dirty blocks of the page to be submitted for a write operation.
--- fs/btrfs/extent_io.c | 68 +++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 41 deletions(-)
fs/btrfs/extent_io.c +27 -41
@@ -3129,22 +3129,22 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,struct inode *inode = page->mapping->host;struct extent_page_data *epd = data;struct extent_io_tree *tree = epd->tree; +struct btrfs_ordered_extent *ordered;u64 start =page_offset (page);u64 delalloc_start;u64 page_end = start +PAGE_CACHE_SIZE -1 ;u64 end;u64 cur = start;u64 extent_offset; +u64 extent_end;u64 last_byte =i_size_read (inode); -u64 block_start;u64 iosize;sector_t sector;struct extent_state *cached_state =NULL ; -struct extent_map *em;struct block_device *bdev;int ret;int nr =0 ; -size_t pg_offset =0 ; +size_t pg_offset;size_t blocksize;loff_t i_size =i_size_read (inode);unsigned long end_index = i_size >>PAGE_CACHE_SHIFT ;
@@ -3184,7 +3184,6 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,kunmap_atomic (userpage);flush_dcache_page (page); } - pg_offset =0 ;set_page_extent_mapped (page);
@@ -3295,57 +3294,45 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, page_end, NULL, 1);break ; } - em = epd->get_extent (inode, page, pg_offset, cur, - end - cur +1 ,1 ); -if (IS_ERR_OR_NULL (em)) { -SetPageError (page); -break ; + + ordered =btrfs_lookup_ordered_extent (inode, cur); +if (!ordered) { + cur += blocksize; +continue ; } - extent_offset = cur - em->start; -BUG_ON (extent_map_end (em) <= cur); + pg_offset = cur & (PAGE_CACHE_SIZE -1 ); + + extent_offset = cur - ordered->file_offset; + extent_end = ordered->file_offset + ordered->len; + extent_end = (extent_end < ordered->file_offset) ?-1 : extent_end; +BUG_ON (extent_end <= cur);BUG_ON (end < cur); - iosize =min (extent_map_end (em) - cur, end - cur +1 ); + iosize =min (extent_end - cur, end - cur +1 ); iosize =ALIGN (iosize, blocksize); - sector = (em->block_start + extent_offset) >>9 ; - bdev = em->bdev; - block_start = em->block_start; - compressed =test_bit (EXTENT_FLAG_COMPRESSED , &em->flags); -free_extent_map (em); - em =NULL ; - + sector = (ordered->start + extent_offset) >>9 ; + bdev =BTRFS_I (inode)->root->fs_info->fs_devices->latest_bdev; + compressed =test_bit (BTRFS_ORDERED_COMPRESSED , &ordered->flags); +btrfs_put_ordered_extent (ordered); + ordered =NULL ;/* * compressed and inline extents are written through other * paths in the FS */ -if (compressed || block_start ==EXTENT_MAP_HOLE || - block_start ==EXTENT_MAP_INLINE ) { -/* -* end_io notification does not happen here for -* compressed extents -*/ -if (!compressed && tree->ops && - tree->ops->writepage_end_io_hook) - tree->ops->writepage_end_io_hook (page, cur, - cur + iosize -1 , -NULL ,1 ); -else if (compressed) { -/* we don't want to end_page_writeback on -* a compressed extent. this happens -* elsewhere -*/ - nr++; - } - +if (compressed) { +/* we don't want to end_page_writeback on +* a compressed extent. this happens +* elsewhere +*/ + nr++; cur += iosize; - pg_offset += iosize;continue ; } +/* leave this out until we have a page_mkwrite call */ if (0 && !test_range_bit (tree, cur, cur + iosize -1 ,EXTENT_DIRTY ,0 ,NULL )) { cur = cur + iosize; - pg_offset += iosize;continue ; }
@@ -3376,7 +3363,6 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,SetPageError (page); } cur = cur + iosize; - pg_offset += iosize; nr++; } done:
Signature · 1 line
1.8.3.1
RFC PATCH v5 10/12 Btrfs: subpagesize-blocksize: fallocate: Work with sectorsized units.
In reply to Chandan RajendraWhile at it, this commit changes btrfs_truncate_page() to truncate sectorsized blocks instead of pages. Hence the function has been renamed to btrfs_truncate_block().
--- fs/btrfs/ctree.h | 2 +- fs/btrfs/file.c | 35 ++++++++++++++++++----------------- fs/btrfs/inode.c | 48 +++++++++++++++++++++++++----------------------- 3 files changed, 44 insertions(+), 41 deletions(-)
fs/btrfs/ctree.h +1 -1
@@ -3721,7 +3721,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,struct btrfs_root *root, struct inode *dir, u64 objectid, const char *name, int name_len); -int btrfs_truncate_page (struct inode *inode,loff_t from,loff_t len, +int btrfs_truncate_block (struct inode *inode,loff_t from,loff_t len,int front); int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
fs/btrfs/file.c +18 -17
@@ -2161,6 +2161,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)struct btrfs_path *path;struct btrfs_block_rsv *rsv;struct btrfs_trans_handle *trans; +unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;u64 lockstart =round_up (offset,BTRFS_I (inode)->root->sectorsize);u64 lockend =round_down (offset + len,BTRFS_I (inode)->root->sectorsize) -1 ;
@@ -2170,8 +2171,8 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)int ret =0 ;int err =0 ;int rsv_count; -bool same_page = ((offset >>PAGE_CACHE_SHIFT ) == - ((offset + len -1 ) >>PAGE_CACHE_SHIFT )); +bool same_block = ((offset >> blocksize_bits) == + ((offset + len -1 ) >> blocksize_bits));bool no_holes =btrfs_fs_incompat (root->fs_info,NO_HOLES ); ret =btrfs_wait_ordered_range (inode, offset, len);
@@ -2180,32 +2181,32 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)mutex_lock (&inode->i_mutex);/* -* We needn't truncate any page which is beyond the end of the file +* We needn't truncate any block which is beyond the end of the file * because we are sure there is no data there. */ /* -* Only do this if we are in the same page and we aren't doing the -* entire page. +* Only do this if we are in the same block and we aren't doing the +* entire block. */ -if (same_page && len <PAGE_CACHE_SIZE ) { -if (offset <round_up (inode->i_size,PAGE_CACHE_SIZE )) - ret =btrfs_truncate_page (inode, offset, len,0 ); +if (same_block && len < root->sectorsize) { +if (offset <round_up (inode->i_size, root->sectorsize)) + ret =btrfs_truncate_block (inode, offset, len,0 );mutex_unlock (&inode->i_mutex);return ret; } -/* zero back part of the first page */ -if (offset <round_up (inode->i_size,PAGE_CACHE_SIZE )) { - ret =btrfs_truncate_page (inode, offset,0 ,0 ); +/* zero back part of the first block */ +if (offset <round_up (inode->i_size, root->sectorsize)) { + ret =btrfs_truncate_block (inode, offset,0 ,0 );if (ret) {mutex_unlock (&inode->i_mutex);return ret; } } -/* zero the front end of the last page */ -if (offset + len <round_up (inode->i_size,PAGE_CACHE_SIZE )) { - ret =btrfs_truncate_page (inode, offset + len,0 ,1 ); +/* zero the front end of the last block */ +if (offset + len <round_up (inode->i_size, root->sectorsize)) { + ret =btrfs_truncate_block (inode, offset + len,0 ,1 );if (ret) {mutex_unlock (&inode->i_mutex);return ret;
@@ -2410,10 +2411,10 @@ static long btrfs_fallocate(struct file *file, int mode, }else {/* * If we are fallocating from the end of the file onward we -* need to zero out the end of the page if i_size lands in the -* middle of a page. +* need to zero out the end of the block if i_size lands in the +* middle of a block. */ - ret =btrfs_truncate_page (inode, inode->i_size,0 ,0 ); + ret =btrfs_truncate_block (inode, inode->i_size,0 ,0 );if (ret) goto out; }
fs/btrfs/inode.c +25 -23
123 lines not on this page · raw message
Signature · 1 line
1.8.3.1
RFC PATCH v5 11/12 Btrfs: subpagesize-blocksize: btrfs_page_mkwrite: Reserve space in sectorsized units.
In reply to Chandan RajendraIn subpagesize-blocksize scenario, if i_size occurs in a block which is not the last block in the page, then the space to be reserved should be calculated appropriately.
--- fs/btrfs/inode.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-)
fs/btrfs/inode.c +22 -11
@@ -7698,26 +7698,23 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)loff_t size;int ret;int reserved =0 ; +u64 delalloc_size;u64 page_start;u64 page_end;sb_start_pagefault (inode->i_sb); - ret =btrfs_delalloc_reserve_space (inode,PAGE_CACHE_SIZE ); -if (!ret) { - ret =file_update_time (vma->vm_file); - reserved =1 ; - } + + ret =file_update_time (vma->vm_file);if (ret) {if (ret == -ENOMEM ) ret =VM_FAULT_OOM ;else /* -ENOSPC, -EIO, etc */ ret =VM_FAULT_SIGBUS ; -if (reserved) - goto out; - goto out_noreserve; + goto out; } ret =VM_FAULT_NOPAGE ;/* make the VM retry the fault */ + again:lock_page (page); size =i_size_read (inode);
@@ -7748,6 +7745,19 @@ again: goto again; } +if (page->index == ((size -1 ) >>PAGE_CACHE_SHIFT )) + delalloc_size =round_up (size - page_start, root->sectorsize); +else + delalloc_size =PAGE_CACHE_SIZE ; + + ret =btrfs_delalloc_reserve_space (inode, delalloc_size); +if (ret) { +/* -ENOSPC */ + ret =VM_FAULT_SIGBUS ; + goto out_unlock; + } + reserved =1 ; +/* * XXX - page_mkwrite gets called every time the page is dirtied, even * if it was already dirty, so for space accounting reasons we need to
@@ -7760,7 +7770,8 @@ again:EXTENT_DO_ACCOUNTING |EXTENT_DEFRAG , 0, 0, &cached_state, GFP_NOFS); - ret =btrfs_set_extent_delalloc (inode, page_start, page_end, + ret =btrfs_set_extent_delalloc (inode, page_start, + page_start + delalloc_size -1 , &cached_state);if (ret) { unlock_extent_cached(io_tree, page_start, page_end,
@@ -7799,8 +7810,8 @@ out_unlock: }unlock_page (page); out: -btrfs_delalloc_release_space (inode,PAGE_CACHE_SIZE ); -out_noreserve: +if (reserved) +btrfs_delalloc_release_space (inode, delalloc_size);sb_end_pagefault (inode->i_sb);return ret; }
Signature · 1 line
1.8.3.1
RFC PATCH v5 12/12 Btrfs: subpagesize-blocksize: Search for all ordered extents that could span across a page.
In reply to Chandan RajendraIn subpagesize-blocksize scenario it is not sufficient to search using the first byte of the page to make sure that there are no ordered extents present across the page. Fix this.
--- fs/btrfs/extent_io.c | 3 ++- fs/btrfs/inode.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/extent_io.c +2 -1
@@ -3066,7 +3066,8 @@ static int __extent_read_full_page(struct extent_io_tree *tree,while (1 ) {lock_extent (tree, start, end); - ordered =btrfs_lookup_ordered_extent (inode, start); + ordered =btrfs_lookup_ordered_range (inode, start, +PAGE_CACHE_SIZE );if (!ordered)break ;unlock_extent (tree, start, end);
fs/btrfs/inode.c +3 -3
@@ -1784,7 +1784,7 @@ again:if (PagePrivate2 (page)) goto out; - ordered =btrfs_lookup_ordered_extent (inode, page_start); + ordered =btrfs_lookup_ordered_range (inode, page_start,PAGE_CACHE_SIZE );if (ordered) {unlock_extent_cached (&BTRFS_I (inode)->io_tree, page_start, page_end, &cached_state,GFP_NOFS );
@@ -7610,7 +7610,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset,if (!inode_evicting)lock_extent_bits (tree, page_start, page_end,0 , &cached_state); - ordered =btrfs_lookup_ordered_extent (inode, page_start); + ordered =btrfs_lookup_ordered_range (inode, page_start,PAGE_CACHE_SIZE );if (ordered) {/* * IO on this page will never be started, so we need
@@ -7735,7 +7735,7 @@ again:* we can't set the delalloc bits if there are pending ordered * extents. Drop our locks and wait for them to finish */ - ordered =btrfs_lookup_ordered_extent (inode, page_start); + ordered =btrfs_lookup_ordered_range (inode, page_start, page_end);if (ordered) {unlock_extent_cached (io_tree, page_start, page_end, &cached_state,GFP_NOFS );
Signature · 1 line
1.8.3.1