Skip to content

Commit 4bdcd1d

Browse files
committed
mm: move filemap_range_needs_writeback() into header
No functional changes in this patch, just in preparation for efficiently calling this light function from the block O_DIRECT handling. Reviewed-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent a08ed9a commit 4bdcd1d

File tree

4 files changed

+33
-31
lines changed

4 files changed

+33
-31
lines changed

fs/iomap/direct-io.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/module.h>
77
#include <linux/compiler.h>
88
#include <linux/fs.h>
9+
#include <linux/pagemap.h>
910
#include <linux/iomap.h>
1011
#include <linux/backing-dev.h>
1112
#include <linux/uio.h>

include/linux/fs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,8 +2847,6 @@ static inline int filemap_fdatawait(struct address_space *mapping)
28472847

28482848
extern bool filemap_range_has_page(struct address_space *, loff_t lstart,
28492849
loff_t lend);
2850-
extern bool filemap_range_needs_writeback(struct address_space *,
2851-
loff_t lstart, loff_t lend);
28522850
extern int filemap_write_and_wait_range(struct address_space *mapping,
28532851
loff_t lstart, loff_t lend);
28542852
extern int __filemap_fdatawrite_range(struct address_space *mapping,

include/linux/pagemap.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,35 @@ static inline int add_to_page_cache(struct page *page,
963963
int __filemap_add_folio(struct address_space *mapping, struct folio *folio,
964964
pgoff_t index, gfp_t gfp, void **shadowp);
965965

966+
bool filemap_range_has_writeback(struct address_space *mapping,
967+
loff_t start_byte, loff_t end_byte);
968+
969+
/**
970+
* filemap_range_needs_writeback - check if range potentially needs writeback
971+
* @mapping: address space within which to check
972+
* @start_byte: offset in bytes where the range starts
973+
* @end_byte: offset in bytes where the range ends (inclusive)
974+
*
975+
* Find at least one page in the range supplied, usually used to check if
976+
* direct writing in this range will trigger a writeback. Used by O_DIRECT
977+
* read/write with IOCB_NOWAIT, to see if the caller needs to do
978+
* filemap_write_and_wait_range() before proceeding.
979+
*
980+
* Return: %true if the caller should do filemap_write_and_wait_range() before
981+
* doing O_DIRECT to a page in this range, %false otherwise.
982+
*/
983+
static inline bool filemap_range_needs_writeback(struct address_space *mapping,
984+
loff_t start_byte,
985+
loff_t end_byte)
986+
{
987+
if (!mapping->nrpages)
988+
return false;
989+
if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) &&
990+
!mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK))
991+
return false;
992+
return filemap_range_has_writeback(mapping, start_byte, end_byte);
993+
}
994+
966995
/**
967996
* struct readahead_control - Describes a readahead request.
968997
*

mm/filemap.c

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ static bool mapping_needs_writeback(struct address_space *mapping)
646646
return mapping->nrpages;
647647
}
648648

649-
static bool filemap_range_has_writeback(struct address_space *mapping,
650-
loff_t start_byte, loff_t end_byte)
649+
bool filemap_range_has_writeback(struct address_space *mapping,
650+
loff_t start_byte, loff_t end_byte)
651651
{
652652
XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT);
653653
pgoff_t max = end_byte >> PAGE_SHIFT;
@@ -667,34 +667,8 @@ static bool filemap_range_has_writeback(struct address_space *mapping,
667667
}
668668
rcu_read_unlock();
669669
return page != NULL;
670-
671-
}
672-
673-
/**
674-
* filemap_range_needs_writeback - check if range potentially needs writeback
675-
* @mapping: address space within which to check
676-
* @start_byte: offset in bytes where the range starts
677-
* @end_byte: offset in bytes where the range ends (inclusive)
678-
*
679-
* Find at least one page in the range supplied, usually used to check if
680-
* direct writing in this range will trigger a writeback. Used by O_DIRECT
681-
* read/write with IOCB_NOWAIT, to see if the caller needs to do
682-
* filemap_write_and_wait_range() before proceeding.
683-
*
684-
* Return: %true if the caller should do filemap_write_and_wait_range() before
685-
* doing O_DIRECT to a page in this range, %false otherwise.
686-
*/
687-
bool filemap_range_needs_writeback(struct address_space *mapping,
688-
loff_t start_byte, loff_t end_byte)
689-
{
690-
if (!mapping_needs_writeback(mapping))
691-
return false;
692-
if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) &&
693-
!mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK))
694-
return false;
695-
return filemap_range_has_writeback(mapping, start_byte, end_byte);
696670
}
697-
EXPORT_SYMBOL_GPL(filemap_range_needs_writeback);
671+
EXPORT_SYMBOL_GPL(filemap_range_has_writeback);
698672

699673
/**
700674
* filemap_write_and_wait_range - write out & wait on a file range

0 commit comments

Comments
 (0)