Skip to content

Commit ffb959b

Browse files
committed
mm: remove optimizations based on i_size in mapping writeback waits
Marcelo added this i_size based optimization with a patch in 2004 (commitid is from the linux-history tree): commit 765dad0 Author: Marcelo Tosatti <marcelo.tosatti@cyclades.com> Date: Tue Sep 7 17:51:17 2004 -0700 small wait_on_page_writeback_range() optimization filemap_fdatawait() calls wait_on_page_writeback_range() with -1 as "end" parameter. This is not needed since we know the EOF from the inode. Use that instead. There may be races here, particularly with clustered or network filesystems. It also seems like a bit of a layering violation since we're operating on an address_space here, not an inode. Finally, it's also questionable whether this optimization really helps on workloads that we care about. Should we be optimizing for writeback vs. truncate races in a codepath where we expect to wait anyway? It doesn't seem worth the risk. Remove this optimization from the filemap_fdatawait codepaths. This means that filemap_fdatawait becomes a trivial wrapper around filemap_fdatawait_range. Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Jeff Layton <jlayton@redhat.com>
1 parent 3b49c9a commit ffb959b

2 files changed

Lines changed: 7 additions & 30 deletions

File tree

‎include/linux/fs.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2538,10 +2538,15 @@ extern int invalidate_inode_pages2_range(struct address_space *mapping,
25382538
extern int write_inode_now(struct inode *, int);
25392539
extern int filemap_fdatawrite(struct address_space *);
25402540
extern int filemap_flush(struct address_space *);
2541-
extern int filemap_fdatawait(struct address_space *);
25422541
extern int filemap_fdatawait_keep_errors(struct address_space *mapping);
25432542
extern int filemap_fdatawait_range(struct address_space *, loff_t lstart,
25442543
loff_t lend);
2544+
2545+
static inline int filemap_fdatawait(struct address_space *mapping)
2546+
{
2547+
return filemap_fdatawait_range(mapping, 0, LLONG_MAX);
2548+
}
2549+
25452550
extern bool filemap_range_has_page(struct address_space *, loff_t lstart,
25462551
loff_t lend);
25472552
extern int __must_check file_fdatawait_range(struct file *file, loff_t lstart,

‎mm/filemap.c‎

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -512,39 +512,11 @@ EXPORT_SYMBOL(file_fdatawait_range);
512512
*/
513513
int filemap_fdatawait_keep_errors(struct address_space *mapping)
514514
{
515-
loff_t i_size = i_size_read(mapping->host);
516-
517-
if (i_size == 0)
518-
return 0;
519-
520-
__filemap_fdatawait_range(mapping, 0, i_size - 1);
515+
__filemap_fdatawait_range(mapping, 0, LLONG_MAX);
521516
return filemap_check_and_keep_errors(mapping);
522517
}
523518
EXPORT_SYMBOL(filemap_fdatawait_keep_errors);
524519

525-
/**
526-
* filemap_fdatawait - wait for all under-writeback pages to complete
527-
* @mapping: address space structure to wait for
528-
*
529-
* Walk the list of under-writeback pages of the given address space
530-
* and wait for all of them. Check error status of the address space
531-
* and return it.
532-
*
533-
* Since the error status of the address space is cleared by this function,
534-
* callers are responsible for checking the return value and handling and/or
535-
* reporting the error.
536-
*/
537-
int filemap_fdatawait(struct address_space *mapping)
538-
{
539-
loff_t i_size = i_size_read(mapping->host);
540-
541-
if (i_size == 0)
542-
return 0;
543-
544-
return filemap_fdatawait_range(mapping, 0, i_size - 1);
545-
}
546-
EXPORT_SYMBOL(filemap_fdatawait);
547-
548520
static bool mapping_needs_writeback(struct address_space *mapping)
549521
{
550522
return (!dax_mapping(mapping) && mapping->nrpages) ||

0 commit comments

Comments
 (0)