pnfs block layout driver fixes V4
Subsystems (2)
This series fixes a wide range of issues with the pnfs block layout driver.
Before this we were seeing frequent silent data corruption, softlockups and kernel crashes when running both user applications and test cases like xfstests.
After this rewrite of the I/O path we've sorted out all issues under normal operations, although error handling in the block layout driver and its interaction with the core nfs and pnfs code still needs further work.
This work was sponsored by NetApp, Inc.
Changes since V3:
- fix debug compile in extent_tree.c
- address a few review nitpicks
Changes since V2:
- drop patches already merged by Trond
- fix compile when NFSv4 isn't enabled
- address a minor style issue pointed out by Anna
- unconditionally try a layoutcommit first during layout recall processing
Changes since V1:
- added two more layout stateid handling fixes
- change the layoutget path so that the layout driver is responsible for freeing the spliced in payload.
PATCH 1/9 pnfs: force a layout commit when encountering busy segments during recall
Expedite layout recall processing by forcing a layout commit when we see busy segments. Without it the layout recall might have to wait until the VM decided to start writeback for the file, which can introduce long delays.
--- fs/nfs/callback_proc.c | 8 +++++++- fs/nfs/pnfs.c | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-)
fs/nfs/callback_proc.c +7 -1
@@ -171,6 +171,13 @@ static u32 initiate_file_draining(struct nfs_client *clp, goto out; ino = lo->plh_inode; + +spin_lock (&ino->i_lock); +pnfs_set_layout_stateid (lo, &args->cbl_stateid, true); +spin_unlock (&ino->i_lock); + +pnfs_layoutcommit_inode (ino, false); +spin_lock (&ino->i_lock);if (test_bit (NFS_LAYOUT_BULK_RECALL , &lo->plh_flags) || pnfs_mark_matching_lsegs_invalid(lo, &free_me_list,
@@ -178,7 +185,6 @@ static u32 initiate_file_draining(struct nfs_client *clp, rv =NFS4ERR_DELAY ; else rv =NFS4ERR_NOMATCHING_LAYOUT ; -pnfs_set_layout_stateid (lo, &args->cbl_stateid, true);spin_unlock (&ino->i_lock);pnfs_free_lseg_list (&free_me_list);pnfs_put_layout_hdr (lo);
fs/nfs/pnfs.c +3 -0
@@ -594,6 +594,9 @@ pnfs_layout_free_bulk_destroy_list(struct list_head *layout_list,dprintk ("%s freeing layout for inode %lu\n" , __func__, lo->plh_inode->i_ino); inode = lo->plh_inode; + +pnfs_layoutcommit_inode (inode, false); +spin_lock (&inode->i_lock);list_del_init (&lo->plh_bulk_destroy); lo->plh_block_lgets++;/* permanently block new LAYOUTGETs */
Signature · 1 line
1.9.1
PATCH 2/9 pnfs: add flag to force read-modify-write in ->write_begin
In reply to Christoph HellwigLike all block based filesystems, the pNFS block layout driver can't read or write at a byte granularity and thus has to perform read-modify-write cycles on writes smaller than this granularity.
Add a flag so that the core NFS code always reads a whole page when starting a smaller write, so that we can do it in the place where the VFS expects it instead of doing in very deadlock prone way in the writeback handler.
Note that in theory we could do less than page size reads here for disks that have a smaller sector size which are served by a server with a smaller pnfs block size. But so far that doesn't seem like a worthwhile optimization.
--- fs/nfs/file.c | 7 +++++++ fs/nfs/pnfs.h | 15 +++++++++++++++ 2 files changed, 22 insertions(+)
fs/nfs/file.c +7 -0
@@ -36,6 +36,7 @@#include "internal.h" #include "iostat.h" #include "fscache.h" +#include "pnfs.h" #include "nfstrace.h"
@@ -327,6 +328,12 @@ static int nfs_want_read_modify_write(struct file *file, struct page *page,unsigned int offset = pos & (PAGE_CACHE_SIZE -1 );unsigned int end = offset + len; +if (pnfs_ld_read_whole_page (file->f_mapping->host)) { +if (!PageUptodate (page)) +return 1 ; +return 0 ; + } + if ((file->f_mode & FMODE_READ) && /* open for read? */ !PageUptodate(page) && /* Uptodate? */ !PagePrivate(page) && /* i/o request already? */
fs/nfs/pnfs.h +15 -0
@@ -72,6 +72,7 @@ enum layoutdriver_policy_flags {/* Should the pNFS client commit and return the layout upon a setattr */ PNFS_LAYOUTRET_ON_SETATTR =1 <<0 ,PNFS_LAYOUTRET_ON_ERROR =1 <<1 , + PNFS_READ_WHOLE_PAGE = 1 << 2, };struct nfs4_deviceid_node ;
@@ -370,6 +371,14 @@ pnfs_ld_layoutret_on_setattr(struct inode *inode) }static inline bool +pnfs_ld_read_whole_page (struct inode *inode) +{ +if (!pnfs_enabled_sb (NFS_SERVER (inode))) +return false; +return NFS_SERVER (inode)->pnfs_curr_ld->flags &PNFS_READ_WHOLE_PAGE ; +} + +static inline bool pnfs_layoutcommit_outstanding (struct inode *inode) {struct nfs_inode *nfsi =NFS_I (inode);
@@ -445,6 +454,12 @@ pnfs_ld_layoutret_on_setattr(struct inode *inode) }static inline bool +pnfs_ld_read_whole_page (struct inode *inode) +{ +return false; +} + +static inline bool pnfs_roc (struct inode *ino) {return false;
Signature · 1 line
1.9.1
PATCH 3/9 pnfs: add return_range method
In reply to Christoph HellwigIf a layout driver keeps per-inode state outside of the layout segments it needs to be notified of any layout returns or recalls on an inode, and not just about the freeing of layout segments. Add a method to acomplish this, which will allow the block layout driver to handle the case of truncated and re-expanded files properly.
--- fs/nfs/callback_proc.c | 12 +++++++++--- fs/nfs/pnfs.c | 10 ++++++++++ fs/nfs/pnfs.h | 3 +++ 3 files changed, 22 insertions(+), 3 deletions(-)
fs/nfs/callback_proc.c +9 -3
@@ -181,10 +181,16 @@ static u32 initiate_file_draining(struct nfs_client *clp,spin_lock (&ino->i_lock);if (test_bit (NFS_LAYOUT_BULK_RECALL , &lo->plh_flags) ||pnfs_mark_matching_lsegs_invalid (lo, &free_me_list, - &args->cbl_range)) + &args->cbl_range)) { rv =NFS4ERR_DELAY ; -else - rv =NFS4ERR_NOMATCHING_LAYOUT ; + goto unlock; + } + +if (NFS_SERVER (ino)->pnfs_curr_ld->return_range) { +NFS_SERVER (ino)->pnfs_curr_ld->return_range (lo, + &args->cbl_range); + } +unlock:spin_unlock (&ino->i_lock);pnfs_free_lseg_list (&free_me_list);pnfs_put_layout_hdr (lo);
fs/nfs/pnfs.c +10 -0
@@ -857,6 +857,16 @@ _pnfs_return_layout(struct inode *ino) empty =list_empty (&lo->plh_segs);pnfs_clear_layoutcommit (ino, &tmp_list);pnfs_mark_matching_lsegs_invalid (lo, &tmp_list,NULL ); + +if (NFS_SERVER (ino)->pnfs_curr_ld->return_range) { +struct pnfs_layout_range range = { + .iomode =IOMODE_ANY , + .offset =0 , + .length =NFS4_MAX_UINT64 , + }; +NFS_SERVER (ino)->pnfs_curr_ld->return_range (lo, &range); + } +/* Don't send a LAYOUTRETURN if list was initially empty */ if (empty) {spin_unlock (&ino->i_lock);
fs/nfs/pnfs.h +3 -0
@@ -94,6 +94,9 @@ struct pnfs_layoutdriver_type {struct pnfs_layout_segment * (*alloc_lseg) (struct pnfs_layout_hdr *layoutid,struct nfs4_layoutget_res *lgr,gfp_t gfp_flags);void (*free_lseg) (struct pnfs_layout_segment *lseg); +void (*return_range) (struct pnfs_layout_hdr *lo, +struct pnfs_layout_range *range); +/* test for nfs page cache coalescing */ const struct nfs_pageio_ops *pg_read_ops;const struct nfs_pageio_ops *pg_write_ops;
Signature · 1 line
1.9.1
Re: [PATCH 3/9] pnfs: add return_range method
Quoted 20 lines · Christoph Hellwig
If a layout driver keeps per-inode state outside of the layout segments it needs to be notified of any layout returns or recalls on an inode, and not just about the freeing of layout segments. Add a method to acomplish this, which will allow the block layout driver to handle the case of truncated and re-expanded files properly.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/nfs/callback_proc.c | 12 +++++++++--- fs/nfs/pnfs.c | 10 ++++++++++ fs/nfs/pnfs.h | 3 +++ 3 files changed, 22 insertions(+), 3 deletions(-)fs/nfs/callback_proc.c +0
-0@@ -181,10 +181,16 @@ static u32 initiate_file_draining(struct nfs_client *clp,spin_lock (&ino->i_lock); if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
fs/nfs/callback_proc.c static u32 initiate_file_draining(struct nfs_client *clp, · line 189
Quoted 10 lines
fs/nfs/callback_proc.c +5
-3pnfs_mark_matching_lsegs_invalid(lo, &free_me_list, - &args->cbl_range)) + &args->cbl_range)) { rv =NFS4ERR_DELAY ; - else - rv =NFS4ERR_NOMATCHING_LAYOUT ; + goto unlock; + } + +if (NFS_SERVER (ino)->pnfs_curr_ld->return_range) {
It looks better to put return_range inside pnfs_mark_matching_lsegs_invalid() to have it called every time a range of layout segments all get freed. So that ld is sure to free things up.
Cheers,
Tao
Re: [PATCH 3/9] pnfs: add return_range method
Quoted 4 lines · Peng Tao
It looks better to put
return_rangeinsidepnfs_mark_matching_lsegs_invalid()to have it called every time a range of layout segments all get freed. So that ld is sure to free things up.
Actually we specificly want to avoid that for cases like the internal new stateid handling in pnfs_layout_process, where we might allocate a new layout that overlaps an existing one, and where we need to keep the extents around.
Re: [PATCH 3/9] pnfs: add return_range method
Quoted 11 lines · Christoph Hellwig
Quoted 4 lines · Peng Tao
It looks better to put
return_rangeinsidepnfs_mark_matching_lsegs_invalid()to have it called every time a range of layout segments all get freed. So that ld is sure to free things up.Actually we specificly want to avoid that for cases like the internal new stateid handling in
pnfs_layout_process, where we might allocate a new layout that overlaps an existing one, and where we need to keep the extents around.
It looks dangerous to have extents lurking around without matching layout segments. One example is NFS4ERR_EXPIRED and NFS4ERR_BAD_STATEID in nfs4_layoutget_done(), client needs to drop all layout segments but may keep the layout header, in which case blocks layout would still hold all extents at hand.
Re: [PATCH 3/9] pnfs: add return_range method
Quoted 5 lines · Peng Tao
It looks dangerous to have extents lurking around without matching layout segments. One example is
NFS4ERR_EXPIREDandNFS4ERR_BAD_STATEIDinnfs4_layoutget_done(), client needs to drop all layout segments but may keep the layout header, in which case blocks layout would still hold all extents at hand.
We never do I/O without a valid layout, but we keep the extents around because we need to keep state like that it's been written to or has a commit pending in a single place, and also need to keep it if a layout goes away temporarily.
I hate the way it has been done in the old client, and tried moving the extent tracking to a per-layout basis, and spent way too much time on it but still couldn't get it to work, so I finally gave up. I think we're between a rock (the idiocy on rfc5663 that it tracks data in extents and not in layouts) and a hard place (the forgetful Linux client and it's lose layout coherency) here.
Re: [PATCH 3/9] pnfs: add return_range method
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Peng Tao
It looks dangerous to have extents lurking around without matching layout segments. One example is
NFS4ERR_EXPIREDandNFS4ERR_BAD_STATEIDinnfs4_layoutget_done(), client needs to drop all layout segments but may keep the layout header, in which case blocks layout would still hold all extents at hand.We never do I/O without a valid layout, but we keep the extents around because we need to keep state like that it's been written to or has a commit pending in a single place, and also need to keep it if a layout goes away temporarily.
We don't know if layout goes away temporarily or permanently. If server happens to move the file's data (enterprise NAS does that for a lot of reasons) in between, next time client does layoutget, it will get a different extent mapping. I'm not sure if the new extent tracking code is able to cope with it. The old code will certainly fail though.
If your concern is current layoutreturn implementation that ignores pending layoutcommit (and inflight IOs), that needs to be fixed. I have a patchset to fix it and it is still under internal QA. I'll post it once it passes testing.
Re: [PATCH 3/9] pnfs: add return_range method
Quoted 10 lines · Peng Tao
Quoted 4 lines
We never do I/O without a valid layout, but we keep the extents around because we need to keep state like that it's been written to or has a commit pending in a single place, and also need to keep it if a layout goes away temporarily.
We don't know if layout goes away temporarily or permanently. If server happens to move the file's data (enterprise NAS does that for a lot of reasons) in between, next time client does layoutget, it will get a different extent mapping. I'm not sure if the new extent tracking code is able to cope with it. The old code will certainly fail though.
A server is expected to do a layout recall with the clora_changed set to true if it moves data around and thus the layout goes away permanently. The Linux client currently irgnores that field, but that's something which needs to fixed in the core pnfs code and not the block layout drivers.
But this isn't one of the cases were we keep the extent around but not the layout - those are the ones were we have stateid mismatches or similar (most of them now fixed by me).
We actually have a much bigger elephant in the room, which this series doesn't address yet: if a layoutcommit fails we curently don't have a way to resend the data to the MDS. This will be more common pnfs core work as we basically need to keep the data in a state similar to NFS unstable writes, instead of claiming that we finished a NFS_FILE_SYNC, which allows the VM to drop the data from the pagecache before the commit happened.
I'm slowly wading through all these issues - I initially only planned to write a server but so far fixing up the client has taken way more of my time compared to the relatively trivial server..
Quoted 4 lines
If your concern is current layoutreturn implementation that ignores pending layoutcommit (and inflight IOs), that needs to be fixed. I have a patchset to fix it and it is still under internal QA. I'll post it once it passes testing.
That's a different issues, but I'm happy to review that as well.
PATCH 4/9 pnfs/blocklayout: remove read-modify-write handling in bl_write_pagelist
In reply to Christoph HellwigUse the new PNFS_READ_WHOLE_PAGE flag to offload read-modify-write handling to core nfs code, and remove a huge chunk of deadlock prone mess from the block layout writeback path.
--- fs/nfs/blocklayout/blocklayout.c | 500 +++++---------------------------------- 1 file changed, 64 insertions(+), 436 deletions(-)
fs/nfs/blocklayout/blocklayout.c +64 -436
@@ -35,7 +35,6 @@#include <linux/mount.h> #include <linux/namei.h> #include <linux/bio.h> /* struct bio */ -#include <linux/buffer_head.h> /* various write calls */ #include <linux/prefetch.h> #include <linux/pagevec.h>
@@ -188,16 +187,6 @@ retry:return bio; } -static struct bio *bl_add_page_to_bio (struct bio *bio,int npg,int rw, -sector_t isect,struct page *page, -struct pnfs_block_extent *be, -void (*end_io)(struct bio *,int err), -struct parallel_io *par) -{ -return do_add_page_to_bio (bio, npg, rw, isect, page, be, - end_io, par,0 ,PAGE_CACHE_SIZE ); -} -/* This is basically copied from mpage_end_io_read */ static void bl_end_io_read (struct bio *bio,int err) {
@@ -293,8 +282,8 @@ bl_read_pagelist(struct nfs_pgio_header *hdr) } } + pg_offset = f_offset & ~PAGE_CACHE_MASK ;if (is_dio) { - pg_offset = f_offset & ~PAGE_CACHE_MASK ;if (pg_offset + bytes_left >PAGE_CACHE_SIZE ) pg_len =PAGE_CACHE_SIZE - pg_offset;else
@@ -305,7 +294,7 @@ bl_read_pagelist(struct nfs_pgio_header *hdr) isect += (pg_offset >>SECTOR_SHIFT ); extent_length -= (pg_offset >>SECTOR_SHIFT ); }else { - pg_offset =0 ; +BUG_ON (pg_offset !=0 ); pg_len =PAGE_CACHE_SIZE ; }
@@ -383,29 +372,6 @@ static void mark_extents_written(struct pnfs_block_layout *bl, } } -static void bl_end_io_write_zero (struct bio *bio,int err) -{ -struct parallel_io *par = bio->bi_private; -struct bio_vec *bvec; -int i; - -bio_for_each_segment_all (bvec, bio, i) { -/* This is the zeroing page we added */ -end_page_writeback (bvec->bv_page); -page_cache_release (bvec->bv_page); - } - -if (unlikely (err)) { -struct nfs_pgio_header *header = par->data; - -if (!header->pnfs_error) - header->pnfs_error = -EIO ; -pnfs_set_lo_fail (header->lseg); - } -bio_put (bio); -put_parallel (par); -} -static void bl_end_io_write (struct bio *bio,int err) {struct parallel_io *par = bio->bi_private;
@@ -455,256 +421,22 @@ static void bl_end_par_io_write(void *data, int num_se)schedule_work (&hdr->task.u.tk_work); } -/* FIXME STUB - mark intersection of layout and page as bad, so is not -* used again. -*/ -static void mark_bad_read (void ) -{ -return ; -} - -/* -* map_block: map a requested I/0 block (isect) into an offset in the LVM -* block_device -*/ -static void -map_block (struct buffer_head *bh,sector_t isect,struct pnfs_block_extent *be) -{ -dprintk ("%s enter be=%p\n" , __func__, be); - -set_buffer_mapped (bh); - bh->b_bdev = be->be_mdev; - bh->b_blocknr = (isect - be->be_f_offset + be->be_v_offset) >> - (be->be_mdev->bd_inode->i_blkbits -SECTOR_SHIFT ); - -dprintk ("%s isect %llu, bh->b_blocknr %ld, using bsize %Zd\n" , - __func__, (unsigned long long )isect, (long )bh->b_blocknr, - bh->b_size); -return ; -} - -static void -bl_read_single_end_io (struct bio *bio,int error) -{ -struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt -1 ; -struct page *page = bvec->bv_page; - -/* Only one page in bvec */ -unlock_page (page); -} - -static int -bl_do_readpage_sync (struct page *page,struct pnfs_block_extent *be, -unsigned int offset,unsigned int len) -{ -struct bio *bio; -struct page *shadow_page; -sector_t isect; -char *kaddr, *kshadow_addr; -int ret =0 ; - -dprintk ("%s: offset %u len %u\n" , __func__, offset, len); - - shadow_page =alloc_page (GFP_NOFS | __GFP_HIGHMEM); -if (shadow_page ==NULL ) -return -ENOMEM ; - - bio =bio_alloc (GFP_NOIO ,1 ); -if (bio ==NULL ) -return -ENOMEM ; - - isect = (page->index <<PAGE_CACHE_SECTOR_SHIFT ) + - (offset /SECTOR_SIZE ); - - bio->bi_iter.bi_sector = isect - be->be_f_offset + be->be_v_offset; - bio->bi_bdev = be->be_mdev; - bio->bi_end_io = bl_read_single_end_io; - -lock_page (shadow_page); -if (bio_add_page (bio, shadow_page, -SECTOR_SIZE ,round_down (offset,SECTOR_SIZE )) ==0 ) { -unlock_page (shadow_page); -bio_put (bio); -return -EIO ; - } - -submit_bio (READ , bio); -wait_on_page_locked (shadow_page); -if (unlikely (!test_bit (BIO_UPTODATE , &bio->bi_flags))) { - ret = -EIO ; - }else { - kaddr =kmap_atomic (page); - kshadow_addr =kmap_atomic (shadow_page); -memcpy (kaddr + offset, kshadow_addr + offset, len); -kunmap_atomic (kshadow_addr); -kunmap_atomic (kaddr); - } -__free_page (shadow_page); -bio_put (bio); - -return ret; -} - -static int -bl_read_partial_page_sync (struct page *page,struct pnfs_block_extent *be, -unsigned int dirty_offset,unsigned int dirty_len, -bool full_page) -{ -int ret =0 ; -unsigned int start, end; - -if (full_page) { - start =0 ; - end =PAGE_CACHE_SIZE ; - }else { - start =round_down (dirty_offset,SECTOR_SIZE ); - end =round_up (dirty_offset + dirty_len,SECTOR_SIZE ); - } - -dprintk ("%s: offset %u len %d\n" , __func__, dirty_offset, dirty_len); -if (!be) { -zero_user_segments (page, start, dirty_offset, - dirty_offset + dirty_len, end); -if (start ==0 && end ==PAGE_CACHE_SIZE && -trylock_page (page)) { -SetPageUptodate (page); -unlock_page (page); - } -return ret; - } - -if (start != dirty_offset) - ret =bl_do_readpage_sync (page, be, start, dirty_offset - start); - -if (!ret && (dirty_offset + dirty_len < end)) - ret =bl_do_readpage_sync (page, be, dirty_offset + dirty_len, - end - dirty_offset - dirty_len); - -return ret; -} - -/* Given an unmapped page, zero it or read in page for COW, page is locked -* by caller. -*/ -static int -init_page_for_write (struct page *page,struct pnfs_block_extent *cow_read) -{ -struct buffer_head *bh =NULL ; -int ret =0 ; -sector_t isect; - -dprintk ("%s enter, %p\n" , __func__, page); -BUG_ON (PageUptodate (page)); -if (!cow_read) { -zero_user_segment (page,0 ,PAGE_SIZE ); -SetPageUptodate (page); - goto cleanup; - } - - bh =alloc_page_buffers (page,PAGE_CACHE_SIZE ,0 ); -if (!bh) { - ret = -ENOMEM ; - goto cleanup; - } - - isect = (sector_t ) page->index <<PAGE_CACHE_SECTOR_SHIFT ; -map_block (bh, isect, cow_read); -if (!bh_uptodate_or_lock (bh)) - ret =bh_submit_read (bh); -if (ret) - goto cleanup; -SetPageUptodate (page); - -cleanup: -if (bh) -free_buffer_head (bh); -if (ret) { -/* Need to mark layout with bad read...should now -* just use nfs4 for reads and writes. -*/ -mark_bad_read (); - } -return ret; -} - -/* Find or create a zeroing page marked being writeback. -* Return ERR_PTR on error, NULL to indicate skip this page and page itself -* to indicate write out. -*/ -static struct page * -bl_find_get_zeroing_page (struct inode *inode,pgoff_t index, -struct pnfs_block_extent *cow_read) -{ -struct page *page; -int locked =0 ; - page =find_get_page (inode->i_mapping, index); -if (page) - goto check_page; - - page =find_or_create_page (inode->i_mapping, index,GFP_NOFS ); -if (unlikely (!page)) { -dprintk ("%s oom\n" , __func__); -return ERR_PTR (-ENOMEM ); - } - locked =1 ; - -check_page: -/* PageDirty: Other will write this out -* PageWriteback: Other is writing this out -* PageUptodate: It was read before -*/ -if (PageDirty (page) ||PageWriteback (page)) { -print_page (page); -if (locked) -unlock_page (page); -page_cache_release (page); -return NULL ; - } - -if (!locked) { -lock_page (page); - locked =1 ; - goto check_page; - } -if (!PageUptodate (page)) { -/* New page, readin or zero it */ -init_page_for_write (page, cow_read); - } -set_page_writeback (page); -unlock_page (page); - -return page; -} -static enum pnfs_try_status bl_write_pagelist (struct nfs_pgio_header *header,int sync) { -int i, ret, npg_zero, pg_index, last =0 ; +int i, ret;struct bio *bio =NULL ; -struct pnfs_block_extent *be =NULL , *cow_read =NULL ; -sector_t isect, last_isect =0 , extent_length =0 ; +struct pnfs_block_extent *be =NULL ; +sector_t isect, extent_length =0 ;struct parallel_io *par =NULL ;loff_t offset = header->args.offset;size_t count = header->args.count; -unsigned int pg_offset, pg_len, saved_len;struct page **pages = header->args.pages; -struct page *page; -pgoff_t index; -u64 temp; -int npg_per_block = -NFS_SERVER (header->inode)->pnfs_blksize >>PAGE_CACHE_SHIFT ; +int pg_index = pg_index = header->args.pgbase >>PAGE_CACHE_SHIFT ;struct blk_plug plug;dprintk ("%s enter, %Zu@%lld\n" , __func__, count, offset); -blk_start_plug (&plug); - -if (header->dreq !=NULL && - (!IS_ALIGNED (offset,NFS_SERVER (header->inode)->pnfs_blksize) || - !IS_ALIGNED (count,NFS_SERVER (header->inode)->pnfs_blksize))) { -dprintk ("pnfsblock nonblock aligned DIO writes. Resend MDS\n" ); - goto out_mds; - }/* At this point, header->page_aray is a (sequential) list of nfs_pages. * We want to write each, and if there is an error set pnfs_error * to have it redone using nfs.
@@ -715,97 +447,20 @@ bl_write_pagelist(struct nfs_pgio_header *header, int sync) par->pnfs_callback = bl_end_par_io_write;/* At this point, have to be more careful with error handling */ - isect = (sector_t) ((offset & (long )PAGE_CACHE_MASK ) >>SECTOR_SHIFT ); - be =bl_find_get_extent (BLK_LSEG2EXT (header->lseg), isect, &cow_read); -if (!be || !is_writable (be, isect)) { -dprintk ("%s no matching extents!\n" , __func__); - goto out_mds; - } - -/* First page inside INVALID extent */ -if (be->be_state ==PNFS_BLOCK_INVALID_DATA ) { -if (likely (!bl_push_one_short_extent (be->be_inval))) - par->bse_count++; -else - goto out_mds; - temp = offset >>PAGE_CACHE_SHIFT ; - npg_zero =do_div (temp, npg_per_block); - isect = (sector_t) (((offset - npg_zero *PAGE_CACHE_SIZE ) & - (long )PAGE_CACHE_MASK ) >>SECTOR_SHIFT ); - extent_length = be->be_length - (isect - be->be_f_offset); - -fill_invalid_ext: -dprintk ("%s need to zero %d pages\n" , __func__, npg_zero); -for (;npg_zero >0 ; npg_zero--) { -if (bl_is_sector_init (be->be_inval, isect)) { -dprintk ("isect %llu already init\n" , - (unsigned long long )isect); - goto next_page; - } -/* page ref released in bl_end_io_write_zero */ - index = isect >>PAGE_CACHE_SECTOR_SHIFT ; -dprintk ("%s zero %dth page: index %lu isect %llu\n" , - __func__, npg_zero, index, - (unsigned long long )isect); - page =bl_find_get_zeroing_page (header->inode, index, - cow_read); -if (unlikely (IS_ERR (page))) { - header->pnfs_error =PTR_ERR (page); - goto out; - }else if (page ==NULL ) - goto next_page; - - ret =bl_mark_sectors_init (be->be_inval, isect, -PAGE_CACHE_SECTORS ); -if (unlikely (ret)) { -dprintk ("%s bl_mark_sectors_init fail %d\n" , - __func__, ret); -end_page_writeback (page); -page_cache_release (page); - header->pnfs_error = ret; - goto out; - } -if (likely (!bl_push_one_short_extent (be->be_inval))) - par->bse_count++; -else { -end_page_writeback (page); -page_cache_release (page); - header->pnfs_error = -ENOMEM ; - goto out; - } -/* FIXME: This should be done in bi_end_io */ -mark_extents_written (BLK_LSEG2EXT (header->lseg), - page->index <<PAGE_CACHE_SHIFT , -PAGE_CACHE_SIZE ); - - bio =bl_add_page_to_bio (bio, npg_zero,WRITE , - isect, page, be, - bl_end_io_write_zero, par); -if (IS_ERR (bio)) { - header->pnfs_error =PTR_ERR (bio); - bio =NULL ; - goto out; - } -next_page: - isect +=PAGE_CACHE_SECTORS ; - extent_length -=PAGE_CACHE_SECTORS ; - } -if (last) - goto write_done; - } - bio =bl_submit_bio (WRITE , bio); +blk_start_plug (&plug); -/* Middle pages */ - pg_index = header->args.pgbase >>PAGE_CACHE_SHIFT ; +/* we always write out the whole page */ + offset = offset & (loff_t )PAGE_CACHE_MASK ; + isect = offset >>SECTOR_SHIFT ; +for (i = pg_index; i < header->page_array.npages; i++) {if (extent_length <=0 ) {/* We've used up the previous extent */ bl_put_extent (be); -bl_put_extent (cow_read); bio =bl_submit_bio (WRITE , bio);/* Get the next one */ be =bl_find_get_extent (BLK_LSEG2EXT (header->lseg), - isect, &cow_read); + isect,NULL );if (!be || !is_writable (be, isect)) { header->pnfs_error = -EINVAL ; goto out;
@@ -823,25 +478,10 @@ next_page: (isect - be->be_f_offset); } -dprintk ("%s offset %lld count %Zu\n" , __func__, offset, count); - pg_offset = offset & ~PAGE_CACHE_MASK ; -if (pg_offset + count >PAGE_CACHE_SIZE ) - pg_len =PAGE_CACHE_SIZE - pg_offset; -else - pg_len = count; +BUG_ON (offset & ~PAGE_CACHE_MASK ); - saved_len = pg_len;if (be->be_state ==PNFS_BLOCK_INVALID_DATA && !bl_is_sector_init (be->be_inval, isect)) { - ret =bl_read_partial_page_sync (pages[i], cow_read, - pg_offset, pg_len, true); -if (ret) { -dprintk ("%s bl_read_partial_page_sync fail %d\n" , - __func__, ret); - header->pnfs_error = ret; - goto out; - } - ret =bl_mark_sectors_init (be->be_inval, isect,PAGE_CACHE_SECTORS );if (unlikely (ret)) {
@@ -850,66 +490,31 @@ next_page: header->pnfs_error = ret; goto out; } - -/* Expand to full page write */ - pg_offset =0 ; - pg_len =PAGE_CACHE_SIZE ; - }else if ((pg_offset & (SECTOR_SIZE -1 )) || - (pg_len & (SECTOR_SIZE -1 ))){ -/* ahh, nasty case. We have to do sync full sector -* read-modify-write cycles. -*/ -unsigned int saved_offset = pg_offset; - ret =bl_read_partial_page_sync (pages[i], be, pg_offset, - pg_len, false); - pg_offset =round_down (pg_offset,SECTOR_SIZE ); - pg_len =round_up (saved_offset + pg_len,SECTOR_SIZE ) - - pg_offset; } - bio =do_add_page_to_bio (bio, header->page_array.npages - i, -WRITE , - isect, pages[i], be, +WRITE , isect, pages[i], be, bl_end_io_write, par, - pg_offset, pg_len); +0 ,PAGE_CACHE_SIZE );if (IS_ERR (bio)) { header->pnfs_error =PTR_ERR (bio); bio =NULL ; goto out; } - offset += saved_len; - count -= saved_len; + offset +=PAGE_CACHE_SIZE ; + count -=PAGE_CACHE_SIZE ; isect +=PAGE_CACHE_SECTORS ; - last_isect = isect; extent_length -=PAGE_CACHE_SECTORS ; } -/* Last page inside INVALID extent */ -if (be->be_state ==PNFS_BLOCK_INVALID_DATA ) { - bio =bl_submit_bio (WRITE , bio); - temp = last_isect >>PAGE_CACHE_SECTOR_SHIFT ; - npg_zero = npg_per_block -do_div (temp, npg_per_block); -if (npg_zero < npg_per_block) { - last =1 ; - goto fill_invalid_ext; - } - } - -write_done: header->res.count = header->args.count; out:bl_put_extent (be); -bl_put_extent (cow_read);bl_submit_bio (WRITE , bio);blk_finish_plug (&plug);put_parallel (par);return PNFS_ATTEMPTED ; out_mds: -blk_finish_plug (&plug); -bl_put_extent (be); -bl_put_extent (cow_read); -kfree (par);return PNFS_NOT_ATTEMPTED ; }
@@ -1188,20 +793,45 @@ bl_clear_layoutdriver(struct nfs_server *server) }static bool -is_aligned_req (struct nfs_page *req,unsigned int alignment) +is_aligned_req (struct nfs_pageio_descriptor *pgio, +struct nfs_page *req,unsigned int alignment) { -return IS_ALIGNED (req->wb_offset, alignment) && -IS_ALIGNED (req->wb_bytes, alignment); +/* +* Always accept buffered writes, higher layers take care of the +* right alignment. +*/ +if (pgio->pg_dreq ==NULL ) +return true; + +if (!IS_ALIGNED (req->wb_offset, alignment)) +return false; + +if (IS_ALIGNED (req->wb_bytes, alignment)) +return true; + +if (req_offset (req) + req->wb_bytes ==i_size_read (pgio->pg_inode)) { +/* +* If the write goes up to the inode size, just write +* the full page. Data past the inode size is +* guaranteed to be zeroed by the higher level client +* code, and this behaviour is mandated by RFC 5663 +* section 2.3.2. +*/ +return true; + } + +return false; }static void bl_pg_init_read (struct nfs_pageio_descriptor *pgio,struct nfs_page *req) { -if (pgio->pg_dreq !=NULL && - !is_aligned_req (req,SECTOR_SIZE )) +if (!is_aligned_req (pgio, req,SECTOR_SIZE )) {nfs_pageio_reset_read_mds (pgio); -else -pnfs_generic_pg_init_read (pgio, req); +return ; + } + +pnfs_generic_pg_init_read (pgio, req); }/*
@@ -1212,10 +842,8 @@ static size_t bl_pg_test_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, struct nfs_page *req) { - if (pgio->pg_dreq != NULL && - !is_aligned_req(req, SECTOR_SIZE)) + if (!is_aligned_req(pgio, req, SECTOR_SIZE)) return 0; - return pnfs_generic_pg_test(pgio, prev, req); }
@@ -1245,19 +873,20 @@ static u64 pnfs_num_cont_bytes(struct inode *inode, pgoff_t idx)static void bl_pg_init_write (struct nfs_pageio_descriptor *pgio,struct nfs_page *req) { -if (pgio->pg_dreq !=NULL && - !is_aligned_req (req,PAGE_CACHE_SIZE )) { +u64 wb_size; + +if (!is_aligned_req (pgio, req,PAGE_SIZE )) {nfs_pageio_reset_write_mds (pgio); - }else { -u64 wb_size; -if (pgio->pg_dreq ==NULL ) - wb_size =pnfs_num_cont_bytes (pgio->pg_inode, - req->wb_index); -else - wb_size =nfs_dreq_bytes_left (pgio->pg_dreq); - -pnfs_generic_pg_init_write (pgio, req, wb_size); +return ; } + +if (pgio->pg_dreq ==NULL ) + wb_size =pnfs_num_cont_bytes (pgio->pg_inode, + req->wb_index); +else + wb_size =nfs_dreq_bytes_left (pgio->pg_dreq); + +pnfs_generic_pg_init_write (pgio, req, wb_size); }/*
@@ -1268,10 +897,8 @@ static size_t bl_pg_test_write(struct nfs_pageio_descriptor *pgio, struct nfs_page *prev, struct nfs_page *req) { - if (pgio->pg_dreq != NULL && - !is_aligned_req(req, PAGE_CACHE_SIZE)) + if (!is_aligned_req(pgio, req, PAGE_SIZE)) return 0; - return pnfs_generic_pg_test(pgio, prev, req); }
@@ -1291,6 +918,7 @@ static struct pnfs_layoutdriver_type blocklayout_type = { .id = LAYOUT_BLOCK_VOLUME, .name = "LAYOUT_BLOCK_VOLUME", .owner = THIS_MODULE, + .flags = PNFS_READ_WHOLE_PAGE, .read_pagelist = bl_read_pagelist, .write_pagelist = bl_write_pagelist, .alloc_layout_hdr = bl_alloc_layout_hdr,
Signature · 1 line
1.9.1
PATCH 5/9 pnfs/blocklayout: don't set pages uptodate
In reply to Christoph HellwigThe core nfs code handles setting pages uptodate on reads, no need to mess with the pageflags outselves. Also remove a debug function to dump page flags.
--- fs/nfs/blocklayout/blocklayout.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-)
fs/nfs/blocklayout/blocklayout.c +1 -23
@@ -49,20 +49,6 @@ MODULE_LICENSE("GPL");MODULE_AUTHOR ("Andy Adamson <[email protected]>" );MODULE_DESCRIPTION ("The NFSv4.1 pNFS Block layout driver" ); -static void print_page (struct page *page) -{ -dprintk ("PRINTPAGE page %p\n" , page); -dprintk (" PagePrivate %d\n" ,PagePrivate (page)); -dprintk (" PageUptodate %d\n" ,PageUptodate (page)); -dprintk (" PageError %d\n" ,PageError (page)); -dprintk (" PageDirty %d\n" ,PageDirty (page)); -dprintk (" PageReferenced %d\n" ,PageReferenced (page)); -dprintk (" PageLocked %d\n" ,PageLocked (page)); -dprintk (" PageWriteback %d\n" ,PageWriteback (page)); -dprintk (" PageMappedToDisk %d\n" ,PageMappedToDisk (page)); -dprintk ("\n" ); -} -/* Given the be associated with isect, determine if page data needs to be * initialized. */
@@ -187,16 +173,9 @@ retry:return bio; } -/* This is basically copied from mpage_end_io_read */ static void bl_end_io_read (struct bio *bio,int err) {struct parallel_io *par = bio->bi_private; -struct bio_vec *bvec; -int i; - -if (!err) -bio_for_each_segment_all (bvec, bio, i) -SetPageUptodate (bvec->bv_page);if (err) {struct nfs_pgio_header *header = par->data;
@@ -205,6 +184,7 @@ static void bl_end_io_read(struct bio *bio, int err) header->pnfs_error = -EIO ;pnfs_set_lo_fail (header->lseg); } +bio_put (bio);put_parallel (par); }
@@ -304,8 +284,6 @@ bl_read_pagelist(struct nfs_pgio_header *hdr)/* Fill hole w/ zeroes w/o accessing device */ dprintk ("%s Zeroing page for hole\n" , __func__);zero_user_segment (pages[i], pg_offset, pg_len); -print_page (pages[i]); -SetPageUptodate (pages[i]); }else {struct pnfs_block_extent *be_read;
Signature · 1 line
1.9.1
PATCH 6/9 pnfs/blocklayout: rewrite extent tracking
In reply to Christoph HellwigCurrently the block layout driver tracks extents in three separate data structures:
- the two list of pnfs_block_extent structures returned by the server
- the list of sectors that were in invalid state but have been written to
- a list of pnfs_block_short_extent structures for LAYOUTCOMMIT
All of these share the property that they are not only highly inefficient data structures, but also that operations on them are even more inefficient than nessecary.
In addition there are various implementation defects like:
- using an int to track sectors, causing corruption for large offsets
- incorrect normalization of page or block granularity ranges
- insufficient error handling
- incorrect synchronization as extents can be modified while they are in use
This patch replace all three data with a single unified rbtree structure tracking all extents, as well as their in-memory state, although we still need to instance for read-only and read-write extent due to the arcane client side COW feature in the block layouts spec.
To fix the problem of extent possibly being modified while in use we make sure to return a copy of the extent for use in the write path - the extent can only be invalidated by a layout recall or return which has to wait until the I/O operations finished due to refcounts on the layout segment.
The new extent tree work similar to the schemes used by block based filesystems like XFS or ext4.
--- fs/nfs/blocklayout/Makefile | 3 +- fs/nfs/blocklayout/blocklayout.c | 258 +++------- fs/nfs/blocklayout/blocklayout.h | 112 +---- fs/nfs/blocklayout/blocklayoutdev.c | 35 +- fs/nfs/blocklayout/extent_tree.c | 547 ++++++++++++++++++++++ fs/nfs/blocklayout/extents.c | 908 ------------------------------------ 6 files changed, 651 insertions(+), 1212 deletions(-) create mode 100644 fs/nfs/blocklayout/extent_tree.c delete mode 100644 fs/nfs/blocklayout/extents.c
fs/nfs/blocklayout/Makefile +2 -1
@@ -2,4 +2,5 @@ # Makefile for the pNFS block layout driver kernel module # obj-$(CONFIG_PNFS_BLOCK) += blocklayoutdriver.o -blocklayoutdriver-objs := blocklayout.o extents.o blocklayoutdev.o blocklayoutdm.o +blocklayoutdriver-objs := blocklayout.o blocklayoutdev.o blocklayoutdm.o \ + extent_tree.o
fs/nfs/blocklayout/blocklayout.c +66 -192
433 lines not on this page · raw message
fs/nfs/blocklayout/blocklayout.h +23 -89
134 lines not on this page · raw message
fs/nfs/blocklayout/blocklayoutdev.c +13 -22
@@ -309,7 +309,7 @@ nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo,* recovery easier. */ for (i =0 ; i < count; i++) { - be =bl_alloc_extent (); + be =kzalloc (sizeof (struct pnfs_block_extent ),GFP_NOFS );if (!be) { status = -ENOMEM ; goto out_err;
@@ -330,13 +330,11 @@ nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo,if (decode_sector_number (&p, &be->be_v_offset) <0 ) goto out_err; be->be_state =be32_to_cpup (p++); -if (be->be_state ==PNFS_BLOCK_INVALID_DATA ) - be->be_inval = &bl->bl_inval;if (verify_extent (be, &lv)) {dprintk ("%s verify failed\n" , __func__); goto out_err; } -list_add_tail (&be->be_node, &extents); +list_add_tail (&be->be_list, &extents); }if (lgr->range.offset + lgr->range.length != lv.start <<SECTOR_SHIFT ) {
@@ -352,21 +350,13 @@ nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo,/* Extents decoded properly, now try to merge them in to * existing layout extents. */ -spin_lock (&bl->bl_ext_lock); -list_for_each_entry_safe (be, save, &extents, be_node) { -list_del (&be->be_node); - status =bl_add_merge_extent (bl, be); -if (status) { -spin_unlock (&bl->bl_ext_lock); -/* This is a fairly catastrophic error, as the -* entire layout extent lists are now corrupted. -* We should have some way to distinguish this. -*/ - be =NULL ; - goto out_err; - } +list_for_each_entry_safe (be, save, &extents, be_list) { +list_del (&be->be_list); + + status =ext_tree_insert (bl, be); +if (status) + goto out_free_list; } -spin_unlock (&bl->bl_ext_lock); status =0 ; out:__free_page (scratch);
@@ -374,12 +364,13 @@ nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo,return status; out_err: -bl_put_extent (be); +kfree (be); + out_free_list:while (!list_empty (&extents)) { be = list_first_entry(&extents, struct pnfs_block_extent, - be_node); -list_del (&be->be_node); -bl_put_extent (be); + be_list); +list_del (&be->be_list); +kfree (be); } goto out; }
fs/nfs/blocklayout/extent_tree.c new file +547 -0
547 lines not on this page · raw message
fs/nfs/blocklayout/extents.c deleted +0 -908
908 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH 6/9] pnfs/blocklayout: rewrite extent tracking
Hi Christoph,
I really like your refactoring. It looks a lot better than the original lists-every-where code. One minor comment below:
<snip..>
Quoted 13 lines
static void
bl_write_cleanup(struct work_struct *work){fs/nfs/blocklayout/blocklayout.c +5
-4-struct rpc_task *task; -struct nfs_pgio_header *hdr; + struct rpc_task *task = container_of(work, struct rpc_task, u.tk_work); +struct nfs_pgio_header *hdr = + container_of(task, struct nfs_pgio_header, task); +dprintk ("%s enter\n" , __func__); - task = container_of(work, struct rpc_task, u.tk_work); - hdr = container_of(task, struct nfs_pgio_header, task); +if (likely (!hdr->pnfs_error)) {
fs/nfs/blocklayout/blocklayout.c static void bl_end_io_write(struct bio *bio, int err) · line 326
Quoted 10 lines
fs/nfs/blocklayout/blocklayout.c +7
-3-/* Marks for LAYOUTCOMMIT */ -mark_extents_written (BLK_LSEG2EXT (hdr->lseg), - hdr->args.offset, hdr->args.count); +struct pnfs_block_layout *bl =BLK_LSEG2EXT (hdr->lseg); +u64 start = hdr->args.offset & (loff_t )PAGE_CACHE_MASK ; +u64 end = (hdr->args.offset + hdr->args.count + +PAGE_CACHE_SIZE -1 ) & (loff_t )PAGE_CACHE_MASK ; + +ext_tree_mark_written (bl, start >>SECTOR_SHIFT , + (end - start) >>SECTOR_SHIFT );
The old code works in a way that mark_extents_written() always succeeds. Now that ext_tree_mark_written() may fail, it should check for the return value and resend to MDS if failed, otherwise there may be silent data corruption.
Thanks,
Tao
Re: [PATCH 6/9] pnfs/blocklayout: rewrite extent tracking
Quoted 4 lines · Peng Tao
The old code works in a way that
mark_extents_written()always succeeds. Now thatext_tree_mark_written()may fail, it should check for the return value and resend to MDS if failed, otherwise there may be silent data corruption.
It can only fail for memory allocation erorrs, which can indeed happen in theory although not in practice for the amount we do. But I'll prepare testing using error injection and will handle it, thanks!
PATCH 7/9 pnfs/blocklayout: implement the return_range method
In reply to Christoph HellwigThis allows removing extents from the extent tree especially on truncate operations, and thus fixing reads from truncated and re-extended that previously returned stale data.
--- fs/nfs/blocklayout/blocklayout.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
fs/nfs/blocklayout/blocklayout.c +30 -0
@@ -470,6 +470,35 @@ static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo, }static void +bl_return_range (struct pnfs_layout_hdr *lo, +struct pnfs_layout_range *range) +{ +struct pnfs_block_layout *bl =BLK_LO2EXT (lo); +sector_t offset = range->offset >>SECTOR_SHIFT , end; +int err; + +if (range->offset %8 ) { +dprintk ("%s: offset %lld not block size aligned\n" , + __func__, range->offset); +return ; + } + +if (range->length !=NFS4_MAX_UINT64 ) { +if (range->length %8 ) { +dprintk ("%s: length %lld not block size aligned\n" , + __func__, range->length); +return ; + } + + end = offset + (range->length >>SECTOR_SHIFT ); + }else { + end =round_down (NFS4_MAX_UINT64 ,PAGE_SIZE ); + } + + err =ext_tree_remove (bl, range->iomode &IOMODE_RW , offset, end); +} + +static void bl_encode_layoutcommit (struct pnfs_layout_hdr *lo,struct xdr_stream *xdr,const struct nfs4_layoutcommit_args *arg) {
@@ -777,6 +806,7 @@ static struct pnfs_layoutdriver_type blocklayout_type = { .free_layout_hdr = bl_free_layout_hdr, .alloc_lseg = bl_alloc_lseg, .free_lseg = bl_free_lseg, + .return_range = bl_return_range, .encode_layoutcommit = bl_encode_layoutcommit, .cleanup_layoutcommit = bl_cleanup_layoutcommit, .set_layoutdriver = bl_set_layoutdriver,
Signature · 1 line
1.9.1
Re: [PATCH 7/9] pnfs/blocklayout: implement the return_range method
Quoted 15 lines · Christoph Hellwig
This allows removing extents from the extent tree especially on truncate operations, and thus fixing reads from truncated and re-extended that previously returned stale data.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/nfs/blocklayout/blocklayout.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)fs/nfs/blocklayout/blocklayout.c +0
-0@@ -470,6 +470,35 @@ static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo, }
fs/nfs/blocklayout/blocklayout.c static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo, · line 480
Quoted 10 lines
fs/nfs/blocklayout/blocklayout.c +8
-0static void +bl_return_range (struct pnfs_layout_hdr *lo, +struct pnfs_layout_range *range) +{ +struct pnfs_block_layout *bl =BLK_LO2EXT (lo); +sector_t offset = range->offset >>SECTOR_SHIFT , end; +int err; + +if (range->offset %8 ) {
why arbitrary block size? You should be able to use the blocksize returned by server, right?
btw, did you test your patchset with smaller block size such as 2K/1K? Did it work?
fs/nfs/blocklayout/blocklayout.c static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo, · line 487
Quoted 7 lines
fs/nfs/blocklayout/blocklayout.c +7
-0+dprintk ("%s: offset %lld not block size aligned\n" , + __func__, range->offset); +return ; + } + +if (range->length !=NFS4_MAX_UINT64 ) { +if (range->length %8 ) {
ditto here.
Cheers,
Tao
Re: [PATCH 7/9] pnfs/blocklayout: implement the return_range method
Quoted 7 lines · Peng Tao
Quoted 7 lines
fs/nfs/blocklayout/blocklayout.c +0
-0@@ -470,6 +470,35 @@ static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo, }
Quoted 11 lines
fs/nfs/blocklayout/blocklayout.c static struct pnfs_layout_segment *bl_alloc_lseg(struct pnfs_layout_hdr *lo, · line 480
Quoted 9 lines
fs/nfs/blocklayout/blocklayout.c +8
-0static void +bl_return_range (struct pnfs_layout_hdr *lo, +struct pnfs_layout_range *range) +{ +struct pnfs_block_layout *bl =BLK_LO2EXT (lo); +sector_t offset = range->offset >>SECTOR_SHIFT , end; +int err; + +if (range->offset %8 ) {why arbitrary block size? You should be able to use the blocksize returned by server, right?
I need to look into it. Right now the client has all extents properly aligned, and allowing a smaller size here would change that. Give me some time to test it and get back to you.
Quoted 3 lines
btw, did you test your patchset with smaller block size such as 2K/1K? Did it work?
I did test a very early version but haven't redone the tests. It worked fine because even although the server supported smaller blocks the client now never asks for anything not aligned to 4k!
PATCH 8/9 pnfs/blocklayout: return layouts on setattr
In reply to Christoph HellwigThis speads up truncate-heavy workloads like fsx by multiple orders of magnitude.
--- fs/nfs/blocklayout/blocklayout.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfs/blocklayout/blocklayout.c +2 -1
@@ -799,7 +799,8 @@ static struct pnfs_layoutdriver_type blocklayout_type = { .id = LAYOUT_BLOCK_VOLUME, .name = "LAYOUT_BLOCK_VOLUME", .owner = THIS_MODULE, - .flags = PNFS_READ_WHOLE_PAGE, + .flags =PNFS_LAYOUTRET_ON_SETATTR | + PNFS_READ_WHOLE_PAGE, .read_pagelist = bl_read_pagelist, .write_pagelist = bl_write_pagelist, .alloc_layout_hdr = bl_alloc_layout_hdr,
Signature · 1 line
1.9.1
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
Quoted 13 lines · Christoph Hellwig
This speads up truncate-heavy workloads like fsx by multiple orders of magnitude.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/nfs/blocklayout/blocklayout.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/nfs/blocklayout/blocklayout.c +0
-0
fs/nfs/blocklayout/blocklayout.c static struct pnfs_layoutdriver_type blocklayout_type = { · line 803
Quoted 6 lines
fs/nfs/blocklayout/blocklayout.c +2
-1@@ -799,7 +799,8 @@ static struct pnfs_layoutdriver_type blocklayout_type = { .id = LAYOUT_BLOCK_VOLUME, .name = "LAYOUT_BLOCK_VOLUME", .owner = THIS_MODULE, - .flags = PNFS_READ_WHOLE_PAGE, + .flags =PNFS_LAYOUTRET_ON_SETATTR | + PNFS_READ_WHOLE_PAGE,
The reason I didn't add it was because PNFS_LAYOUTRET_ON_SETATTR is too much for blocks layout. What we really want is to return layouts on truncate and chown, instead of _all_ setattr requests.
Boaz, does object layout require return on setattr for other reasons? If not, I'd suggest we change PNFS_LAYOUTRET_ON_SETATTR to return only on chown/truncate events.
Thanks,
Tao
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
Quoted 24 lines · Peng Tao
Quoted 13 lines · Christoph Hellwig
This speads up truncate-heavy workloads like fsx by multiple orders of magnitude.
Signed-off-by Christoph Hellwig <[email protected]>--- fs/nfs/blocklayout/blocklayout.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/nfs/blocklayout/blocklayout.c +0
-0fs/nfs/blocklayout/blocklayout.c static struct pnfs_layoutdriver_type blocklayout_type = { · line 803
Quoted 6 lines
fs/nfs/blocklayout/blocklayout.c +2
-1@@ -799,7 +799,8 @@ static struct pnfs_layoutdriver_type blocklayout_type = { .id = LAYOUT_BLOCK_VOLUME, .name = "LAYOUT_BLOCK_VOLUME", .owner = THIS_MODULE, - .flags = PNFS_READ_WHOLE_PAGE, + .flags =PNFS_LAYOUTRET_ON_SETATTR | + PNFS_READ_WHOLE_PAGE,The reason I didn't add it was because
PNFS_LAYOUTRET_ON_SETATTRis too much for blocks layout. What we really want is to return layouts on truncate and chown, instead of _all_ setattr requests.
Quoted 4 lines
Boaz, does object layout require return on setattr for other reasons? If not, I'd suggest we change
PNFS_LAYOUTRET_ON_SETATTRto return only on chown/truncate events.
ACK. chown/truncate
Quoted 3 lines
Thanks,
Tao
Thanks
Boaz
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
In reply to Peng TaoQuoted 7 lines · Peng Tao
The reason I didn't add it was because
PNFS_LAYOUTRET_ON_SETATTRis too much for blocks layout. What we really want is to return layouts on truncate and chown, instead of _all_ setattr requests.Boaz, does object layout require return on setattr for other reasons? If not, I'd suggest we change
PNFS_LAYOUTRET_ON_SETATTRto return only on chown/truncate events.
I was actually going to ask the same question, I can't see a point why the object layout driver would want it on any other setattr.
In fact it could probably be narrowed down to chown or truncate to a smaller size.
I'd also love to know why we don't want to do this for the filelayout driver.
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Peng Tao
The reason I didn't add it was because
PNFS_LAYOUTRET_ON_SETATTRis too much for blocks layout. What we really want is to return layouts on truncate and chown, instead of _all_ setattr requests.Boaz, does object layout require return on setattr for other reasons? If not, I'd suggest we change
PNFS_LAYOUTRET_ON_SETATTRto return only on chown/truncate events.
Quoted 8 lines
I was actually going to ask the same question, I can't see a point why the object layout driver would want it on any other setattr.
In fact it could probably be narrowed down to chown or truncate to a smaller size.
I'd also love to know why we don't want to do this for the filelayout driver.
Why would it be needed? The layout isn't expected to change. If the chown affects permissions then it is up to the DS to enforce that (although POSIX does not require it to do that).
Signature · 5 lines
Trond Myklebust Linux NFS client maintainer, PrimaryData [email protected]
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
Quoted 3 lines · Trond Myklebust
Why would it be needed? The layout isn't expected to change. If the chown affects permissions then it is up to the DS to enforce that (although POSIX does not require it to do that).
I was wondering about the truncate case. Even if the DS needs to be able to enforce the new size it seems pointless to keep a layout beyond the size around.
I don't really see a need to drop on a chown for the blocklayout or objlayout drivers either, given that these semantics are enforced at a higher level.
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Trond Myklebust
Why would it be needed? The layout isn't expected to change. If the chown affects permissions then it is up to the DS to enforce that (although POSIX does not require it to do that).
I was wondering about the truncate case. Even if the DS needs to be able to enforce the new size it seems pointless to keep a layout beyond the size around.
In the files layout case, it is actually quite common for the server to hand out an "infinite" sized layout in response to a LAYOUTGET. It means that the client doesn't need to ask for a new layout in order to append to the file.
Quoted 3 lines
I don't really see a need to drop on a chown for the blocklayout or objlayout drivers either, given that these semantics are enforced at a higher level.
Signature · 5 lines
Trond Myklebust Linux NFS client maintainer, PrimaryData [email protected]
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
On 09/11/2014 07:14 PM, Trond Myklebust wrote:
<>
Quoted 5 lines
In the files layout case, it is actually quite common for the server to hand out an "infinite" sized layout in response to a LAYOUTGET. It means that the client doesn't need to ask for a new layout in order to append to the file.
You mean to say that: "The Linux files-layout driver only supports infinite
sized layout, so it is pointless to return a layout which will be returned again, exactly the same"
Because I agree that "an infinite sized layout" need not be returned but an none-infinite should, only we do not have any.
Cheers
Boaz
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
Quoted 8 lines · Boaz Harrosh
On 09/11/2014 07:14 PM, Trond Myklebust wrote:
<>Quoted 5 lines
In the files layout case, it is actually quite common for the server to hand out an "infinite" sized layout in response to a LAYOUTGET. It means that the client doesn't need to ask for a new layout in order to append to the file.
Quoted 7 lines
You mean to say that: "The Linux files-layout driver only supports infinite
sized layout, so it is pointless to return a layout which will be returned again, exactly the same"Because I agree that "an infinite sized layout" need not be returned but an none-infinite should, only we do not have any.
No Boaz. I mean that it is utterly pointless and stupid to return a layout that doesn't preallocate any resources when it isn't necessary to do so.
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
Quoted 1 line · Trond Myklebust
On Sun, Sep 14, 2014 at 6:55 AM, Boaz Harrosh <[email protected]> wrote:
<>
Quoted 5 lines
No Boaz. I mean that it is utterly pointless and stupid to return a layout that doesn't preallocate any resources when it isn't necessary to do so.
"preallocate any resources" where? at the client it might not but the server might have allocated resources per lo-segment.
For example a CEPH server allocates a device_id per file-lo-segment. If you lo_return a truncated segment it might be able to free that device_id.
Cheers
Boaz
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
Quoted 9 lines · Boaz Harrosh
Quoted 1 line · Trond Myklebust
On Sun, Sep 14, 2014 at 6:55 AM, Boaz Harrosh <[email protected]> wrote:
<>
Quoted 5 lines
No Boaz. I mean that it is utterly pointless and stupid to return a layout that doesn't preallocate any resources when it isn't necessary to do so.
Quoted 5 lines
"preallocate any resources" where? at the client it might not but the server might have allocated resources per lo-segment.
For example a CEPH server allocates adevice_idper file-lo-segment. If youlo_returna truncated segment it might be able to free thatdevice_id.
There is no requirement anywhere in RFC5661 to state that a truncate must be prefixed by a layout return. Not in section 12 (Parallel NFS) nor in section 13 (NFSv4.1 as a Storage Protocol in pNFS: the File Layout Type), nor in the ERRATA. Existing pNFS files servers (i.e. NetApp) don't need it either.
If a future CEPH server wants to add its own requirements, then it is free to issue a layoutrecall. However my understanding from conversations with Matt (the Ganesha release notes appear to confirm) was that the CRUSH algorithm is pretty much impossible to implement as a files layout type, so I'm confused as to why it would be a problem in the first place.
Re: [PATCH 8/9] pnfs/blocklayout: return layouts on setattr
On 09/14/2014 05:16 PM, Trond Myklebust wrote:
<>
Quoted 7 lines
There is no requirement anywhere in RFC5661 to state that a truncate must be prefixed by a layout return. Not in section 12 (Parallel NFS) nor in section 13 (NFSv4.1 as a Storage Protocol in pNFS: the File Layout Type), nor in the ERRATA. Existing pNFS files servers (i.e. NetApp) don't need it either.
Yes! which is why it sucks ;-)
Quoted 7 lines
If a future CEPH server wants to add its own requirements, then it is free to issue a layoutrecall. However my understanding from conversations with Matt (the Ganesha release notes appear to confirm) was that the CRUSH algorithm is pretty much impossible to implement as a files layout type, so I'm confused as to why it would be a problem in the first place.
"impossible to implement" without lo-segments yes. *With* lo-segments it is my opinion that it is possible. With the contraption of device_id per segment.
But this argument is mute we both agree that in current code it is not needed.
[ If at future time someone will want to implement lo-segments for
Linux files layout, I think it could be a nice optimization, just as it is with objects and blocks.
Imagine a most simple files MDS that wants to not create filehandles(files) on DSs that will not be reached. (Create on demand). In such case deleting the DS-files on truncate might make sense no?
]
Xheers
Boaz
PATCH 9/9 pnfs/blocklayout: allocate separate pages for the layoutcommit payload
In reply to Christoph HellwigInstead of overflowing the XDR send buffer with our extent list allocate pages and pre-encode the layoutupdate payload into them. We optimistically allocate a single page use alloc_page and only switch to vmalloc when we have more extents outstanding. Currently there is only a single testcase (xfstests generic/113) which can reproduce large enough extent lists for this to occur.
--- fs/nfs/blocklayout/blocklayout.c | 15 ++---- fs/nfs/blocklayout/blocklayout.h | 8 ++-- fs/nfs/blocklayout/extent_tree.c | 100 +++++++++++++++++++++++++++++++-------- 3 files changed, 90 insertions(+), 33 deletions(-)
fs/nfs/blocklayout/blocklayout.c +5 -10
@@ -498,21 +498,16 @@ bl_return_range(struct pnfs_layout_hdr *lo, err =ext_tree_remove (bl, range->iomode &IOMODE_RW , offset, end); } -static void -bl_encode_layoutcommit (struct pnfs_layout_hdr *lo,struct xdr_stream *xdr, -const struct nfs4_layoutcommit_args *arg) +static int +bl_prepare_layoutcommit (struct nfs4_layoutcommit_args *arg) { -dprintk ("%s enter\n" , __func__); -ext_tree_encode_commit (BLK_LO2EXT (lo), xdr); +return ext_tree_prepare_commit (arg); }static void bl_cleanup_layoutcommit (struct nfs4_layoutcommit_data *lcdata) { -struct pnfs_layout_hdr *lo =NFS_I (lcdata->args.inode)->layout; - -dprintk ("%s enter\n" , __func__); -ext_tree_mark_committed (BLK_LO2EXT (lo), lcdata->res.status); +ext_tree_mark_committed (&lcdata->args, lcdata->res.status); }static void free_blk_mountid (struct block_mount_id *mid)
@@ -808,7 +803,7 @@ static struct pnfs_layoutdriver_type blocklayout_type = { .alloc_lseg = bl_alloc_lseg, .free_lseg = bl_free_lseg, .return_range = bl_return_range, - .encode_layoutcommit = bl_encode_layoutcommit, + .prepare_layoutcommit = bl_prepare_layoutcommit, .cleanup_layoutcommit = bl_cleanup_layoutcommit, .set_layoutdriver = bl_set_layoutdriver, .clear_layoutdriver = bl_clear_layoutdriver,
fs/nfs/blocklayout/blocklayout.h +5 -3
@@ -80,6 +80,9 @@ struct pnfs_block_extent {unsigned int be_tag; }; +/* on the wire size of the extent */ +#define BL_EXTENT_SIZE (7 * sizeof(__be32) + NFS4_DEVICEID4_SIZE) +struct pnfs_block_layout {struct pnfs_layout_hdr bl_layout;struct rb_root bl_ext_rw;
@@ -138,8 +141,7 @@ int ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start, sector_t len);bool ext_tree_lookup (struct pnfs_block_layout *bl,sector_t isect,struct pnfs_block_extent *ret,bool rw); -int ext_tree_encode_commit (struct pnfs_block_layout *bl, -struct xdr_stream *xdr); -void ext_tree_mark_committed (struct pnfs_block_layout *bl,int status); +int ext_tree_prepare_commit (struct nfs4_layoutcommit_args *arg); +void ext_tree_mark_committed (struct nfs4_layoutcommit_args *arg,int status);#endif /* FS_NFS_NFS4BLOCKLAYOUT_H */
fs/nfs/blocklayout/extent_tree.c +80 -20
136 lines not on this page · raw message
Signature · 1 line
1.9.1