Skip to content

Commit e4b3448

Browse files
Matthew Wilcoxdjbw
authored andcommitted
dax: Flush partial PMDs correctly
The radix tree would rewind the index in an iterator to the lowest index of a multi-slot entry. The XArray iterators instead leave the index unchanged, but I overlooked that when converting DAX from the radix tree to the XArray. Adjust the index that we use for flushing to the start of the PMD range. Fixes: c1901cd ("page cache: Convert find_get_entries_tag to XArray") Cc: <[email protected]> Reported-by: Piotr Balcer <[email protected]> Tested-by: Dan Williams <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Matthew Wilcox <[email protected]> Signed-off-by: Dan Williams <[email protected]>
1 parent 0cefc36 commit e4b3448

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

fs/dax.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,8 @@ static void dax_entry_mkclean(struct address_space *mapping, pgoff_t index,
843843
static int dax_writeback_one(struct xa_state *xas, struct dax_device *dax_dev,
844844
struct address_space *mapping, void *entry)
845845
{
846-
unsigned long pfn;
846+
unsigned long pfn, index, count;
847847
long ret = 0;
848-
size_t size;
849848

850849
/*
851850
* A page got tagged dirty in DAX mapping? Something is seriously
@@ -894,17 +893,18 @@ static int dax_writeback_one(struct xa_state *xas, struct dax_device *dax_dev,
894893
xas_unlock_irq(xas);
895894

896895
/*
897-
* Even if dax_writeback_mapping_range() was given a wbc->range_start
898-
* in the middle of a PMD, the 'index' we are given will be aligned to
899-
* the start index of the PMD, as will the pfn we pull from 'entry'.
896+
* If dax_writeback_mapping_range() was given a wbc->range_start
897+
* in the middle of a PMD, the 'index' we use needs to be
898+
* aligned to the start of the PMD.
900899
* This allows us to flush for PMD_SIZE and not have to worry about
901900
* partial PMD writebacks.
902901
*/
903902
pfn = dax_to_pfn(entry);
904-
size = PAGE_SIZE << dax_entry_order(entry);
903+
count = 1UL << dax_entry_order(entry);
904+
index = xas->xa_index & ~(count - 1);
905905

906-
dax_entry_mkclean(mapping, xas->xa_index, pfn);
907-
dax_flush(dax_dev, page_address(pfn_to_page(pfn)), size);
906+
dax_entry_mkclean(mapping, index, pfn);
907+
dax_flush(dax_dev, page_address(pfn_to_page(pfn)), count * PAGE_SIZE);
908908
/*
909909
* After we have flushed the cache, we can clear the dirty tag. There
910910
* cannot be new dirty data in the pfn after the flush has completed as
@@ -917,8 +917,7 @@ static int dax_writeback_one(struct xa_state *xas, struct dax_device *dax_dev,
917917
xas_clear_mark(xas, PAGECACHE_TAG_DIRTY);
918918
dax_wake_entry(xas, entry, false);
919919

920-
trace_dax_writeback_one(mapping->host, xas->xa_index,
921-
size >> PAGE_SHIFT);
920+
trace_dax_writeback_one(mapping->host, index, count);
922921
return ret;
923922

924923
put_unlocked:

0 commit comments

Comments
 (0)