Allow I/O on blocks whose size is less than page size
Subsystems (2)
v17 cover Allow I/O on blocks whose size is less than page size
Btrfs assumes block size to be the same as the machine's page size. This would mean that a Btrfs instance created on a 4k page size machine (e.g. x86) will not be mountable on machines with larger page sizes (e.g. PPC64/AARCH64). This patchset aims to resolve this incompatibility.
This patchset continues with the work posted previously at
http://thread.gmane.org/gmane.comp.file-systems.btrfs/53073.
I have reverted the upstream commit "btrfs: fix lockups from btrfs_clear_path_blocking" (f82c458a2c3ffb94b431fc6ad791a79df1b3713e) since this led to soft-lockups when the patch "Btrfs:
subpagesize-blocksize: Prevent writes to an extent buffer when PG_writeback flag is set" is applied. During 2015's Vault Conference Btrfs meetup, Chris Mason had suggested that he will write up a suitable locking function to be used when writing dirty pages that map metadata blocks. Until we have a suitable locking function available, this patchset temporarily disables the commit f82c458a2c3ffb94b431fc6ad791a79df1b3713e.
The commits for the Btrfs kernel module can be found at
https://github.com/chandanr/linux/tree/btrfs/subpagesize-blocksize.
To create a filesystem with block size < page size, a patched version of the Btrfs-progs package is required. The corresponding fixes for Btrfs-progs can be found at
https://github.com/chandanr/btrfs-progs/tree/btrfs/subpagesize-blocksize.
Fstests run status:
1. x86_64
- With 4k sectorsize, all the tests that succeed with the master branch at git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git
branch also do so with the patches applied.
2. ppc64
- With 4k sectorsize, 16k nodesize and with "nospace_cache" mount option, except for scrub and compression tests, all the tests that succeed with the master branch at
git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git
branch also do so with the patches applied.
- With 64k sectorsize & nodesize, all the tests that succeed with the master branch at
git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git
branch also do so with the patches applied.
TODO:
1. The selftests code needs to be fixed to work in subpage-blocksize scenario.
2. I am planning to fix Scrub & Compression via a separate patchset.
Changes from V16:
1. The V15 patchset consisted of patches obtained from an incorrect git branch. Apologies for the mistake. All the entries listed under "Changes from V15" hold good for V16.
Changes from V15:
1. The invocation of cleancache_get_page() in __do_readpage() assumed blocksize to be same as PAGE_SIZE. We now invoke cleancache_get_page() only if blocksize is same as PAGE_SIZE. Thanks to David Sterba for pointing this out.
2. In __extent_writepage_io() we used to accumulate all the contiguous dirty blocks within the page before submitting the file offset range for I/O. In some cases this caused the bio to span across more than a stripe. For example, With 4k block size, 64K stripe size and 64K page size, assume
- All the blocks mapped by the page are contiguous on the logical address space.
- The first block of the page is mapped to the second block of the stripe.
In such a scenario, we would add all the blocks of the page to bio. This would mean that we would overflow the stripe by one 4K block. Hence this patchset removes the optimization and invokes submit_extent_page() for every dirty 4K block.
3. The following patches are newly added:
- Btrfs: subpage-blocksize: __btrfs_lookup_bio_sums: Set offset when moving to a new bio_vec
- Btrfs: subpage-blocksize: Make file extent relocate code subpage blocksize aware
- Btrfs: btrfs_clone: Flush dirty blocks of a page that do not map the clone range
Changes from V14:
1. Fix usage of cleancache_get_page() in __do_readpage(). In filesystems which support subpage-blocksize scenario, a page can map one or more blocks. Hence cleancache_get_page() should be invoked only when the page maps a non-hole extent and block size being used is equal to the page size. Thanks to David Sterba for pointing this out.
2. Replace page_read_complete() and page_write_complete() functions with page_io_complete().
3. Provide more documentation (as part of both commit message and code comments) about the usage of the per-page btrfs_page_private->io_lock.
Changes from V13:
1. Enable dedup ioctl to work in subpagesize-blocksize scenario.
Changes from V12:
1. The logic in the function btrfs_punch_hole() has been fixed to check for the presence of BLK_STATE_UPTODATE flags for blocks in pages which partially map the file range being punched.
Changes from V11:
1. Addressed the review comments provided by Liu Bo for version V11.
2. Fixed file defragmentation code to work in subpagesize-blocksize scenario.
3. Many "hard to reproduce" bugs were fixed.
Chandan Rajendra (18):
Btrfs: subpage-blocksize: Fix whole page read.
Btrfs: subpage-blocksize: Fix whole page write
Btrfs: subpage-blocksize: Make sure delalloc range intersects with the
locked page's range
Btrfs: subpage-blocksize: Define extent_buffer_head.
Btrfs: subpage-blocksize: Read tree blocks whose size is <
PAGE_CACHE_SIZE
Btrfs: subpage-blocksize: Write only dirty extent buffers belonging to
a page
Btrfs: subpage-blocksize: Allow mounting filesystems where sectorsize
< PAGE_SIZE
Btrfs: subpage-blocksize: Deal with partial ordered extent
allocations.
Btrfs: subpage-blocksize: Explicitly track I/O status of blocks of an
ordered extent.
Btrfs: subpage-blocksize: btrfs_punch_hole: Fix uptodate blocks check
Btrfs: subpage-blocksize: Prevent writes to an extent buffer when
PG_writeback flag is set
Revert "btrfs: fix lockups from btrfs_clear_path_blocking"
Btrfs: subpage-blocksize: Fix file defragmentation code
Btrfs: subpage-blocksize: extent_clear_unlock_delalloc: Prevent page
from being unlocked more than once
Btrfs: subpage-blocksize: Enable dedupe ioctl
Btrfs: btrfs_clone: Flush dirty blocks of a page that do not map the
clone range
Btrfs: subpage-blocksize: Make file extent relocate code subpage
blocksize aware
Btrfs: subpage-blocksize: __btrfs_lookup_bio_sums: Set offset when
moving to a new bio_vec
fs/btrfs/ctree.c | 37 +- fs/btrfs/ctree.h | 6 +- fs/btrfs/disk-io.c | 156 ++-- fs/btrfs/disk-io.h | 3 + fs/btrfs/extent-tree.c | 17 +- fs/btrfs/extent_io.c | 1611 +++++++++++++++++++++++++++++------------- fs/btrfs/extent_io.h | 145 +++- fs/btrfs/file-item.c | 7 +- fs/btrfs/file.c | 82 ++- fs/btrfs/inode.c | 491 +++++++++---- fs/btrfs/ioctl.c | 219 ++++-- fs/btrfs/locking.c | 24 +- fs/btrfs/locking.h | 2 - fs/btrfs/ordered-data.c | 19 + fs/btrfs/ordered-data.h | 4 + fs/btrfs/relocation.c | 70 +- fs/btrfs/root-tree.c | 2 +- fs/btrfs/volumes.c | 2 +- include/trace/events/btrfs.h | 2 +- 19 files changed, 2050 insertions(+), 849 deletions(-)
Signature · 1 line
2.1.0
PATCH v17 1/18 Btrfs: subpage-blocksize: Fix whole page read.
For the subpage-blocksize scenario, a page can contain multiple blocks. In such cases, this patch handles reading data from files.
To track the status of individual blocks of a page, this patch makes use of a bitmap pointed to by the newly introduced per-page 'struct btrfs_page_private'.
The per-page btrfs_page_private->io_lock plays the same role as BH_Uptodate_Lock (see end_buffer_async_read()) i.e. without the io_lock we may end up in the following situation,
NOTE: Assume 64k page size and 4k block size. Also assume that the first 12 blocks of the page are contiguous while the next 4 blocks are contiguous. When reading the page we end up submitting two "logical address space" bios. So end_bio_extent_readpage function is invoked twice, once for each bio.
|-------------------------+-------------------------+-------------| | Task A | Task B | Task C | |-------------------------+-------------------------+-------------| | end_bio_extent_readpage | | | | process block 0 | | | | - clear BLK_STATE_IO | | | | - page_read_complete | | | | process block 1 | | | | | | | | | | | | | end_bio_extent_readpage | | | | process block 0 | | | | - clear BLK_STATE_IO | | | | - page_read_complete | | | | process block 1 | | | | | | | process block 11 | process block 3 | | | - clear BLK_STATE_IO | - clear BLK_STATE_IO | | | - page_read_complete | - page_read_complete | | | - returns true | - returns true | | | - unlock_page() | | | | | | lock_page() | | | - unlock_page() | | |-------------------------+-------------------------+-------------|
We end up incorrectly unlocking the page twice and "Task C" ends up working on an unlocked page. So private->io_lock makes sure that only one of the tasks gets "true" as the return value when page_io_complete() is invoked. As an optimization the patch gets the io_lock only when the last block of the bio_vec is being processed.
--- fs/btrfs/extent_io.c | 321 +++++++++++++++++++++++++++++++++------------------ fs/btrfs/extent_io.h | 71 +++++++++++- fs/btrfs/inode.c | 13 +-- 3 files changed, 280 insertions(+), 125 deletions(-)
fs/btrfs/extent_io.c +210 -111
@@ -1321,6 +1321,95 @@ int clear_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, changeset); } +static int modify_page_blks_state (struct page *page, +unsigned long blk_states, +u64 start,u64 end,int set) +{ +struct inode *inode = page->mapping->host; +unsigned long *bitmap; +unsigned long first_state; +unsigned long state; +u64 nr_blks; +u64 blk; + +BUG_ON (!PagePrivate (page)); + + bitmap = ((struct btrfs_page_private *)page->private)->bstate; + + blk =BTRFS_BYTES_TO_BLKS (BTRFS_I (inode)->root->fs_info, + start & (PAGE_SIZE -1 )); + nr_blks =BTRFS_BYTES_TO_BLKS (BTRFS_I (inode)->root->fs_info, + (end - start +1 )); + + first_state =find_next_bit (&blk_states,BLK_NR_STATE ,0 ); + +while (nr_blks--) { + state = first_state; + +while (state <BLK_NR_STATE ) { +if (set) +set_bit ((blk *BLK_NR_STATE ) + state, bitmap); +else +clear_bit ((blk *BLK_NR_STATE ) + state, bitmap); + + state =find_next_bit (&blk_states,BLK_NR_STATE , + state +1 ); + } + + ++blk; + } + +return 0 ; +} + +int set_page_blks_state (struct page *page,unsigned long blk_states, +u64 start,u64 end) +{ +return modify_page_blks_state (page, blk_states, start, end,1 ); +} + +int clear_page_blks_state (struct page *page,unsigned long blk_states, +u64 start,u64 end) +{ +return modify_page_blks_state (page, blk_states, start, end,0 ); +} + +int test_page_blks_state (struct page *page,enum blk_state blk_state, +u64 start,u64 end,int check_all) +{ +struct inode *inode = page->mapping->host; +unsigned long *bitmap; +unsigned long blk; +u64 nr_blks; +int found =0 ; + +BUG_ON (!PagePrivate (page)); + + bitmap = ((struct btrfs_page_private *)page->private)->bstate; + + blk =BTRFS_BYTES_TO_BLKS (BTRFS_I (inode)->root->fs_info, + start & (PAGE_SIZE -1 )); + nr_blks =BTRFS_BYTES_TO_BLKS (BTRFS_I (inode)->root->fs_info, + (end - start +1 )); + +while (nr_blks--) { +if (test_bit ((blk *BLK_NR_STATE ) + blk_state, bitmap)) { +if (!check_all) +return 1 ; + found =1 ; + }else if (check_all) { +return 0 ; + } + + ++blk; + } + +if (!check_all && !found) +return 0 ; + +return 1 ; +} +/* * either insert or lock state struct between start and end use mask to tell * us if waiting is desired.
@@ -1958,14 +2047,22 @@ 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 page *page) {u64 start =page_offset (page);u64 end = start +PAGE_SIZE -1 ; -if (test_range_bit (tree, start, end,EXTENT_UPTODATE ,1 ,NULL )) +if (test_page_blks_state (page,BLK_STATE_UPTODATE , start, end,1 ))SetPageUptodate (page); } +static int page_io_complete (struct page *page) +{ +u64 start =page_offset (page); +u64 end = start +PAGE_SIZE -1 ; + +return !test_page_blks_state (page,BLK_STATE_IO , start, end,0 ); +} +int free_io_failure (struct inode *inode,struct io_failure_record *rec) {int ret;
@@ -2282,7 +2379,9 @@ int btrfs_check_repairable(struct inode *inode, struct bio *failed_bio,* 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,
@@ -2488,18 +2587,6 @@ static void end_bio_extent_writepage(struct bio *bio)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
@@ -2516,67 +2603,50 @@ static void end_bio_extent_readpage(struct bio *bio)struct bio_vec *bvec;int uptodate = !bio->bi_error;struct btrfs_io_bio *io_bio =btrfs_io_bio (bio); +struct extent_state *cached =NULL ; +struct btrfs_page_private *pg_private;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;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=%u\n" , (u64 )bio->bi_iter.bi_sector, bio->bi_error, 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_SIZE ) { -if (bvec->bv_offset + bvec->bv_len !=PAGE_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 =BTRFS_BYTES_TO_BLKS (root->fs_info, + bvec->bv_len); mirror = io_bio->mirror_num; + +next_block:if (likely (uptodate && tree->ops && - tree->ops->readpage_end_io_hook)) { + tree->ops->readpage_end_io_hook)) { 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 (inode, start, page,0 ); +clean_io_failure (inode, start, page, + start -page_offset (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 && !bio->bi_error) - uptodate =1 ; - }else { +if (!uptodate) {/* * The generic bio_readpage_error handles errors the * following way: If possible, new read requests are
@@ -2587,58 +2657,61 @@ static void end_bio_extent_readpage(struct bio *bio)* 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 = !bio->bi_error; - offset += len; -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_SHIFT ; -unsigned off; - -/* Zero out the end if this page straddles i_size */ - off = i_size & (PAGE_SIZE -1 ); -if (page->index == end_index && off) -zero_user_segment (page, off,PAGE_SIZE ); -SetPageUptodate (page); + +if (uptodate) { +set_page_blks_state (page,1 <<BLK_STATE_UPTODATE , start, + start + root->sectorsize -1 ); +check_page_uptodate (page); }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_page_blks_state (page,1 <<BLK_STATE_IO , + start, start + root->sectorsize -1 ); +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)); + + pg_private = (struct btrfs_page_private *)page->private; + +spin_lock_irqsave (&pg_private->io_lock, flags); + +clear_page_blks_state (page,1 <<BLK_STATE_IO , + start, start + root->sectorsize -1 ); + + unlock =page_io_complete (page); + +spin_unlock_irqrestore (&pg_private->io_lock, 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, bio->bi_error);bio_put (bio);
@@ -2828,13 +2901,36 @@ static void attach_extent_buffer_page(struct extent_buffer *eb, } } -void set_page_extent_mapped (struct page *page) +int set_page_extent_mapped (struct page *page) { +struct btrfs_page_private *pg_private; +if (!PagePrivate (page)) { + pg_private =kzalloc (sizeof (*pg_private),GFP_NOFS ); +if (!pg_private) +return -ENOMEM ; + +spin_lock_init (&pg_private->io_lock); +SetPagePrivate (page); +get_page (page); -set_page_private (page,EXTENT_PAGE_PRIVATE ); +set_page_private (page, (unsigned long )pg_private); } + +return 0 ; +} + +int clear_page_extent_mapped (struct page *page) +{ +if (PagePrivate (page)) { +kfree ((struct btrfs_page_private *)(page->private)); +ClearPagePrivate (page); +set_page_private (page,0 ); +put_page (page); + } + +return 0 ; } static struct extent_map *
@@ -2901,13 +2997,6 @@ static int __do_readpage(struct extent_io_tree *tree,set_page_extent_mapped (page); end = page_end; -if (!PageUptodate (page)) { -if (cleancache_get_page (page) ==0 ) { -BUG_ON (blocksize !=PAGE_SIZE ); -unlock_extent (tree, start, end); - goto out; - } - }if (page->index == last_byte >>PAGE_SHIFT ) {char *userpage;
@@ -2927,18 +3016,17 @@ static int __do_readpage(struct extent_io_tree *tree,if (cur >= last_byte) {char *userpage; -struct extent_state *cached =NULL ; iosize =PAGE_SIZE - pg_offset; userpage =kmap_atomic (page);memset (userpage + pg_offset,0 , iosize);flush_dcache_page (page);kunmap_atomic (userpage); -set_extent_uptodate (tree, cur, cur + iosize -1 , - &cached,GFP_NOFS ); +set_page_blks_state (page,1 <<BLK_STATE_UPTODATE , cur, + cur + iosize -1 );unlock_extent_cached (tree, cur, cur + iosize -1 , - &cached,GFP_NOFS ); +NULL ,GFP_NOFS );break ; } em = __get_extent_map(inode, page, pg_offset, cur,
@@ -2973,6 +3061,13 @@ static int __do_readpage(struct extent_io_tree *tree,if (test_bit (EXTENT_FLAG_PREALLOC , &em->flags)) block_start =EXTENT_MAP_HOLE ; +if ((block_start !=EXTENT_MAP_HOLE ) && + (blocksize ==PAGE_SIZE ) && !PageUptodate (page) && + (cleancache_get_page (page) ==0 )) { +unlock_extent (tree, cur, end); +break ; + } +/* * If we have a file range that points to a compressed extent * and it's followed by a consecutive file range that points to
@@ -3028,8 +3123,8 @@ static int __do_readpage(struct extent_io_tree *tree,flush_dcache_page (page);kunmap_atomic (userpage); -set_extent_uptodate (tree, cur, cur + iosize -1 , - &cached,GFP_NOFS ); +set_page_blks_state (page,1 <<BLK_STATE_UPTODATE , cur, + cur + iosize -1 );unlock_extent_cached (tree, cur, cur + iosize -1 , &cached,GFP_NOFS );
@@ -3038,9 +3133,9 @@ static int __do_readpage(struct extent_io_tree *tree,continue ; }/* 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); +if (test_page_blks_state (page,BLK_STATE_UPTODATE , cur, + cur_end,1 )) { +check_page_uptodate (page);unlock_extent (tree, cur, cur + iosize -1 ); cur = cur + iosize; pg_offset += iosize;
@@ -3058,6 +3153,8 @@ static int __do_readpage(struct extent_io_tree *tree, } pnr -= page->index; +set_page_blks_state (page,1 <<BLK_STATE_IO , cur, + cur + iosize -1 ); ret = submit_extent_page(rw, tree, NULL, page, sector, disk_io_size, pg_offset, bdev, bio, pnr,
@@ -3070,12 +3167,14 @@ static int __do_readpage(struct extent_io_tree *tree, *bio_flags = this_bio_flag; }else {SetPageError (page); +clear_page_blks_state (page,1 <<BLK_STATE_IO , cur, + cur + iosize -1 );unlock_extent (tree, cur, cur + iosize -1 ); } cur = cur + iosize; pg_offset += iosize; } -out: +if (!nr) {if (!PageError (page))SetPageUptodate (page);
fs/btrfs/extent_io.h +65 -6
84 lines not on this page · raw message
fs/btrfs/inode.c +5 -8
@@ -6750,7 +6750,6 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,struct btrfs_key found_key;struct extent_map *em =NULL ;struct extent_map_tree *em_tree = &BTRFS_I (inode)->extent_tree; -struct extent_io_tree *io_tree = &BTRFS_I (inode)->io_tree;struct btrfs_trans_handle *trans =NULL ;const bool new_inline = !page || create;
@@ -6927,8 +6926,8 @@ next:kunmap (page);btrfs_mark_buffer_dirty (leaf); } -set_extent_uptodate (io_tree, em->start, -extent_map_end (em) -1 ,NULL ,GFP_NOFS ); +set_page_blks_state (page,1 <<BLK_STATE_UPTODATE , em->start, +extent_map_end (em) -1 ); goto insert; } not_found:
@@ -8716,11 +8715,9 @@ static int __btrfs_releasepage(struct page *page, gfp_t gfp_flags) tree = &BTRFS_I (page->mapping->host)->io_tree; map = &BTRFS_I (page->mapping->host)->extent_tree; ret =try_release_extent_mapping (map, tree, page, gfp_flags); -if (ret ==1 ) { -ClearPagePrivate (page); -set_page_private (page,0 ); -put_page (page); - } +if (ret ==1 ) +clear_page_extent_mapped (page); +return ret; }
Signature · 1 line
2.1.0
PATCH v17 2/18 Btrfs: subpage-blocksize: Fix whole page write
In reply to Chandan RajendraFor the subpage-blocksize scenario, a page can contain multiple blocks. In such cases, this patch handles writing data to files.
Also, When setting EXTENT_DELALLOC, we no longer set EXTENT_UPTODATE bit on the extent_io_tree since uptodate status is being tracked by the bitmap pointed to by page->private.
--- fs/btrfs/extent_io.c | 129 +++++++++++++++++++++----------------------------- fs/btrfs/file.c | 16 +++++++ fs/btrfs/inode.c | 64 ++++++++++++++++++++----- fs/btrfs/relocation.c | 3 ++ 4 files changed, 125 insertions(+), 87 deletions(-)
fs/btrfs/extent_io.c +54 -75
@@ -1481,24 +1481,6 @@ void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end) } } -/* -* helper function to set both pages and extents in the tree writeback -*/ -static void set_range_writeback (struct extent_io_tree *tree,u64 start,u64 end) -{ -unsigned long index = start >>PAGE_SHIFT ; -unsigned long end_index = end >>PAGE_SHIFT ; -struct page *page; - -while (index <= end_index) { - page =find_get_page (tree->mapping, index); -BUG_ON (!page);/* Pages should be in the extent_io_tree */ -set_page_writeback (page); -put_page (page); - index++; - } -} -/* find the first state struct with 'bits' set after 'start', and * return it. tree->lock must be held. NULL will returned if * nothing was found after 'start'
@@ -2552,36 +2534,34 @@ void end_extent_writepage(struct page *page, int err, u64 start, u64 end)*/ static void end_bio_extent_writepage (struct bio *bio) { +struct btrfs_page_private *pg_private;struct bio_vec *bvec; +unsigned long flags;u64 start;u64 end; +int clear_writeback;int i;bio_for_each_segment_all (bvec, bio, i) {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_SIZE ) { -if (bvec->bv_offset + bvec->bv_len !=PAGE_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) + bvec->bv_offset; + end = start + bvec->bv_len -1 ; + + pg_private = (struct btrfs_page_private *)page->private; - start =page_offset (page); - end = start + bvec->bv_offset + bvec->bv_len -1 ; +spin_lock_irqsave (&pg_private->io_lock, flags);end_extent_writepage (page, bio->bi_error, start, end); -end_page_writeback (page); + +clear_page_blks_state (page,1 <<BLK_STATE_IO , start, end); + + clear_writeback =page_io_complete (page); + +spin_unlock_irqrestore (&pg_private->io_lock, flags); + +if (clear_writeback) +end_page_writeback (page); }bio_put (bio);
@@ -3423,10 +3403,9 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,u64 block_start;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 ;
@@ -3473,20 +3452,29 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode, page_end, NULL, 1);break ; } - em = epd->get_extent (inode, page, pg_offset, cur, - end - cur +1 ,1 ); + +if (!test_page_blks_state (page,BLK_STATE_DIRTY , cur, + cur + blocksize -1 ,1 )) { + cur += blocksize; +continue ; + } + + pg_offset = cur & (PAGE_SIZE -1 ); + + em = epd->get_extent (inode, page, pg_offset, cur, blocksize,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);BUG_ON (end < cur); - iosize =min (em_end - cur, end - cur +1 ); - iosize =ALIGN (iosize, blocksize); + + iosize = blocksize; + + extent_offset = cur - em->start; sector = (em->block_start + extent_offset) >>9 ; bdev = em->bdev; block_start = em->block_start;
@@ -3494,32 +3482,20 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,free_extent_map (em); em =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++; - } +BUG_ON (compressed); +BUG_ON (block_start ==EXTENT_MAP_INLINE ); - cur += iosize; - pg_offset += iosize; -continue ; +if (block_start ==EXTENT_MAP_HOLE ) { +if (test_page_blks_state (page,BLK_STATE_UPTODATE , cur, + cur + iosize -1 ,1 )) { +clear_page_blks_state (page, +1 <<BLK_STATE_DIRTY , cur, + cur + iosize -1 ); + cur += iosize; +continue ; + }else { +BUG (); + } }if (tree->ops && tree->ops->writepage_io_hook) {
@@ -3533,7 +3509,13 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode, }else {unsigned long max_nr = (i_size >>PAGE_SHIFT ) +1 ; -set_range_writeback (tree, cur, cur + iosize -1 ); +clear_page_blks_state (page,1 <<BLK_STATE_DIRTY , cur, + cur + iosize -1 ); +set_page_writeback (page); + +set_page_blks_state (page,1 <<BLK_STATE_IO , cur, + cur + iosize -1 ); +if (!PageWriteback (page)) { btrfs_err(BTRFS_I(inode)->root->fs_info, "page %lu not writeback, cur %llu end %llu",
@@ -3548,17 +3530,14 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,if (ret)SetPageError (page); } - cur = cur + iosize; - pg_offset += iosize; + + cur += iosize; nr++; } done: *nr_ret = nr; done_unlocked: - -/* drop our reference on any cached states */ -free_extent_state (cached_state);return ret; }
fs/btrfs/file.c +16 -0
@@ -495,6 +495,9 @@ int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,u64 num_bytes;u64 start_pos;u64 end_of_last_block; +u64 start; +u64 end; +u64 page_end;u64 end_pos = pos + write_bytes;loff_t isize =i_size_read (inode);
@@ -507,11 +510,24 @@ int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode,if (err)return err; + start = start_pos; +for (i =0 ; i < num_pages; i++) {struct page *p = pages[i];SetPageUptodate (p);ClearPageChecked (p); + + end = page_end =page_offset (p) +PAGE_SIZE -1 ; + +if (i == num_pages -1 ) + end =min_t (u64, page_end, end_of_last_block); + +set_page_blks_state (p, +1 <<BLK_STATE_DIRTY |1 <<BLK_STATE_UPTODATE , + start, end);set_page_dirty (p); + + start = page_end +1 ; }/*
fs/btrfs/inode.c +52 -12
108 lines not on this page · raw message
fs/btrfs/relocation.c +3 -0
@@ -3187,6 +3187,9 @@ static int relocate_file_extent_cluster(struct inode *inode, }btrfs_set_extent_delalloc (inode, page_start, page_end,NULL ); +set_page_blks_state (page, +1 <<BLK_STATE_DIRTY |1 <<BLK_STATE_UPTODATE , + page_start, page_end);set_page_dirty (page); unlock_extent(&BTRFS_I(inode)->io_tree,
Signature · 1 line
2.1.0
PATCH v17 3/18 Btrfs: subpage-blocksize: Make sure delalloc range intersects with the locked page's range
In reply to Chandan Rajendrafind_delalloc_range indirectly depends on EXTENT_UPTODDATE to make sure that the delalloc range returned intersects with the file range mapped by the page. Since we now track "uptodate" state in a per-page
bitmap (i.e. in btrfs_page_private->bstate), this commit makes an explicit check to make sure that the delalloc range starts from within the file range mapped by the page.
--- fs/btrfs/extent_io.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
fs/btrfs/extent_io.c +9 -3
@@ -1568,6 +1568,7 @@ out:* 1 is returned if we find something, 0 if nothing was in the tree */ static noinline u64 find_delalloc_range(struct extent_io_tree *tree, +struct page *locked_page,u64 *start,u64 *end,u64 max_bytes,struct extent_state **cached_state) {
@@ -1576,6 +1577,9 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree,u64 cur_start = *start;u64 found =0 ;u64 total_bytes =0 ; +u64 page_end; + + page_end =page_offset (locked_page) +PAGE_CACHE_SIZE -1 ;spin_lock (&tree->lock);
@@ -1596,7 +1600,8 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree, (state->state & EXTENT_BOUNDARY))) { goto out; } -if (!(state->state &EXTENT_DELALLOC )) { +if (!(state->state &EXTENT_DELALLOC ) + || (page_end < state->start)) {if (!found) *end = state->end; goto out;
@@ -1734,8 +1739,9 @@ again:/* step one, find a bunch of delalloc bytes starting at start */ delalloc_start = *start; delalloc_end =0 ; - found =find_delalloc_range (tree, &delalloc_start, &delalloc_end, - max_bytes, &cached_state); + found =find_delalloc_range (tree, locked_page, + &delalloc_start, &delalloc_end, + max_bytes, &cached_state);if (!found || delalloc_end <= *start) { *start = delalloc_start; *end = delalloc_end;
Signature · 1 line
2.1.0
PATCH 1/1 Btrfs: subpage-blocksize: Make sure delalloc range intersects with the locked page's range
find_delalloc_range indirectly depends on EXTENT_UPTODDATE to make sure that the delalloc range returned intersects with the file range mapped by the page. Since we now track "uptodate" state in a per-page
bitmap (i.e. in btrfs_page_private->bstate), this commit makes an explicit check to make sure that the delalloc range starts from within the file range mapped by the page.
--- fs/btrfs/extent_io.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
fs/btrfs/extent_io.c +9 -3
@@ -1568,6 +1568,7 @@ out:* 1 is returned if we find something, 0 if nothing was in the tree */ static noinline u64 find_delalloc_range(struct extent_io_tree *tree, +struct page *locked_page,u64 *start,u64 *end,u64 max_bytes,struct extent_state **cached_state) {
@@ -1576,6 +1577,9 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree,u64 cur_start = *start;u64 found =0 ;u64 total_bytes =0 ; +u64 page_end; + + page_end =page_offset (locked_page) +PAGE_SIZE -1 ;spin_lock (&tree->lock);
@@ -1596,7 +1600,8 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree, (state->state & EXTENT_BOUNDARY))) { goto out; } -if (!(state->state &EXTENT_DELALLOC )) { +if (!(state->state &EXTENT_DELALLOC ) + || (page_end < state->start)) {if (!found) *end = state->end; goto out;
@@ -1734,8 +1739,9 @@ again:/* step one, find a bunch of delalloc bytes starting at start */ delalloc_start = *start; delalloc_end =0 ; - found =find_delalloc_range (tree, &delalloc_start, &delalloc_end, - max_bytes, &cached_state); + found =find_delalloc_range (tree, locked_page, + &delalloc_start, &delalloc_end, + max_bytes, &cached_state);if (!found || delalloc_end <= *start) { *start = delalloc_start; *end = delalloc_end;
Signature · 1 line
2.1.0
PATCH v17 4/18 Btrfs: subpage-blocksize: Define extent_buffer_head.
In reply to Chandan RajendraIn 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 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/ctree.c | 2 +- fs/btrfs/ctree.h | 6 +- fs/btrfs/disk-io.c | 72 +++--- fs/btrfs/extent-tree.c | 6 +- fs/btrfs/extent_io.c | 590 ++++++++++++++++++++++++++++--------------- fs/btrfs/extent_io.h | 63 +++-- fs/btrfs/root-tree.c | 2 +- fs/btrfs/volumes.c | 2 +- include/trace/events/btrfs.h | 2 +- 9 files changed, 490 insertions(+), 255 deletions(-)
fs/btrfs/ctree.c +1 -1
@@ -160,7 +160,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
@@ -2464,14 +2464,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_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_SIZE -1)); \ p->member = cpu_to_le##bits(val); \ }
fs/btrfs/disk-io.c +43 -29
197 lines not on this page · raw message
fs/btrfs/extent-tree.c +3 -3
@@ -6849,7 +6849,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 );
@@ -6867,7 +6867,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); }/* Can return -ENOMEM */
@@ -7907,7 +7907,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->fs_info, buf); -clear_bit (EXTENT_BUFFER_STALE , &buf->bflags); +clear_bit (EXTENT_BUFFER_STALE , &buf->ebflags);btrfs_set_lock_blocking (buf);set_extent_buffer_uptodate (buf);
fs/btrfs/extent_io.c +392 -198
1,174 lines not on this page · raw message
fs/btrfs/extent_io.h +44 -19
105 lines not on this page · raw message
fs/btrfs/root-tree.c +1 -1
@@ -45,7 +45,7 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,if (!need_reset &&btrfs_root_generation (item) !=btrfs_root_generation_v2 (item)) {if (btrfs_root_generation_v2 (item) !=0 ) { -btrfs_warn (eb->fs_info, +btrfs_warn (eb_head (eb)->fs_info,"mismatching " "generation and generation_v2 " "found in root item. This root "
fs/btrfs/volumes.c +1 -1
@@ -6528,7 +6528,7 @@ int btrfs_read_sys_array(struct btrfs_root *root)* to silence the warning eg. on PowerPC 64. */ if (PAGE_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
@@ -700,7 +700,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
kbuild test robot
build botRe: [PATCH V17 04/18] Btrfs: subpage-blocksize: Define extent_buffer_head.
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…
Hi Chandan,
[auto build test WARNING on tip/perf/core]
[also build test WARNING on v4.6-rc3 next-20160414]
[cannot apply to btrfs/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Chandan-Rajendra/Allow-I-O-on-blocks-whose-size-is-less-than-page-size/20160414-214339 config: arm-allyesconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm
All warnings (new ones prefixed by >>):
fs/btrfs/extent_io.c: In function 'alloc_test_extent_buffer':
fs/btrfs/extent_io.c:5037:4: error: 'struct extent_buffer' has no member named 'fs_info'
eb->fs_info = fs_info;
^
In file included from include/linux/bitops.h:36:0,
from fs/btrfs/extent_io.c:1:
fs/btrfs/extent_io.c:5055:41: error: 'struct extent_buffer' has no member named 'bflags'
set_bit(EXTENT_BUFFER_HEAD_IN_TREE, &eb->bflags);
^
arch/arm/include/asm/bitops.h:182:45: note: in definition of macro 'ATOMIC_BITOP'
#define ATOMIC_BITOP(name,nr,p) _##name(nr,p)
^
>> fs/btrfs/extent_io.c:5055:2: note: in expansion of macro 'set_bit'
set_bit(EXTENT_BUFFER_HEAD_IN_TREE, &eb->bflags);
^
In file included from include/linux/atomic.h:4:0,
from include/linux/debug_locks.h:5,
from include/linux/lockdep.h:23,
from include/linux/spinlock_types.h:18,
from include/linux/spinlock.h:81,
from include/linux/mmzone.h:7,
from include/linux/gfp.h:5,
from include/linux/slab.h:14,
from fs/btrfs/extent_io.c:2:
fs/btrfs/extent_io.c:5063:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/arm/include/asm/atomic.h:208:38: note: in definition of macro 'atomic_inc'
#define atomic_inc(v) atomic_add(1, v)
^
In file included from arch/arm/include/asm/bitops.h:26:0,
from include/linux/bitops.h:36,
from fs/btrfs/extent_io.c:1:
fs/btrfs/extent_io.c: In function 'release_extent_buffer':
fs/btrfs/extent_io.c:5233:16: error: 'buf' undeclared (first use in this function)
&eb_head(buf)->bflags))) {
^
include/linux/compiler.h:170:42: note: in definition of macro 'unlikely'
# define unlikely(x) __builtin_expect(!!(x), 0)
^
fs/btrfs/extent_io.c:5233:16: note: each undeclared identifier is reported only once for each function it appears in
&eb_head(buf)->bflags))) {
^
include/linux/compiler.h:170:42: note: in definition of macro 'unlikely'
# define unlikely(x) __builtin_expect(!!(x), 0)
^
fs/btrfs/extent_io.c:5234:33: error: 'eb' undeclared (first use in this function)
__free_extent_buffer(eb_head(eb));
^vim +/set_bit +5055 fs/btrfs/extent_io.c
5039 ret = radix_tree_preload(GFP_NOFS & ~__GFP_HIGHMEM);
5040 if (ret)
5041 goto free_eb;
5042 spin_lock(&fs_info->buffer_lock);
5043 ret = radix_tree_insert(&fs_info->buffer_radix,
5044 start >> PAGE_SHIFT, eb);
5045 spin_unlock(&fs_info->buffer_lock);
5046 radix_tree_preload_end();
5047 if (ret == -EEXIST) {
5048 exists = find_extent_buffer(fs_info, start);
5049 if (exists)
5050 goto free_eb;
5051 else
5052 goto again;
5053 }
5054 check_buffer_tree_ref(eb);
> 5055 set_bit(EXTENT_BUFFER_HEAD_IN_TREE, &eb->bflags);
5056
5057 /*
5058 * We will free dummy extent buffer's if they come into
5059 * free_extent_buffer with a ref count of 2, but if we are using this we
5060 * want the buffers to stay in memory until we're done with them, so
5061 * bump the ref count again.
5062 */
5063 atomic_inc(&eb->refs);
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH 1/1 Btrfs: subpage-blocksize: Define extent_buffer_head.
In reply to Chandan RajendraIn 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 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/ctree.c | 2 +- fs/btrfs/ctree.h | 6 +- fs/btrfs/disk-io.c | 72 +++--- fs/btrfs/extent-tree.c | 6 +- fs/btrfs/extent_io.c | 588 ++++++++++++++++++++++++++++--------------- fs/btrfs/extent_io.h | 63 +++-- fs/btrfs/root-tree.c | 2 +- fs/btrfs/volumes.c | 2 +- include/trace/events/btrfs.h | 2 +- 9 files changed, 489 insertions(+), 254 deletions(-)
fs/btrfs/ctree.c +1 -1
@@ -160,7 +160,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
@@ -2464,14 +2464,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_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_SIZE -1)); \ p->member = cpu_to_le##bits(val); \ }
fs/btrfs/disk-io.c +43 -29
197 lines not on this page · raw message
fs/btrfs/extent-tree.c +3 -3
@@ -6849,7 +6849,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 );
@@ -6867,7 +6867,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); }/* Can return -ENOMEM */
@@ -7907,7 +7907,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->fs_info, buf); -clear_bit (EXTENT_BUFFER_STALE , &buf->bflags); +clear_bit (EXTENT_BUFFER_STALE , &buf->ebflags);btrfs_set_lock_blocking (buf);set_extent_buffer_uptodate (buf);
fs/btrfs/extent_io.c +391 -197
1,166 lines not on this page · raw message
fs/btrfs/extent_io.h +44 -19
105 lines not on this page · raw message
fs/btrfs/root-tree.c +1 -1
@@ -45,7 +45,7 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,if (!need_reset &&btrfs_root_generation (item) !=btrfs_root_generation_v2 (item)) {if (btrfs_root_generation_v2 (item) !=0 ) { -btrfs_warn (eb->fs_info, +btrfs_warn (eb_head (eb)->fs_info,"mismatching " "generation and generation_v2 " "found in root item. This root "
fs/btrfs/volumes.c +1 -1
@@ -6528,7 +6528,7 @@ int btrfs_read_sys_array(struct btrfs_root *root)* to silence the warning eg. on PowerPC 64. */ if (PAGE_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
@@ -700,7 +700,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
kbuild test robot
build botRe: [PATCH] Btrfs: subpage-blocksize: Define extent_buffer_head.
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…
Hi Chandan,
[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.6-rc3 next-20160415]
[cannot apply to btrfs/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Chandan-Rajendra/Btrfs-subpage-blocksize-Define-extent_buffer_head/20160417-202933 config: xtensa-allyesconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=xtensa
All errors (new ones prefixed by >>):
fs/btrfs/extent_io.c: In function 'alloc_test_extent_buffer':
>> fs/btrfs/extent_io.c:4953:4: error: 'struct extent_buffer' has no member named 'fs_info'
eb->fs_info = fs_info;
^
>> fs/btrfs/extent_io.c:4971:41: error: 'struct extent_buffer' has no member named 'bflags'
set_bit(EXTENT_BUFFER_HEAD_IN_TREE, &eb->bflags);
^
In file included from include/linux/atomic.h:4:0,
from include/linux/debug_locks.h:5,
from include/linux/lockdep.h:23,
from include/linux/spinlock_types.h:18,
from include/linux/spinlock.h:81,
from include/linux/mmzone.h:7,
from include/linux/gfp.h:5,
from include/linux/slab.h:14,
from fs/btrfs/extent_io.c:2:
>> fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/xtensa/include/asm/atomic.h:173:37: note: in definition of macro 'atomic_inc'
#define atomic_inc(v) atomic_add(1,(v))
^
In file included from arch/xtensa/include/asm/processor.h:16:0,
from arch/xtensa/include/asm/bitops.h:22,
from include/linux/bitops.h:36,
from fs/btrfs/extent_io.c:1:
fs/btrfs/extent_io.c: In function 'release_extent_buffer':
>> fs/btrfs/extent_io.c:5149:16: error: 'buf' undeclared (first use in this function)
&eb_head(buf)->bflags))) {
^
include/linux/compiler.h:170:42: note: in definition of macro 'unlikely'
# define unlikely(x) __builtin_expect(!!(x), 0)
^
fs/btrfs/extent_io.c:5149:16: note: each undeclared identifier is reported only once for each function it appears in
&eb_head(buf)->bflags))) {
^
include/linux/compiler.h:170:42: note: in definition of macro 'unlikely'
# define unlikely(x) __builtin_expect(!!(x), 0)
^
>> fs/btrfs/extent_io.c:5150:33: error: 'eb' undeclared (first use in this function)
__free_extent_buffer(eb_head(eb));
^vim +4953 fs/btrfs/extent_io.c
faa2dbf00 Josef Bacik 2014-05-07 4947 eb = find_extent_buffer(fs_info, start);
faa2dbf00 Josef Bacik 2014-05-07 4948 if (eb)
faa2dbf00 Josef Bacik 2014-05-07 4949 return eb;
3f556f785 David Sterba 2014-06-15 4950 eb = alloc_dummy_extent_buffer(fs_info, start);
faa2dbf00 Josef Bacik 2014-05-07 4951 if (!eb)
faa2dbf00 Josef Bacik 2014-05-07 4952 return NULL;
faa2dbf00 Josef Bacik 2014-05-07 @4953 eb->fs_info = fs_info;
faa2dbf00 Josef Bacik 2014-05-07 4954 again:
faa2dbf00 Josef Bacik 2014-05-07 4955 ret = radix_tree_preload(GFP_NOFS & ~__GFP_HIGHMEM);
faa2dbf00 Josef Bacik 2014-05-07 4956 if (ret)
faa2dbf00 Josef Bacik 2014-05-07 4957 goto free_eb;
faa2dbf00 Josef Bacik 2014-05-07 4958 spin_lock(&fs_info->buffer_lock);
faa2dbf00 Josef Bacik 2014-05-07 4959 ret = radix_tree_insert(&fs_info->buffer_radix,
09cbfeaf1 Kirill A. Shutemov 2016-04-01 4960 start >> PAGE_SHIFT, eb);
faa2dbf00 Josef Bacik 2014-05-07 4961 spin_unlock(&fs_info->buffer_lock);
faa2dbf00 Josef Bacik 2014-05-07 4962 radix_tree_preload_end();
faa2dbf00 Josef Bacik 2014-05-07 4963 if (ret == -EEXIST) {
faa2dbf00 Josef Bacik 2014-05-07 4964 exists = find_extent_buffer(fs_info, start);
faa2dbf00 Josef Bacik 2014-05-07 4965 if (exists)
faa2dbf00 Josef Bacik 2014-05-07 4966 goto free_eb;
faa2dbf00 Josef Bacik 2014-05-07 4967 else
faa2dbf00 Josef Bacik 2014-05-07 4968 goto again;
faa2dbf00 Josef Bacik 2014-05-07 4969 }
faa2dbf00 Josef Bacik 2014-05-07 4970 check_buffer_tree_ref(eb);
e6fa7cb7e Chandan Rajendra 2016-04-17 @4971 set_bit(EXTENT_BUFFER_HEAD_IN_TREE, &eb->bflags);
faa2dbf00 Josef Bacik 2014-05-07 4972
faa2dbf00 Josef Bacik 2014-05-07 4973 /*
faa2dbf00 Josef Bacik 2014-05-07 4974 * We will free dummy extent buffer's if they come into
faa2dbf00 Josef Bacik 2014-05-07 4975 * free_extent_buffer with a ref count of 2, but if we are using this we
faa2dbf00 Josef Bacik 2014-05-07 4976 * want the buffers to stay in memory until we're done with them, so
faa2dbf00 Josef Bacik 2014-05-07 4977 * bump the ref count again.
faa2dbf00 Josef Bacik 2014-05-07 4978 */
faa2dbf00 Josef Bacik 2014-05-07 @4979 atomic_inc(&eb->refs);
faa2dbf00 Josef Bacik 2014-05-07 4980 return eb;
faa2dbf00 Josef Bacik 2014-05-07 4981 free_eb:
faa2dbf00 Josef Bacik 2014-05-07 4982 btrfs_release_extent_buffer(eb);
faa2dbf00 Josef Bacik 2014-05-07 4983 return exists;
faa2dbf00 Josef Bacik 2014-05-07 4984 }
faa2dbf00 Josef Bacik 2014-05-07 4985 #endif
faa2dbf00 Josef Bacik 2014-05-07 4986
f28491e0a Josef Bacik 2013-12-16 4987 struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
ce3e69847 David Sterba 2014-06-15 4988 u64 start)
d1310b2e0 Chris Mason 2008-01-24 4989 {
ce3e69847 David Sterba 2014-06-15 4990 unsigned long len = fs_info->tree_root->nodesize;
d1310b2e0 Chris Mason 2008-01-24 4991 unsigned long num_pages = num_extent_pages(start, len);
d1310b2e0 Chris Mason 2008-01-24 4992 unsigned long i;
09cbfeaf1 Kirill A. Shutemov 2016-04-01 4993 unsigned long index = start >> PAGE_SHIFT;
e6fa7cb7e Chandan Rajendra 2016-04-17 4994 struct extent_buffer *eb, *cur_eb;
6af118ce5 Chris Mason 2008-07-22 4995 struct extent_buffer *exists = NULL;
d1310b2e0 Chris Mason 2008-01-24 4996 struct page *p;
f28491e0a Josef Bacik 2013-12-16 4997 struct address_space *mapping = fs_info->btree_inode->i_mapping;
d1310b2e0 Chris Mason 2008-01-24 4998 int uptodate = 1;
19fe0a8b7 Miao Xie 2010-10-26 4999 int ret;
d1310b2e0 Chris Mason 2008-01-24 5000
f28491e0a Josef Bacik 2013-12-16 5001 eb = find_extent_buffer(fs_info, start);
452c75c3d Chandra Seetharaman 2013-10-07 5002 if (eb)
6af118ce5 Chris Mason 2008-07-22 5003 return eb;
6af118ce5 Chris Mason 2008-07-22 5004
23d79d81b David Sterba 2014-06-15 5005 eb = __alloc_extent_buffer(fs_info, start, len);
2b114d1d3 Peter 2008-04-01 5006 if (!eb)
d1310b2e0 Chris Mason 2008-01-24 5007 return NULL;
d1310b2e0 Chris Mason 2008-01-24 5008
727011e07 Chris Mason 2010-08-06 5009 for (i = 0; i < num_pages; i++, index++) {
d1b5c5671 Michal Hocko 2015-08-19 5010 p = find_or_create_page(mapping, index, GFP_NOFS|__GFP_NOFAIL);
4804b3829 Josef Bacik 2012-10-05 5011 if (!p)
6af118ce5 Chris Mason 2008-07-22 5012 goto free_eb;
4f2de97ac Josef Bacik 2012-03-07 5013
4f2de97ac Josef Bacik 2012-03-07 5014 spin_lock(&mapping->private_lock);
4f2de97ac Josef Bacik 2012-03-07 5015 if (PagePrivate(p)) {
4f2de97ac Josef Bacik 2012-03-07 5016 /*
4f2de97ac Josef Bacik 2012-03-07 5017 * We could have already allocated an eb for this page
4f2de97ac Josef Bacik 2012-03-07 5018 * and attached one so lets see if we can get a ref on
4f2de97ac Josef Bacik 2012-03-07 5019 * the existing eb, and if we can we know it's good and
4f2de97ac Josef Bacik 2012-03-07 5020 * we can just return that one, else we know we can just
4f2de97ac Josef Bacik 2012-03-07 5021 * overwrite page->private.
4f2de97ac Josef Bacik 2012-03-07 5022 */
4f2de97ac Josef Bacik 2012-03-07 5023 exists = (struct extent_buffer *)p->private;
e6fa7cb7e Chandan Rajendra 2016-04-17 5024 if (atomic_inc_not_zero(&eb_head(exists)->refs)) {
4f2de97ac Josef Bacik 2012-03-07 5025 spin_unlock(&mapping->private_lock);
4f2de97ac Josef Bacik 2012-03-07 5026 unlock_page(p);
09cbfeaf1 Kirill A. Shutemov 2016-04-01 5027 put_page(p);
e6fa7cb7e Chandan Rajendra 2016-04-17 5028 do {
e6fa7cb7e Chandan Rajendra 2016-04-17 5029 if (exists->start == start) {
2457aec63 Mel Gorman 2014-06-04 5030 mark_extent_buffer_accessed(exists, p);
4f2de97ac Josef Bacik 2012-03-07 5031 goto free_eb;
4f2de97ac Josef Bacik 2012-03-07 5032 }
e6fa7cb7e Chandan Rajendra 2016-04-17 5033 } while ((exists = exists->eb_next) != NULL);
e6fa7cb7e Chandan Rajendra 2016-04-17 5034
e6fa7cb7e Chandan Rajendra 2016-04-17 5035 BUG();
e6fa7cb7e Chandan Rajendra 2016-04-17 5036 }
5ca64f45e Omar Sandoval 2015-02-24 5037 exists = NULL;
4f2de97ac Josef Bacik 2012-03-07 5038
4f2de97ac Josef Bacik 2012-03-07 5039 /*
4f2de97ac Josef Bacik 2012-03-07 5040 * Do this so attach doesn't complain and we need to
4f2de97ac Josef Bacik 2012-03-07 5041 * drop the ref the old guy had.
4f2de97ac Josef Bacik 2012-03-07 5042 */
4f2de97ac Josef Bacik 2012-03-07 5043 ClearPagePrivate(p);
0b32f4bbb Josef Bacik 2012-03-13 5044 WARN_ON(PageDirty(p));
09cbfeaf1 Kirill A. Shutemov 2016-04-01 5045 put_page(p);
d1310b2e0 Chris Mason 2008-01-24 5046 }
e6fa7cb7e Chandan Rajendra 2016-04-17 5047 attach_extent_buffer_page(&(eb_head(eb)->eb), p);
4f2de97ac Josef Bacik 2012-03-07 5048 spin_unlock(&mapping->private_lock);
0b32f4bbb Josef Bacik 2012-03-13 5049 WARN_ON(PageDirty(p));
e6fa7cb7e Chandan Rajendra 2016-04-17 5050 mark_page_accessed(p);
e6fa7cb7e Chandan Rajendra 2016-04-17 5051 eb_head(eb)->pages[i] = p;
d1310b2e0 Chris Mason 2008-01-24 5052 if (!PageUptodate(p))
d1310b2e0 Chris Mason 2008-01-24 5053 uptodate = 0;
eb14ab8ed Chris Mason 2011-02-10 5054
eb14ab8ed Chris Mason 2011-02-10 5055 /*
eb14ab8ed Chris Mason 2011-02-10 5056 * see below about how we avoid a nasty race with release page
eb14ab8ed Chris Mason 2011-02-10 5057 * and why we unlock later
eb14ab8ed Chris Mason 2011-02-10 5058 */
d1310b2e0 Chris Mason 2008-01-24 5059 }
e6fa7cb7e Chandan Rajendra 2016-04-17 5060 if (uptodate) {
e6fa7cb7e Chandan Rajendra 2016-04-17 5061 cur_eb = &(eb_head(eb)->eb);
e6fa7cb7e Chandan Rajendra 2016-04-17 5062 do {
e6fa7cb7e Chandan Rajendra 2016-04-17 5063 set_bit(EXTENT_BUFFER_UPTODATE, &cur_eb->ebflags);
e6fa7cb7e Chandan Rajendra 2016-04-17 5064 } while ((cur_eb = cur_eb->eb_next) != NULL);
e6fa7cb7e Chandan Rajendra 2016-04-17 5065 }
115391d23 Josef Bacik 2012-03-09 5066 again:
19fe0a8b7 Miao Xie 2010-10-26 5067 ret = radix_tree_preload(GFP_NOFS & ~__GFP_HIGHMEM);
e6fa7cb7e Chandan Rajendra 2016-04-17 5068 if (ret) {
e6fa7cb7e Chandan Rajendra 2016-04-17 5069 exists = NULL;
19fe0a8b7 Miao Xie 2010-10-26 5070 goto free_eb;
e6fa7cb7e Chandan Rajendra 2016-04-17 5071 }
19fe0a8b7 Miao Xie 2010-10-26 5072
f28491e0a Josef Bacik 2013-12-16 5073 spin_lock(&fs_info->buffer_lock);
f28491e0a Josef Bacik 2013-12-16 5074 ret = radix_tree_insert(&fs_info->buffer_radix,
e6fa7cb7e Chandan Rajendra 2016-04-17 5075 start >> PAGE_SHIFT, eb_head(eb));
f28491e0a Josef Bacik 2013-12-16 5076 spin_unlock(&fs_info->buffer_lock);
19fe0a8b7 Miao Xie 2010-10-26 5077 radix_tree_preload_end();
452c75c3d Chandra Seetharaman 2013-10-07 5078 if (ret == -EEXIST) {
f28491e0a Josef Bacik 2013-12-16 5079 exists = find_extent_buffer(fs_info, start);
452c75c3d Chandra Seetharaman 2013-10-07 5080 if (exists)
6af118ce5 Chris Mason 2008-07-22 5081 goto free_eb;
452c75c3d Chandra Seetharaman 2013-10-07 5082 else
452c75c3d Chandra Seetharaman 2013-10-07 5083 goto again;
6af118ce5 Chris Mason 2008-07-22 5084 }
6af118ce5 Chris Mason 2008-07-22 5085 /* add one reference for the tree */
0b32f4bbb Josef Bacik 2012-03-13 5086 check_buffer_tree_ref(eb);
e6fa7cb7e Chandan Rajendra 2016-04-17 5087 set_bit(EXTENT_BUFFER_HEAD_IN_TREE, &eb_head(eb)->bflags);
eb14ab8ed Chris Mason 2011-02-10 5088
eb14ab8ed Chris Mason 2011-02-10 5089 /*
eb14ab8ed Chris Mason 2011-02-10 5090 * there is a race where release page may have
eb14ab8ed Chris Mason 2011-02-10 5091 * tried to find this extent buffer in the radix
eb14ab8ed Chris Mason 2011-02-10 5092 * but failed. It will tell the VM it is safe to
eb14ab8ed Chris Mason 2011-02-10 5093 * reclaim the, and it will clear the page private bit.
eb14ab8ed Chris Mason 2011-02-10 5094 * We must make sure to set the page private bit properly
eb14ab8ed Chris Mason 2011-02-10 5095 * after the extent buffer is in the radix tree so
eb14ab8ed Chris Mason 2011-02-10 5096 * it doesn't get lost
eb14ab8ed Chris Mason 2011-02-10 5097 */
e6fa7cb7e Chandan Rajendra 2016-04-17 5098 SetPageChecked(eb_head(eb)->pages[0]);
727011e07 Chris Mason 2010-08-06 5099 for (i = 1; i < num_pages; i++) {
e6fa7cb7e Chandan Rajendra 2016-04-17 5100 p = eb_head(eb)->pages[i];
727011e07 Chris Mason 2010-08-06 5101 ClearPageChecked(p);
727011e07 Chris Mason 2010-08-06 5102 unlock_page(p);
727011e07 Chris Mason 2010-08-06 5103 }
e6fa7cb7e Chandan Rajendra 2016-04-17 5104 unlock_page(eb_head(eb)->pages[0]);
d1310b2e0 Chris Mason 2008-01-24 5105 return eb;
d1310b2e0 Chris Mason 2008-01-24 5106
6af118ce5 Chris Mason 2008-07-22 5107 free_eb:
e6fa7cb7e Chandan Rajendra 2016-04-17 5108 WARN_ON(!atomic_dec_and_test(&eb_head(eb)->refs));
727011e07 Chris Mason 2010-08-06 5109 for (i = 0; i < num_pages; i++) {
e6fa7cb7e Chandan Rajendra 2016-04-17 5110 if (eb_head(eb)->pages[i])
e6fa7cb7e Chandan Rajendra 2016-04-17 5111 unlock_page(eb_head(eb)->pages[i]);
727011e07 Chris Mason 2010-08-06 5112 }
eb14ab8ed Chris Mason 2011-02-10 5113
897ca6e9b Miao Xie 2010-10-26 5114 btrfs_release_extent_buffer(eb);
6af118ce5 Chris Mason 2008-07-22 5115 return exists;
d1310b2e0 Chris Mason 2008-01-24 5116 }
d1310b2e0 Chris Mason 2008-01-24 5117
3083ee2e1 Josef Bacik 2012-03-09 5118 static inline void btrfs_release_extent_buffer_rcu(struct rcu_head *head)
3083ee2e1 Josef Bacik 2012-03-09 5119 {
e6fa7cb7e Chandan Rajendra 2016-04-17 5120 struct extent_buffer_head *ebh =
e6fa7cb7e Chandan Rajendra 2016-04-17 5121 container_of(head, struct extent_buffer_head, rcu_head);
3083ee2e1 Josef Bacik 2012-03-09 5122
e6fa7cb7e Chandan Rajendra 2016-04-17 5123 __free_extent_buffer(ebh);
3083ee2e1 Josef Bacik 2012-03-09 5124 }
3083ee2e1 Josef Bacik 2012-03-09 5125
3083ee2e1 Josef Bacik 2012-03-09 5126 /* Expects to have eb->eb_lock already held */
e6fa7cb7e Chandan Rajendra 2016-04-17 5127 static int release_extent_buffer(struct extent_buffer_head *ebh)
3083ee2e1 Josef Bacik 2012-03-09 5128 {
e6fa7cb7e Chandan Rajendra 2016-04-17 5129 WARN_ON(atomic_read(&ebh->refs) == 0);
e6fa7cb7e Chandan Rajendra 2016-04-17 5130 if (atomic_dec_and_test(&ebh->refs)) {
e6fa7cb7e Chandan Rajendra 2016-04-17 5131 if (test_and_clear_bit(EXTENT_BUFFER_HEAD_IN_TREE,
e6fa7cb7e Chandan Rajendra 2016-04-17 5132 &ebh->bflags)) {
e6fa7cb7e Chandan Rajendra 2016-04-17 5133 struct btrfs_fs_info *fs_info = ebh->fs_info;
3083ee2e1 Josef Bacik 2012-03-09 5134
e6fa7cb7e Chandan Rajendra 2016-04-17 5135 spin_unlock(&ebh->refs_lock);
3083ee2e1 Josef Bacik 2012-03-09 5136
f28491e0a Josef Bacik 2013-12-16 5137 spin_lock(&fs_info->buffer_lock);
f28491e0a Josef Bacik 2013-12-16 5138 radix_tree_delete(&fs_info->buffer_radix,
e6fa7cb7e Chandan Rajendra 2016-04-17 5139 ebh->eb.start >> PAGE_SHIFT);
f28491e0a Josef Bacik 2013-12-16 5140 spin_unlock(&fs_info->buffer_lock);
34b41acec Josef Bacik 2013-12-13 5141 } else {
e6fa7cb7e Chandan Rajendra 2016-04-17 5142 spin_unlock(&ebh->refs_lock);
815a51c74 Jan Schmidt 2012-05-16 5143 }
3083ee2e1 Josef Bacik 2012-03-09 5144
3083ee2e1 Josef Bacik 2012-03-09 5145 /* Should be safe to release our pages at this point */
e6fa7cb7e Chandan Rajendra 2016-04-17 5146 btrfs_release_extent_buffer_page(&ebh->eb);
bcb7e449e Josef Bacik 2015-03-16 5147 #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
e6fa7cb7e Chandan Rajendra 2016-04-17 5148 if (unlikely(test_bit(EXTENT_BUFFER_HEAD_DUMMY,
e6fa7cb7e Chandan Rajendra 2016-04-17 @5149 &eb_head(buf)->bflags))) {
e6fa7cb7e Chandan Rajendra 2016-04-17 @5150 __free_extent_buffer(eb_head(eb));
bcb7e449e Josef Bacik 2015-03-16 5151 return 1;
bcb7e449e Josef Bacik 2015-03-16 5152 }
bcb7e449e Josef Bacik 2015-03-16 5153 #endif:::::: The code at line 4953 was first introduced by commit
:::::: faa2dbf004e89e8f7ccd28fbe6f07c308417b8ae Btrfs: add sanity tests for new qgroup accounting code
:::::: TO: Josef Bacik <[email protected]> :::::: CC: Chris Mason <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH] Btrfs: subpage-blocksize: Define extent_buffer_head.
In reply to Chandan Rajendrareproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…
Hi Chandan,
[auto build test WARNING on tip/perf/core]
[also build test WARNING on v4.6-rc4 next-20160418]
[cannot apply to btrfs/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Chandan-Rajendra/Btrfs-subpage-blocksize-Define-extent_buffer_head/20160417-202933 config: ia64-allmodconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=ia64
All warnings (new ones prefixed by >>):
fs/btrfs/extent_io.c: In function 'alloc_test_extent_buffer':
fs/btrfs/extent_io.c:4953:4: error: 'struct extent_buffer' has no member named 'fs_info'
eb->fs_info = fs_info;
^
fs/btrfs/extent_io.c:4971:41: error: 'struct extent_buffer' has no member named 'bflags'
set_bit(EXTENT_BUFFER_HEAD_IN_TREE, &eb->bflags);
^
In file included from arch/ia64/include/asm/intrinsics.h:10:0,
from arch/ia64/include/asm/bitops.h:18,
from include/linux/bitops.h:36,
from fs/btrfs/extent_io.c:1:
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:60:24: note: in definition of macro 'ia64_fetchadd'
volatile __typeof__(*(v)) *_v = (v); \
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:60:35: note: in definition of macro 'ia64_fetchadd'
volatile __typeof__(*(v)) *_v = (v); \
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:43:10: note: in definition of macro 'IA64_FETCHADD'
switch (sz) { \
^
arch/ia64/include/uapi/asm/intrinsics.h:83:34: note: in expansion of macro 'ia64_fetchadd'
#define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:43:10: note: in definition of macro 'IA64_FETCHADD'
switch (sz) { \
^
arch/ia64/include/uapi/asm/intrinsics.h:83:34: note: in expansion of macro 'ia64_fetchadd'
#define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:43:10: note: in definition of macro 'IA64_FETCHADD'
switch (sz) { \
^
arch/ia64/include/uapi/asm/intrinsics.h:83:34: note: in expansion of macro 'ia64_fetchadd'
#define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:43:10: note: in definition of macro 'IA64_FETCHADD'
switch (sz) { \
^
arch/ia64/include/uapi/asm/intrinsics.h:83:34: note: in expansion of macro 'ia64_fetchadd'
#define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:43:10: note: in definition of macro 'IA64_FETCHADD'
switch (sz) { \
^
arch/ia64/include/uapi/asm/intrinsics.h:83:34: note: in expansion of macro 'ia64_fetchadd'
#define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:43:10: note: in definition of macro 'IA64_FETCHADD'
switch (sz) { \
^
arch/ia64/include/uapi/asm/intrinsics.h:83:34: note: in expansion of macro 'ia64_fetchadd'
#define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:43:10: note: in definition of macro 'IA64_FETCHADD'
switch (sz) { \
^
arch/ia64/include/uapi/asm/intrinsics.h:83:34: note: in expansion of macro 'ia64_fetchadd'
#define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:43:10: note: in definition of macro 'IA64_FETCHADD'
switch (sz) { \
^
arch/ia64/include/uapi/asm/intrinsics.h:83:34: note: in expansion of macro 'ia64_fetchadd'
#define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/uapi/asm/intrinsics.h:80:16: note: in definition of macro 'ia64_fetchadd'
(__typeof__(*(v))) (_tmp); /* return old value */ \
^
arch/ia64/include/asm/atomic.h:56:5: note: in expansion of macro 'ia64_fetch_and_add'
? ia64_fetch_and_add(__ia64_aar_i, &(v)->counter) \
^
arch/ia64/include/asm/atomic.h:202:33: note: in expansion of macro 'atomic_add_return'
#define atomic_add(i,v) (void)atomic_add_return((i), (v))
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
In file included from include/linux/atomic.h:4:0,
from arch/ia64/include/asm/processor.h:80,
from arch/ia64/include/asm/thread_info.h:11,
from include/linux/thread_info.h:54,
from include/asm-generic/preempt.h:4,
from arch/ia64/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:59,
from include/linux/spinlock.h:50,
from include/linux/mmzone.h:7,
from include/linux/gfp.h:5,
from include/linux/slab.h:14,
from fs/btrfs/extent_io.c:2:
fs/btrfs/extent_io.c:4979:16: error: 'struct extent_buffer' has no member named 'refs'
atomic_inc(&eb->refs);
^
arch/ia64/include/asm/atomic.h:57:35: note: in definition of macro 'atomic_add_return'
: ia64_atomic_add(__ia64_aar_i, v); \
^
arch/ia64/include/asm/atomic.h:204:25: note: in expansion of macro 'atomic_add'
#define atomic_inc(v) atomic_add(1, (v))
^
>> fs/btrfs/extent_io.c:4979:2: note: in expansion of macro 'atomic_inc'
atomic_inc(&eb->refs);
^
In file included from arch/ia64/include/asm/bitops.h:16:0,
from include/linux/bitops.h:36,
from fs/btrfs/extent_io.c:1:
fs/btrfs/extent_io.c: In function 'release_extent_buffer':
fs/btrfs/extent_io.c:5149:16: error: 'buf' undeclared (first use in this function)
&eb_head(buf)->bflags))) {
^
include/linux/compiler.h:170:42: note: in definition of macro 'unlikely'
# define unlikely(x) __builtin_expect(!!(x), 0)
^
fs/btrfs/extent_io.c:5149:16: note: each undeclared identifier is reported only once for each function it appears in
&eb_head(buf)->bflags))) {
^
include/linux/compiler.h:170:42: note: in definition of macro 'unlikely'
# define unlikely(x) __builtin_expect(!!(x), 0)
^
fs/btrfs/extent_io.c:5150:33: error: 'eb' undeclared (first use in this function)
__free_extent_buffer(eb_head(eb));
^vim +/atomic_inc +4979 fs/btrfs/extent_io.c
faa2dbf0 Josef Bacik 2014-05-07 4963 if (ret == -EEXIST) {
faa2dbf0 Josef Bacik 2014-05-07 4964 exists = find_extent_buffer(fs_info, start);
faa2dbf0 Josef Bacik 2014-05-07 4965 if (exists)
faa2dbf0 Josef Bacik 2014-05-07 4966 goto free_eb;
faa2dbf0 Josef Bacik 2014-05-07 4967 else
faa2dbf0 Josef Bacik 2014-05-07 4968 goto again;
faa2dbf0 Josef Bacik 2014-05-07 4969 }
faa2dbf0 Josef Bacik 2014-05-07 4970 check_buffer_tree_ref(eb);
e6fa7cb7 Chandan Rajendra 2016-04-17 4971 set_bit(EXTENT_BUFFER_HEAD_IN_TREE, &eb->bflags);
faa2dbf0 Josef Bacik 2014-05-07 4972
faa2dbf0 Josef Bacik 2014-05-07 4973 /*
faa2dbf0 Josef Bacik 2014-05-07 4974 * We will free dummy extent buffer's if they come into
faa2dbf0 Josef Bacik 2014-05-07 4975 * free_extent_buffer with a ref count of 2, but if we are using this we
faa2dbf0 Josef Bacik 2014-05-07 4976 * want the buffers to stay in memory until we're done with them, so
faa2dbf0 Josef Bacik 2014-05-07 4977 * bump the ref count again.
faa2dbf0 Josef Bacik 2014-05-07 4978 */
faa2dbf0 Josef Bacik 2014-05-07 @4979 atomic_inc(&eb->refs);
faa2dbf0 Josef Bacik 2014-05-07 4980 return eb;
faa2dbf0 Josef Bacik 2014-05-07 4981 free_eb:
faa2dbf0 Josef Bacik 2014-05-07 4982 btrfs_release_extent_buffer(eb);
faa2dbf0 Josef Bacik 2014-05-07 4983 return exists;
faa2dbf0 Josef Bacik 2014-05-07 4984 }
faa2dbf0 Josef Bacik 2014-05-07 4985 #endif
faa2dbf0 Josef Bacik 2014-05-07 4986
f28491e0 Josef Bacik 2013-12-16 4987 struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,:::::: The code at line 4979 was first introduced by commit
:::::: faa2dbf004e89e8f7ccd28fbe6f07c308417b8ae Btrfs: add sanity tests for new qgroup accounting code
:::::: TO: Josef Bacik <[email protected]>
:::::: CC: Chris Mason <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v17 5/18 Btrfs: subpage-blocksize: Read tree blocks whose size is < PAGE_CACHE_SIZE
In reply to Chandan RajendraIn the case of subpage-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 | 52 +++++++++------------ fs/btrfs/disk-io.h | 3 ++ fs/btrfs/extent_io.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 139 insertions(+), 40 deletions(-)
fs/btrfs/disk-io.c +20 -32
@@ -612,29 +612,36 @@ 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 address_space *mapping = (io_bio->bio).bi_io_vec->bv_page->mapping; +struct extent_buffer_head *ebh;struct extent_buffer *eb; -struct btrfs_root *root =BTRFS_I (page->mapping->host)->root; +struct btrfs_root *root =BTRFS_I (mapping->host)->root;struct btrfs_fs_info *fs_info = root->fs_info; -int ret =0 ; +u64 found_start; +int found_level;int reads_done; - -if (!page->private) - goto out; +int ret =0 ; eb = (struct extent_buffer *)page->private; +do { +if ((eb->start <= start) && (eb->start + eb->len -1 > start)) +break ; + }while ((eb = eb->eb_next) !=NULL ); + +ASSERT (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_head (eb)->io_bvecs); + reads_done =atomic_dec_and_test (&ebh->io_bvecs);if (!reads_done) goto err;
@@ -690,30 +697,13 @@ err:btree_readahead_hook (fs_info, eb, eb->start, ret);if (ret) { -/* -* our io error hook is going to dec the io pages -* again, we have to make sure it has something -* to decrement -*/ atomic_inc (&eb_head (eb)->io_bvecs);clear_extent_buffer_uptodate (eb); } -free_extent_buffer (eb); -out: -return ret; -} -static int btree_io_failed_hook (struct page *page,int failed_mirror) -{ -struct extent_buffer *eb; +free_extent_buffer (eb); - eb = (struct extent_buffer *)page->private; -set_bit (EXTENT_BUFFER_READ_ERR , &eb->ebflags); - eb->read_mirror = failed_mirror; -atomic_dec (&eb_head (eb)->io_bvecs); -if (test_and_clear_bit (EXTENT_BUFFER_READAHEAD , &eb->ebflags)) -btree_readahead_hook (eb_head (eb)->fs_info, eb, eb->start, -EIO ); -return -EIO ;/* we fixed nothing */ +return ret; }static void end_workqueue_bio (struct bio *bio)
@@ -4505,8 +4495,6 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root) }static const 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
@@ -113,6 +113,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 +116 -8
171 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v17 6/18 Btrfs: subpage-blocksize: Write only dirty extent buffers belonging to a page
In reply to Chandan RajendraFor the subpage-blocksize scenario, this patch adds the ability to write a single extent buffer to the disk.
--- fs/btrfs/disk-io.c | 32 +++--- fs/btrfs/extent_io.c | 277 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 242 insertions(+), 67 deletions(-)
fs/btrfs/disk-io.c +17 -15
@@ -504,28 +504,30 @@ static int btree_read_extent_buffer_pages(struct btrfs_root *root,static int csum_dirty_buffer (struct btrfs_fs_info *fs_info,struct page *page) { -u64 start =page_offset (page); -u64 found_start;struct extent_buffer *eb; +u64 found_start; +int ret; eb = (struct extent_buffer *)page->private;if (page !=eb_head (eb)->pages[0 ])return 0 ; - found_start =btrfs_header_bytenr (eb); -/* -* Please do not consolidate these warnings into a single if. -* It is useful to know what went wrong. -*/ -if (WARN_ON (found_start != start)) -return -EUCLEAN ; -if (WARN_ON (!PageUptodate (page))) -return -EUCLEAN ; - -ASSERT (memcmp_extent_buffer (eb, fs_info->fsid, -btrfs_header_fsid (),BTRFS_FSID_SIZE ) ==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 ; +ASSERT (memcmp_extent_buffer (eb, fs_info->fsid, +btrfs_header_fsid (),BTRFS_FSID_SIZE ) ==0 ); + ret =csum_tree_block (fs_info, eb,0 ); +if (ret) +return ret; + }while ((eb = eb->eb_next) !=NULL ); -return csum_tree_block (fs_info, eb,0 ); +return 0 ; } static int check_tree_block_fsid(struct btrfs_fs_info *fs_info,
fs/btrfs/extent_io.c +225 -52
394 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v17 7/18 Btrfs: subpage-blocksize: Allow mounting filesystems where sectorsize < PAGE_SIZE
In reply to Chandan RajendraThis patch allows mounting filesystems with sectorsize smaller than the PAGE_SIZE.
--- fs/btrfs/disk-io.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
fs/btrfs/disk-io.c +3 -7
@@ -4076,17 +4076,12 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,* Check sectorsize and nodesize first, other check will need it. * Check all possible sectorsize(4K, 8K, 16K, 32K, 64K) here. */ -if (!is_power_of_2 (sectorsize) || sectorsize <4096 || +if (!is_power_of_2 (sectorsize) || sectorsize <2048 || sectorsize >BTRFS_MAX_METADATA_BLOCKSIZE ) {printk (KERN_ERR "BTRFS: invalid sectorsize %llu\n" , sectorsize); ret = -EINVAL ; } -/* Only PAGE SIZE is supported yet */ -if (sectorsize !=PAGE_SIZE ) { -printk (KERN_ERR "BTRFS: sectorsize %llu not supported yet, only support %lu\n" , - sectorsize,PAGE_SIZE ); - ret = -EINVAL ; - } +if (!is_power_of_2 (nodesize) || nodesize < sectorsize || nodesize >BTRFS_MAX_METADATA_BLOCKSIZE ) {printk (KERN_ERR "BTRFS: invalid nodesize %llu\n" , nodesize);
@@ -4110,6 +4105,7 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, btrfs_super_chunk_root(sb)); ret = -EINVAL ; } +if (!IS_ALIGNED (btrfs_super_log_root (sb), sectorsize)) {printk (KERN_WARNING "BTRFS: log_root block unaligned: %llu\n" ,btrfs_super_log_root (sb));
Signature · 1 line
2.1.0
PATCH v17 8/18 Btrfs: subpage-blocksize: Deal with partial ordered extent allocations.
In reply to Chandan RajendraIn subpage-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 pages to be submitted.
--- fs/btrfs/extent_io.c | 27 ++++++++++++++------------- fs/btrfs/inode.c | 39 ++++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 26 deletions(-)
fs/btrfs/extent_io.c +14 -13
@@ -1851,17 +1851,23 @@ void 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) {put_page (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_SET_ERROR ) -SetPageError (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]);
@@ -2539,7 +2545,7 @@ void 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 ;
@@ -3357,7 +3363,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
@@ -3577,7 +3582,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_SIZE -1 ;int ret;int nr =0 ;size_t pg_offset =0 ;
@@ -3622,7 +3626,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,
@@ -3636,10 +3640,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/inode.c +26 -13
@@ -940,6 +940,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)) {
@@ -984,8 +986,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,
@@ -1038,7 +1038,7 @@ static noinline int cow_file_range(struct inode *inode, ret =btrfs_reloc_clone_csums (inode, start, cur_alloc_size);if (ret) - goto out_drop_extent_cache; + goto out_remove_ordered_extent; }if (disk_num_bytes < cur_alloc_size)
@@ -1051,13 +1051,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;
@@ -1066,16 +1065,30 @@ static noinline int cow_file_range(struct inode *inode, out:return ret; +out_remove_ordered_extent: + ordered =btrfs_lookup_ordered_extent (inode, start); +BUG_ON (!ordered); +btrfs_remove_ordered_extent (inode, ordered); +/* once for us */ +btrfs_put_ordered_extent (ordered); +/* once for the tree */ +btrfs_put_ordered_extent (ordered); + out_drop_extent_cache: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
PATCH v17 9/18 Btrfs: subpage-blocksize: Explicitly track I/O status of blocks of an ordered extent.
In reply to Chandan RajendraIn subpage-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 | 365 ++++++++++++++++++++++++++++++++++-------------- fs/btrfs/ordered-data.c | 19 +++ fs/btrfs/ordered-data.h | 4 + 5 files changed, 297 insertions(+), 115 deletions(-)
fs/btrfs/extent_io.c +10 -9
@@ -4569,11 +4569,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_SIZE -1 ;int ret =1 ; if (test_range_bit(tree, start, end,
@@ -4607,12 +4606,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_SIZE -1 ; +u64 orig_start = start; +u64 orig_end = end;if (gfpflags_allow_blocking (mask) && page->mapping->host->i_size >SZ_16M ) {
@@ -4646,7 +4645,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
@@ -273,8 +273,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_bits (struct extent_io_tree *tree,u64 start,u64 end,struct extent_state **cached);
fs/btrfs/inode.c +261 -104
444 lines not on this page · raw message
fs/btrfs/ordered-data.c +19 -0
@@ -190,12 +190,27 @@ 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; +u64 nr_blks; tree = &BTRFS_I (inode)->ordered_tree; entry =kmem_cache_zalloc (btrfs_ordered_extent_cache,GFP_NOFS );if (!entry)return -ENOMEM ; + nr_blks =BTRFS_BYTES_TO_BLKS (root->fs_info, len); + nr_longs =BITS_TO_LONGS (nr_blks); +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;
@@ -577,6 +592,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
@@ -139,6 +139,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
PATCH v17 10/18 Btrfs: subpage-blocksize: btrfs_punch_hole: Fix uptodate blocks check
In reply to Chandan RajendraIn case of subpage-blocksize, the file blocks to be punched may map only part of a page. For file blocks inside such pages, we need to check for the presence of BLK_STATE_UPTODATE flag.
--- fs/btrfs/file.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-)
fs/btrfs/file.c +65 -1
@@ -2321,6 +2321,8 @@ 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; +struct address_space *mapping = inode->i_mapping; +pgoff_t start_index, end_index;u64 lockstart;u64 lockend;u64 tail_start;
@@ -2333,6 +2335,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)int err =0 ;unsigned int rsv_count;bool same_block; +bool same_page;bool no_holes =btrfs_fs_incompat (root->fs_info,NO_HOLES );u64 ino_size;bool truncated_block = false;
@@ -2429,11 +2432,43 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) goto out_only_mutex; } + start_index = lockstart >>PAGE_CACHE_SHIFT ; + end_index = lockend >>PAGE_CACHE_SHIFT ; + + same_page = lockstart >>PAGE_CACHE_SHIFT + == lockend >>PAGE_CACHE_SHIFT ; +while (1 ) {struct btrfs_ordered_extent *ordered; +struct page *start_page =NULL ; +struct page *end_page =NULL ; +u64 nr_pages;truncate_pagecache_range (inode, lockstart, lockend); +if (lockstart & (PAGE_CACHE_SIZE -1 )) { + start_page =find_or_create_page (mapping, start_index, +GFP_NOFS ); +if (!start_page) { +mutex_unlock (&inode->i_mutex); +return -ENOMEM ; + } + } + +if (!same_page && ((lockend +1 ) & (PAGE_CACHE_SIZE -1 ))) { + end_page =find_or_create_page (mapping, end_index, +GFP_NOFS ); +if (!end_page) { +if (start_page) { +unlock_page (start_page); +page_cache_release (start_page); + } +mutex_unlock (&inode->i_mutex); +return -ENOMEM ; + } + } + +lock_extent_bits (&BTRFS_I (inode)->io_tree, lockstart, lockend, &cached_state); ordered =btrfs_lookup_first_ordered_extent (inode, lockend);
@@ -2443,18 +2478,47 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)* and nobody raced in and read a page in this range, if we did * we need to try again. */ + nr_pages =round_up (lockend,PAGE_CACHE_SIZE ) + -round_down (lockstart,PAGE_CACHE_SIZE ); + nr_pages >>=PAGE_CACHE_SHIFT ; +if ((!ordered || (ordered->file_offset + ordered->len <= lockstart || ordered->file_offset > lockend)) && - !btrfs_page_exists_in_range (inode, lockstart, lockend)) { + (!(start_page &&PagePrivate (start_page) && +test_page_blks_state (start_page,1 <<BLK_STATE_UPTODATE , + lockstart, +min (lockstart +PAGE_CACHE_SIZE -1 , lockend),0 )) && + !(end_page &&PagePrivate (end_page) && +test_page_blks_state (end_page,1 <<BLK_STATE_UPTODATE , +page_offset (end_page), lockend,0 )) && + !(nr_pages >2 &&btrfs_page_exists_in_range (inode, +round_up (lockstart,PAGE_CACHE_SIZE ), +round_down (lockend,PAGE_CACHE_SIZE ) -1 )))) {if (ordered)btrfs_put_ordered_extent (ordered); +if (end_page) { +unlock_page (end_page); +page_cache_release (end_page); + } +if (start_page) { +unlock_page (start_page); +page_cache_release (start_page); + }break ; }if (ordered)btrfs_put_ordered_extent (ordered);unlock_extent_cached (&BTRFS_I (inode)->io_tree, lockstart, lockend, &cached_state,GFP_NOFS ); +if (end_page) { +unlock_page (end_page); +page_cache_release (end_page); + } +if (start_page) { +unlock_page (start_page); +page_cache_release (start_page); + } ret =btrfs_wait_ordered_range (inode, lockstart, lockend - lockstart +1 );if (ret) {
Signature · 1 line
2.1.0
kbuild test robot
build botRe: [PATCH V17 10/18] Btrfs: subpage-blocksize: btrfs_punch_hole: Fix uptodate blocks check
reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…
Hi Chandan,
[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.6-rc3 next-20160414]
[cannot apply to btrfs/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Chandan-Rajendra/Allow-I-O-on-blocks-whose-size-is-less-than-page-size/20160414-214339 config: arm-allyesconfig (attached as .config)
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm
Note: the linux-review/Chandan-Rajendra/Allow-I-O-on-blocks-whose-size-is-less-than-page-size/20160414-214339 HEAD cb75f40d8b4d47c9133c24f3cc01b3eef831bf19 builds fine.
It only hurts bisectibility.
All error/warnings (new ones prefixed by >>):
fs/btrfs/file.c: In function 'btrfs_punch_hole':
>> fs/btrfs/file.c:2435:29: error: 'PAGE_CACHE_SHIFT' undeclared (first use in this function)
start_index = lockstart >> PAGE_CACHE_SHIFT;
^
fs/btrfs/file.c:2435:29: note: each undeclared identifier is reported only once for each function it appears in
>> fs/btrfs/file.c:2449:20: error: 'PAGE_CACHE_SIZE' undeclared (first use in this function)
if (lockstart & (PAGE_CACHE_SIZE - 1)) {
^
>> fs/btrfs/file.c:2464:6: error: implicit declaration of function 'page_cache_release' [-Werror=implicit-function-declaration]
page_cache_release(start_page);
^
In file included from include/linux/list.h:8:0,
from include/linux/wait.h:6,
from include/linux/fs.h:5,
from fs/btrfs/file.c:19:
include/linux/kernel.h:735:17: warning: comparison of distinct pointer types lacks a cast
(void) (&_min1 == &_min2); \
^
>> fs/btrfs/file.c:2491:5: note: in expansion of macro 'min'
min(lockstart + PAGE_CACHE_SIZE - 1, lockend), 0)) &&
^cc1: some warnings being treated as errors
vim +/PAGE_CACHE_SHIFT +2435 fs/btrfs/file.c
2429
2430 if (lockend < lockstart) {
2431 ret = 0;
2432 goto out_only_mutex;
2433 }
2434
> 2435 start_index = lockstart >> PAGE_CACHE_SHIFT;
2436 end_index = lockend >> PAGE_CACHE_SHIFT;
2437
2438 same_page = lockstart >> PAGE_CACHE_SHIFT
2439 == lockend >> PAGE_CACHE_SHIFT;
2440
2441 while (1) {
2442 struct btrfs_ordered_extent *ordered;
2443 struct page *start_page = NULL;
2444 struct page *end_page = NULL;
2445 u64 nr_pages;
2446
2447 truncate_pagecache_range(inode, lockstart, lockend);
2448
> 2449 if (lockstart & (PAGE_CACHE_SIZE - 1)) {
2450 start_page = find_or_create_page(mapping, start_index,
2451 GFP_NOFS);
2452 if (!start_page) {
2453 mutex_unlock(&inode->i_mutex);
2454 return -ENOMEM;
2455 }
2456 }
2457
2458 if (!same_page && ((lockend + 1) & (PAGE_CACHE_SIZE - 1))) {
2459 end_page = find_or_create_page(mapping, end_index,
2460 GFP_NOFS);
2461 if (!end_page) {
2462 if (start_page) {
2463 unlock_page(start_page);
> 2464 page_cache_release(start_page);
2465 }
2466 mutex_unlock(&inode->i_mutex);
2467 return -ENOMEM;
2468 }
2469 }
2470
2471
2472 lock_extent_bits(&BTRFS_I(inode)->io_tree, lockstart, lockend,
2473 &cached_state);
2474 ordered = btrfs_lookup_first_ordered_extent(inode, lockend);
2475
2476 /*
2477 * We need to make sure we have no ordered extents in this range
2478 * and nobody raced in and read a page in this range, if we did
2479 * we need to try again.
2480 */
2481 nr_pages = round_up(lockend, PAGE_CACHE_SIZE)
2482 - round_down(lockstart, PAGE_CACHE_SIZE);
2483 nr_pages >>= PAGE_CACHE_SHIFT;
2484
2485 if ((!ordered ||
2486 (ordered->file_offset + ordered->len <= lockstart ||
2487 ordered->file_offset > lockend)) &&
2488 (!(start_page && PagePrivate(start_page) &&
2489 test_page_blks_state(start_page, 1 << BLK_STATE_UPTODATE,
2490 lockstart,
> 2491 min(lockstart + PAGE_CACHE_SIZE - 1, lockend), 0)) && 2492 !(end_page && PagePrivate(end_page) &&
2493 test_page_blks_state(end_page, 1 << BLK_STATE_UPTODATE,
2494 page_offset(end_page), lockend, 0)) &&
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH 1/1 Btrfs: subpage-blocksize: btrfs_punch_hole: Fix uptodate blocks check
In reply to Chandan RajendraIn case of subpage-blocksize, the file blocks to be punched may map only part of a page. For file blocks inside such pages, we need to check for the presence of BLK_STATE_UPTODATE flag.
--- fs/btrfs/file.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-)
fs/btrfs/file.c +65 -1
@@ -2321,6 +2321,8 @@ 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; +struct address_space *mapping = inode->i_mapping; +pgoff_t start_index, end_index;u64 lockstart;u64 lockend;u64 tail_start;
@@ -2333,6 +2335,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)int err =0 ;unsigned int rsv_count;bool same_block; +bool same_page;bool no_holes =btrfs_fs_incompat (root->fs_info,NO_HOLES );u64 ino_size;bool truncated_block = false;
@@ -2429,11 +2432,43 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) goto out_only_mutex; } + start_index = lockstart >>PAGE_SHIFT ; + end_index = lockend >>PAGE_SHIFT ; + + same_page = lockstart >>PAGE_SHIFT + == lockend >>PAGE_SHIFT ; +while (1 ) {struct btrfs_ordered_extent *ordered; +struct page *start_page =NULL ; +struct page *end_page =NULL ; +u64 nr_pages;truncate_pagecache_range (inode, lockstart, lockend); +if (lockstart & (PAGE_SIZE -1 )) { + start_page =find_or_create_page (mapping, start_index, +GFP_NOFS ); +if (!start_page) { +mutex_unlock (&inode->i_mutex); +return -ENOMEM ; + } + } + +if (!same_page && ((lockend +1 ) & (PAGE_SIZE -1 ))) { + end_page =find_or_create_page (mapping, end_index, +GFP_NOFS ); +if (!end_page) { +if (start_page) { +unlock_page (start_page); +put_page (start_page); + } +mutex_unlock (&inode->i_mutex); +return -ENOMEM ; + } + } + +lock_extent_bits (&BTRFS_I (inode)->io_tree, lockstart, lockend, &cached_state); ordered =btrfs_lookup_first_ordered_extent (inode, lockend);
@@ -2443,18 +2478,47 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)* and nobody raced in and read a page in this range, if we did * we need to try again. */ + nr_pages =round_up (lockend,PAGE_SIZE ) + -round_down (lockstart,PAGE_SIZE ); + nr_pages >>=PAGE_SHIFT ; +if ((!ordered || (ordered->file_offset + ordered->len <= lockstart || ordered->file_offset > lockend)) && - !btrfs_page_exists_in_range (inode, lockstart, lockend)) { + (!(start_page &&PagePrivate (start_page) && +test_page_blks_state (start_page,1 <<BLK_STATE_UPTODATE , + lockstart, +min (lockstart +PAGE_SIZE -1 , lockend),0 )) && + !(end_page &&PagePrivate (end_page) && +test_page_blks_state (end_page,1 <<BLK_STATE_UPTODATE , +page_offset (end_page), lockend,0 )) && + !(nr_pages >2 &&btrfs_page_exists_in_range (inode, +round_up (lockstart,PAGE_SIZE ), +round_down (lockend,PAGE_SIZE ) -1 )))) {if (ordered)btrfs_put_ordered_extent (ordered); +if (end_page) { +unlock_page (end_page); +put_page (end_page); + } +if (start_page) { +unlock_page (start_page); +put_page (start_page); + }break ; }if (ordered)btrfs_put_ordered_extent (ordered);unlock_extent_cached (&BTRFS_I (inode)->io_tree, lockstart, lockend, &cached_state,GFP_NOFS ); +if (end_page) { +unlock_page (end_page); +put_page (end_page); + } +if (start_page) { +unlock_page (start_page); +put_page (start_page); + } ret =btrfs_wait_ordered_range (inode, lockstart, lockend - lockstart +1 );if (ret) {
Signature · 1 line
2.1.0
PATCH 1/1 Btrfs: subpage-blocksize: btrfs_punch_hole: Fix uptodate blocks check
In reply to Chandan RajendraIn case of subpage-blocksize, the file blocks to be punched may map only part of a page. For file blocks inside such pages, we need to check for the presence of BLK_STATE_UPTODATE flag.
--- fs/btrfs/file.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-)
fs/btrfs/file.c +65 -1
@@ -2321,6 +2321,8 @@ 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; +struct address_space *mapping = inode->i_mapping; +pgoff_t start_index, end_index;u64 lockstart;u64 lockend;u64 tail_start;
@@ -2333,6 +2335,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)int err =0 ;unsigned int rsv_count;bool same_block; +bool same_page;bool no_holes =btrfs_fs_incompat (root->fs_info,NO_HOLES );u64 ino_size;bool truncated_block = false;
@@ -2429,11 +2432,43 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) goto out_only_mutex; } + start_index = lockstart >>PAGE_SHIFT ; + end_index = lockend >>PAGE_SHIFT ; + + same_page = lockstart >>PAGE_SHIFT + == lockend >>PAGE_SHIFT ; +while (1 ) {struct btrfs_ordered_extent *ordered; +struct page *start_page =NULL ; +struct page *end_page =NULL ; +u64 nr_pages;truncate_pagecache_range (inode, lockstart, lockend); +if (lockstart & (PAGE_SIZE -1 )) { + start_page =find_or_create_page (mapping, start_index, +GFP_NOFS ); +if (!start_page) { +mutex_unlock (&inode->i_mutex); +return -ENOMEM ; + } + } + +if (!same_page && ((lockend +1 ) & (PAGE_SIZE -1 ))) { + end_page =find_or_create_page (mapping, end_index, +GFP_NOFS ); +if (!end_page) { +if (start_page) { +unlock_page (start_page); +put_page (start_page); + } +mutex_unlock (&inode->i_mutex); +return -ENOMEM ; + } + } + +lock_extent_bits (&BTRFS_I (inode)->io_tree, lockstart, lockend, &cached_state); ordered =btrfs_lookup_first_ordered_extent (inode, lockend);
@@ -2443,18 +2478,47 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)* and nobody raced in and read a page in this range, if we did * we need to try again. */ + nr_pages =round_up (lockend,PAGE_SIZE ) + -round_down (lockstart,PAGE_SIZE ); + nr_pages >>=PAGE_SHIFT ; +if ((!ordered || (ordered->file_offset + ordered->len <= lockstart || ordered->file_offset > lockend)) && - !btrfs_page_exists_in_range (inode, lockstart, lockend)) { + (!(start_page &&PagePrivate (start_page) && +test_page_blks_state (start_page,1 <<BLK_STATE_UPTODATE , + lockstart, +min (lockstart +PAGE_SIZE -1 , lockend),0 )) && + !(end_page &&PagePrivate (end_page) && +test_page_blks_state (end_page,1 <<BLK_STATE_UPTODATE , +page_offset (end_page), lockend,0 )) && + !(nr_pages >2 &&btrfs_page_exists_in_range (inode, +round_up (lockstart,PAGE_SIZE ), +round_down (lockend,PAGE_SIZE ) -1 )))) {if (ordered)btrfs_put_ordered_extent (ordered); +if (end_page) { +unlock_page (end_page); +put_page (end_page); + } +if (start_page) { +unlock_page (start_page); +put_page (start_page); + }break ; }if (ordered)btrfs_put_ordered_extent (ordered);unlock_extent_cached (&BTRFS_I (inode)->io_tree, lockstart, lockend, &cached_state,GFP_NOFS ); +if (end_page) { +unlock_page (end_page); +put_page (end_page); + } +if (start_page) { +unlock_page (start_page); +put_page (start_page); + } ret =btrfs_wait_ordered_range (inode, lockstart, lockend - lockstart +1 );if (ret) {
Signature · 1 line
2.1.0
kbuild test robot
build botRe: [PATCH] Btrfs: subpage-blocksize: btrfs_punch_hole: Fix uptodate blocks check
reproduce:
Hi Chandan,
[auto build test ERROR on btrfs/next]
[also build test ERROR on v4.6-rc3 next-20160415]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Chandan-Rajendra/Btrfs-subpage-blocksize-btrfs_punch_hole-Fix-uptodate-blocks-check/20160417-201821 base: https://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git next config: i386-randconfig-x008-04171808 (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
fs/btrfs/file.c: In function 'btrfs_punch_hole':
>> fs/btrfs/file.c:2473:4: error: implicit declaration of function 'test_page_blks_state' [-Werror=implicit-function-declaration]
test_page_blks_state(start_page, 1 << BLK_STATE_UPTODATE,
^
>> fs/btrfs/file.c:2473:42: error: 'BLK_STATE_UPTODATE' undeclared (first use in this function) test_page_blks_state(start_page, 1 << BLK_STATE_UPTODATE,
^
fs/btrfs/file.c:2473:42: note: each undeclared identifier is reported only once for each function it appears in
cc1: some warnings being treated as errors
vim +/test_page_blks_state +2473 fs/btrfs/file.c
2467 nr_pages >>= PAGE_SHIFT;
2468
2469 if ((!ordered ||
2470 (ordered->file_offset + ordered->len <= lockstart ||
2471 ordered->file_offset > lockend)) &&
2472 (!(start_page && PagePrivate(start_page) &&
> 2473 test_page_blks_state(start_page, 1 << BLK_STATE_UPTODATE,
2474 lockstart,
2475 min(lockstart + PAGE_SIZE - 1, lockend), 0)) &&
2476 !(end_page && PagePrivate(end_page) &&
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH] Btrfs: subpage-blocksize: btrfs_punch_hole: Fix uptodate blocks check
In reply to Chandan Rajendrareproduce:
Hi Chandan,
[auto build test ERROR on btrfs/next]
[also build test ERROR on v4.6-rc4 next-20160418]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Chandan-Rajendra/Btrfs-subpage-blocksize-btrfs_punch_hole-Fix-uptodate-blocks-check/20160417-202629 base: https://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs.git next config: x86_64-lkp (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
fs/btrfs/file.c: In function 'btrfs_punch_hole':
>> fs/btrfs/file.c:2473:4: error: implicit declaration of function 'test_page_blks_state' [-Werror=implicit-function-declaration]
test_page_blks_state(start_page, 1 << BLK_STATE_UPTODATE,
^
>> fs/btrfs/file.c:2473:42: error: 'BLK_STATE_UPTODATE' undeclared (first use in this function) test_page_blks_state(start_page, 1 << BLK_STATE_UPTODATE,
^
fs/btrfs/file.c:2473:42: note: each undeclared identifier is reported only once for each function it appears in
cc1: some warnings being treated as errors
vim +/test_page_blks_state +2473 fs/btrfs/file.c
2467 nr_pages >>= PAGE_SHIFT;
2468
2469 if ((!ordered ||
2470 (ordered->file_offset + ordered->len <= lockstart ||
2471 ordered->file_offset > lockend)) &&
2472 (!(start_page && PagePrivate(start_page) &&
> 2473 test_page_blks_state(start_page, 1 << BLK_STATE_UPTODATE,
2474 lockstart,
2475 min(lockstart + PAGE_SIZE - 1, lockend), 0)) &&
2476 !(end_page && PagePrivate(end_page) &&
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v17 11/18 Btrfs: subpage-blocksize: Prevent writes to an extent buffer when PG_writeback flag is set
In reply to Chandan RajendraIn non-subpage-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 subpage-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 | 21 ++++++- fs/btrfs/extent-tree.c | 11 ++++ fs/btrfs/extent_io.c | 150 ++++++++++++++++++++++++++++++++++++++++--------- fs/btrfs/extent_io.h | 1 + fs/btrfs/file.c | 34 +++++------ 5 files changed, 172 insertions(+), 45 deletions(-)
fs/btrfs/ctree.c +20 -1
@@ -1539,6 +1539,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;
@@ -1552,6 +1553,14 @@ 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_io (&ebh->bflags, +EXTENT_BUFFER_HEAD_WRITEBACK , +TASK_UNINTERRUPTIBLE ); + } *cow_ret = buf;return 0 ; }
@@ -2671,6 +2680,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;
@@ -2773,8 +2783,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_io (&ebh->bflags, +EXTENT_BUFFER_HEAD_WRITEBACK , +TASK_UNINTERRUPTIBLE ); + } goto cow_done; + }/* * must have write locks on this node and the
fs/btrfs/extent-tree.c +11 -0
@@ -7898,14 +7898,25 @@ static struct extent_buffer * btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 bytenr, int level) { + struct extent_buffer_head *ebh;struct extent_buffer *buf; buf =btrfs_find_create_tree_block (root, bytenr);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_io (&ebh->bflags,EXTENT_BUFFER_HEAD_WRITEBACK , +TASK_UNINTERRUPTIBLE ); + } +clean_tree_block (trans, root->fs_info, buf);clear_bit (EXTENT_BUFFER_STALE , &buf->ebflags);
fs/btrfs/extent_io.c +123 -27
299 lines not on this page · raw message
fs/btrfs/extent_io.h +1 -0
@@ -35,6 +35,7 @@#define EXTENT_BUFFER_HEAD_TREE_REF 0#define EXTENT_BUFFER_HEAD_DUMMY 1#define EXTENT_BUFFER_HEAD_IN_TREE 2 +#define EXTENT_BUFFER_HEAD_WRITEBACK 3/* these are bit numbers for test/set bit on extent buffer */ #define EXTENT_BUFFER_UPTODATE 0
fs/btrfs/file.c +17 -17
@@ -2432,11 +2432,11 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) goto out_only_mutex; } - start_index = lockstart >>PAGE_CACHE_SHIFT ; - end_index = lockend >>PAGE_CACHE_SHIFT ; + start_index = lockstart >>PAGE_SHIFT ; + end_index = lockend >>PAGE_SHIFT ; - same_page = lockstart >>PAGE_CACHE_SHIFT - == lockend >>PAGE_CACHE_SHIFT ; + same_page = lockstart >>PAGE_SHIFT + == lockend >>PAGE_SHIFT ;while (1 ) {struct btrfs_ordered_extent *ordered;
@@ -2446,7 +2446,7 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)truncate_pagecache_range (inode, lockstart, lockend); -if (lockstart & (PAGE_CACHE_SIZE -1 )) { +if (lockstart & (PAGE_SIZE -1 )) { start_page =find_or_create_page (mapping, start_index,GFP_NOFS );if (!start_page) {
@@ -2455,13 +2455,13 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) } } -if (!same_page && ((lockend +1 ) & (PAGE_CACHE_SIZE -1 ))) { +if (!same_page && ((lockend +1 ) & (PAGE_SIZE -1 ))) { end_page =find_or_create_page (mapping, end_index,GFP_NOFS );if (!end_page) {if (start_page) {unlock_page (start_page); -page_cache_release (start_page); +put_page (start_page); }mutex_unlock (&inode->i_mutex);return -ENOMEM ;
@@ -2478,9 +2478,9 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)* and nobody raced in and read a page in this range, if we did * we need to try again. */ - nr_pages =round_up (lockend,PAGE_CACHE_SIZE ) - -round_down (lockstart,PAGE_CACHE_SIZE ); - nr_pages >>=PAGE_CACHE_SHIFT ; + nr_pages =round_up (lockend,PAGE_SIZE ) + -round_down (lockstart,PAGE_SIZE ); + nr_pages >>=PAGE_SHIFT ; if ((!ordered || (ordered->file_offset + ordered->len <= lockstart ||
@@ -2488,22 +2488,22 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) (!(start_page &&PagePrivate (start_page) &&test_page_blks_state (start_page,1 <<BLK_STATE_UPTODATE , lockstart, -min (lockstart +PAGE_CACHE_SIZE -1 , lockend),0 )) && +min (lockstart +PAGE_SIZE -1 , lockend),0 )) && !(end_page &&PagePrivate (end_page) &&test_page_blks_state (end_page,1 <<BLK_STATE_UPTODATE ,page_offset (end_page), lockend,0 )) && !(nr_pages >2 &&btrfs_page_exists_in_range (inode, -round_up (lockstart,PAGE_CACHE_SIZE ), - round_down(lockend, PAGE_CACHE_SIZE) - 1)))) { +round_up (lockstart,PAGE_SIZE ), + round_down(lockend, PAGE_SIZE) - 1)))) { if (ordered)btrfs_put_ordered_extent (ordered);if (end_page) {unlock_page (end_page); -page_cache_release (end_page); +put_page (end_page); }if (start_page) {unlock_page (start_page); -page_cache_release (start_page); +put_page (start_page); }break ; }
@@ -2513,11 +2513,11 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len) lockend, &cached_state, GFP_NOFS);if (end_page) {unlock_page (end_page); -page_cache_release (end_page); +put_page (end_page); }if (start_page) {unlock_page (start_page); -page_cache_release (start_page); +put_page (start_page); } ret =btrfs_wait_ordered_range (inode, lockstart, lockend - lockstart +1 );
Signature · 1 line
2.1.0
PATCH 1/1 Btrfs: subpage-blocksize: Prevent writes to an extent buffer when PG_writeback flag is set
In non-subpage-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 subpage-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 | 21 ++++++- fs/btrfs/extent-tree.c | 11 ++++ fs/btrfs/extent_io.c | 150 ++++++++++++++++++++++++++++++++++++++++--------- fs/btrfs/extent_io.h | 1 + 4 files changed, 155 insertions(+), 28 deletions(-)
fs/btrfs/ctree.c +20 -1
@@ -1539,6 +1539,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;
@@ -1552,6 +1553,14 @@ 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_io (&ebh->bflags, +EXTENT_BUFFER_HEAD_WRITEBACK , +TASK_UNINTERRUPTIBLE ); + } *cow_ret = buf;return 0 ; }
@@ -2671,6 +2680,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;
@@ -2773,8 +2783,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_io (&ebh->bflags, +EXTENT_BUFFER_HEAD_WRITEBACK , +TASK_UNINTERRUPTIBLE ); + } goto cow_done; + }/* * must have write locks on this node and the
fs/btrfs/extent-tree.c +11 -0
@@ -7898,14 +7898,25 @@ static struct extent_buffer * btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 bytenr, int level) { + struct extent_buffer_head *ebh;struct extent_buffer *buf; buf =btrfs_find_create_tree_block (root, bytenr);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_io (&ebh->bflags,EXTENT_BUFFER_HEAD_WRITEBACK , +TASK_UNINTERRUPTIBLE ); + } +clean_tree_block (trans, root->fs_info, buf);clear_bit (EXTENT_BUFFER_STALE , &buf->ebflags);
fs/btrfs/extent_io.c +123 -27
299 lines not on this page · raw message
fs/btrfs/extent_io.h +1 -0
@@ -35,6 +35,7 @@#define EXTENT_BUFFER_HEAD_TREE_REF 0#define EXTENT_BUFFER_HEAD_DUMMY 1#define EXTENT_BUFFER_HEAD_IN_TREE 2 +#define EXTENT_BUFFER_HEAD_WRITEBACK 3/* these are bit numbers for test/set bit on extent buffer */ #define EXTENT_BUFFER_UPTODATE 0
Signature · 1 line
2.1.0
PATCH v17 12/18 Revert "btrfs: fix lockups from btrfs_clear_path_blocking"
In reply to Chandan RajendraThe patch "Btrfs: subpage-blocksize: Prevent writes to an extent buffer when PG_writeback flag is set" requires btrfs_try_tree_write_lock() to be a true try lock w.r.t to both spinning and blocking locks. During 2015's Vault Conference Btrfs meetup, Chris Mason had suggested that he will write up a suitable locking function to be used when writing dirty pages that map metadata blocks. Until we have a suitable locking function available, this patch temporarily disables the commit f82c458a2c3ffb94b431fc6ad791a79df1b3713e.
--- fs/btrfs/ctree.c | 14 ++++++++++++-- fs/btrfs/locking.c | 24 +++--------------------- fs/btrfs/locking.h | 2 -- 3 files changed, 15 insertions(+), 25 deletions(-)
fs/btrfs/ctree.c +12 -2
@@ -81,6 +81,13 @@ noinline void btrfs_clear_path_blocking(struct btrfs_path *p, {int i; +#ifdef CONFIG_DEBUG_LOCK_ALLOC +/* lockdep really cares that we take all of these spinlocks +* in the right order. If any of the locks in the path are not +* currently blocking, it is going to complain. So, make really +* really sure by forcing the path to blocking before we clear +* the path blocking. +*/ if (held) {btrfs_set_lock_blocking_rw (held, held_rw);if (held_rw ==BTRFS_WRITE_LOCK )
@@ -89,6 +96,7 @@ noinline void btrfs_clear_path_blocking(struct btrfs_path *p, held_rw = BTRFS_READ_LOCK_BLOCKING; }btrfs_set_path_blocking (p); +#endif for (i =BTRFS_MAX_LEVEL -1 ; i >=0 ; i--) {if (p->nodes[i] && p->locks[i]) {
@@ -100,8 +108,10 @@ noinline void btrfs_clear_path_blocking(struct btrfs_path *p, } } +#ifdef CONFIG_DEBUG_LOCK_ALLOC if (held)btrfs_clear_lock_blocking_rw (held, held_rw); +#endif }/* this also releases the path */
@@ -2904,7 +2914,7 @@ cow_done: } p->locks[level] =BTRFS_WRITE_LOCK ; }else { - err =btrfs_tree_read_lock_atomic (b); + err =btrfs_try_tree_read_lock (b);if (!err) {btrfs_set_path_blocking (p);btrfs_tree_read_lock (b);
@@ -3036,7 +3046,7 @@ again: } level =btrfs_header_level (b); - err =btrfs_tree_read_lock_atomic (b); + err =btrfs_try_tree_read_lock (b);if (!err) {btrfs_set_path_blocking (p);btrfs_tree_read_lock (b);
fs/btrfs/locking.c +3 -21
@@ -132,26 +132,6 @@ again: }/* -* take a spinning read lock. -* returns 1 if we get the read lock and 0 if we don't -* this won't wait for blocking writers -*/ -int btrfs_tree_read_lock_atomic (struct extent_buffer *eb) -{ -if (atomic_read (&eb->blocking_writers)) -return 0 ; - -read_lock (&eb->lock); -if (atomic_read (&eb->blocking_writers)) { -read_unlock (&eb->lock); -return 0 ; - } -atomic_inc (&eb->read_locks); -atomic_inc (&eb->spinning_readers); -return 1 ; -} - -/* * returns 1 if we get the read lock and 0 if we don't * this won't wait for blocking writers */
@@ -182,7 +162,9 @@ int btrfs_try_tree_write_lock(struct extent_buffer *eb) atomic_read(&eb->blocking_readers))return 0 ; -write_lock (&eb->lock); +if (!write_trylock (&eb->lock)) +return 0 ; +if (atomic_read (&eb->blocking_writers) ||atomic_read (&eb->blocking_readers)) {write_unlock (&eb->lock);
fs/btrfs/locking.h +0 -2
@@ -35,8 +35,6 @@ void btrfs_clear_lock_blocking_rw(struct extent_buffer *eb, int rw);void btrfs_assert_tree_locked (struct extent_buffer *eb);int btrfs_try_tree_read_lock (struct extent_buffer *eb);int btrfs_try_tree_write_lock (struct extent_buffer *eb); -int btrfs_tree_read_lock_atomic (struct extent_buffer *eb); -static inline void btrfs_tree_unlock_rw (struct extent_buffer *eb,int rw) {
Signature · 1 line
2.1.0
PATCH v17 13/18 Btrfs: subpage-blocksize: Fix file defragmentation code
In reply to Chandan RajendraThis commit gets file defragmentation code to work in subpage-blocksize scenario. It does this by keeping track of page offsets that mark block boundaries and passing them as arguments to the functions that implement the defragmentation logic.
--- fs/btrfs/ioctl.c | 193 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 132 insertions(+), 61 deletions(-)
fs/btrfs/ioctl.c +132 -61
@@ -893,12 +893,13 @@ out_unlock:static int check_defrag_in_cache (struct inode *inode,u64 offset,u32 thresh) {struct extent_io_tree *io_tree = &BTRFS_I (inode)->io_tree; +struct btrfs_root *root =BTRFS_I (inode)->root;struct extent_map *em =NULL ;struct extent_map_tree *em_tree = &BTRFS_I (inode)->extent_tree;u64 end;read_lock (&em_tree->lock); - em =lookup_extent_mapping (em_tree, offset,PAGE_SIZE ); + em =lookup_extent_mapping (em_tree, offset, root->sectorsize);read_unlock (&em_tree->lock);if (em) {
@@ -988,7 +989,7 @@ static struct extent_map *defrag_lookup_extent(struct inode *inode, u64 start)struct extent_map_tree *em_tree = &BTRFS_I (inode)->extent_tree;struct extent_io_tree *io_tree = &BTRFS_I (inode)->io_tree;struct extent_map *em; -u64 len =PAGE_SIZE ; +u64 len =BTRFS_I (inode)->root->sectorsize;/* * hopefully we have this extent in the tree already, try without
@@ -1107,15 +1108,18 @@ out:* before calling this. */ static int cluster_pages_for_defrag (struct inode *inode, -struct page **pages, -unsigned long start_index, -unsigned long num_pages) +struct page **pages, +unsigned long start_index, +size_t pg_offset, +unsigned long num_blks) { -unsigned long file_end;u64 isize =i_size_read (inode); +u64 start_blk; +u64 end_blk;u64 page_start;u64 page_end;u64 page_cnt; +u64 blk_cnt;int ret;int i;int i_done;
@@ -1124,20 +1128,25 @@ static int cluster_pages_for_defrag(struct inode *inode,struct extent_io_tree *tree;gfp_t mask =btrfs_alloc_write_mask (inode->i_mapping); - file_end = (isize -1 ) >>PAGE_SHIFT ; -if (!isize || start_index > file_end) + start_blk = (start_index <<PAGE_SHIFT ) + pg_offset; + start_blk >>= inode->i_blkbits; + end_blk = (isize -1 ) >> inode->i_blkbits; +if (!isize || start_blk > end_blk)return 0 ; - page_cnt =min_t (u64, (u64 )num_pages, (u64 )file_end - start_index +1 ); + blk_cnt =min_t (u64, (u64 )num_blks, (u64 )end_blk - start_blk +1 ); ret =btrfs_delalloc_reserve_space (inode, - start_index <<PAGE_SHIFT , - page_cnt <<PAGE_SHIFT ); + start_blk << inode->i_blkbits, + blk_cnt << inode->i_blkbits);if (ret)return ret; i_done =0 ; tree = &BTRFS_I (inode)->io_tree; + page_cnt =DIV_ROUND_UP (pg_offset + (blk_cnt << inode->i_blkbits), +PAGE_SIZE ); +/* step one, lock all the pages */ for (i =0 ; i < page_cnt; i++) {struct page *page;
@@ -1148,12 +1157,22 @@ again:break ; page_start =page_offset (page); - page_end = page_start +PAGE_SIZE -1 ; + +if (i ==0 ) + page_start += pg_offset; + +if (i == page_cnt -1 ) { + page_end = (start_index <<PAGE_SHIFT ) + pg_offset; + page_end += (blk_cnt << inode->i_blkbits) -1 ; + }else { + page_end =page_offset (page) +PAGE_SIZE -1 ; + } +while (1 ) {lock_extent_bits (tree, page_start, page_end, &cached_state); - ordered =btrfs_lookup_ordered_extent (inode, - page_start); + ordered =btrfs_lookup_ordered_range (inode, page_start, + page_end - page_start +1 );unlock_extent_cached (tree, page_start, page_end, &cached_state,GFP_NOFS );if (!ordered)
@@ -1192,7 +1211,7 @@ again: } pages[i] = page; - i_done++; + i_done += (page_end - page_start +1 ) >> inode->i_blkbits; }if (!i_done || ret) goto out;
@@ -1204,55 +1223,76 @@ again:* so now we have a nice long stream of locked * and up to date pages, lets wait on them */ -for (i =0 ; i < i_done; i++) + page_cnt =DIV_ROUND_UP (pg_offset + (i_done << inode->i_blkbits), +PAGE_SIZE ); +for (i =0 ; i < page_cnt; i++)wait_on_page_writeback (pages[i]); - page_start =page_offset (pages[0 ]); - page_end =page_offset (pages[i_done -1 ]) +PAGE_SIZE ; + page_start =page_offset (pages[0 ]) + pg_offset; + page_end = page_start + (i_done << inode->i_blkbits) -1 ;lock_extent_bits (&BTRFS_I (inode)->io_tree, - page_start, page_end -1 , &cached_state); + page_start, page_end, &cached_state);clear_extent_bit (&BTRFS_I (inode)->io_tree, page_start, - page_end -1 ,EXTENT_DIRTY |EXTENT_DELALLOC | + page_end,EXTENT_DIRTY |EXTENT_DELALLOC |EXTENT_DO_ACCOUNTING |EXTENT_DEFRAG ,0 ,0 , &cached_state,GFP_NOFS ); -if (i_done != page_cnt) { +if (i_done != blk_cnt) {spin_lock (&BTRFS_I (inode)->lock);BTRFS_I (inode)->outstanding_extents++;spin_unlock (&BTRFS_I (inode)->lock);btrfs_delalloc_release_space (inode, - start_index <<PAGE_SHIFT , - (page_cnt - i_done) <<PAGE_SHIFT ); + start_blk << inode->i_blkbits, + (blk_cnt - i_done) << inode->i_blkbits); } -set_extent_defrag (&BTRFS_I (inode)->io_tree, page_start, page_end -1 , +set_extent_defrag (&BTRFS_I (inode)->io_tree, page_start, page_end, &cached_state,GFP_NOFS );unlock_extent_cached (&BTRFS_I (inode)->io_tree, - page_start, page_end -1 , &cached_state, + page_start, page_end, &cached_state,GFP_NOFS ); -for (i =0 ; i < i_done; i++) { +for (i =0 ; i < page_cnt; i++) {clear_page_dirty_for_io (pages[i]);ClearPageChecked (pages[i]);set_page_extent_mapped (pages[i]); + + page_start =page_offset (pages[i]); +if (i ==0 ) + page_start += pg_offset; + +if (i == page_cnt -1 ) { + page_end =page_offset (pages[0 ]) + pg_offset; + page_end += (i_done << inode->i_blkbits) -1 ; + }else { + page_end =page_offset (pages[i]) +PAGE_SIZE -1 ; + } + +set_page_blks_state (pages[i], +1 <<BLK_STATE_UPTODATE |1 <<BLK_STATE_DIRTY , + page_start, page_end);set_page_dirty (pages[i]);unlock_page (pages[i]);put_page (pages[i]); }return i_done; out: -for (i =0 ; i < i_done; i++) { -unlock_page (pages[i]); -put_page (pages[i]); +if (i_done) { + page_cnt =DIV_ROUND_UP (pg_offset + (i_done << inode->i_blkbits), +PAGE_SIZE ); +for (i =0 ; i < page_cnt; i++) { +unlock_page (pages[i]); +put_page (pages[i]); + } } +btrfs_delalloc_release_space (inode, - start_index <<PAGE_SHIFT , - page_cnt <<PAGE_SHIFT ); + start_blk << inode->i_blkbits, + blk_cnt << inode->i_blkbits);return ret; - } int btrfs_defrag_file(struct inode *inode, struct file *file,
@@ -1261,19 +1301,24 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, {struct btrfs_root *root =BTRFS_I (inode)->root;struct file_ra_state *ra =NULL ; +unsigned long first_off, last_off; +unsigned long first_block, last_block;unsigned long last_index;u64 isize =i_size_read (inode);u64 last_len =0 ;u64 skip =0 ;u64 defrag_end =0 ;u64 newer_off = range->start; +u64 start; +u64 page_cnt;unsigned long i;unsigned long ra_index =0 ; +size_t pg_offset;int ret;int defrag_count =0 ;int compress_type =BTRFS_COMPRESS_ZLIB ;u32 extent_thresh = range->extent_thresh; -unsigned long max_cluster =SZ_256K >>PAGE_SHIFT ; +unsigned long max_cluster =SZ_256K >> inode->i_blkbits;unsigned long cluster = max_cluster;u64 new_align = ~((u64 )SZ_128K -1 );struct page **pages =NULL ;
@@ -1307,8 +1352,14 @@ int btrfs_defrag_file(struct inode *inode, struct file *file, ra = &file->f_ra; } - pages =kmalloc_array (max_cluster,sizeof (struct page *), -GFP_NOFS ); +/* +* In subpage-blocksize scenario the first of "max_cluster" blocks +* may start on a non-zero page offset. In such scenarios we need one +* page more than what would be needed in the case where the first block +* maps to first block of a page. +*/ + page_cnt = (max_cluster >> (PAGE_SHIFT - inode->i_blkbits)) +1 ; + pages =kmalloc_array (page_cnt,sizeof (struct page *),GFP_NOFS );if (!pages) { ret = -ENOMEM ; goto out_ra;
@@ -1316,12 +1367,15 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,/* find the last page to defrag */ if (range->start + range->len > range->start) { - last_index =min_t (u64, isize -1 , - range->start + range->len -1 ) >>PAGE_SHIFT ; + last_off =min_t (u64, isize -1 , range->start + range->len -1 ); }else { - last_index = (isize -1 ) >>PAGE_SHIFT ; + last_off = isize -1 ; } + last_off =round_up (last_off, root->sectorsize) -1 ; + last_block = last_off >> inode->i_blkbits; + last_index = last_off >>PAGE_SHIFT ; +if (newer_than) { ret =find_new_extents (root, inode, newer_than, &newer_off,SZ_64K );
@@ -1331,14 +1385,20 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,* we always align our defrag to help keep * the extents in the file evenly spaced */ - i = (newer_off & new_align) >>PAGE_SHIFT ; + first_off = newer_off & new_align; }else goto out_ra; }else { - i = range->start >>PAGE_SHIFT ; + first_off = range->start; } + + first_off =round_down (first_off, root->sectorsize); + first_block = first_off >> inode->i_blkbits; + i = first_off >>PAGE_SHIFT ; + pg_offset = first_off & (PAGE_SIZE -1 ); +if (!max_to_defrag) - max_to_defrag = last_index - i +1 ; + max_to_defrag = last_block - first_block +1 ;/* * make writeback starts from i, so the defrag range can be
@@ -1362,39 +1422,50 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,break ; } -if (!should_defrag_range (inode, (u64 )i <<PAGE_SHIFT , - extent_thresh, &last_len, &skip, - &defrag_end, range->flags & -BTRFS_DEFRAG_RANGE_COMPRESS )) { + start = pg_offset + ((u64 )i <<PAGE_SHIFT ); +if (!should_defrag_range (inode, start, + extent_thresh, &last_len, &skip, + &defrag_end, range->flags & +BTRFS_DEFRAG_RANGE_COMPRESS )) {unsigned long next;/* * the should_defrag function tells us how much to skip * bump our counter by the suggested amount */ - next =DIV_ROUND_UP (skip,PAGE_SIZE ); - i =max (i +1 , next); + next =max (skip, start + root->sectorsize); + next >>= inode->i_blkbits; + + first_off = next << inode->i_blkbits; + i = first_off >>PAGE_SHIFT ; + pg_offset = first_off & (PAGE_SIZE -1 );continue ; }if (!newer_than) { - cluster = (PAGE_ALIGN (defrag_end) >> -PAGE_SHIFT ) - i; + cluster = (defrag_end >> inode->i_blkbits) + - (start >> inode->i_blkbits); + cluster =min (cluster, max_cluster); }else { cluster = max_cluster; } -if (i + cluster > ra_index) { + page_cnt = pg_offset + (cluster << inode->i_blkbits) -1 ; + page_cnt =DIV_ROUND_UP (page_cnt,PAGE_SIZE ); +if (i + page_cnt > ra_index) { ra_index =max (i, ra_index);btrfs_force_ra (inode->i_mapping, ra, file, ra_index, - cluster); - ra_index += cluster; + page_cnt); + ra_index +=DIV_ROUND_UP (pg_offset + + (cluster << inode->i_blkbits), +PAGE_SIZE ); }inode_lock (inode);if (range->flags &BTRFS_DEFRAG_RANGE_COMPRESS )BTRFS_I (inode)->force_compress = compress_type; - ret =cluster_pages_for_defrag (inode, pages, i, cluster); + ret =cluster_pages_for_defrag (inode, pages, i, pg_offset, + cluster);if (ret <0 ) {inode_unlock (inode); goto out_ra;
@@ -1408,29 +1479,29 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,if (newer_off == (u64)-1 )break ; -if (ret >0 ) - i += ret; - newer_off =max (newer_off +1 , - (u64 )i <<PAGE_SHIFT ); + start + (ret << inode->i_blkbits)); ret =find_new_extents (root, inode, newer_than, &newer_off,SZ_64K );if (!ret) { range->start = newer_off; - i = (newer_off & new_align) >>PAGE_SHIFT ; + first_off = newer_off & new_align; }else {break ; } }else {if (ret >0 ) { - i += ret; - last_len += ret <<PAGE_SHIFT ; + first_off = start + (ret << inode->i_blkbits); + last_len += ret << inode->i_blkbits; }else { - i++; + first_off = start + root->sectorsize; last_len =0 ; } } + first_off =round_down (first_off, root->sectorsize); + i = first_off >>PAGE_SHIFT ; + pg_offset = first_off & (PAGE_SIZE -1 ); }if ((range->flags &BTRFS_DEFRAG_RANGE_START_IO )) {
Signature · 1 line
2.1.0
PATCH v17 14/18 Btrfs: subpage-blocksize: extent_clear_unlock_delalloc: Prevent page from being unlocked more than once
In reply to Chandan Rajendraextent_clear_unlock_delalloc() can unlock a page more than once as shown below (assume 4k as the block size and 64k as the page size).
cow_file_range
create 4k ordered extent corresponding to page offsets 0 - 4095 extent_clear_unlock_delalloc corresponding to page offsets 0 - 4095
unlock page
create 4k ordered extent corresponding to page offsets 4096 - 8191 extent_clear_unlock_delalloc corresponding to page offsets 4096 - 8191
unlock page
To prevent such a scenario this commit passes "delalloc end" to extent_clear_unlock_delalloc() to help decide whether the page can be unlocked or not.
NOTE: Since extent_clear_unlock_delalloc() is used by compression code as well, the commit passes ordered extent "end" as the value for the argument corresponding to "delalloc end" for invocations made from compression code path. This will be fixed by a future commit that gets compression to work in subpage-blocksize scenario.
--- fs/btrfs/extent_io.c | 16 ++++++---- fs/btrfs/extent_io.h | 5 ++-- fs/btrfs/inode.c | 84 ++++++++++++++++++++++++++++++---------------------- 3 files changed, 61 insertions(+), 44 deletions(-)
fs/btrfs/extent_io.c +11 -5
@@ -1823,9 +1823,8 @@ out_failed: }void extent_clear_unlock_delalloc (struct inode *inode,u64 start,u64 end, -struct page *locked_page, -unsigned clear_bits, -unsigned long page_ops) +u64 delalloc_end,struct page *locked_page, +unsigned clear_bits,unsigned long page_ops) {struct extent_io_tree *tree = &BTRFS_I (inode)->io_tree;int ret;
@@ -1833,6 +1832,7 @@ void extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,unsigned long index = start >>PAGE_SHIFT ;unsigned long end_index = end >>PAGE_SHIFT ;unsigned long nr_pages = end_index - index +1 ; +u64 page_end;int i;clear_extent_bit (tree, start, end, clear_bits,1 ,0 ,NULL ,GFP_NOFS );
@@ -1869,8 +1869,14 @@ void extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end,if ((page_ops &PAGE_END_WRITEBACK ) && !PagePrivate2 (pages[i]))end_page_writeback (pages[i]); -if (page_ops &PAGE_UNLOCK ) -unlock_page (pages[i]); + +if (page_ops &PAGE_UNLOCK ) { + page_end =page_offset (pages[i]) + +PAGE_SIZE -1 ; +if ((page_end <= end) + || (end == delalloc_end)) +unlock_page (pages[i]); + }put_page (pages[i]); } nr_pages -= ret;
fs/btrfs/extent_io.h +2 -3
@@ -499,9 +499,8 @@ int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,void extent_range_clear_dirty_for_io (struct inode *inode,u64 start,u64 end);void extent_range_redirty_for_io (struct inode *inode,u64 start,u64 end);void extent_clear_unlock_delalloc (struct inode *inode,u64 start,u64 end, -struct page *locked_page, -unsigned bits_to_clear, -unsigned long page_ops); +u64 delalloc_end,struct page *locked_page, +unsigned bits_to_clear,unsigned long page_ops);struct bio *btrfs_bio_alloc (struct block_device *bdev,u64 first_sector,int nr_vecs,gfp_t gfp_flags);
fs/btrfs/inode.c +48 -36
192 lines not on this page · raw message
Signature · 1 line
2.1.0
PATCH v17 15/18 Btrfs: subpage-blocksize: Enable dedupe ioctl
In reply to Chandan RajendraThe function implementing the dedupe ioctl
i.e. btrfs_ioctl_file_extent_same(), returns with an error in subpage-blocksize scenario. This was done due to the fact that Btrfs did not have code to deal with block size < page size. This commit removes this restriction since we now support "block size < page size".
--- fs/btrfs/ioctl.c | 10 ---------- 1 file changed, 10 deletions(-)
fs/btrfs/ioctl.c +0 -10
@@ -3256,21 +3256,11 @@ ssize_t btrfs_dedupe_file_range(struct file *src_file, u64 loff, u64 olen, {struct inode *src =file_inode (src_file);struct inode *dst =file_inode (dst_file); -u64 bs =BTRFS_I (src)->root->fs_info->sb->s_blocksize;ssize_t res;if (olen >BTRFS_MAX_DEDUPE_LEN ) olen =BTRFS_MAX_DEDUPE_LEN ; -if (WARN_ON_ONCE (bs <PAGE_SIZE )) { -/* -* Btrfs does not support blocksize < page_size. As a -* result, btrfs_cmp_data() won't correctly handle -* this situation without an update. -*/ -return -EINVAL ; - } - res =btrfs_extent_same (src, loff, olen, dst, dst_loff);if (res)return res;
Signature · 1 line
2.1.0
PATCH v17 16/18 Btrfs: btrfs_clone: Flush dirty blocks of a page that do not map the clone range
In reply to Chandan RajendraAfter cloning the required extents, we truncate all the pages that map the file range being cloned. In subpage-blocksize scenario, we could have dirty blocks before and/or after the clone range in the leading/trailing pages. Truncating these pages would lead to data loss. Hence this commit forces such dirty blocks to be flushed to disk before performing the clone operation.
--- fs/btrfs/ioctl.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
fs/btrfs/ioctl.c +16 -0
@@ -3849,6 +3849,7 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,int ret;u64 len = olen;u64 bs = root->fs_info->sb->s_blocksize; +u64 dest_end;int same_inode = src == inode;/*
@@ -3909,6 +3910,21 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src, goto out_unlock; } +if ((round_down (destoff,PAGE_SIZE ) < inode->i_size) && + !IS_ALIGNED (destoff,PAGE_SIZE )) { + ret =filemap_write_and_wait_range (inode->i_mapping, +round_down (destoff,PAGE_SIZE ), + destoff -1 ); + } + + dest_end = destoff + len -1 ; +if ((dest_end < inode->i_size) && + !IS_ALIGNED (dest_end +1 ,PAGE_SIZE )) { + ret =filemap_write_and_wait_range (inode->i_mapping, + dest_end +1 , +round_up (dest_end,PAGE_SIZE )); + } +if (destoff > inode->i_size) { ret =btrfs_cont_expand (inode, inode->i_size, destoff);if (ret)
Signature · 1 line
2.1.0
PATCH v17 17/18 Btrfs: subpage-blocksize: Make file extent relocate code subpage blocksize aware
In reply to Chandan RajendraThe file extent relocation code currently assumes blocksize to be same as PAGE_SIZE. This commit adds code to support subpage blocksize scenario.
--- fs/btrfs/relocation.c | 73 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 25 deletions(-)
fs/btrfs/relocation.c +48 -25
@@ -3103,14 +3103,19 @@ static int relocate_file_extent_cluster(struct inode *inode, {u64 page_start;u64 page_end; +u64 block_start; +u64 block_end;u64 offset =BTRFS_I (inode)->index_cnt; +u64 blocksize =BTRFS_I (inode)->root->sectorsize;unsigned long index;unsigned long last_index;struct page *page;struct file_ra_state *ra;gfp_t mask =btrfs_alloc_write_mask (inode->i_mapping); +int nr_blocks;int nr =0 ;int ret =0 ; +int i;if (!cluster->nr)return 0 ;
@@ -3130,13 +3135,13 @@ static int relocate_file_extent_cluster(struct inode *inode,if (ret) goto out; + page_start = cluster->start - offset; + page_end =min_t (u64, page_start +PAGE_SIZE -1 , + cluster->end - offset); + index = (cluster->start - offset) >>PAGE_SHIFT ; last_index = (cluster->end - offset) >>PAGE_SHIFT ;while (index <= last_index) { - ret =btrfs_delalloc_reserve_metadata (inode,PAGE_SIZE ); -if (ret) - goto out; - page =find_lock_page (inode->i_mapping, index);if (!page) { page_cache_sync_readahead(inode->i_mapping,
@@ -3145,8 +3150,6 @@ static int relocate_file_extent_cluster(struct inode *inode, page =find_or_create_page (inode->i_mapping, index, mask);if (!page) { -btrfs_delalloc_release_metadata (inode, -PAGE_SIZE ); ret = -ENOMEM ; goto out; }
@@ -3164,42 +3167,62 @@ static int relocate_file_extent_cluster(struct inode *inode,if (!PageUptodate (page)) {unlock_page (page);put_page (page); -btrfs_delalloc_release_metadata (inode, -PAGE_SIZE ); ret = -EIO ; goto out; } } - page_start =page_offset (page); - page_end = page_start +PAGE_SIZE -1 ; + nr_blocks = (page_end +1 - page_start) >> inode->i_blkbits; + i =0 ; -lock_extent (&BTRFS_I (inode)->io_tree, page_start, page_end); +while (i < nr_blocks) { + ret =btrfs_delalloc_reserve_metadata (inode, blocksize); +if (ret) { +if (i) +set_page_dirty (page); +unlock_page (page); +put_page (page); + goto out; + } + + block_start = page_start + (i << inode->i_blkbits); + block_end = block_start + blocksize -1 ; + +lock_extent (&BTRFS_I (inode)->io_tree, block_start, + block_end); + +set_page_extent_mapped (page); -set_page_extent_mapped (page); +if (nr < cluster->nr && + block_start + offset == cluster->boundary[nr]) { +set_extent_bits (&BTRFS_I (inode)->io_tree, + block_start, block_end, +EXTENT_BOUNDARY ,GFP_NOFS ); + nr++; + } + +btrfs_set_extent_delalloc (inode, block_start, + block_end,NULL ); +set_page_blks_state (page, +1 <<BLK_STATE_DIRTY |1 <<BLK_STATE_UPTODATE , + block_start, block_end); -if (nr < cluster->nr && - page_start + offset == cluster->boundary[nr]) { -set_extent_bits (&BTRFS_I (inode)->io_tree, - page_start, page_end, -EXTENT_BOUNDARY ,GFP_NOFS ); - nr++; +unlock_extent (&BTRFS_I (inode)->io_tree, + block_start, block_end); + i++; } -btrfs_set_extent_delalloc (inode, page_start, page_end,NULL ); -set_page_blks_state (page, -1 <<BLK_STATE_DIRTY |1 <<BLK_STATE_UPTODATE , - page_start, page_end);set_page_dirty (page); - -unlock_extent (&BTRFS_I (inode)->io_tree, - page_start, page_end);unlock_page (page);put_page (page); index++;balance_dirty_pages_ratelimited (inode->i_mapping);btrfs_throttle (BTRFS_I (inode)->root); + + page_start +=PAGE_SIZE ; + page_end =min_t (u64, page_start +PAGE_SIZE -1 , + cluster->end - offset); }WARN_ON (nr != cluster->nr); out:
Signature · 1 line
2.1.0
PATCH v17 18/18 Btrfs: subpage-blocksize: __btrfs_lookup_bio_sums: Set offset when moving to a new bio_vec
In reply to Chandan RajendraIn __btrfs_lookup_bio_sums() we set the file offset value at the beginning of every iteration of the while loop. This is incorrect since the blocks mapped by the current bvec->bv_page might not yet have been completely processed.
This commit fixes the issue by setting the file offset value when we move to the next bvec of the bio.
--- fs/btrfs/file-item.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/btrfs/file-item.c +5 -2
@@ -222,11 +222,11 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, disk_bytenr = (u64 )bio->bi_iter.bi_sector <<9 ;if (dio) offset = logical_offset; +else + offset =page_offset (bvec->bv_page) + bvec->bv_offset; page_bytes_left = bvec->bv_len;while (bio_index < bio->bi_vcnt) { -if (!dio) - offset =page_offset (bvec->bv_page) + bvec->bv_offset; count =btrfs_find_ordered_sum (inode, offset, disk_bytenr, (u32 *)csum, nblocks);if (count)
@@ -301,6 +301,9 @@ found: goto done; } bvec++; +if (!dio) + offset =page_offset (bvec->bv_page) + + bvec->bv_offset; page_bytes_left = bvec->bv_len; }
Signature · 1 line
2.1.0
Quoted 44 lines · On Thursday 14 Apr 2016 19:08:09 Chandan Rajendra wrote:
Btrfs assumes block size to be the same as the machine's page size. This would mean that a Btrfs instance created on a 4k page size machine (e.g. x86) will not be mountable on machines with larger page sizes (e.g. PPC64/AARCH64). This patchset aims to resolve this incompatibility.
This patchset continues with the work posted previously at
http://thread.gmane.org/gmane.comp.file-systems.btrfs/53073.I have reverted the upstream commit "btrfs: fix lockups from
btrfs_clear_path_blocking" (f82c458a2c3ffb94b431fc6ad791a79df1b3713e) since this led to soft-lockups when the patch "Btrfs:
subpagesize-blocksize: Prevent writes to an extent buffer whenPG_writebackflag is set" is applied. During 2015's Vault Conference Btrfs meetup, Chris Mason had suggested that he will write up a suitable locking function to be used when writing dirty pages that map metadata blocks. Until we have a suitable locking function available, this patchset temporarily disables the commitf82c458a2c3ffb94b431fc6ad791a79df1b3713e.The commits for the Btrfs kernel module can be found at
https://github.com/chandanr/linux/tree/btrfs/subpagesize-blocksize.To create a filesystem with block size < page size, a patched version of the Btrfs-progs package is required. The corresponding fixes for Btrfs-progs can be found at
https://github.com/chandanr/btrfs-progs/tree/btrfs/subpagesize-blocksize.Fstests run status:
1.x86_64
- With 4k sectorsize, all the tests that succeed with the master branch atgit://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git
branch also do so with the patches applied.
2. ppc64
- With 4k sectorsize, 16k nodesize and with "nospace_cache" mount option, except for scrub and compression tests, all the tests that succeed with the master branch at
git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git
branch also do so with the patches applied.
- With 64k sectorsize & nodesize, all the tests that succeed with the master branch at
git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git
branch also do so with the patches applied.
Quoted 5 lines
TODO:
1. The selftests code needs to be fixed to work in subpage-blocksize scenario.
2. I am planning to fix Scrub & Compression via a separate patchset.
Hi,
I had messed up the following four patches during rebase operations. [PATCH] Btrfs: subpage-blocksize: btrfs_punch_hole: Fix uptodate blocks check [PATCH] Btrfs: subpage-blocksize: Define extent_buffer_head. [PATCH] Btrfs: subpage-blocksize: Make sure delalloc range intersects with the locked page's range
[PATCH] Btrfs: subpage-blocksize: Prevent writes to an extent buffer when PG_writeback flag is set
Instead of sending the complete patchset once again, I have resent only the above listed patches as replies to the corresponding mails. Please use the new patches instead of the corresponding old ones.
Signature · 1 line
chandan