Allow I/O on blocks whose size is less than page size
Subsystems (2)
v19 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/55653.
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.
The patchset is based off kdave/master branch. I had cherry picked the following fixes to self-tests (from kdave/for-next branch) before applying the subpage-blocksize patchset:
Btrfs: self-tests: Fix extent buffer bitmap test fail on BE system
Btrfs: self-tests: Fix test_bitmaps fail on 64k sectorsize
Btrfs: self-tests: Use macros instead of constants and add missing newline
Btrfs: self-tests: Support testing all possible sectorsizes and nodesizes
Btrfs: self-tests: Execute page straddling test only when nodesize < PAGE_SIZE
Btrfs: self-tests: Support non-4k page size
Btrfs: Fix integer overflow when calculating bytes_per_bitmap
Btrfs: test_check_exists: Fix infinite loop when searching for free space entries
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.
- With 2k sectorsize, generic/027 never seems to complete. In my case, the test did not complete even after 45 mins of run time.
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. On ppc64, btrfsck segfaults when checking a filesystem instance having 2k sectorsize.
2. I am planning to fix scrub & compression via a separate patchset.
Changes from V18:
1. The per-page bitmap used to track the block status is now allocated from a slab cache.
2. The per-page bitmap is allocated and used only in cases where sectorsize < PAGE_SIZE.
3. The new patch "Btrfs: subpage-blocksize: Disable compression" disables compression in subpage-blocksize scenario.
Changes from V17:
1. Due to mistakes made during git rebase operations, fixes ended up in incorrect patches. This patchset gets the fixes in the right patches.
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 (19):
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_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: subpage-blocksize: 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
Btrfs: subpage-blocksize: Disable compression
fs/btrfs/ctree.c | 37 +- fs/btrfs/ctree.h | 6 +- fs/btrfs/disk-io.c | 167 ++-- fs/btrfs/disk-io.h | 5 +- fs/btrfs/extent-tree.c | 21 +- fs/btrfs/extent_io.c | 1702 +++++++++++++++++++++++--------- fs/btrfs/extent_io.h | 152 ++- fs/btrfs/file-item.c | 7 +- fs/btrfs/file.c | 106 +- fs/btrfs/inode.c | 503 +++++++--- fs/btrfs/ioctl.c | 232 +++-- 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 | 53 +- fs/btrfs/root-tree.c | 2 +- fs/btrfs/super.c | 27 +- fs/btrfs/tests/btrfs-tests.c | 12 +- fs/btrfs/tests/extent-io-tests.c | 5 +- fs/btrfs/tests/free-space-tree-tests.c | 79 +- fs/btrfs/tree-log.c | 2 +- fs/btrfs/volumes.c | 11 +- include/trace/events/btrfs.h | 2 +- 24 files changed, 2263 insertions(+), 917 deletions(-)
Signature · 1 line
2.1.0
PATCH v19 1/19 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 | 371 ++++++++++++++++++++++++++++++++++++--------------- fs/btrfs/extent_io.h | 74 +++++++++- fs/btrfs/inode.c | 16 +-- 3 files changed, 338 insertions(+), 123 deletions(-)
fs/btrfs/extent_io.c +260 -111
@@ -23,6 +23,7 @@static struct kmem_cache *extent_state_cache;static struct kmem_cache *extent_buffer_cache; +static struct kmem_cache *page_private_cache;static struct bio_set *btrfs_bioset;static inline bool extent_state_in_tree (const struct extent_state *state)
@@ -173,10 +174,16 @@ int __init extent_io_init(void)if (!extent_buffer_cache) goto free_state_cache; + page_private_cache =kmem_cache_create ("btrfs_page_private" , +sizeof (struct btrfs_page_private ),0 , +SLAB_RECLAIM_ACCOUNT |SLAB_MEM_SPREAD ,NULL ); +if (!page_private_cache) + goto free_buffer_cache; + btrfs_bioset =bioset_create (BIO_POOL_SIZE , offsetof(struct btrfs_io_bio , bio));if (!btrfs_bioset) - goto free_buffer_cache; + goto free_page_private_cache;if (bioset_integrity_create (btrfs_bioset,BIO_POOL_SIZE )) goto free_bioset;
@@ -187,6 +194,10 @@ free_bioset:bioset_free (btrfs_bioset); btrfs_bioset =NULL ; +free_page_private_cache: +kmem_cache_destroy (page_private_cache); + page_private_cache =NULL ; + free_buffer_cache:kmem_cache_destroy (extent_buffer_cache); extent_buffer_cache =NULL ;
@@ -1322,6 +1333,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; + +ASSERT (BTRFS_I (inode)->root->sectorsize <PAGE_SIZE ); + + 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 ; + +ASSERT (BTRFS_I (inode)->root->sectorsize <PAGE_SIZE ); + + 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.
@@ -1959,14 +2059,27 @@ 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) { +struct inode *inode = page->mapping->host; +struct btrfs_root *root =BTRFS_I (inode)->root;u64 start =page_offset (page);u64 end = start +PAGE_SIZE -1 ; -if (test_range_bit (tree, start, end,EXTENT_UPTODATE ,1 ,NULL )) + +if (root->sectorsize ==PAGE_SIZE + ||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;
@@ -2292,7 +2405,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,
@@ -2498,18 +2613,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
@@ -2526,67 +2629,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)) { 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
@@ -2597,58 +2683,69 @@ 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) { +if (root->sectorsize <PAGE_SIZE ) +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) { +if (root->sectorsize <PAGE_SIZE ) +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)); + + unlock =1 ; + +if (root->sectorsize <PAGE_SIZE ) { + 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);
@@ -2838,13 +2935,51 @@ 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 inode *inode = page->mapping->host; +struct btrfs_root *root =BTRFS_I (inode)->root; +struct btrfs_page_private *pg_private; +unsigned long private =EXTENT_PAGE_PRIVATE ; +if (!PagePrivate (page)) { +if (root->sectorsize <PAGE_SIZE ) { + pg_private =kmem_cache_zalloc (page_private_cache, +GFP_NOFS ); +if (!pg_private) +return -ENOMEM ; + +spin_lock_init (&pg_private->io_lock); + + private = (unsigned long )pg_private; + } +SetPagePrivate (page);get_page (page); -set_page_private (page,EXTENT_PAGE_PRIVATE ); +set_page_private (page, private); + } + +return 0 ; +} + +int clear_page_extent_mapped (struct page *page) +{ +struct inode *inode = page->mapping->host; +struct btrfs_root *root =BTRFS_I (inode)->root; +struct btrfs_page_private *pg_private; + +if (PagePrivate (page)) { +if (root->sectorsize <PAGE_SIZE ) { + pg_private = (struct btrfs_page_private *)(page->private); +kmem_cache_free (page_private_cache, pg_private); + } + +ClearPagePrivate (page); +set_page_private (page,0 ); +put_page (page); } + +return 0 ; } static struct extent_map *
@@ -2889,6 +3024,7 @@ static int __do_readpage(struct extent_io_tree *tree, u64 *prev_em_start) {struct inode *inode = page->mapping->host; +struct btrfs_root *root =BTRFS_I (inode)->root;u64 start =page_offset (page);u64 page_end = start +PAGE_SIZE -1 ;u64 end;
@@ -2911,13 +3047,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;
@@ -2937,18 +3066,18 @@ 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 ); +if (root->sectorsize <PAGE_SIZE ) +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,
@@ -2983,6 +3112,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
@@ -3038,8 +3174,11 @@ 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 ); +if (root->sectorsize <PAGE_SIZE ) +set_page_blks_state (page, +1 <<BLK_STATE_UPTODATE , cur, + cur + iosize -1 ); +unlock_extent_cached (tree, cur, cur + iosize -1 , &cached,GFP_NOFS );
@@ -3048,9 +3187,13 @@ 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 ((root->sectorsize ==PAGE_SIZE + &&PageUptodate (page)) + || (root->sectorsize <PAGE_SIZE + &&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;
@@ -3068,6 +3211,9 @@ static int __do_readpage(struct extent_io_tree *tree, } pnr -= page->index; +if (root->sectorsize <PAGE_SIZE ) +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,
@@ -3080,12 +3226,15 @@ static int __do_readpage(struct extent_io_tree *tree, *bio_flags = this_bio_flag; }else {SetPageError (page); +if (root->sectorsize <PAGE_SIZE ) +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 +70 -4
89 lines not on this page · raw message
fs/btrfs/inode.c +8 -8
@@ -6765,7 +6765,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;
@@ -6942,8 +6941,11 @@ next:kunmap (page);btrfs_mark_buffer_dirty (leaf); } -set_extent_uptodate (io_tree, em->start, -extent_map_end (em) -1 ,NULL ,GFP_NOFS ); +if (root->sectorsize ==PAGE_SIZE ) +SetPageUptodate (page); +else +set_page_blks_state (page,1 <<BLK_STATE_UPTODATE , + em->start,extent_map_end (em) -1 ); goto insert; } not_found:
@@ -8748,11 +8750,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 v19 2/19 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 | 150 ++++++++++++++++++++++++-------------------------- fs/btrfs/file.c | 17 ++++++ fs/btrfs/inode.c | 75 +++++++++++++++++++++---- fs/btrfs/relocation.c | 3 + 4 files changed, 155 insertions(+), 90 deletions(-)
fs/btrfs/extent_io.c +72 -78
@@ -1493,24 +1493,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'
@@ -2578,36 +2560,41 @@ 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; +struct btrfs_root *root =BTRFS_I (page->mapping->host)->root; -/* 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); - } + pg_private =NULL ; + flags =0 ; + clear_writeback =1 ; - start =page_offset (page); - end = start + bvec->bv_offset + bvec->bv_len -1 ; + start =page_offset (page) + bvec->bv_offset; + end = start + bvec->bv_len -1 ; + +if (root->sectorsize <PAGE_SIZE ) { + pg_private = (struct btrfs_page_private *)page->private; +spin_lock_irqsave (&pg_private->io_lock, flags); + }end_extent_writepage (page, bio->bi_error, start, end); -end_page_writeback (page); + +if (root->sectorsize <PAGE_SIZE ) { +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);
@@ -3479,7 +3466,6 @@ 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 ;
@@ -3531,20 +3517,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 (blocksize <PAGE_SIZE + && !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;
@@ -3552,65 +3547,64 @@ 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++; - } +ASSERT (!compressed); +ASSERT (block_start !=EXTENT_MAP_INLINE ); +if (block_start ==EXTENT_MAP_HOLE ) { +if (blocksize <PAGE_SIZE ) { +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 ); + }else { +BUG (); + } + }else if (!PageUptodate (page)) { +BUG (); + } cur += iosize; - pg_offset += iosize;continue ; } max_nr = (i_size >>PAGE_SHIFT ) +1 ; -set_range_writeback (tree, cur, cur + iosize -1 ); +if (blocksize <PAGE_SIZE ) +clear_page_blks_state (page, +1 <<BLK_STATE_DIRTY , cur, + cur + iosize -1 ); +set_page_writeback (page); + +if (blocksize <PAGE_SIZE ) +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" , - page->index, cur, end); +"page %lu not writeback, cur %llu end %llu" , + page->index, cur, end); } ret =submit_extent_page (write_flags, tree, wbc, page, - sector, iosize, pg_offset, - bdev, &epd->bio, max_nr, - end_bio_extent_writepage, -0 ,0 ,0 , false); + sector, iosize, pg_offset, + bdev, &epd->bio, max_nr, + end_bio_extent_writepage, +0 ,0 ,0 , false);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; } +/* * the writepage semantics are similar to regular writepage. extent * records are inserted to lock ranges in the tree, and as dirty areas
fs/btrfs/file.c +17 -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,25 @@ 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); + +if (root->sectorsize <PAGE_SIZE ) +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 +63 -12
137 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 v19 3/19 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
@@ -1580,6 +1580,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) {
@@ -1588,6 +1589,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);
@@ -1608,7 +1612,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;
@@ -1746,8 +1751,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 v19 4/19 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 | 602 ++++++++++++++++++++++----------- fs/btrfs/extent_io.h | 63 ++-- fs/btrfs/root-tree.c | 2 +- fs/btrfs/super.c | 7 +- fs/btrfs/tests/btrfs-tests.c | 12 +- fs/btrfs/tests/extent-io-tests.c | 5 +- fs/btrfs/tests/free-space-tree-tests.c | 79 +++-- fs/btrfs/volumes.c | 2 +- include/trace/events/btrfs.h | 2 +- 13 files changed, 555 insertions(+), 305 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
@@ -1473,14 +1473,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
@@ -6962,7 +6962,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 );
@@ -6980,7 +6980,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 */
@@ -8022,7 +8022,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 +399 -203
1,201 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/super.c +6 -1
@@ -2321,11 +2321,16 @@ static int btrfs_run_sanity_tests(void)int ret, i;u32 sectorsize, nodesize;u32 test_sectorsize[] = { -PAGE_SIZE , +4096 , +8192 , +16384 , +32768 , +65536 , }; ret =btrfs_init_test_fs ();if (ret)return ret; +for (i =0 ; i <ARRAY_SIZE (test_sectorsize); i++) { sectorsize = test_sectorsize[i]; for (nodesize = sectorsize;
fs/btrfs/tests/btrfs-tests.c +6 -6
@@ -138,19 +138,19 @@ static void btrfs_free_dummy_fs_info(struct btrfs_fs_info *fs_info)spin_lock (&fs_info->buffer_lock);radix_tree_for_each_slot (slot, &fs_info->buffer_radix, &iter,0 ) { -struct extent_buffer *eb; +struct extent_buffer_head *ebh; - eb =radix_tree_deref_slot_protected (slot, &fs_info->buffer_lock); -if (!eb) + ebh =radix_tree_deref_slot_protected (slot, &fs_info->buffer_lock); +if (!ebh)continue ;/* Shouldn't happen but that kind of thinking creates CVE's */ -if (radix_tree_exception (eb)) { -if (radix_tree_deref_retry (eb)) +if (radix_tree_exception (ebh)) { +if (radix_tree_deref_retry (ebh)) slot =radix_tree_iter_retry (&iter);continue ; }spin_unlock (&fs_info->buffer_lock); -free_extent_buffer_stale (eb); +free_extent_buffer_stale (&ebh->eb);spin_lock (&fs_info->buffer_lock); }spin_unlock (&fs_info->buffer_lock);
fs/btrfs/tests/extent-io-tests.c +3 -2
@@ -375,11 +375,12 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)test_msg ("Running extent buffer bitmap tests\n" ); +/* * In ppc64, sectorsize can be 64K, thus 4 * 64K will be larger than * BTRFS_MAX_METADATA_BLOCKSIZE. */ - len = (sectorsize <BTRFS_MAX_METADATA_BLOCKSIZE ) + len = ((sectorsize *4 ) <=BTRFS_MAX_METADATA_BLOCKSIZE ) ? sectorsize *4 : sectorsize; bitmap =kmalloc (len,GFP_KERNEL );
@@ -401,7 +402,7 @@ static int test_eb_bitmaps(u32 sectorsize, u32 nodesize)/* Do it over again with an extent buffer which isn't page-aligned. */ free_extent_buffer (eb); - eb =__alloc_dummy_extent_buffer (NULL , nodesize /2 , len); + eb =__alloc_dummy_extent_buffer (NULL ,PAGE_SIZE /2 , len);if (!eb) {test_msg ("Couldn't allocate test extent buffer\n" );kfree (bitmap);
fs/btrfs/tests/free-space-tree-tests.c +43 -36
213 lines not on this page · raw message
fs/btrfs/volumes.c +1 -1
@@ -6580,7 +6580,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
PATCH v19 5/19 Btrfs: subpage-blocksize: Read tree blocks whose size is < PAGE_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 | 127 +++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 142 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)
@@ -4518,8 +4508,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 +119 -8
180 lines not on this page · raw message
Signature · 1 line
2.1.0
Re: [PATCH V19 05/19] Btrfs: subpage-blocksize: Read tree blocks whose size is < PAGE_SIZE
Quoted 3 lines · Chandan Rajendra
In 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.
This patch has a conflict with a next pending patch
"Btrfs: fix eb memory leak due to readpage failure"
https://patchwork.kernel.org/patch/9153927/
in this hunk:
Quoted 34 lines
fs/btrfs/extent_io.c +26
-4@@ -5557,10 +5645,32 @@ int read_extent_buffer_pages(struct extent_io_tree *tree, page =eb_head (eb)->pages[i];if (!PageUptodate (page)) {ClearPageError (page); - err =__extent_read_full_page (tree, page, - get_extent, &bio, - mirror_num, &bio_flags, -READ |REQ_META ); +if (eb->len <PAGE_SIZE ) { +lock_extent_bits (tree, eb->start, eb->start + eb->len -1 , + &cached_state); + err =submit_extent_page (READ |REQ_META , tree, +NULL , page, + eb->start >>9 , eb->len, + eb->start -page_offset (page), + fs_info->fs_devices->latest_bdev, + &bio,-1 , + end_bio_extent_buffer_readpage, + mirror_num, bio_flags, + bio_flags, false); + }else { +lock_extent_bits (tree,page_offset (page), +page_offset (page) +PAGE_SIZE -1 , + &cached_state); + err =submit_extent_page (READ |REQ_META , tree, +NULL , page, +page_offset (page) >>9 , +PAGE_SIZE ,0 , + fs_info->fs_devices->latest_bdev, + &bio,-1 , + end_bio_extent_buffer_readpage, + mirror_num, bio_flags, + bio_flags, false); + }
Re: [PATCH V19 05/19] Btrfs: subpage-blocksize: Read tree blocks whose size is < PAGE_SIZE
Quoted 10 lines · David Sterba
Quoted 3 lines · Chandan Rajendra
In 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.
This patch has a conflict with a next pending patch
"Btrfs: fix eb memory leak due to readpage failure"
https://patchwork.kernel.org/patch/9153927/
I will fix this and also the merge conflict in the patch " [PATCH V19 11/19]
Btrfs: subpage-blocksize: Prevent writes to an extent buffer when PG_writeback flag is set" and resend the patchset.
Signature · 1 line
chandan
PATCH v19 6/19 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 v19 7/19 Btrfs: subpage-blocksize: Allow mounting filesystems where sectorsize < PAGE_SIZE
In reply to Chandan RajendraThis commit allows mounting filesystem instances with sectorsize smaller than the PAGE_SIZE.
Since the code assumes that the super block is either equal to or larger than sectorsize, this commit brings back the nodesize argument for btrfs_find_create_tree_block() function. This change allows us to be able to mount and use filesystems with 2048 bytes as the sectorsize.
--- fs/btrfs/disk-io.c | 21 ++++++++------------- fs/btrfs/disk-io.h | 2 +- fs/btrfs/extent-tree.c | 4 ++-- fs/btrfs/extent_io.c | 3 +-- fs/btrfs/extent_io.h | 4 ++-- fs/btrfs/tree-log.c | 2 +- fs/btrfs/volumes.c | 9 ++------- 7 files changed, 17 insertions(+), 28 deletions(-)
fs/btrfs/disk-io.c +8 -13
@@ -1099,7 +1099,7 @@ void readahead_tree_block(struct btrfs_root *root, u64 bytenr)struct extent_buffer *buf =NULL ;struct inode *btree_inode = root->fs_info->btree_inode; - buf =btrfs_find_create_tree_block (root, bytenr); + buf =btrfs_find_create_tree_block (root, bytenr, root->nodesize);if (!buf)return ; read_extent_buffer_pages(&BTRFS_I(btree_inode)->io_tree,
@@ -1115,7 +1115,7 @@ int reada_tree_block_flagged(struct btrfs_root *root, u64 bytenr,struct extent_io_tree *io_tree = &BTRFS_I (btree_inode)->io_tree;int ret; - buf =btrfs_find_create_tree_block (root, bytenr); + buf =btrfs_find_create_tree_block (root, bytenr, root->nodesize);if (!buf)return 0 ;
@@ -1146,12 +1146,12 @@ struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info, }struct extent_buffer *btrfs_find_create_tree_block (struct btrfs_root *root, -u64 bytenr) +u64 bytenr,u32 blocksize) {if (btrfs_test_is_dummy_root (root))return alloc_test_extent_buffer (root->fs_info, bytenr, - root->nodesize); -return alloc_extent_buffer (root->fs_info, bytenr); + blocksize); +return alloc_extent_buffer (root->fs_info, bytenr, blocksize); }
@@ -1175,7 +1175,7 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,struct extent_buffer *buf =NULL ;int ret; - buf =btrfs_find_create_tree_block (root, bytenr); + buf =btrfs_find_create_tree_block (root, bytenr, root->nodesize);if (!buf)return ERR_PTR (-ENOMEM );
@@ -4089,17 +4089,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);
fs/btrfs/disk-io.h +1 -1
@@ -50,7 +50,7 @@ void readahead_tree_block(struct btrfs_root *root, u64 bytenr);int reada_tree_block_flagged (struct btrfs_root *root,u64 bytenr,int mirror_num,struct extent_buffer **eb);struct extent_buffer *btrfs_find_create_tree_block (struct btrfs_root *root, -u64 bytenr); +u64 bytenr,u32 blocksize);void clean_tree_block (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,struct extent_buffer *buf); int open_ctree(struct super_block *sb,
fs/btrfs/extent-tree.c +2 -2
@@ -8015,7 +8015,7 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root, {struct extent_buffer *buf; - buf =btrfs_find_create_tree_block (root, bytenr); + buf =btrfs_find_create_tree_block (root, bytenr, root->nodesize);if (!buf)return ERR_PTR (-ENOMEM );btrfs_set_header_generation (buf, trans->transid);
@@ -8658,7 +8658,7 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, next =btrfs_find_tree_block (root->fs_info, bytenr);if (!next) { - next =btrfs_find_create_tree_block (root, bytenr); + next =btrfs_find_create_tree_block (root, bytenr, blocksize);if (!next)return -ENOMEM ; btrfs_set_buffer_lockdep_class(root->root_key.objectid, next,
fs/btrfs/extent_io.c +1 -2
@@ -5405,9 +5405,8 @@ free_eb:#endif struct extent_buffer *alloc_extent_buffer (struct btrfs_fs_info *fs_info, -u64 start) +u64 start,unsigned long len) { -unsigned long len = fs_info->tree_root->nodesize;unsigned long num_pages =num_extent_pages (start, len);unsigned long i;unsigned long index = start >>PAGE_SHIFT ;
fs/btrfs/extent_io.h +2 -2
@@ -435,7 +435,7 @@ int clear_page_blks_state(struct page *page, unsigned long blk_states,int test_page_blks_state (struct page *page,enum blk_state blk_state,u64 start,u64 end,int check_all);struct extent_buffer *alloc_extent_buffer (struct btrfs_fs_info *fs_info, -u64 start); +u64 start,unsigned long len);struct extent_buffer *__alloc_dummy_extent_buffer (struct btrfs_fs_info *fs_info,u64 start,unsigned long len); struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
@@ -559,5 +559,5 @@ noinline u64 find_lock_delalloc_range(struct inode *inode, u64 *end, u64 max_bytes);#endif struct extent_buffer *alloc_test_extent_buffer (struct btrfs_fs_info *fs_info, -u64 start,u32 nodesize); +u64 start,u32 nodesize);#endif
fs/btrfs/tree-log.c +1 -1
@@ -2421,7 +2421,7 @@ static noinline int walk_down_log_tree(struct btrfs_trans_handle *trans, parent = path->nodes[*level]; root_owner =btrfs_header_owner (parent); - next =btrfs_find_create_tree_block (root, bytenr); + next =btrfs_find_create_tree_block (root, bytenr, blocksize);if (!next)return -ENOMEM ;
fs/btrfs/volumes.c +2 -7
@@ -6556,13 +6556,8 @@ int btrfs_read_sys_array(struct btrfs_root *root)u32 cur_offset;struct btrfs_key key; -ASSERT (BTRFS_SUPER_INFO_SIZE <= root->nodesize); -/* -* This will create extent buffer of nodesize, superblock size is -* fixed to BTRFS_SUPER_INFO_SIZE. If nodesize > sb size, this will -* overallocate but we can keep it as-is, only the first page is used. -*/ - sb =btrfs_find_create_tree_block (root,BTRFS_SUPER_INFO_OFFSET ); + sb =btrfs_find_create_tree_block (root,BTRFS_SUPER_INFO_OFFSET , +BTRFS_SUPER_INFO_SIZE );if (!sb)return -ENOMEM ;set_extent_buffer_uptodate (sb);
Signature · 1 line
2.1.0
PATCH v19 8/19 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
@@ -1863,17 +1863,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]);
@@ -2565,7 +2571,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 ;
@@ -3420,7 +3426,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
@@ -3641,7 +3646,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 ;
@@ -3686,7 +3690,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,
@@ -3700,10 +3704,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
@@ -943,6 +943,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)) {
@@ -987,8 +989,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,
@@ -1041,7 +1041,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; }btrfs_dec_block_group_reservations (root->fs_info, ins.objectid);
@@ -1056,13 +1056,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;
@@ -1071,17 +1070,31 @@ 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_dec_block_group_reservations (root->fs_info, ins.objectid);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 v19 9/19 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, 296 insertions(+), 116 deletions(-)
fs/btrfs/extent_io.c +10 -9
@@ -4654,11 +4654,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,
@@ -4692,12 +4691,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 ) {
@@ -4731,7 +4730,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
@@ -279,8 +279,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 +260 -105
445 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 v19 10/19 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 | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-)
fs/btrfs/file.c +88 -1
@@ -2327,6 +2327,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;
@@ -2339,6 +2341,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;
@@ -2435,11 +2438,45 @@ 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; +int start_page_blks_uptodate; +int end_page_blks_uptodate;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) { +inode_unlock (inode); +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); + } +inode_unlock (inode); +return -ENOMEM ; + } + } + +lock_extent_bits (&BTRFS_I (inode)->io_tree, lockstart, lockend, &cached_state); ordered =btrfs_lookup_first_ordered_extent (inode, lockend);
@@ -2449,18 +2486,68 @@ 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 ; + + start_page_blks_uptodate =0 ; + end_page_blks_uptodate =0 ; +if (root->sectorsize <PAGE_SIZE ) { +u64 page_end; + + page_end =round_down (lockstart,PAGE_SIZE ) + +PAGE_SIZE -1 ; + page_end =min (page_end, lockend); +if (start_page + &&PagePrivate (start_page) + &&test_page_blks_state (start_page,1 <<BLK_STATE_UPTODATE , + lockstart, page_end,0 )) + start_page_blks_uptodate =1 ; +if (end_page + &&PagePrivate (end_page) + &&test_page_blks_state (end_page,1 <<BLK_STATE_UPTODATE , +page_offset (end_page), lockend,0 )) + end_page_blks_uptodate =1 ; + }else { +if (start_page &&PagePrivate (start_page) + &&PageUptodate (start_page)) + start_page_blks_uptodate =1 ; +if (end_page &&PagePrivate (end_page) + &&PageUptodate (end_page)) + end_page_blks_uptodate =1 ; + } +if ((!ordered || (ordered->file_offset + ordered->len <= lockstart || ordered->file_offset > lockend)) && - !btrfs_page_exists_in_range (inode, lockstart, lockend)) { + (!start_page_blks_uptodate && !end_page_blks_uptodate && + !(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 v19 11/19 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 + 4 files changed, 155 insertions(+), 28 deletions(-)
fs/btrfs/ctree.c +20 -1
@@ -1541,6 +1541,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;
@@ -1554,6 +1555,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 ; }
@@ -2673,6 +2682,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;
@@ -2775,8 +2785,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
@@ -8013,14 +8013,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, root->nodesize);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
Re: [PATCH V19 11/19] Btrfs: subpage-blocksize: Prevent writes to an extent buffer when PG_writeback flag is set
Quoted 6 lines · Chandan Rajendra
In non-subpage-blocksize scenario,
BTRFS_HEADER_FLAG_WRITTENflag 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.
Quoted 6 lines
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.Signed-off-by Chandan Rajendra <[email protected]>
This patch has a minor conflict with patch merged into 4.7-rc4 and I'm not sure if the resolution is correct.
btrfs: account for non-CoW'd blocks in btrfs_abort_transaction 64c12921e11b3a0c10d088606e328c58e29274d8
introduces trans->dirty, the conflicts are in btrfs_cow_block and btrfs_search_slot.
PATCH v19 12/19 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 */
@@ -2906,7 +2916,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);
@@ -3038,7 +3048,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 v19 13/19 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 | 198 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 136 insertions(+), 62 deletions(-)
fs/btrfs/ioctl.c +136 -62
@@ -902,12 +902,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) {
@@ -997,7 +998,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
@@ -1116,37 +1117,47 @@ 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;struct btrfs_ordered_extent *ordered;struct extent_state *cached_state =NULL ;struct extent_io_tree *tree; +struct btrfs_root *root;gfp_t mask =btrfs_alloc_write_mask (inode->i_mapping); - file_end = (isize -1 ) >>PAGE_SHIFT ; -if (!isize || start_index > file_end) + root =BTRFS_I (inode)->root; + 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;
@@ -1157,12 +1168,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)
@@ -1201,7 +1222,7 @@ again: } pages[i] = page; - i_done++; + i_done += (page_end - page_start +1 ) >> inode->i_blkbits; }if (!i_done || ret) goto out;
@@ -1213,55 +1234,77 @@ 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 , - &cached_state); +set_extent_defrag (&BTRFS_I (inode)->io_tree, page_start, page_end, + &cached_state);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 ; + } + +if (root->sectorsize <PAGE_SIZE ) +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,
@@ -1270,19 +1313,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 ;
@@ -1316,8 +1364,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;
@@ -1325,12 +1379,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 );
@@ -1340,14 +1397,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
@@ -1371,39 +1434,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;
@@ -1417,29 +1491,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 v19 14/19 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
@@ -1835,9 +1835,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;
@@ -1845,6 +1844,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 );
@@ -1881,8 +1881,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
@@ -505,9 +505,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 v19 15/19 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
@@ -3321,21 +3321,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 v19 16/19 Btrfs: subpage-blocksize: 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
@@ -3917,6 +3917,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;/*
@@ -3977,6 +3978,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 v19 17/19 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 | 56 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 18 deletions(-)
fs/btrfs/relocation.c +38 -18
@@ -3103,14 +3103,19 @@ static int relocate_file_extent_cluster(struct inode *inode, {u64 page_start;u64 page_end; +u64 block_start;u64 offset =BTRFS_I (inode)->index_cnt; +u64 blocksize =BTRFS_I (inode)->root->sectorsize; +u64 reserved_space;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,10 +3135,16 @@ static int relocate_file_extent_cluster(struct inode *inode,if (ret) goto out; + page_start = cluster->start - offset; + page_end =min_t (u64,round_down (page_start,PAGE_SIZE ) +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 ); + reserved_space = page_end - page_start +1 ; + + ret =btrfs_delalloc_reserve_metadata (inode, reserved_space);if (ret) goto out;
@@ -3146,7 +3157,7 @@ static int relocate_file_extent_cluster(struct inode *inode, mask);if (!page) {btrfs_delalloc_release_metadata (inode, -PAGE_SIZE ); + reserved_space); ret = -ENOMEM ; goto out; }
@@ -3165,41 +3176,50 @@ static int relocate_file_extent_cluster(struct inode *inode,unlock_page (page);put_page (page);btrfs_delalloc_release_metadata (inode, -PAGE_SIZE ); + reserved_space); ret = -EIO ; goto out; } } - page_start =page_offset (page); - page_end = page_start +PAGE_SIZE -1 ; -lock_extent (&BTRFS_I (inode)->io_tree, page_start, page_end);set_page_extent_mapped (page); -if (nr < cluster->nr && - page_start + offset == cluster->boundary[nr]) { -set_extent_bits (&BTRFS_I (inode)->io_tree, - page_start, page_end, -EXTENT_BOUNDARY ); - nr++; + nr_blocks = (page_end +1 - page_start) >> inode->i_blkbits; + + block_start = page_start; +for (i =0 ; i < nr_blocks; i++) { +if (nr < cluster->nr && + block_start + offset == cluster->boundary[nr]) { +set_extent_bits (&BTRFS_I (inode)->io_tree, + block_start, block_start + blocksize -1 , +EXTENT_BOUNDARY ); + nr++; + } + + block_start += blocksize; }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); +if (blocksize <PAGE_SIZE ) +set_page_blks_state (page, +1 <<BLK_STATE_DIRTY |1 <<BLK_STATE_UPTODATE , + page_start, page_end); + +unlock_extent (&BTRFS_I (inode)->io_tree, page_start, page_end); -unlock_extent (&BTRFS_I (inode)->io_tree, - page_start, page_end); +set_page_dirty (page);unlock_page (page);put_page (page); index++;balance_dirty_pages_ratelimited (inode->i_mapping);btrfs_throttle (BTRFS_I (inode)->root); + + page_start = page_end +1 ; + 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 v19 18/19 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
PATCH v19 19/19 Btrfs: subpage-blocksize: Disable compression
In reply to Chandan RajendraThe subpage-blocksize patchset does not yet support compression. Hence, the kernel might crash when executing compression code in subpage-blocksize scenario. This commit disables enabling compression feature during 'mount' and also when the user invokes 'chattr +c <filename>' command.
--- fs/btrfs/ioctl.c | 8 +++++++- fs/btrfs/super.c | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-)
fs/btrfs/ioctl.c +7 -1
@@ -322,6 +322,11 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) }else if (flags &FS_COMPR_FL ) {const char *comp; +if (root->sectorsize <PAGE_SIZE ) { + ret = -EINVAL ; + goto out_drop; + } + ip->flags |=BTRFS_INODE_COMPRESS ; ip->flags &= ~BTRFS_INODE_NOCOMPRESS ;
@@ -1342,7 +1347,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,return -EINVAL ;if (range->flags &BTRFS_DEFRAG_RANGE_COMPRESS ) { -if (range->compress_type >BTRFS_COMPRESS_TYPES ) +if ((range->compress_type >BTRFS_COMPRESS_TYPES ) + || (root->sectorsize <PAGE_SIZE ))return -EINVAL ;if (range->compress_type) compress_type = range->compress_type;
fs/btrfs/super.c +20 -0
@@ -368,6 +368,17 @@ static const match_table_t tokens = { {Opt_err, NULL}, }; +static int can_enable_compression (struct btrfs_fs_info *fs_info) +{ +if (btrfs_super_sectorsize (fs_info->super_copy) <PAGE_SIZE ) { +btrfs_err (fs_info, +"Compression is not supported for subpage-blocksize" ); +return 0 ; + } + +return 1 ; +} +/* * Regular mount options parser. Everything that is needed only when * reading in a new superblock is parsed here.
@@ -477,6 +488,10 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,if (token == Opt_compress || token == Opt_compress_force ||strcmp (args[0 ].from,"zlib" ) ==0 ) { +if (!can_enable_compression (info)) { + ret = -EINVAL ; + goto out; + } compress_type ="zlib" ; info->compress_type =BTRFS_COMPRESS_ZLIB ;btrfs_set_opt (info->mount_opt,COMPRESS );
@@ -484,6 +499,10 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,btrfs_clear_opt (info->mount_opt,NODATASUM ); no_compress =0 ; }else if (strcmp (args[0 ].from,"lzo" ) ==0 ) { +if (!can_enable_compression (info)) { + ret = -EINVAL ; + goto out; + } compress_type ="lzo" ; info->compress_type =BTRFS_COMPRESS_LZO ;btrfs_set_opt (info->mount_opt,COMPRESS );
@@ -806,6 +825,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options,break ; } } + check:/* * Extra check for current option against current flag
Signature · 1 line
2.1.0