Btrfs: Subpagesize-blocksize: Get rid of whole page I/O.
Subsystems (2)
v10 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]/msg38862.html.
Changes from V9:
1. Earlier, In read_extent_buffer_pages(), we used to check for extent buffer pages' PG_uptodate flag immediately after the page was unlocked by the endio function. However, the PG_uptodate flag is set on the pages only after the read operation on all pages complete successfully and the verification of the extent buffer's contents is done. Fix this by checking only for EXTENT_BUFFER_UPTODATE flag in read_extent_buffer_pages().
2. Add the new EXTENT_READ_IO extent state bit to reliably unlock pages in readpage's end bio function.
3. Use (eb->start, seq) as search key for tree modification log.
4. btrfs_submit_direct_hook: Prevent zero length bios from being submitted when map_length < bio vector length.
5. Enabled POSIX ACL support.
Changes from V8:
1. In subpagesize-blocksize scenario, prevent writes to an extent buffer when the corresponding page's PG_writeback flag is set. This race condition was triggered when running xfstests' generic/083 test. With the new patch applied, I have run the complete xfstests suite as well as run generic/083 multiple times on both 4k and 2k block size setups. There were 2 non-related test failures that occured rarely, but they were reproducible even when the patch was not applied.
Changes from V7:
1. Fix a softlockup issue that occured because the page corresponding to the delalloc region did not exist. This bug was introduced by the code added in btrfs_invalidatepage and related functions in V7 version.
Changes from V6:
1. Fix softlockup issue that occured during unmounting a 4k blocksized filesystem instance.
2. Track blocks of an ordered extent submitted for write I/O to avoid I/O resubmission in certain scenarios.
Changes from V5:
1. Rebased patchset on top of current btrfs-next tree (i.e. commit 8d875f95da43c6a8f18f77869f2ef26e9594fecc). This involved using "immutable biovecs".
2. Deal with partially allocated ordered extents across a page.
3. Explicitly track I/O status of blocks of an ordered extent.
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.
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 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 V1:
1. Remove usage of bio_vec->bv_{len,offset} in end_bio_extent_readpage() and end_bio_extent_writepage().
Xfstests' generic tests were run on an x86_64 machine with the patches applied for blocksizes 2k and 4k.
For 2k blocksize, the following xfstests' generic tests failed:
1. generic/068
The following xfstests' generic tests failed for both 2k and 4k blocksize:
1. generic/008 - FALLOC_FL_ZERO_RANGE is not supported by Btrfs.
2. generic/091 - FALLOC_FL_ZERO_RANGE is not supported by Btrfs.
3. generic/224
This looks mostly an issue caused by non-btrfs code as the test failed for the exact same reason when run on an ext4 filesystem instance.
4. generic/263 - FALLOC_FL_ZERO_RANGE is not supported by Btrfs.
5. generic/274
This test very rarely results in a hung task.
The following is a list of known TODO items which will be implemented in future revisions of this patchset:
1. The xfstests suite was based off the corresponding git tree as available on March 2014. Pull the latest from the xfstests git tree and execute the tests.
2. Rebase the patches on top of the current linux-btrfs/next branch.
3. Get Xfstests' generic tests to successfully run on both 4k and 2k blocksizes.
4. Remove PAGE_CACHE_SIZE delalloc reservation in btrfs_writepage_fixup_worker().
5. Create separate slab caches for 'extent buffer head' and 'extent buffer'.
6. Add 'leak list' tracking for 'extent buffer' instances.
7. Rename EXTENT_BUFFER_TREE_REF and EXTENT_BUFFER_IN_TREE to EXTENT_BUFFER_HEAD_TREE_REF and EXTENT_BUFFER_HEAD_IN_TREE respectively.
Chandan Rajendra (17):
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.
Btrfs: subpagesize-blocksize: Deal with partial ordered extent
allocations.
Btrfs: subpagesize-blocksize: Explicitly Track I/O status of blocks of
an ordered extent.
Btrfs: subpagesize-blocksize: Revert commit
fc4adbff823f76577ece26dcb88bf6f8392dbd43.
Btrfs: subpagesize-blocksize: Track blocks of ordered extent submitted
for write I/O.
Btrfs: subpagesize-blocksize: Prevent writes to an extent buffer when
PG_writeback flag is set.
Btrfs: subpagesize-blocksize: Use (eb->start, seq) as search key for
tree modification log.
Btrfs: subpagesize-blocksize: btrfs_submit_direct_hook: Handle
map_length < bio vector length
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/btrfs_inode.h | 2 - fs/btrfs/ctree.c | 56 +- fs/btrfs/ctree.h | 8 +- fs/btrfs/disk-io.c | 117 ++-- fs/btrfs/disk-io.h | 3 + fs/btrfs/extent-tree.c | 18 +- fs/btrfs/extent_io.c | 1274 +++++++++++++++++++++++++++++------------- fs/btrfs/extent_io.h | 60 +- fs/btrfs/file-item.c | 87 +-- fs/btrfs/file.c | 77 +-- fs/btrfs/inode.c | 603 ++++++++++++-------- fs/btrfs/ordered-data.c | 19 + fs/btrfs/ordered-data.h | 8 + fs/btrfs/volumes.c | 2 +- include/trace/events/btrfs.h | 2 +- 16 files changed, 1573 insertions(+), 765 deletions(-)
Signature · 1 line
2.1.0
RFC PATCH v10 1/19 Btrfs: subpagesize-blocksize: Get rid of whole page reads.
Based on original patch from Aneesh Kumar K.V <[email protected]>
For the subpagesize-blocksize scenario, a page can contain multiple blocks. This patch handles this case.
This patch adds the new EXTENT_READ_IO extent state bit to reliably unlock pages in readpage's end bio function.
--- fs/btrfs/extent_io.c | 182 ++++++++++++++++++++++++--------------------------- fs/btrfs/extent_io.h | 5 +- 2 files changed, 89 insertions(+), 98 deletions(-)
fs/btrfs/extent_io.c +86 -96
@@ -1951,14 +1951,23 @@ 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); } +static int page_read_complete (struct extent_io_tree *tree,struct page *page) +{ +u64 start =page_offset (page); +u64 end = start +PAGE_CACHE_SIZE -1 ; + +return !test_range_bit (tree, start, end,EXTENT_READ_IO ,0 ,NULL ); +} +/* * When IO fails, either with EIO or csum verification fails, we * try other mirrors that might have a good copy of the data. This
@@ -2275,7 +2284,9 @@ 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 ) { +if ((failed_bio->bi_vcnt >1 ) + || (failed_bio->bi_io_vec->bv_len + >BTRFS_I (inode)->root->sectorsize)) {/* * 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,
@@ -2422,18 +2433,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
@@ -2450,14 +2449,15 @@ static void end_bio_extent_readpage(struct bio *bio, int err)struct bio_vec *bvec;int uptodate =test_bit (BIO_UPTODATE , &bio->bi_flags);struct btrfs_io_bio *io_bio =btrfs_io_bio (bio); +struct extent_state *cached =NULL ;struct extent_io_tree *tree; +unsigned long flags;u64 offset =0 ;u64 start;u64 end; -u64 len; -u64 extent_start =0 ; -u64 extent_len =0 ; +int nr_sectors;int mirror; +int unlock;int ret;int i;
@@ -2467,54 +2467,31 @@ static void end_bio_extent_readpage(struct bio *bio, int err)bio_for_each_segment_all (bvec, bio, i) {struct page *page = bvec->bv_page;struct inode *inode = page->mapping->host; +struct btrfs_root *root =BTRFS_I (inode)->root;pr_debug ("end_bio_extent_readpage: bi_sector=%llu, err=%d, " "mirror=%lu\n" , (u64 )bio->bi_iter.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 =page_offset (page); - end = start + bvec->bv_offset + bvec->bv_len -1 ; - len = bvec->bv_len; - + start =page_offset (page) + bvec->bv_offset; + end = start + bvec->bv_len -1 ; + nr_sectors = bvec->bv_len >> inode->i_sb->s_blocksize_bits; mirror = io_bio->mirror_num; -if (likely (uptodate && tree->ops && - tree->ops->readpage_end_io_hook)) { + +next_block: +if (likely (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
@@ -2525,60 +2502,64 @@ 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 ; + offset += root->sectorsize; +if (--nr_sectors) { + start += root->sectorsize; + goto next_block; + }else { +continue ; + } } } -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; + + offset += root->sectorsize; + +if (--nr_sectors) { +clear_extent_bit (tree, start, start + root->sectorsize -1 , +EXTENT_READ_IO ,0 ,0 , &cached,GFP_ATOMIC ); +clear_extent_bit (tree, start, start + root->sectorsize -1 , +EXTENT_LOCKED ,1 ,0 , &cached,GFP_ATOMIC ); + start += root->sectorsize; + goto next_block; } + +WARN_ON (!PagePrivate (page)); + +local_irq_save (flags); +bit_spin_lock (EXTENT_PAGE_UPTODATE_LOCK , &page->private); + +clear_extent_bit (tree, start, start + root->sectorsize -1 , +EXTENT_READ_IO ,0 ,0 , &cached,GFP_ATOMIC ); + + unlock =page_read_complete (tree, page); + +bit_spin_unlock (EXTENT_PAGE_UPTODATE_LOCK , &page->private); +local_irq_restore (flags); + +clear_extent_bit (tree, start, start + root->sectorsize -1 , +EXTENT_LOCKED ,1 ,0 , &cached,GFP_ATOMIC ); + +if (unlock) +unlock_page (page); } -if (extent_len) -endio_readpage_release_extent (tree, extent_start, extent_len, - uptodate);if (io_bio->end_io) io_bio->end_io (io_bio, err);bio_put (bio);
@@ -2799,6 +2780,7 @@ static int __do_readpage(struct extent_io_tree *tree, unsigned long *bio_flags, int rw) {struct inode *inode = page->mapping->host; +struct extent_state *cached =NULL ;u64 start =page_offset (page);u64 page_end = start +PAGE_CACHE_SIZE -1 ;u64 end;
@@ -2918,7 +2900,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;
@@ -2938,6 +2920,10 @@ static int __do_readpage(struct extent_io_tree *tree, } pnr -= page->index; + +set_extent_bit (tree, cur, cur + iosize -1 ,EXTENT_READ_IO , +NULL , &cached,GFP_NOFS ); + ret = submit_extent_page(rw, tree, page, sector, disk_io_size, pg_offset, bdev, bio, pnr,
@@ -2949,8 +2935,12 @@ static int __do_readpage(struct extent_io_tree *tree, *bio_flags = this_bio_flag; }else {SetPageError (page); +clear_extent_bit (tree, cur, cur + iosize -1 , +EXTENT_READ_IO ,0 ,0 , &cached, +GFP_NOFS );if (!parent_locked) -unlock_extent (tree, cur, cur + iosize -1 ); +unlock_extent_cached (tree, cur, cur + iosize -1 , + &cached,GFP_NOFS ); } cur = cur + iosize; pg_offset += iosize;
fs/btrfs/extent_io.h +3 -2
@@ -20,6 +20,7 @@#define EXTENT_NEED_WAIT (1 << 13)#define EXTENT_DAMAGED (1 << 14)#define EXTENT_NORESERVE (1 << 15) +#define EXTENT_READ_IO (1 << 16)#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)#define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC)
@@ -56,8 +57,8 @@* page->private values. Every page that is controlled by the extent * map has page->private set to one. */ -#define EXTENT_PAGE_PRIVATE 1 -#define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3 +#define EXTENT_PAGE_PRIVATE (1 << 0) +#define EXTENT_PAGE_UPTODATE_LOCK (1 << 1)struct extent_state ;struct btrfs_root ;
Signature · 1 line
2.1.0
RFC PATCH v10 2/19 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 | 47 +++++++++++++++++++++++++++-------------------- fs/btrfs/inode.c | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 58 insertions(+), 29 deletions(-)
fs/btrfs/extent_io.c +27 -20
@@ -1300,6 +1300,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.
@@ -1406,6 +1420,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 ; }
@@ -2403,31 +2418,23 @@ static void end_bio_extent_writepage(struct bio *bio, int err)bio_for_each_segment_all (bvec, bio, i) {struct page *page = bvec->bv_page; +struct inode *inode = page->mapping->host; +struct extent_io_tree *tree = &BTRFS_I (inode)->io_tree; +u64 page_start, page_end; -/* 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 ; + start =page_offset (page) + bvec->bv_offset; + end = start + bvec->bv_len -1 ;if (end_extent_writepage (page, err, start, end))continue ; -end_page_writeback (page); +clear_extent_writeback (tree, start, end,NULL ,GFP_ATOMIC ); + + page_start =page_offset (page); + page_end =page_offset (page) +PAGE_CACHE_SIZE -1 ; +if (!test_range_bit (tree, page_start, page_end, +EXTENT_WRITEBACK ,0 ,NULL )) +end_page_writeback (page); }bio_put (bio);
fs/btrfs/inode.c +31 -9
@@ -2823,22 +2823,44 @@ static int btrfs_writepage_end_io_hook(struct page *page, u64 start, u64 end,struct btrfs_root *root =BTRFS_I (inode)->root;struct btrfs_ordered_extent *ordered_extent =NULL ;struct btrfs_workqueue *workers; +u64 ordered_start, ordered_end; +int done;trace_btrfs_writepage_end_io_hook (page, start, end, uptodate);ClearPagePrivate2 (page); -if (!btrfs_dec_test_ordered_pending (inode, &ordered_extent, start, - end - start +1 , uptodate)) -return 0 ; +loop: + ordered_extent =btrfs_lookup_ordered_range (inode, start, + end - start +1 ); +if (!ordered_extent) + goto out; -btrfs_init_work (&ordered_extent->work, finish_ordered_fn,NULL ,NULL ); + ordered_start =max_t (u64, start, ordered_extent->file_offset); + ordered_end =min_t (u64, end, + ordered_extent->file_offset + ordered_extent->len -1 ); -if (btrfs_is_free_space_inode (inode)) - workers = root->fs_info->endio_freespace_worker; -else - workers = root->fs_info->endio_write_workers; -btrfs_queue_work (workers, &ordered_extent->work); + done =btrfs_dec_test_ordered_pending (inode, &ordered_extent, + ordered_start, + ordered_end - ordered_start +1 , + uptodate); +if (done) { +btrfs_init_work (&ordered_extent->work, finish_ordered_fn,NULL ,NULL ); + +if (btrfs_is_free_space_inode (inode)) + workers = root->fs_info->endio_freespace_worker; +else + workers = root->fs_info->endio_write_workers; +btrfs_queue_work (workers, &ordered_extent->work); + } + +btrfs_put_ordered_extent (ordered_extent); + + start = ordered_end +1 ; + +if (start < end) + goto loop; +out:return 0 ; }
Signature · 1 line
2.1.0
RFC PATCH v10 3/19 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
@@ -1366,18 +1366,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);
@@ -1494,6 +1497,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);
@@ -1514,7 +1518,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 |
@@ -1529,7 +1535,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 ;
@@ -1564,8 +1572,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;
@@ -1602,9 +1610,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++;
@@ -1618,7 +1626,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,
@@ -1640,7 +1648,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
2.1.0
RFC PATCH v10 4/19 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 | 373 +++++++++++++++++++++++++++++-------------- fs/btrfs/extent_io.h | 47 ++++-- fs/btrfs/volumes.c | 2 +- include/trace/events/btrfs.h | 2 +- 9 files changed, 328 insertions(+), 158 deletions(-)
fs/btrfs/backref.c +1 -1
@@ -1305,7 +1305,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
@@ -2215,14 +2215,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
@@ -6209,7 +6209,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 ,0 );
@@ -6226,7 +6226,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); }
@@ -7212,7 +7212,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 +253 -120
704 lines not on this page · raw message
fs/btrfs/extent_io.h +34 -13
87 lines not on this page · raw message
fs/btrfs/volumes.c +1 -1
@@ -6060,7 +6060,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
@@ -697,7 +697,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
2.1.0
RFC PATCH v10 5/19 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 | 129 ++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 140 insertions(+), 37 deletions(-)
fs/btrfs/disk-io.c +19 -26
@@ -431,7 +431,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,
@@ -450,7 +450,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,
@@ -582,12 +582,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 ;
@@ -597,18 +598,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; }
@@ -650,7 +659,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 ; }
@@ -658,7 +667,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) {
@@ -667,7 +676,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);
@@ -675,20 +684,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;
@@ -4156,8 +4151,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
@@ -111,6 +111,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 +118 -11
181 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC PATCH v10 6/19 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 | 300 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 250 insertions(+), 70 deletions(-)
fs/btrfs/disk-io.c +13 -7
@@ -484,17 +484,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 +237 -63
422 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC PATCH v10 7/19 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
@@ -2634,12 +2634,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
2.1.0
RFC PATCH v10 8/19 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 | 87 ++++++++++++++++++++++++++++++++-------------------- fs/btrfs/inode.c | 53 +++++++++++++++++++++----------- 2 files changed, 89 insertions(+), 51 deletions(-)
fs/btrfs/file-item.c +54 -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_iter.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; - bio_index += count; +while (count--) { - disk_bytenr += bvec->bv_len; - offset += bvec->bv_len; - 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;
@@ -469,41 +480,51 @@ 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_iter.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_iter.bi_sector <<9 ) + - total_bytes; - index =0 ; + 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_iter.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_iter.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 +35 -18
72 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC PATCH v10 9/19 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 | 74 ++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 45 deletions(-)
fs/btrfs/extent_io.c +29 -45
@@ -3212,18 +3212,18 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode, int write_flags, int *nr_ret) { struct extent_io_tree *tree = epd->tree; +struct btrfs_ordered_extent *ordered;u64 start =page_offset (page);u64 page_end = start +PAGE_CACHE_SIZE -1 ;u64 end;u64 cur = start;u64 extent_offset; -u64 block_start; +u64 extent_end;u64 iosize;sector_t sector;struct extent_state *cached_state =NULL ; -struct extent_map *em;struct block_device *bdev; -size_t pg_offset =0 ; +size_t pg_offset;size_t blocksize;int ret =0 ;int nr =0 ;
@@ -3263,59 +3263,46 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode, blocksize = inode->i_sb->s_blocksize;while (cur <= end) { -u64 em_end;if (cur >= i_size) {if (tree->ops && tree->ops->writepage_end_io_hook) tree->ops->writepage_end_io_hook (page, cur, 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); - ret =PTR_ERR_OR_ZERO (em); -break ; - } - extent_offset = cur - em->start; - em_end =extent_map_end (em); -BUG_ON (em_end <= cur); + ordered =btrfs_lookup_ordered_extent (inode, cur); +if (!ordered) { + cur += blocksize; +continue ; + } + + 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 (em_end - 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 ; }
@@ -3346,7 +3333,6 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,SetPageError (page); } cur = cur + iosize; - pg_offset += iosize; nr++; } done:
@@ -3374,7 +3360,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,u64 page_end = start +PAGE_CACHE_SIZE -1 ;int ret;int nr =0 ; -size_t pg_offset =0 ; +size_t pg_offset;loff_t i_size =i_size_read (inode);unsigned long end_index = i_size >>PAGE_CACHE_SHIFT ;int write_flags;
@@ -3409,8 +3395,6 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,flush_dcache_page (page); } - pg_offset =0 ; -set_page_extent_mapped (page); ret =writepage_delalloc (inode, page, wbc, epd, start, &nr_written);
Signature · 1 line
2.1.0
RFC PATCH v10 10/19 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 | 41 ++++++++++++++++++++++------------------- fs/btrfs/inode.c | 48 +++++++++++++++++++++++++----------------------- 3 files changed, 48 insertions(+), 43 deletions(-)
fs/btrfs/ctree.h +1 -1
@@ -3815,7 +3815,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 +22 -19
93 lines not on this page · raw message
fs/btrfs/inode.c +25 -23
123 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC PATCH v10 11/19 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
@@ -7812,26 +7812,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);
@@ -7862,6 +7859,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
@@ -7874,7 +7884,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,
@@ -7913,8 +7924,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
2.1.0
RFC PATCH v10 12/19 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
@@ -3053,7 +3053,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
@@ -1821,7 +1821,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 );
@@ -7724,7 +7724,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
@@ -7849,7 +7849,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
2.1.0
RFC PATCH v10 13/19 Btrfs: subpagesize-blocksize: Deal with partial ordered extent allocations.
In reply to Chandan RajendraIn subpagesize-blocksize scenario, extent allocations for only some of the dirty blocks of a page can succeed, while allocation for rest of the blocks can fail. This patch allows I/O against such partially allocated ordered extents to be submitted.
--- fs/btrfs/extent_io.c | 24 +++++++++++++----------- fs/btrfs/extent_io.h | 1 + fs/btrfs/inode.c | 39 +++++++++++++++++++++++++-------------- 3 files changed, 39 insertions(+), 25 deletions(-)
fs/btrfs/extent_io.c +13 -11
@@ -1774,15 +1774,22 @@ int extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,if (page_ops &PAGE_SET_PRIVATE2 )SetPagePrivate2 (pages[i]); +if (page_ops &PAGE_SET_ERROR ) +SetPageError (pages[i]); +if (pages[i] == locked_page) {page_cache_release (pages[i]);continue ; } -if (page_ops &PAGE_CLEAR_DIRTY ) + +if ((page_ops &PAGE_CLEAR_DIRTY ) + && !PagePrivate2 (pages[i]))clear_page_dirty_for_io (pages[i]); -if (page_ops &PAGE_SET_WRITEBACK ) +if ((page_ops &PAGE_SET_WRITEBACK ) + && !PagePrivate2 (pages[i]))set_page_writeback (pages[i]); -if (page_ops &PAGE_END_WRITEBACK ) +if ((page_ops &PAGE_END_WRITEBACK ) + && !PagePrivate2 (pages[i]))end_page_writeback (pages[i]);if (page_ops &PAGE_UNLOCK )unlock_page (pages[i]);
@@ -2398,7 +2405,7 @@ int end_extent_writepage(struct page *page, int err, u64 start, u64 end) uptodate =0 ; } -if (!uptodate) { +if (!uptodate ||PageError (page)) {ClearPageUptodate (page);SetPageError (page); ret = ret <0 ? ret : -EIO ;
@@ -3149,7 +3156,6 @@ static noinline_for_stack int writepage_delalloc(struct inode *inode, nr_written);/* File system has been set read-only */ if (ret) { -SetPageError (page);/* fill_delalloc should be return < 0 for error * but just in case, we use > 0 here meaning the * IO is started, so we don't want to return > 0
@@ -3358,7 +3364,6 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,struct inode *inode = page->mapping->host;struct extent_page_data *epd = data;u64 start =page_offset (page); -u64 page_end = start +PAGE_CACHE_SIZE -1 ;int ret;int nr =0 ;size_t pg_offset;
@@ -3401,7 +3406,7 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc, ret =writepage_delalloc (inode, page, wbc, epd, start, &nr_written);if (ret ==1 ) goto done_unlocked; -if (ret) +if (ret && !PagePrivate2 (page)) goto done; ret = __extent_writepage_io(inode, page, wbc, epd,
@@ -3415,10 +3420,7 @@ done:set_page_writeback (page);end_page_writeback (page); } -if (PageError (page)) { - ret = ret <0 ? ret : -EIO ; -end_extent_writepage (page, ret, start, page_end); - } +unlock_page (page);return ret;
fs/btrfs/extent_io.h +1 -0
@@ -52,6 +52,7 @@#define PAGE_SET_WRITEBACK (1 << 2)#define PAGE_END_WRITEBACK (1 << 3)#define PAGE_SET_PRIVATE2 (1 << 4) +#define PAGE_SET_ERROR (1 << 5)/* * page->private values. Every page that is controlled by the extent
fs/btrfs/inode.c +25 -14
@@ -880,6 +880,8 @@ static noinline int cow_file_range(struct inode *inode,struct btrfs_key ins;struct extent_map *em;struct extent_map_tree *em_tree = &BTRFS_I (inode)->extent_tree; +struct btrfs_ordered_extent *ordered; +unsigned long page_ops, extent_ops;int ret =0 ;if (btrfs_is_free_space_inode (inode)) {
@@ -924,8 +926,6 @@ static noinline int cow_file_range(struct inode *inode,btrfs_drop_extent_cache (inode, start, start + num_bytes -1 ,0 );while (disk_num_bytes >0 ) { -unsigned long op; - cur_alloc_size = disk_num_bytes; ret = btrfs_reserve_extent(root, cur_alloc_size, root->sectorsize, 0, alloc_hint,
@@ -971,14 +971,14 @@ static noinline int cow_file_range(struct inode *inode, ret =btrfs_add_ordered_extent (inode, start, ins.objectid, ram_size, cur_alloc_size,0 );if (ret) - goto out_reserve; + goto out_remove_extent_map;if (root->root_key.objectid ==BTRFS_DATA_RELOC_TREE_OBJECTID ) { ret =btrfs_reloc_clone_csums (inode, start, cur_alloc_size);if (ret) - goto out_reserve; + goto out_remove_ordered_extent; }if (disk_num_bytes < cur_alloc_size)
@@ -991,13 +991,12 @@ static noinline int cow_file_range(struct inode *inode,* Do set the Private2 bit so we know this page was properly * setup for writepage */ - op = unlock ?PAGE_UNLOCK :0 ; - op |=PAGE_SET_PRIVATE2 ; - + page_ops = unlock ?PAGE_UNLOCK :0 ; + page_ops |=PAGE_SET_PRIVATE2 ; + extent_ops =EXTENT_LOCKED |EXTENT_DELALLOC ;extent_clear_unlock_delalloc (inode, start, - start + ram_size -1 , locked_page, -EXTENT_LOCKED |EXTENT_DELALLOC , - op); + start + ram_size -1 , locked_page, + extent_ops, page_ops); disk_num_bytes -= cur_alloc_size; num_bytes -= cur_alloc_size; alloc_hint = ins.objectid + ins.offset;
@@ -1006,14 +1005,26 @@ static noinline int cow_file_range(struct inode *inode, out:return ret; +out_remove_ordered_extent: + ordered =btrfs_lookup_ordered_extent (inode, ins.objectid); +BUG_ON (!ordered); +btrfs_remove_ordered_extent (inode, ordered); + +out_remove_extent_map: +btrfs_drop_extent_cache (inode, start, start + ram_size -1 ,0 ); + out_reserve:btrfs_free_reserved_extent (root, ins.objectid, ins.offset,1 ); + out_unlock: + page_ops = unlock ?PAGE_UNLOCK :0 ; + page_ops |=PAGE_CLEAR_DIRTY |PAGE_SET_WRITEBACK |PAGE_END_WRITEBACK + |PAGE_SET_ERROR ; + extent_ops =EXTENT_LOCKED |EXTENT_DELALLOC |EXTENT_DO_ACCOUNTING + |EXTENT_DEFRAG ; +extent_clear_unlock_delalloc (inode, start, end, locked_page, -EXTENT_LOCKED |EXTENT_DO_ACCOUNTING | -EXTENT_DELALLOC |EXTENT_DEFRAG , -PAGE_UNLOCK |PAGE_CLEAR_DIRTY | -PAGE_SET_WRITEBACK |PAGE_END_WRITEBACK ); + extent_ops, page_ops); goto out; }
Signature · 1 line
2.1.0
RFC PATCH v10 14/19 Btrfs: subpagesize-blocksize: Explicitly Track I/O status of blocks of an ordered extent.
In reply to Chandan RajendraIn subpagesize-blocksize scenario a page can have more than one block. So in addition to PagePrivate2 flag, we would have to track the I/O status of each block of a page to reliably mark the ordered extent as complete.
--- fs/btrfs/extent_io.c | 19 +-- fs/btrfs/extent_io.h | 5 +- fs/btrfs/inode.c | 338 +++++++++++++++++++++++++++++++++++------------- fs/btrfs/ordered-data.c | 17 +++ fs/btrfs/ordered-data.h | 4 + 5 files changed, 285 insertions(+), 98 deletions(-)
fs/btrfs/extent_io.c +10 -9
@@ -4302,11 +4302,10 @@ int extent_invalidatepage(struct extent_io_tree *tree,* to drop the page. */ static int try_release_extent_state (struct extent_map_tree *map, -struct extent_io_tree *tree, -struct page *page,gfp_t mask) +struct extent_io_tree *tree, +struct page *page,u64 start,u64 end, +gfp_t mask) { -u64 start =page_offset (page); -u64 end = start +PAGE_CACHE_SIZE -1 ;int ret =1 ; if (test_range_bit(tree, start, end,
@@ -4340,12 +4339,12 @@ static int try_release_extent_state(struct extent_map_tree *map,* map records are removed */ int try_release_extent_mapping (struct extent_map_tree *map, -struct extent_io_tree *tree,struct page *page, -gfp_t mask) +struct extent_io_tree *tree,struct page *page, +u64 start,u64 end,gfp_t mask) {struct extent_map *em; -u64 start =page_offset (page); -u64 end = start +PAGE_CACHE_SIZE -1 ; +u64 orig_start = start; +u64 orig_end = end;if ((mask & __GFP_WAIT) && page->mapping->host->i_size >16 *1024 *1024 ) {
@@ -4379,7 +4378,9 @@ int try_release_extent_mapping(struct extent_map_tree *map,free_extent_map (em); } } -return try_release_extent_state (map, tree, page, mask); +return try_release_extent_state (map, tree, page, + orig_start, orig_end, + mask); }/*
fs/btrfs/extent_io.h +3 -2
@@ -209,8 +209,9 @@ typedef struct extent_map *(get_extent_t)(struct inode *inode,void extent_io_tree_init (struct extent_io_tree *tree,struct address_space *mapping);int try_release_extent_mapping (struct extent_map_tree *map, -struct extent_io_tree *tree,struct page *page, -gfp_t mask); +struct extent_io_tree *tree,struct page *page, +u64 start,u64 end, +gfp_t mask);int try_release_extent_buffer (struct page *page);int lock_extent (struct extent_io_tree *tree,u64 start,u64 end); int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
fs/btrfs/inode.c +251 -87
415 lines not on this page · raw message
fs/btrfs/ordered-data.c +17 -0
@@ -189,12 +189,25 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,struct btrfs_ordered_inode_tree *tree;struct rb_node *node;struct btrfs_ordered_extent *entry; +u64 nr_longs; tree = &BTRFS_I (inode)->ordered_tree; entry =kmem_cache_zalloc (btrfs_ordered_extent_cache,GFP_NOFS );if (!entry)return -ENOMEM ; + nr_longs =BITS_TO_LONGS (len >> inode->i_sb->s_blocksize_bits); +if (nr_longs ==1 ) { + entry->blocks_done = &entry->blocks_bitmap; + }else { + entry->blocks_done =kzalloc (nr_longs *sizeof (unsigned long ), +GFP_NOFS ); +if (!entry->blocks_done) { +kmem_cache_free (btrfs_ordered_extent_cache, entry); +return -ENOMEM ; + } + } + entry->file_offset = file_offset; entry->start = start; entry->len = len;
@@ -541,6 +554,10 @@ void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry)list_del (&sum->list);kfree (sum); } + +if (entry->blocks_done != &entry->blocks_bitmap) +kfree (entry->blocks_done); +kmem_cache_free (btrfs_ordered_extent_cache, entry); } }
fs/btrfs/ordered-data.h +4 -0
@@ -135,6 +135,10 @@ struct btrfs_ordered_extent {struct completion completion;struct btrfs_work flush_work;struct list_head work_list; + +/* bitmap to track the blocks that have been written to disk */ +unsigned long *blocks_done; +unsigned long blocks_bitmap; };/*
Signature · 1 line
2.1.0
RFC PATCH v10 15/19 Btrfs: subpagesize-blocksize: Revert commit fc4adbff823f76577ece26dcb88bf6f8392dbd43.
In reply to Chandan RajendraIn subpagesize-blocksize, we have multiple blocks in a page. Checking for existence of a page in the page cache isn't a sufficient check, since we could be truncating a subset of the blocks mapped by the page.
--- fs/btrfs/btrfs_inode.h | 2 -- fs/btrfs/file.c | 4 ++- fs/btrfs/inode.c | 77 +++----------------------------------------------- 3 files changed, 7 insertions(+), 76 deletions(-)
fs/btrfs/btrfs_inode.h +0 -2
@@ -278,6 +278,4 @@ static inline void btrfs_inode_resume_unlocked_dio(struct inode *inode) &BTRFS_I(inode)->runtime_flags); } -bool btrfs_page_exists_in_range (struct inode *inode,loff_t start,loff_t end); -#endif
fs/btrfs/file.c +3 -1
@@ -2314,7 +2314,9 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)if ((!ordered || (ordered->file_offset + ordered->len <= lockstart || ordered->file_offset > lockend)) && - !btrfs_page_exists_in_range (inode, lockstart, lockend)) { + !test_range_bit (&BTRFS_I (inode)->io_tree, lockstart, + lockend,EXTENT_UPTODATE ,0 , + cached_state)) {if (ordered)btrfs_put_ordered_extent (ordered);break ;
fs/btrfs/inode.c +4 -73
89 lines not on this page · raw message
Signature · 1 line
2.1.0
RFC PATCH v10 16/19 Btrfs: subpagesize-blocksize: Track blocks of ordered extent submitted for write I/O.
In reply to Chandan RajendraIn the subpagesize-blocksize scenario, the following command (with 4k as the PAGE_SIZE and 2k as the block size) can cause false accounting of blocks of an ordered extent that is written to disk:
$ xfs_io -f -c "pwrite 0 10240" \ -c "sync_range 0 4096" \ -c "sync_range 8192 2048" \ -c "pwrite 10240 2048" \ -c "sync_range 10240 2048" \ /mnt/btrfs/file.bin
To fix this, we would have to explicitly track the blocks of an ordered extent that have already been submitted for write I/O.
--- fs/btrfs/extent_io.c | 24 ++++++++++++++++++++++-- fs/btrfs/ordered-data.c | 4 +++- fs/btrfs/ordered-data.h | 4 ++++ 3 files changed, 29 insertions(+), 3 deletions(-)
fs/btrfs/extent_io.c +22 -2
@@ -3227,6 +3227,8 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,u64 extent_offset;u64 extent_end;u64 iosize; +u64 blk, nr_blks; +u64 blk_submitted;sector_t sector;struct extent_state *cached_state =NULL ;struct block_device *bdev;
@@ -3293,11 +3295,26 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode, iosize =min (extent_end - cur, end - cur +1 ); iosize =ALIGN (iosize, blocksize); + blk = extent_offset >> inode->i_sb->s_blocksize_bits; + nr_blks = iosize >> inode->i_sb->s_blocksize_bits; + + blk_submitted =find_next_bit (ordered->blocks_submitted, + ordered->len >> inode->i_sb->s_blocksize_bits, + blk); +if (blk_submitted < blk + nr_blks) { +if (blk_submitted == blk) { + cur += blocksize; +btrfs_put_ordered_extent (ordered); +continue ; + } + iosize = (blk_submitted - blk) + << inode->i_sb->s_blocksize_bits; + nr_blks = iosize >> inode->i_sb->s_blocksize_bits; + } + 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
@@ -3310,6 +3327,7 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,*/ nr++; cur += iosize; +btrfs_put_ordered_extent (ordered);continue ; }
@@ -3324,6 +3342,8 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode, }else {unsigned long max_nr = (i_size >>PAGE_CACHE_SHIFT ) +1 ; +bitmap_set (ordered->blocks_submitted, blk, nr_blks); +btrfs_put_ordered_extent (ordered);set_range_writeback (tree, cur, cur + iosize -1 );if (!PageWriteback (page)) { btrfs_err(BTRFS_I(inode)->root->fs_info,
fs/btrfs/ordered-data.c +3 -1
@@ -199,13 +199,15 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, nr_longs =BITS_TO_LONGS (len >> inode->i_sb->s_blocksize_bits);if (nr_longs ==1 ) { entry->blocks_done = &entry->blocks_bitmap; + entry->blocks_submitted = &entry->blocks_submitted_bitmap; }else { - entry->blocks_done =kzalloc (nr_longs *sizeof (unsigned long ), + entry->blocks_done =kzalloc (2 * nr_longs *sizeof (unsigned long ),GFP_NOFS );if (!entry->blocks_done) {kmem_cache_free (btrfs_ordered_extent_cache, entry);return -ENOMEM ; } + entry->blocks_submitted = entry->blocks_done + nr_longs; } entry->file_offset = file_offset;
fs/btrfs/ordered-data.h +4 -0
@@ -139,6 +139,10 @@ struct btrfs_ordered_extent {/* bitmap to track the blocks that have been written to disk */ unsigned long *blocks_done;unsigned long blocks_bitmap; + +/* bitmap to track the blocks that have been submitted for write i/o */ +unsigned long *blocks_submitted; +unsigned long blocks_submitted_bitmap; };/*
Signature · 1 line
2.1.0
RFC PATCH v10 17/19 Btrfs: subpagesize-blocksize: Prevent writes to an extent buffer when PG_writeback flag is set.
In reply to Chandan RajendraIn non-subpagesize-blocksize scenario, BTRFS_HEADER_FLAG_WRITTEN flag prevents Btrfs code from writing into an extent buffer whose pages are under writeback. This facility isn't sufficient for achieving the same in subpagesize-blocksize scenario, since we have more than one extent buffer mapped to a page.
Hence this patch adds a new flag (i.e. EXTENT_BUFFER_HEAD_WRITEBACK) and corresponding code to track the writeback status of the page and to prevent writes to any of the extent buffers mapped to the page while writeback is going on.
--- fs/btrfs/ctree.c | 20 ++++++- fs/btrfs/extent-tree.c | 12 ++++ fs/btrfs/extent_io.c | 153 +++++++++++++++++++++++++++++++++++++++---------- fs/btrfs/extent_io.h | 2 + 4 files changed, 157 insertions(+), 30 deletions(-)
fs/btrfs/ctree.c +19 -1
@@ -1543,6 +1543,7 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans, struct extent_buffer *parent, int parent_slot, struct extent_buffer **cow_ret) { + struct extent_buffer_head *ebh = eb_head(buf);u64 search_start;int ret;
@@ -1556,6 +1557,13 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans, trans->transid, root->fs_info->generation);if (!should_cow_block (trans, root, buf)) { +if (test_bit (EXTENT_BUFFER_HEAD_WRITEBACK , &ebh->bflags)) { +if (parent) +btrfs_set_lock_blocking (parent); +btrfs_set_lock_blocking (buf); +wait_on_bit (&ebh->bflags,EXTENT_BUFFER_HEAD_WRITEBACK , + eb_wait,TASK_UNINTERRUPTIBLE ); + } *cow_ret = buf;return 0 ; }
@@ -2687,6 +2695,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_key *key, struct btrfs_path *p, int ins_len, int cow) { +struct extent_buffer_head *ebh;struct extent_buffer *b;int slot;int ret;
@@ -2789,8 +2798,17 @@ again:* then we don't want to set the path blocking, * so we test it here */ -if (!should_cow_block (trans, root, b)) +if (!should_cow_block (trans, root, b)) { + ebh =eb_head (b); +if (test_bit (EXTENT_BUFFER_HEAD_WRITEBACK , + &ebh->bflags)) { +btrfs_set_path_blocking (p); +wait_on_bit (&ebh->bflags, +EXTENT_BUFFER_HEAD_WRITEBACK , + eb_wait,TASK_UNINTERRUPTIBLE ); + } goto cow_done; + }btrfs_set_path_blocking (p);
fs/btrfs/extent-tree.c +12 -0
@@ -7203,14 +7203,26 @@ static struct extent_buffer * btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 bytenr, u32 blocksize, int level) { + struct extent_buffer_head *ebh;struct extent_buffer *buf; buf =btrfs_find_create_tree_block (root, bytenr, blocksize);if (!buf)return ERR_PTR (-ENOMEM ); + + ebh =eb_head (buf);btrfs_set_header_generation (buf, trans->transid);btrfs_set_buffer_lockdep_class (root->root_key.objectid, buf, level);btrfs_tree_lock (buf); + +if (test_bit (EXTENT_BUFFER_HEAD_WRITEBACK , + &ebh->bflags)) { +btrfs_set_lock_blocking (buf); +wait_on_bit (&ebh->bflags, +EXTENT_BUFFER_HEAD_WRITEBACK , + eb_wait,TASK_UNINTERRUPTIBLE ); + } +clean_tree_block (trans, root, buf);clear_bit (EXTENT_BUFFER_STALE , &buf->ebflags);
fs/btrfs/extent_io.c +124 -29
316 lines not on this page · raw message
fs/btrfs/extent_io.h +2 -0
@@ -45,6 +45,7 @@#define EXTENT_BUFFER_IOERR 8#define EXTENT_BUFFER_DUMMY 9#define EXTENT_BUFFER_IN_TREE 10 +#define EXTENT_BUFFER_HEAD_WRITEBACK 11/* these are flags for extent_clear_unlock_delalloc */ #define PAGE_UNLOCK (1 << 0)
@@ -302,6 +303,7 @@ void free_extent_buffer_stale(struct extent_buffer *eb);int read_extent_buffer_pages (struct extent_io_tree *tree,struct extent_buffer *eb,u64 start,int wait,get_extent_t *get_extent,int mirror_num); +int eb_wait (void *word);void wait_on_extent_buffer_writeback (struct extent_buffer *eb);static inline unsigned long num_extent_pages (u64 start,u64 len)
Signature · 1 line
2.1.0
RFC PATCH v10 18/19 Btrfs: subpagesize-blocksize: Use (eb->start, seq) as search key for tree modification log.
In reply to Chandan RajendraIn subpagesize-blocksize a page can map multiple extent buffers and hence using (page index, seq) as the search key is incorrect. For example, searching through tree modification log tree can return an entry associated with the first extent buffer mapped by the page (if such an entry exists), when we are actually searching for entries associated with extent buffers that are mapped at position 2 or more in the page.
--- fs/btrfs/ctree.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
fs/btrfs/ctree.c +17 -17
@@ -314,7 +314,7 @@ struct tree_mod_root {struct tree_mod_elem {struct rb_node node; -u64 index;/* shifted logical */ +u64 logical;u64 seq;enum mod_log_op op;
@@ -438,11 +438,11 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,/* * key order of the log: -* index -> sequence +* node/leaf start address -> sequence * -* the index is the shifted logical of the *new* root node for root replace -* operations, or the shifted logical of the affected block for all other -* operations. +* The 'start address' is the logical address of the *new* root node +* for root replace operations, or the logical address of the affected +* block for all other operations. * * Note: must be called with write lock (tree_mod_log_write_lock). */
@@ -463,9 +463,9 @@ __tree_mod_log_insert(struct btrfs_fs_info *fs_info, struct tree_mod_elem *tm)while (*new) { cur = container_of(*new, struct tree_mod_elem, node); parent = *new; -if (cur->index < tm->index) +if (cur->logical < tm->logical) new = &((*new)->rb_left); -else if (cur->index > tm->index) +else if (cur->logical > tm->logical) new = &((*new)->rb_right);else if (cur->seq < tm->seq) new = &((*new)->rb_left);
@@ -526,7 +526,7 @@ alloc_tree_mod_elem(struct extent_buffer *eb, int slot,if (!tm)return NULL ; - tm->index = eb->start >>PAGE_CACHE_SHIFT ; + tm->logical = eb->start;if (op !=MOD_LOG_KEY_ADD ) {btrfs_node_key (eb, &tm->key, slot); tm->blockptr =btrfs_node_blockptr (eb, slot);
@@ -591,7 +591,7 @@ tree_mod_log_insert_move(struct btrfs_fs_info *fs_info, goto free_tms; } - tm->index = eb->start >>PAGE_CACHE_SHIFT ; + tm->logical = eb->start; tm->slot = src_slot; tm->move.dst_slot = dst_slot; tm->move.nr_items = nr_items;
@@ -702,7 +702,7 @@ tree_mod_log_insert_root(struct btrfs_fs_info *fs_info, goto free_tms; } - tm->index = new_root->start >>PAGE_CACHE_SHIFT ; + tm->logical = new_root->start; tm->old_root.logical = old_root->start; tm->old_root.level =btrfs_header_level (old_root); tm->generation =btrfs_header_generation (old_root);
@@ -742,16 +742,15 @@ __tree_mod_log_search(struct btrfs_fs_info *fs_info, u64 start, u64 min_seq,struct rb_node *node;struct tree_mod_elem *cur =NULL ;struct tree_mod_elem *found =NULL ; -u64 index = start >>PAGE_CACHE_SHIFT ;tree_mod_log_read_lock (fs_info); tm_root = &fs_info->tree_mod_log; node = tm_root->rb_node;while (node) { cur = container_of(node, struct tree_mod_elem, node); -if (cur->index < index) { +if (cur->logical < start) { node = node->rb_left; - }else if (cur->index > index) { + }else if (cur->logical > start) { node = node->rb_right; }else if (cur->seq < min_seq) { node = node->rb_left;
@@ -1232,9 +1231,10 @@ __tree_mod_log_oldest_root(struct btrfs_fs_info *fs_info,return NULL ;/* -* the very last operation that's logged for a root is the replacement -* operation (if it is replaced at all). this has the index of the *new* -* root, making it the very first operation that's logged for this root. +* the very last operation that's logged for a root is the +* replacement operation (if it is replaced at all). this has +* the logical address of the *new* root, making it the very +* first operation that's logged for this root. */ while (1 ) { tm = tree_mod_log_search_oldest(fs_info, root_logical,
@@ -1338,7 +1338,7 @@ __tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct extent_buffer *eb,if (!next)break ; tm = container_of(next, struct tree_mod_elem, node); -if (tm->index != first_tm->index) +if (tm->logical != first_tm->logical)break ; }tree_mod_log_read_unlock (fs_info);
Signature · 1 line
2.1.0
RFC PATCH v10 19/19 Btrfs: subpagesize-blocksize: btrfs_submit_direct_hook: Handle map_length < bio vector length
In reply to Chandan RajendraIn subpagesize-blocksize scenario, map_length can be less than the length of a bio vector. Such a condition may cause btrfs_submit_direct_hook() to submit a zero length bio. Fix this.
--- fs/btrfs/inode.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
fs/btrfs/inode.c +16 -7
@@ -7346,9 +7346,11 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip,u64 file_offset = dip->logical_offset;u64 submit_len =0 ;u64 map_length; -int nr_pages =0 ; +u32 blocksize = root->sectorsize;int ret =0 ;int async_submit =0 ; +int nr_sectors; +int i; map_length = orig_bio->bi_iter.bi_size; ret = btrfs_map_block(root->fs_info, rw, start_sector << 9,
@@ -7378,9 +7380,12 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip,atomic_inc (&dip->pending_bios);while (bvec <= (orig_bio->bi_io_vec + orig_bio->bi_vcnt -1 )) { -if (unlikely (map_length < submit_len + bvec->bv_len || -bio_add_page (bio, bvec->bv_page, bvec->bv_len, - bvec->bv_offset) < bvec->bv_len)) { + nr_sectors = bvec->bv_len >> inode->i_sb->s_blocksize_bits; + i =0 ; +next_block: +if (unlikely (map_length < submit_len + blocksize || +bio_add_page (bio, bvec->bv_page, blocksize, + bvec->bv_offset + (i * blocksize)) < blocksize)) {/* * inc the count before we submit the bio so * we know the end IO handler won't happen before
@@ -7401,7 +7406,6 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip, file_offset += submit_len; submit_len =0 ; - nr_pages =0 ; bio =btrfs_dio_bio_alloc (orig_bio->bi_bdev, start_sector,GFP_NOFS );
@@ -7418,9 +7422,14 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip,bio_put (bio); goto out_err; } + + goto next_block; }else { - submit_len += bvec->bv_len; - nr_pages++; + submit_len += blocksize; +if (--nr_sectors) { + i++; + goto next_block; + } bvec++; } }
Signature · 1 line
2.1.0