support large folios for NFS
Subsystems (5)
Hi all,
this series adds large folio support to NFS, and almost doubles the buffered write throughput from the previous bottleneck of ~2.5GB/s (just like for other file systems).
The first patch is an old one from willy that I've updated very slightly. Note that this update now requires the mapping_max_folio_size helper merged into Linus' tree only a few minutes ago.
Diffstat:
fs/nfs/file.c | 4 +++- fs/nfs/inode.c | 1 + mm/filemap.c | 40 +++++++++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 16 deletions(-)
PATCH 1/2 filemap: Convert generic_perform_write() to support large folios
From: "Matthew Wilcox (Oracle)" <[email protected]>
Modelled after the loop in iomap_write_iter(), copy larger chunks from userspace if the filesystem has created large folios.
[hch: use mapping_max_folio_size to keep supporting file systems that do
not support large folios]
--- mm/filemap.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-)
mm/filemap.c +25 -15
@@ -3981,21 +3981,24 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)loff_t pos = iocb->ki_pos;struct address_space *mapping = file->f_mapping;const struct address_space_operations *a_ops = mapping->a_ops; +size_t chunk =mapping_max_folio_size (mapping);long status =0 ;ssize_t written =0 ; do { struct page *page; - unsigned long offset; /* Offset into pagecache page */ - unsigned long bytes; /* Bytes to write to page */ + struct folio *folio; + size_t offset; /* Offset into folio */ + size_t bytes; /* Bytes to write to folio */ size_t copied; /* Bytes copied from user */ void *fsdata = NULL; - offset = (pos & (PAGE_SIZE - 1)); - bytes = min_t(unsigned long, PAGE_SIZE - offset, - iov_iter_count(i)); + bytes = iov_iter_count(i); +retry: + offset = pos & (chunk - 1); + bytes = min(chunk - offset, bytes); + balance_dirty_pages_ratelimited(mapping); -again: /* * Bring in the user page that we will copy from _first_. * Otherwise there's a nasty deadlock on copying from the
@@ -4017,11 +4020,16 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)if (unlikely (status <0 ))break ; + folio =page_folio (page); + offset =offset_in_folio (folio, pos); +if (bytes >folio_size (folio) - offset) + bytes =folio_size (folio) - offset; +if (mapping_writably_mapped (mapping)) -flush_dcache_page (page); +flush_dcache_folio (folio); - copied =copy_page_from_iter_atomic (page, offset, bytes, i); -flush_dcache_page (page); + copied =copy_folio_from_iter_atomic (folio, offset, bytes, i); +flush_dcache_folio (folio); status = a_ops->write_end (file, mapping, pos, bytes, copied, page, fsdata);
@@ -4039,14 +4047,16 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)* halfway through, might be a race with munmap, * might be severe memory pressure. */ -if (copied) +if (chunk >PAGE_SIZE ) + chunk /=2 ; +if (copied) { bytes = copied; - goto again; + goto retry; + } + }else { + pos += status; + written += status; } - pos += status; - written += status; - -balance_dirty_pages_ratelimited (mapping); }while (iov_iter_count (i));if (!written)
Signature · 1 line
2.43.0
Matthew Wilcox
maintainerRe: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios
Quoted 9 lines · Christoph Hellwig
From: "Matthew Wilcox (Oracle)" <[email protected]>
Modelled after the loop in
iomap_write_iter(), copy larger chunks from userspace if the filesystem has created large folios.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>[hch: use
mapping_max_folio_sizeto keep supporting file systems that do
not support large folios]Signed-off-by Christoph Hellwig <[email protected]>
Yup, this still makes sense to me.
Could you remind me why we need to call flush_dcache_folio() in generic_perform_write() while we don't in iomap_write_iter()?
mm/filemap.c ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) · line 4029
Quoted 3 lines
mm/filemap.c +1
-1if (mapping_writably_mapped (mapping)) -flush_dcache_page (page); +flush_dcache_folio (folio);
(i'm not talking about this one)
mm/filemap.c ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) · line 4032
Quoted 4 lines
mm/filemap.c +2
-2- copied =copy_page_from_iter_atomic (page, offset, bytes, i); -flush_dcache_page (page); + copied =copy_folio_from_iter_atomic (folio, offset, bytes, i); +flush_dcache_folio (folio);
(this one has no equivalent in iomap)
Quoted 2 lines
mm/filemap.c +0
-0status = a_ops->write_end (file, mapping, pos, bytes, copied, page, fsdata);
Re: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios
Quoted 9 lines · Matthew Wilcox
Could you remind me why we need to call
flush_dcache_folio()ingeneric_perform_write()while we don't iniomap_write_iter()?mm/filemap.c ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) · line 4032
Quoted 4 lines
mm/filemap.c +2
-2- copied =copy_page_from_iter_atomic (page, offset, bytes, i); -flush_dcache_page (page); + copied =copy_folio_from_iter_atomic (folio, offset, bytes, i); +flush_dcache_folio (folio);(this one has no equivalent in iomap)
The iomap equivalent is in __iomap_write_end and iomap_write_end_inline and block_write_end.
Re: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios
In reply to Christoph HellwigHi Christoph, Matthew,
Quoted 58 lines · Christoph Hellwig
From: "Matthew Wilcox (Oracle)" <[email protected]>
Modelled after the loop in
iomap_write_iter(), copy larger chunks from userspace if the filesystem has created large folios.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>[hch: use
mapping_max_folio_sizeto keep supporting file systems that do
not support large folios]Signed-off-by Christoph Hellwig <[email protected]>--- mm/filemap.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-)mm/filemap.c +14
-6@@ -3981,21 +3981,24 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)loff_t pos = iocb->ki_pos;struct address_space *mapping = file->f_mapping;const struct address_space_operations *a_ops = mapping->a_ops; +size_t chunk =mapping_max_folio_size (mapping);long status =0 ;ssize_t written =0 ; do { struct page *page; - unsigned long offset; /* Offset into pagecache page */ - unsigned long bytes; /* Bytes to write to page */ + struct folio *folio; + size_t offset; /* Offset into folio */ + size_t bytes; /* Bytes to write to folio */ size_t copied; /* Bytes copied from user */ void *fsdata = NULL; - offset = (pos & (PAGE_SIZE - 1)); - bytes = min_t(unsigned long, PAGE_SIZE - offset, - iov_iter_count(i)); + bytes = iov_iter_count(i); +retry: + offset = pos & (chunk - 1); + bytes = min(chunk - offset, bytes); + balance_dirty_pages_ratelimited(mapping); -again: /* * Bring in the user page that we will copy from _first_. * Otherwise there's a nasty deadlock on copying from the@@ -4017,11 +4020,16 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)if (unlikely (status <0 ))break ; + folio =page_folio (page); + offset =offset_in_folio (folio, pos); +if (bytes >folio_size (folio) - offset) + bytes =folio_size (folio) - offset; +if (mapping_writably_mapped (mapping))
mm/filemap.c ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) · line 4035
Quoted 10 lines
mm/filemap.c +3
-3-flush_dcache_page (page); +flush_dcache_folio (folio); - copied =copy_page_from_iter_atomic (page, offset, bytes, i); -flush_dcache_page (page); + copied =copy_folio_from_iter_atomic (folio, offset, bytes, i); +flush_dcache_folio (folio); status = a_ops->write_end (file, mapping, pos, bytes, copied, page, fsdata);
I have the same patch for shmem and large folios tree. That was the last piece needed for getting better performance results. However, it is also needed to support folios in the write_begin() and write_end() callbacks. In order to avoid making them local to shmem, how should we do the transition to folios in these 2 callbacks? I was looking into aops->read_folio approach but what do you think?
Quoted 26 lines
mm/filemap.c +8
-6@@ -4039,14 +4047,16 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)* halfway through, might be a race with munmap, * might be severe memory pressure. */ -if (copied) +if (chunk >PAGE_SIZE ) + chunk /=2 ; +if (copied) { bytes = copied; - goto again; + goto retry; + } + }else { + pos += status; + written += status; } - pos += status; - written += status; - -balance_dirty_pages_ratelimited (mapping); }while (iov_iter_count (i));if (!written)Signature · 1 line
2.43.0
Daniel
Matthew Wilcox
maintainerRe: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios
Quoted 3 lines · Daniel Gomez
I have the same patch for shmem and large folios tree. That was the last piece needed for getting better performance results. However, it is also needed to support folios in the
write_begin()andwrite_end()callbacks.
I don't think it's *needed*. It's nice! But clearly not necessary since Christoph made nfs work without doing that.
Quoted 3 lines
In order to avoid
making them local to shmem, how should we do the transition to folios in these 2 callbacks? I was looking intoaops->read_folioapproach but what do you think?
See the v2 of buffer_write_operations that I just posted. I was waiting for feedback from Christoph on the revised method for passing fsdata around, but I may as well just post a v2 and see what happens.
Re: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios
Quoted 7 lines · Matthew Wilcox
Quoted 3 lines · Daniel Gomez
I have the same patch for shmem and large folios tree. That was the last piece needed for getting better performance results. However, it is also needed to support folios in the
write_begin()andwrite_end()callbacks.I don't think it's *needed*. It's nice! But clearly not necessary since Christoph made nfs work without doing that.
I see. We send anyway the length with bytes and the folio allocated inside write_begin() is retrieved with folio_page().
I did test this patch (+mapping_max_folio_size() patch) for shmem an it works fine for me.
Quoted 8 lines
Quoted 4 lines
In order to avoid
making them local to shmem, how should we do the transition to folios in these 2 callbacks? I was looking intoaops->read_folioapproach but what do you think?See the v2 of
buffer_write_operationsthat I just posted. I was waiting for feedback from Christoph on the revised method for passing fsdata around, but I may as well just post a v2 and see what happens.
Interesting. I think it makes sense to convert tmpfs to buffered_write_operations as well. Can you add me to the v2 so I can add/review it for tmpfs?
Thanks
Re: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios
In reply to Christoph HellwigQuoted 18 lines · Christoph Hellwig
From: "Matthew Wilcox (Oracle)" <[email protected]>
Modelled after the loop in
iomap_write_iter(), copy larger chunks from userspace if the filesystem has created large folios.Signed-off-by Matthew Wilcox (Oracle) <[email protected]>[hch: use
mapping_max_folio_sizeto keep supporting file systems that do
not support large folios]Signed-off-by Christoph Hellwig <[email protected]>--- mm/filemap.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-)mm/filemap.c +0
-0
mm/filemap.c ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) · line 3984
Quoted 4 lines
mm/filemap.c +1
-0@@ -3981,21 +3981,24 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)loff_t pos = iocb->ki_pos;struct address_space *mapping = file->f_mapping;const struct address_space_operations *a_ops = mapping->a_ops; +size_t chunk =mapping_max_folio_size (mapping);
Better to default chunk to PAGE_SIZE for backward compat + size_t chunk = PAGE_SIZE;
mm/filemap.c ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) · line 3987
Quoted 3 lines
mm/filemap.c +0
-0long status =0 ;ssize_t written =0 ;
Have fs opt in to large folio support:
+ if (mapping_large_folio_support(mapping)) + chunk = PAGE_SIZE << MAX_PAGECACHE_ORDER;
Quoted 56 lines
mm/filemap.c +22
-11do { struct page *page; - unsigned long offset; /* Offset into pagecache page */ - unsigned long bytes; /* Bytes to write to page */ + struct folio *folio; + size_t offset; /* Offset into folio */ + size_t bytes; /* Bytes to write to folio */ size_t copied; /* Bytes copied from user */ void *fsdata = NULL; - offset = (pos & (PAGE_SIZE - 1)); - bytes = min_t(unsigned long, PAGE_SIZE - offset, - iov_iter_count(i)); + bytes = iov_iter_count(i); +retry: + offset = pos & (chunk - 1); + bytes = min(chunk - offset, bytes); + balance_dirty_pages_ratelimited(mapping); -again: /* * Bring in the user page that we will copy from _first_. * Otherwise there's a nasty deadlock on copying from the@@ -4017,11 +4020,16 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)if (unlikely (status <0 ))break ; + folio =page_folio (page); + offset =offset_in_folio (folio, pos); +if (bytes >folio_size (folio) - offset) + bytes =folio_size (folio) - offset; +if (mapping_writably_mapped (mapping)) -flush_dcache_page (page); +flush_dcache_folio (folio); - copied =copy_page_from_iter_atomic (page, offset, bytes, i); -flush_dcache_page (page); + copied =copy_folio_from_iter_atomic (folio, offset, bytes, i); +flush_dcache_folio (folio); status = a_ops->write_end (file, mapping, pos, bytes, copied, page, fsdata);@@ -4039,14 +4047,16 @@ ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i)* halfway through, might be a race with munmap, * might be severe memory pressure. */ -if (copied) +if (chunk >PAGE_SIZE ) + chunk /=2 ; +if (copied) { bytes = copied; - goto again; + goto retry; + } + }else {
mm/filemap.c ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) · line 4062
Quoted 10 lines
mm/filemap.c +2
-4+ pos += status; + written += status; } - pos += status; - written += status; - -balance_dirty_pages_ratelimited (mapping); }while (iov_iter_count (i));if (!written)
Tested with Lustre with large folios and kernel 6.6 with this patch (and suggested changes).
Re: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios
Quoted 6 lines · Shaun Tancheff
mm/filemap.c ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) · line 3984
Quoted 2 lines
const struct address_space_operations *a_ops = mapping->a_ops;mm/filemap.c +1
-0+size_t chunk =mapping_max_folio_size (mapping);Better to default chunk to
PAGE_SIZEfor backward compat +size_tchunk =PAGE_SIZE;
Quoted 8 lines
Quoted 3 lines
long status = 0; ssize_t written = 0;Have fs opt in to large folio support:
+ if (
mapping_large_folio_support(mapping)) + chunk =PAGE_SIZE<<MAX_PAGECACHE_ORDER;
I don't think you've actually read the code, have you?
Re: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Shaun Tancheff
mm/filemap.c ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) · line 3984
Quoted 2 lines
const struct address_space_operations *a_ops = mapping->a_ops;mm/filemap.c +1
-0+size_t chunk =mapping_max_folio_size (mapping);Better to default chunk to
PAGE_SIZEfor backward compat +size_tchunk =PAGE_SIZE;
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
long status = 0; ssize_t written = 0;Have fs opt in to large folio support:
+ if (
mapping_large_folio_support(mapping)) + chunk =PAGE_SIZE<<MAX_PAGECACHE_ORDER;I don't think you've actually read the code, have you?
I checked from 6.6 to linux-next with this patch and my ext4 VM does not boot without the opt-in.
Almost certainly there is something I am missing, probably not looking at the correct tree.
Thanks!
--Shaun
Re: [PATCH 1/2] filemap: Convert generic_perform_write() to support large folios
Quoted 11 lines · Shaun Tancheff
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Shaun Tancheff
mm/filemap.c ssize_t generic_perform_write(struct kiocb *iocb, struct iov_iter *i) · line 3984
Quoted 2 lines
const struct address_space_operations *a_ops = mapping->a_ops;mm/filemap.c +1
-0+size_t chunk =mapping_max_folio_size (mapping);Better to default chunk to
PAGE_SIZEfor backward compat +size_tchunk =PAGE_SIZE;Quoted 3 lines
long status = 0; ssize_t written = 0;
Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Have fs opt in to large folio support:
+ if (
mapping_large_folio_support(mapping)) + chunk =PAGE_SIZE<<MAX_PAGECACHE_ORDER;I don't think you've actually read the code, have you?
I checked from 6.6 to linux-next with this patch and my ext4 VM does not boot without the opt-in.
Please take a look at the definition of mapping_max_folio_size, which is called above in the quoted patch.
PATCH 2/2 nfs: add support for large folios
In reply to Christoph HellwigNFS already is void of folio size assumption, so just pass the chunk size to __filemap_get_folio and set the large folio address_space flag for all regular files.
--- fs/nfs/file.c | 4 +++- fs/nfs/inode.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
fs/nfs/file.c +3 -1
@@ -339,6 +339,7 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, struct page **pagep, void **fsdata) { + fgf_t fgp = FGP_WRITEBEGIN;struct folio *folio;int once_thru =0 ;int ret;
@@ -346,8 +347,9 @@ static int nfs_write_begin(struct file *file, struct address_space *mapping,dfprintk (PAGECACHE ,"NFS: write_begin(%pD2(%lu), %u@%lld)\n" , file, mapping->host->i_ino, len, (long long ) pos); + fgp |=fgf_set_order (len); start: - folio =__filemap_get_folio (mapping, pos >>PAGE_SHIFT ,FGP_WRITEBEGIN , + folio =__filemap_get_folio (mapping, pos >>PAGE_SHIFT , fgp,mapping_gfp_mask (mapping));if (IS_ERR (folio))return PTR_ERR (folio);
fs/nfs/inode.c +1 -0
@@ -491,6 +491,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr) inode->i_fop =NFS_SB (sb)->nfs_client->rpc_ops->file_ops; inode->i_data.a_ops = &nfs_file_aops;nfs_inode_init_regular (nfsi); +mapping_set_large_folios (inode->i_mapping); }else if (S_ISDIR (inode->i_mode)) { inode->i_op =NFS_SB (sb)->nfs_client->rpc_ops->dir_inode_ops; inode->i_fop = &nfs_dir_operations;
Signature · 1 line
2.43.0
Sagi Grimberg
Tested-byQuoted 9 lines · Christoph Hellwig
Hi all,
this series adds large folio support to NFS, and almost doubles the buffered write throughput from the previous bottleneck of ~2.5GB/s (just like for other file systems).
The first patch is an old one from willy that I've updated very slightly. Note that this update now requires the
mapping_max_folio_sizehelper merged into Linus' tree only a few minutes ago.
I'll confirm that NFS buffered writes saw a dramatic >2x improvement against my test system.
For the series:
Matthew Wilcox (Oracle)
maintainerPATCH 1/1 nfs: Fix misuses of folio_shift() and folio_order()
In reply to Christoph HellwigPage cache indices are in units of PAGE_SIZE, not in units of the folio size. Revert the change in nfs_grow_file(), and pass the inode to nfs_folio_length() so it can be reimplemented in terms of folio_mkwrite_check_truncate() which handles this correctly.
--- fs/nfs/file.c | 6 +++--- fs/nfs/internal.h | 16 +++++----------- fs/nfs/read.c | 2 +- fs/nfs/write.c | 9 +++++---- include/linux/pagemap.h | 4 ++-- 5 files changed, 16 insertions(+), 21 deletions(-)
fs/nfs/file.c +3 -3
@@ -301,7 +301,7 @@ EXPORT_SYMBOL_GPL(nfs_file_fsync);static bool nfs_folio_is_full_write (struct folio *folio,loff_t pos,unsigned int len) { -unsigned int pglen =nfs_folio_length (folio); +unsigned int pglen =nfs_folio_length (folio, folio->mapping->host);unsigned int offset =offset_in_folio (folio, pos);unsigned int end = offset + len;
@@ -386,7 +386,7 @@ static int nfs_write_end(struct file *file, struct address_space *mapping,*/ if (!folio_test_uptodate (folio)) {size_t fsize =folio_size (folio); -unsigned pglen =nfs_folio_length (folio); +unsigned pglen =nfs_folio_length (folio, mapping->host);unsigned end = offset + copied;if (pglen ==0 ) {
@@ -610,7 +610,7 @@ static vm_fault_t nfs_vm_page_mkwrite(struct vm_fault *vmf)folio_wait_writeback (folio); - pagelen =nfs_folio_length (folio); + pagelen =nfs_folio_length (folio, inode);if (pagelen ==0 ) goto out_unlock;
fs/nfs/internal.h +5 -11
@@ -819,19 +819,13 @@ unsigned int nfs_page_length(struct page *page)/* * Determine the number of bytes of data the page contains */ -static inline size_t nfs_folio_length (struct folio *folio) +static inline size_t nfs_folio_length (struct folio *folio,struct inode *inode) { -loff_t i_size =i_size_read (folio_file_mapping (folio)->host); +ssize_t ret =folio_mkwrite_check_truncate (folio, inode); -if (i_size >0 ) { -pgoff_t index =folio_index (folio) >>folio_order (folio); -pgoff_t end_index = (i_size -1 ) >>folio_shift (folio); -if (index < end_index) -return folio_size (folio); -if (index == end_index) -return offset_in_folio (folio, i_size -1 ) +1 ; - } -return 0 ; +if (ret <0 ) + ret =0 ; +return ret; }/*
fs/nfs/read.c +1 -1
@@ -296,7 +296,7 @@ int nfs_read_add_folio(struct nfs_pageio_descriptor *pgio,unsigned int len, aligned_len;int error; - len =nfs_folio_length (folio); + len =nfs_folio_length (folio, inode);if (len ==0 )return nfs_return_empty_folio (folio);
fs/nfs/write.c +5 -4
@@ -278,8 +278,8 @@ static void nfs_grow_file(struct folio *folio, unsigned int offset,spin_lock (&inode->i_lock); i_size =i_size_read (inode); - end_index = ((i_size -1 ) >>folio_shift (folio)) <<folio_order (folio); -if (i_size >0 &&folio_index (folio) < end_index) + end_index = (i_size -1 ) >>PAGE_SHIFT ; +if (i_size >0 && folio->index < end_index) goto out; end =folio_file_pos (folio) + (loff_t )offset + (loff_t )count;if (i_size >= end)
@@ -358,7 +358,8 @@ nfs_page_group_search_locked(struct nfs_page *head, unsigned int page_offset)*/ static bool nfs_page_group_covers_page (struct nfs_page *req) { -unsigned int len =nfs_folio_length (nfs_page_to_folio (req)); +struct folio *folio =nfs_page_to_folio (req); +unsigned int len =nfs_folio_length (folio, folio->mapping->host);struct nfs_page *tmp;unsigned int pos =0 ;
@@ -1356,7 +1357,7 @@ int nfs_update_folio(struct file *file, struct folio *folio,struct nfs_open_context *ctx =nfs_file_open_context (file);struct address_space *mapping =folio_file_mapping (folio);struct inode *inode = mapping->host; -unsigned int pagelen =nfs_folio_length (folio); +unsigned int pagelen =nfs_folio_length (folio, inode);int status =0 ;nfs_inc_stats (inode,NFSIOS_VFSUPDATEPAGE );
include/linux/pagemap.h +2 -2
@@ -212,8 +212,8 @@ enum mapping_flags { AS_FOLIO_ORDER_MAX = 21, /* Bits 16-25 are used for FOLIO_ORDER */ }; -#define AS_FOLIO_ORDER_MIN_MASK 0x001f0000 -#define AS_FOLIO_ORDER_MAX_MASK 0x03e00000 +#define AS_FOLIO_ORDER_MIN_MASK (31 << AS_FOLIO_ORDER_MIN) +#define AS_FOLIO_ORDER_MAX_MASK (31 << AS_FOLIO_ORDER_MAX)#define AS_FOLIO_ORDER_MASK (AS_FOLIO_ORDER_MIN_MASK | AS_FOLIO_ORDER_MAX_MASK)/**
Signature · 1 line
2.43.0
Re: [PATCH] nfs: Fix misuses of folio_shift() and folio_order()
include/linux/pagemap.h enum mapping_flags { · line 216
Quoted 12 lines
include/linux/pagemap.h +2
-2@@ -212,8 +212,8 @@ enum mapping_flags { AS_FOLIO_ORDER_MAX = 21, /* Bits 16-25 are used for FOLIO_ORDER */ }; -#define AS_FOLIO_ORDER_MIN_MASK 0x001f0000 -#define AS_FOLIO_ORDER_MAX_MASK 0x03e00000 +#define AS_FOLIO_ORDER_MIN_MASK (31 << AS_FOLIO_ORDER_MIN) +#define AS_FOLIO_ORDER_MAX_MASK (31 << AS_FOLIO_ORDER_MAX)
This looks unrelated.
The NFS changes do look good to me, I'll kick off a testing run on them in a bit.
Re: [PATCH] nfs: Fix misuses of folio_shift() and folio_order()
In reply to Matthew Wilcox (Oracle)Quoted 5 lines · Matthew Wilcox (Oracle)
Page cache indices are in units of
PAGE_SIZE, not in units of the folio size. Revert the change innfs_grow_file(), and pass the inode tonfs_folio_length()so it can be reimplemented in terms offolio_mkwrite_check_truncate()which handles this correctly.
I had to apply the incremental patch below to make the change compile. With that it causes a new xfstests failure in generic/127 that I haven't looked into yet. The mm-level bugs I've seen even with baseline Linus' tree also happened more often than in my previous tests, but that might just be coincidence.
fs/nfs/nfstrace.h +8 -8
@@ -938,7 +938,7 @@ TRACE_EVENT(nfs_sillyrename_unlink, DECLARE_EVENT_CLASS(nfs_folio_event, TP_PROTO( - const struct inode *inode, + struct inode *inode, struct folio *folio ),
@@ -954,14 +954,14 @@ DECLARE_EVENT_CLASS(nfs_folio_event, ),TP_fast_assign ( - const struct nfs_inode *nfsi = NFS_I(inode); + struct nfs_inode *nfsi = NFS_I(inode); __entry->dev = inode->i_sb->s_dev; __entry->fileid = nfsi->fileid; __entry->fhandle =nfs_fhandle_hash (&nfsi->fh); __entry->version =inode_peek_iversion_raw (inode); __entry->offset =folio_file_pos (folio); - __entry->count =nfs_folio_length (folio); + __entry->count =nfs_folio_length (folio, inode); ), TP_printk(
@@ -977,14 +977,14 @@ DECLARE_EVENT_CLASS(nfs_folio_event,#define DEFINE_NFS_FOLIO_EVENT (name) \ DEFINE_EVENT(nfs_folio_event, name, \ TP_PROTO( \ - const struct inode *inode, \ + struct inode *inode, \ struct folio *folio \ ), \ TP_ARGS(inode, folio)) DECLARE_EVENT_CLASS(nfs_folio_event_done, TP_PROTO( - const struct inode *inode, + struct inode *inode, struct folio *folio, int ret ),
@@ -1002,14 +1002,14 @@ DECLARE_EVENT_CLASS(nfs_folio_event_done, ),TP_fast_assign ( - const struct nfs_inode *nfsi = NFS_I(inode); + struct nfs_inode *nfsi = NFS_I(inode); __entry->dev = inode->i_sb->s_dev; __entry->fileid = nfsi->fileid; __entry->fhandle =nfs_fhandle_hash (&nfsi->fh); __entry->version =inode_peek_iversion_raw (inode); __entry->offset =folio_file_pos (folio); - __entry->count =nfs_folio_length (folio); + __entry->count =nfs_folio_length (folio, inode); __entry->ret = ret; ),
@@ -1026,7 +1026,7 @@ DECLARE_EVENT_CLASS(nfs_folio_event_done,#define DEFINE_NFS_FOLIO_EVENT_DONE (name) \ DEFINE_EVENT(nfs_folio_event_done, name, \ TP_PROTO( \ - const struct inode *inode, \ + struct inode *inode, \ struct folio *folio, \ int ret \ ), \
Re: [PATCH] nfs: Fix misuses of folio_shift() and folio_order()
In reply to Matthew Wilcox (Oracle)Quoted 5 lines · Matthew Wilcox (Oracle)
Page cache indices are in units of
PAGE_SIZE, not in units of the folio size. Revert the change innfs_grow_file(), and pass the inode tonfs_folio_length()so it can be reimplemented in terms offolio_mkwrite_check_truncate()which handles this correctly.
For the record, the code being replaced here is not assuming that page cache indices are in units of the folio size. It is assuming that folio boundaries will lie on offsets that are multiples of the folio size and that the current page attributes (page lock, uptodate, etc) are expected to apply to the data that lies within those folio boundaries. The way the folio code is written today, that assumption appears to be correct.
I'm fine with replacing NFS-specific code with generic code when obviously correct, but AFAICS this would be a cleanup, and not a bug fix.
Quoted 154 lines
Fixes 0c493b5cf16e ("NFS: Convert buffered writes to use folios")Signed-off-by Matthew Wilcox (Oracle) <[email protected]>Cc Trond Myklebust <[email protected]>Cc Anna Schumaker <[email protected]>Cc Christoph Hellwig <[email protected]>---
fs/nfs/file.c | 6 +++---
fs/nfs/internal.h | 16 +++++-----------
fs/nfs/read.c | 2 +-
fs/nfs/write.c | 9 +++++----
include/linux/pagemap.h | 4 ++--5 files changed, 16 insertions(+), 21 deletions(-)fs/nfs/file.c +1
-1@@ -301,7 +301,7 @@ EXPORT_SYMBOL_GPL(nfs_file_fsync); static bool nfs_folio_is_full_write(struct folio *folio, loff_t pos, unsigned int len) { -unsigned int pglen =nfs_folio_length (folio); +unsigned int pglen =nfs_folio_length (folio, folio->mapping- >host); unsigned int offset = offset_in_folio(folio, pos); unsigned int end = offset + len;fs/nfs/file.c +1
-1@@ -386,7 +386,7 @@ static int nfs_write_end(struct file *file,struct address_space *mapping, */ if (!folio_test_uptodate(folio)) { size_t fsize = folio_size(folio); -unsigned pglen =nfs_folio_length (folio); +unsigned pglen =nfs_folio_length (folio, mapping- >host); unsigned end = offset + copied;
if (pglen == 0) {fs/nfs/file.c +0
-0@@ -610,7 +610,7 @@ static vm_fault_t nfs_vm_page_mkwrite(struct vm_fault *vmf)
folio_wait_writeback(folio);fs/nfs/file.c +1
-1- pagelen =nfs_folio_length (folio); + pagelen =nfs_folio_length (folio, inode);if (pagelen == 0)
gotoout_unlock;fs/nfs/internal.h +2
-2@@ -819,19 +819,13 @@ unsigned int nfs_page_length(struct page *page) /** Determine the number of bytes of data the page contains */ -static inline size_t nfs_folio_length (struct folio *folio) +static inline size_t nfs_folio_length (struct folio *folio,struct inode *inode) { -loff_t i_size =i_size_read (folio_file_mapping (folio)- >host); +ssize_t ret =folio_mkwrite_check_truncate (folio, inode);fs/nfs/internal.h +0
-2-if (i_size >0 ) { - pgoff_t index = folio_index(folio) >>
folio_order(folio);fs/nfs/internal.h +0
-1- pgoff_t end_index = (i_size - 1) >>
folio_shift(folio);fs/nfs/internal.h +0
-4-if (index < end_index) -return folio_size (folio); -if (index == end_index) - return offset_in_folio(folio, i_size - 1) +1;
fs/nfs/internal.h +3
-2- } -return 0 ; +if (ret <0 ) + ret =0 ; +return ret;}
/*fs/nfs/read.c +0
-0@@ -296,7 +296,7 @@ int nfs_read_add_folio(structnfs_pageio_descriptor *pgio, unsigned int len, aligned_len; int error;fs/nfs/read.c +1
-1- len =nfs_folio_length (folio); + len =nfs_folio_length (folio, inode);if (len == 0)
returnnfs_return_empty_folio(folio);fs/nfs/write.c +0
-0@@ -278,8 +278,8 @@ static void nfs_grow_file(struct folio *folio, unsigned int offset,
spin_lock(&inode->i_lock);
i_size=i_size_read(inode);fs/nfs/write.c +0
-1- end_index = ((i_size - 1) >> folio_shift(folio)) <<
folio_order(folio);fs/nfs/write.c +2
-1-if (i_size >0 &&folio_index (folio) < end_index) + end_index = (i_size -1 ) >>PAGE_SHIFT ; +if (i_size >0 && folio->index < end_index)goto out;
end =folio_file_pos(folio)+ (loff_t)offset + (loff_t)count;
if (i_size>= end)fs/nfs/write.c +2
-1@@ -358,7 +358,8 @@ nfs_page_group_search_locked(struct nfs_page*head, unsigned int page_offset) */ static bool nfs_page_group_covers_page(struct nfs_page *req) { -unsigned int len =nfs_folio_length (nfs_page_to_folio (req)); +struct folio *folio =nfs_page_to_folio (req); +unsigned int len =nfs_folio_length (folio, folio->mapping- >host); struct nfs_page *tmp;unsigned int pos = 0;
fs/nfs/write.c +1
-1@@ -1356,7 +1357,7 @@ int nfs_update_folio(struct file *file, struct folio *folio, struct nfs_open_context *ctx = nfs_file_open_context(file); struct address_space *mapping = folio_file_mapping(folio); struct inode *inode = mapping->host; -unsigned int pagelen =nfs_folio_length (folio); +unsigned int pagelen =nfs_folio_length (folio, inode); int status = 0;
nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE);include/linux/pagemap.h +0
-0@@ -212,8 +212,8 @@ enum mapping_flags {
AS_FOLIO_ORDER_MAX= 21, /* Bits 16-25 are used forFOLIO_ORDER*/
};include/linux/pagemap.h +2
-2-#define AS_FOLIO_ORDER_MIN_MASK 0x001f0000 -#define AS_FOLIO_ORDER_MAX_MASK 0x03e00000 +#define AS_FOLIO_ORDER_MIN_MASK (31 << AS_FOLIO_ORDER_MIN) +#define AS_FOLIO_ORDER_MAX_MASK (31 << AS_FOLIO_ORDER_MAX)#define
AS_FOLIO_ORDER_MASK(AS_FOLIO_ORDER_MIN_MASK|AS_FOLIO_ORDER_MAX_MASK)
/**
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Matthew Wilcox
maintainerQuoted 9 lines · Christoph Hellwig
Hi all,
this series adds large folio support to NFS, and almost doubles the buffered write throughput from the previous bottleneck of ~2.5GB/s (just like for other file systems).
The first patch is an old one from willy that I've updated very slightly. Note that this update now requires the
mapping_max_folio_sizehelper merged into Linus' tree only a few minutes ago.
Kind of surprised this didn't fall over given the bugs I just sent a patch for ... misinterpreting the folio indices seems like it should have caused a failure in _some_ fstest.
Quoted 7 lines · Matthew Wilcox
Quoted 6 lines · Christoph Hellwig
Hi all,
this series adds large folio support to NFS, and almost doubles the buffered write throughput from the previous bottleneck of ~2.5GB/s (just like for other file systems).
Quoted 7 lines
Quoted 3 lines
The first patch is an old one from willy that I've updated very slightly. Note that this update now requires the
mapping_max_folio_sizehelper merged into Linus' tree only a few minutes ago.Kind of surprised this didn't fall over given the bugs I just sent a patch for ... misinterpreting the folio indices seems like it should have caused a failure in _some_ fstest.
I've run quite few tests with different NFS protocol versions, and there were no new failures, and the existing one is a MM one also reproducible with local XFS. That's indeed a bit odd.
Quoted 13 lines · Matthew Wilcox
Quoted 11 lines · Christoph Hellwig
Hi all,
this series adds large folio support to NFS, and almost doubles the buffered write throughput from the previous bottleneck of ~2.5GB/s (just like for other file systems).
The first patch is an old one from willy that I've updated very slightly.
Note that this update now requires themapping_max_folio_sizehelper
merged into Linus' tree only a few minutes ago.
Quoted 3 lines
Kind of surprised this didn't fall over given the bugs I just sent a patch for ... misinterpreting the folio indices seems like it should have caused a failure in _some_ fstest.
Why wouldn't it work? The code you're replacing isn't assuming that page cache indices are in units of the folio size. It is just assuming that folio boundaries are multiples of the folio size.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 11 lines · Christoph Hellwig
Hi all,
this series adds large folio support to NFS, and almost doubles the buffered write throughput from the previous bottleneck of ~2.5GB/s (just like for other file systems).
The first patch is an old one from willy that I've updated very slightly.
Note that this update now requires themapping_max_folio_sizehelper merged into Linus' tree only a few minutes ago.
Quoted 6 lines
Diffstat:
fs/nfs/file.c | 4 +++-
fs/nfs/inode.c | 1 +
mm/filemap.c | 40 +++++++++++++++++++++++++---------------3 files changed, 29 insertions(+), 16 deletions(-)
Which tree did you intend to merge this through? Willy's or Anna and mine? I'm OK either way. I just want to make sure we're on the same page.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Quoted 3 lines · Trond Myklebust
Which tree did you intend to merge this through? Willy's or Anna and mine? I'm OK either way. I just want to make sure we're on the same page.
I'm perfectly fine either way too. If willy wants to get any other work for generic_perform_write in as per his RFC patches the pagecache tree might be a better place, if not maybe the nfs tree.
Quoted 8 lines · On Fri, May 31, 2024 at 08:14:43AM +0200, [email protected] wrote:
Quoted 3 lines · Trond Myklebust
Which tree did you intend to merge this through? Willy's or Anna and mine? I'm OK either way. I just want to make sure we're on the same page.
I'm perfectly fine either way too. If willy wants to get any other work for
generic_perform_writein as per his RFC patches the pagecache tree might be a better place, if not maybe the nfs tree.
That maintainer celebrity death match was a bit boring :) Any takers?
Quoted 7 lines · On Fri, 7 Jun 2024 at 07:29, [email protected] <[email protected]> wrote:
Quoted 5 lines · On Fri, May 31, 2024 at 08:14:43AM +0200, [email protected] wrote:
Quoted 3 lines · Trond Myklebust
Which tree did you intend to merge this through? Willy's or Anna and mine? I'm OK either way. I just want to make sure we're on the same page.
Quoted 6 lines
Quoted 3 lines
I'm perfectly fine either way too. If willy wants to get any other work for
generic_perform_writein as per his RFC patches the pagecache tree might be a better place, if not maybe the nfs tree.That maintainer celebrity death match was a bit boring :) Any takers?
As much as we like to see blood, gore, WH4K chainsawswords, ripped off brains and ethernet cables, it would be easier (and less expensive) to just apply the patch :)
Ced
Signature · 3 lines
Cedric Blancher <[email protected]> [https://plus.google.com/u/0/+CedricBlancher/] Institute Pasteur
Quoted 8 lines · On Fri, 2024-06-07 at 07:29 +0200, [email protected] wrote:
Quoted 7 lines · On Fri, May 31, 2024 at 08:14:43AM +0200, [email protected] wrote:
Quoted 5 lines · Trond Myklebust
Which tree did you intend to merge this through? Willy's or Anna and
mine? I'm OK either way. I just want to make sure we're on the same
page.
Quoted 8 lines
Quoted 4 lines
I'm perfectly fine either way too. If willy wants to get any other work for
generic_perform_writein as per his RFC patches the pagecache
tree might be a better place, if not maybe the nfs tree.That maintainer celebrity death match was a bit boring :) Any takers?
🙂 We'll push them through the NFS tree.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]