Revert "ext4: remove no longer used functions in inode.c"
Subsystems (6)
PATCH 1/8 Revert "ext4: remove no longer used functions in inode.c"
This reverts commit ccb4d7af914e0fe9b2f1022f8ea6c300463fd5e6.
This commit reintroduces functions ext4_block_truncate_page() and ext4_block_zero_page_range() which has been previously removed in favour of ext4_discard_partial_page_buffers().
In future commits we want to reintroduce those function and remove ext4_discard_partial_page_buffers() since it is duplicating some code and also partially duplicating work of truncate_pagecache_range(), moreover the old implementation was much clearer.
--- fs/ext4/ext4.h | 4 ++ fs/ext4/inode.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 0 deletions(-)
fs/ext4/ext4.h +4 -0
@@ -1995,6 +1995,10 @@ extern int ext4_alloc_da_blocks(struct inode *inode);extern void ext4_set_aops (struct inode *inode);extern int ext4_writepage_trans_blocks (struct inode *);extern int ext4_chunk_trans_blocks (struct inode *,int nrblocks); +extern int ext4_block_truncate_page (handle_t *handle, +struct address_space *mapping,loff_t from); +extern int ext4_block_zero_page_range (handle_t *handle, +struct address_space *mapping,loff_t from,loff_t length);extern int ext4_discard_partial_page_buffers (handle_t *handle,struct address_space *mapping,loff_t from,loff_t length,int flags);
fs/ext4/inode.c +120 -0
126 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH 2/8 Revert "ext4: fix fsx truncate failure"
This reverts commit 189e868fa8fdca702eb9db9d8afc46b5cb9144c9.
This commit reintroduces the use of ext4_block_truncate_page() in ext4 truncate operation instead of ext4_discard_partial_page_buffers().
The statement in the commit description that the truncate operation only zero block unaligned portion of the last page is not exactly right, since truncate_pagecache_range() also zeroes and invalidate the unaligned portion of the page. Then there is no need to zero and unmap it once more and ext4_block_truncate_page() was doing the right job, although we still need to update the buffer head containing the last block, which is exactly what ext4_block_truncate_page() is doing.
This was tested on ppc64 machine with block size of 1024 bytes without any problems.
--- fs/ext4/extents.c | 13 ++----------- fs/ext4/indirect.c | 13 ++----------- 2 files changed, 4 insertions(+), 22 deletions(-)
fs/ext4/extents.c +2 -11
@@ -4222,7 +4222,6 @@ void ext4_ext_truncate(struct inode *inode)struct super_block *sb = inode->i_sb;ext4_lblk_t last_block;handle_t *handle; -loff_t page_len;int err =0 ;/*
@@ -4239,16 +4238,8 @@ void ext4_ext_truncate(struct inode *inode)if (IS_ERR (handle))return ; -if (inode->i_size %PAGE_CACHE_SIZE !=0 ) { - page_len =PAGE_CACHE_SIZE - - (inode->i_size & (PAGE_CACHE_SIZE -1 )); - - err =ext4_discard_partial_page_buffers (handle, - mapping, inode->i_size, page_len,0 ); - -if (err) - goto out_stop; - } +if (inode->i_size & (sb->s_blocksize -1 )) +ext4_block_truncate_page (handle, mapping, inode->i_size);if (ext4_orphan_add (handle, inode)) goto out_stop;
fs/ext4/indirect.c +0 -8
@@ -1349,9 +1349,7 @@ void ext4_ind_truncate(struct inode *inode)__le32 nr =0 ;int n =0 ;ext4_lblk_t last_block, max_block; -loff_t page_len;unsigned blocksize = inode->i_sb->s_blocksize; -int err; handle =start_transaction (inode);if (IS_ERR (handle))
@@ -1362,16 +1360,9 @@ void ext4_ind_truncate(struct inode *inode) max_block = (EXT4_SB (inode->i_sb)->s_bitmap_maxbytes + blocksize-1 ) >>EXT4_BLOCK_SIZE_BITS (inode->i_sb); -if (inode->i_size %PAGE_CACHE_SIZE !=0 ) { - page_len =PAGE_CACHE_SIZE - - (inode->i_size & (PAGE_CACHE_SIZE -1 )); - - err =ext4_discard_partial_page_buffers (handle, - mapping, inode->i_size, page_len,0 );
PATCH 3/8 shmem: pass LLONG_MAX to shmem_truncate_range
In reply to Lukas CzernerCurrently we're passing -1 to shmem_truncate_range which can then call truncate_inode_pages_range() which is actually really confusing since the argument is signed so we do not get "huge" number as one would expect, but rather just -1. To make things clearer and easier for truncate_inode_pages_range() just pass LLONG_MAX since it is actually what was intended anyway.
It also makes thing easier for allowing truncate_inode_pages_range() to handle non page aligned regions. Moreover letting the lend argument to be negative might actually hide some bugs.
--- mm/shmem.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
mm/shmem.c +2 -1
@@ -2960,7 +2960,8 @@ void shmem_unlock_mapping(struct address_space *mapping)void shmem_truncate_range (struct inode *inode,loff_t lstart,loff_t lend) { -truncate_inode_pages_range (inode->i_mapping, lstart, lend); +truncate_inode_pages_range (inode->i_mapping, lstart, + lend ==-1 ?LLONG_MAX : last); }EXPORT_SYMBOL_GPL (shmem_truncate_range);
Signature · 1 line
1.7.7.6
PATCH 4/8 xfs: pass LLONG_MAX to truncate_inode_pages_range
In reply to Lukas CzernerCurrently we're passing -1 to truncate_inode_pages_range() which is actually really confusing since the argument is signed so we do not get "huge" number as one would expect, but rather just -1. To make things clearer and easier for truncate_inode_pages_range() just pass LLONG_MAX since it is actually what was intended anyway.
It also makes thing easier for allowing truncate_inode_pages_range() to handle non page aligned regions. Moreover letting the lend argument to be negative might actually hide some bugs.
--- fs/xfs/xfs_fs_subr.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
fs/xfs/xfs_fs_subr.c +4 -2
@@ -34,7 +34,8 @@ xfs_tosspages( {/* can't toss partial tail pages, so mask them out */ last &= ~(PAGE_SIZE -1 ); -truncate_inode_pages_range (VFS_I (ip)->i_mapping, first, last -1 ); +truncate_inode_pages_range (VFS_I (ip)->i_mapping, first, + last ==-1 ?LLONG_MAX : last); }int
@@ -53,7 +54,8 @@ xfs_flushinval_pages( ret =filemap_write_and_wait_range (mapping, first, last ==-1 ?LLONG_MAX : last);if (!ret) -truncate_inode_pages_range (mapping, first, last); +truncate_inode_pages_range (mapping, first, + last ==-1 ?LLONG_MAX : last);return -ret; }
Signature · 1 line
1.7.7.6
PATCH 5/8 mm: pass LLONG_MAX to truncate_inode_pages_range
In reply to Lukas CzernerCurrently we're passing -1 to truncate_inode_pages_range() which is actually really confusing since the argument is signed so we do not get "huge" number as one would expect, but rather just -1. To make things clearer and easier for truncate_inode_pages_range() just pass LLONG_MAX since it is actually what was intended anyway.
It also makes thing easier for allowing truncate_inode_pages_range() to handle non page aligned regions. Moreover letting the lend argument to be negative might actually hide some bugs.
--- mm/truncate.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
mm/truncate.c +1 -1
@@ -310,7 +310,7 @@ EXPORT_SYMBOL(truncate_inode_pages_range);*/ void truncate_inode_pages (struct address_space *mapping,loff_t lstart) { -truncate_inode_pages_range (mapping, lstart, (loff_t)-1 ); +truncate_inode_pages_range (mapping, lstart, (loff_t )LLONG_MAX ); }EXPORT_SYMBOL (truncate_inode_pages);
Signature · 1 line
1.7.7.6
PATCH 6/8 mm: teach truncate_inode_pages_range() to hadnle non page aligned ranges
In reply to Lukas CzernerThis commit changes truncate_inode_pages_range() so it can handle non page aligned regions of the truncate. Currently we can hit BUG_ON when the end of the range is not page aligned, but he can handle unaligned start of the range.
Being able to handle non page aligned regions of the page can help file system punch_hole implementations and save some work, because once we're holding the page we might as well deal with it right away.
--- mm/truncate.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 50 insertions(+), 11 deletions(-)
mm/truncate.c +50 -11
@@ -49,6 +49,16 @@ void do_invalidatepage(struct page *page, unsigned long offset) (*invalidatepage)(page, offset); } +static inline void punch_hole_into_page (struct page *page,unsigned start, +unsigned end) +{ +BUG_ON (end >PAGE_CACHE_SIZE ); +zero_user_segment (page, start, end); +cleancache_invalidate_page (page->mapping, page); +if (page_has_private (page)) +do_invalidatepage (page, start); +} +static inline void truncate_partial_page (struct page *page,unsigned partial) {zero_user_segment (page, partial,PAGE_CACHE_SIZE );
@@ -206,24 +216,30 @@ int invalidate_inode_page(struct page *page)void truncate_inode_pages_range (struct address_space *mapping,loff_t lstart,loff_t lend) { -const pgoff_t start = (lstart +PAGE_CACHE_SIZE -1 ) >>PAGE_CACHE_SHIFT ; -const unsigned partial = lstart & (PAGE_CACHE_SIZE -1 ); +const unsigned partial_start = lstart & (PAGE_CACHE_SIZE -1 ); +const unsigned partial_end = lend & (PAGE_CACHE_SIZE -1 ); +loff_t start = lstart >>PAGE_CACHE_SHIFT ; +loff_t end = lend >>PAGE_CACHE_SHIFT ;struct pagevec pvec; -pgoff_t index; -pgoff_t end; +loff_t index;int i; +BUG_ON (lend < start || lend <0 ); +cleancache_invalidate_inode (mapping);if (mapping->nrpages ==0 )return ; -BUG_ON ((lend & (PAGE_CACHE_SIZE -1 )) != (PAGE_CACHE_SIZE -1 )); - end = (lend >>PAGE_CACHE_SHIFT ); +/* Adjust start and end so we cover only full pages */ +if (partial_start) + start++; +if (partial_end <PAGE_CACHE_SIZE -1 ) + end--;pagevec_init (&pvec,0 ); index = start;while (index <= end &&pagevec_lookup (&pvec, mapping, index, -min (end - index, (pgoff_t )PAGEVEC_SIZE -1 ) +1 )) { +min (end - index, (loff_t )PAGEVEC_SIZE -1 ) +1 )) {mem_cgroup_uncharge_start ();for (i =0 ; i <pagevec_count (&pvec); i++) {struct page *page = pvec.pages[i];
@@ -249,21 +265,44 @@ void truncate_inode_pages_range(struct address_space *mapping, index++; } -if (partial) { +/* truncate happened within the page - punch hole */ +if ((start > end) && (start - end >1 )) {struct page *page =find_lock_page (mapping, start -1 );if (page) {wait_on_page_writeback (page); -truncate_partial_page (page, partial); +punch_hole_into_page (page, partial_start, + partial_end +1 );unlock_page (page);page_cache_release (page); } + }else { +/* Partial page truncate at the start of the region */ +if (partial_start) { +struct page *page =find_lock_page (mapping, start -1 ); +if (page) { +wait_on_page_writeback (page); +truncate_partial_page (page, partial_start); +unlock_page (page); +page_cache_release (page); + } + } +/* Partial page truncate at the end of the region */ +if (partial_end <PAGE_CACHE_SIZE -1 ) { +struct page *page =find_lock_page (mapping, end +1 ); +if (page) { +wait_on_page_writeback (page); +punch_hole_into_page (page,0 , partial_end +1 ); +unlock_page (page); +page_cache_release (page); + } + } } index = start; -for ( ; ; ) { +while (index <= end) {cond_resched ();if (!pagevec_lookup (&pvec, mapping, index, -min (end - index, (pgoff_t )PAGEVEC_SIZE -1 ) +1 )) { +min (end - index, (loff_t )PAGEVEC_SIZE -1 ) +1 )) {if (index == start)break ; index = start;
Signature · 1 line
1.7.7.6
PATCH 7/8 ext4: use ext4_zero_partial_blocks in punch_hole
In reply to Lukas CzernerWe're doing to get rid of ext4_discard_partial_page_buffers() since it is duplicating some code and also partially duplicating work of truncate_pagecache_range(), moreover the old implementation was much clearer.
Now when the truncate_inode_pages_range() can handle truncating non page aligned regions we can use this to invalidate and zero out block aligned region of the punched out range and then use ext4_block_truncate_page() to zero the unaligned blocks on the start and end of the range. This will greatly simplify the punch hole code. Moreover after this commit we can get rid of the ext4_discard_partial_page_buffers() completely.
This has been tested on ppc64 with 1k block size with fsx and xfstests without any problems.
--- fs/ext4/ext4.h | 2 + fs/ext4/extents.c | 81 ++++++---------------------------------------------- fs/ext4/inode.c | 28 ++++++++++++++++++ 3 files changed, 40 insertions(+), 71 deletions(-)
fs/ext4/ext4.h +2 -0
@@ -1999,6 +1999,8 @@ extern int ext4_block_truncate_page(handle_t *handle, struct address_space *mapping, loff_t from);extern int ext4_block_zero_page_range (handle_t *handle,struct address_space *mapping,loff_t from,loff_t length); +extern int ext4_zero_partial_blocks (handle_t *handle,struct inode *inode, +loff_t lstart,loff_t lend);extern int ext4_discard_partial_page_buffers (handle_t *handle,struct address_space *mapping,loff_t from,loff_t length,int flags);
fs/ext4/extents.c +10 -71
106 lines not on this page · raw message
fs/ext4/inode.c +28 -0
@@ -3501,6 +3501,34 @@ unlock:return err; } +int ext4_zero_partial_blocks (handle_t *handle,struct inode *inode, +loff_t lstart,loff_t lend) +{ +struct super_block *sb = inode->i_sb; +unsigned partial = lstart & (sb->s_blocksize -1 ); +ext4_fsblk_t start = lstart >> sb->s_blocksize_bits; +ext4_fsblk_t end = lend >> sb->s_blocksize_bits; +int err =0 ; + +if (start == end) { + err =ext4_block_zero_page_range (handle, inode->i_mapping, + lstart, lend - lstart +1 ); +return err; + } +/* Handle partial zero out on the start of the range */ +if (partial) { + err =ext4_block_zero_page_range (handle, inode->i_mapping, + lstart, sb->s_blocksize); +if (err) +return err; + } + partial = lend & (sb->s_blocksize -1 ); +if (partial != sb->s_blocksize -1 ) + err =ext4_block_zero_page_range (handle, inode->i_mapping, + lend - partial, partial +1 ); +return err; +} +int ext4_can_truncate (struct inode *inode) {if (S_ISREG (inode->i_mode))
Signature · 1 line
1.7.7.6
PATCH 8/8 ext4: remove unused discard_partial_page_buffers
In reply to Lukas CzernerThe discard_partial_page_buffers is no longer used anywhere so we can simply remove it including the *_no_lock variant and EXT4_DISCARD_PARTIAL_PG_ZERO_UNMAPPED define.
--- fs/ext4/ext4.h | 8 -- fs/ext4/inode.c | 206 ------------------------------------------------------- 2 files changed, 0 insertions(+), 214 deletions(-)
fs/ext4/ext4.h +0 -8
@@ -583,11 +583,6 @@ enum {#define EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER 0x0020/* -* Flags used by ext4_discard_partial_page_buffers -*/ -#define EXT4_DISCARD_PARTIAL_PG_ZERO_UNMAPPED 0x0001 - -/* * ioctl commands */ #define EXT4_IOC_GETFLAGS FS_IOC_GETFLAGS
@@ -2001,9 +1996,6 @@ extern int ext4_block_zero_page_range(handle_t *handle, struct address_space *mapping, loff_t from, loff_t length);extern int ext4_zero_partial_blocks (handle_t *handle,struct inode *inode,loff_t lstart,loff_t lend); -extern int ext4_discard_partial_page_buffers (handle_t *handle, -struct address_space *mapping,loff_t from, -loff_t length,int flags);extern int ext4_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf);extern qsize_t *ext4_get_reserved_space (struct inode *inode); extern void ext4_da_update_reserve_space(struct inode *inode,
fs/ext4/inode.c +0 -206
218 lines not on this page · raw message
Signature · 1 line
1.7.7.6