Skip to content

Commit b9d0b38

Browse files
Qu Wenruomasoncl
authored andcommitted
btrfs: Add handler for invalidate page
For btrfs_invalidatepage() and its variant evict_inode_truncate_page(), there will be pages don't reach disk. In that case, their reserved space won't be release nor freed by finish_ordered_io() nor delayed_ref handler. So we must free their qgroup reserved space, or we will leaking reserved space again. So this will patch will call btrfs_qgroup_free_data() for invalidatepage() and its variant evict_inode_truncate_page(). And due to the nature of new btrfs_qgroup_reserve/free_data() reserved space will only be reserved or freed once, so for pages which are already flushed to disk, their reserved space will be released and freed by delayed_ref handler. Double free won't be a problem. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 94ed938 commit b9d0b38

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

fs/btrfs/inode.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5132,6 +5132,18 @@ static void evict_inode_truncate_pages(struct inode *inode)
51325132
spin_unlock(&io_tree->lock);
51335133

51345134
lock_extent_bits(io_tree, start, end, 0, &cached_state);
5135+
5136+
/*
5137+
* If still has DELALLOC flag, the extent didn't reach disk,
5138+
* and its reserved space won't be freed by delayed_ref.
5139+
* So we need to free its reserved space here.
5140+
* (Refer to comment in btrfs_invalidatepage, case 2)
5141+
*
5142+
* Note, end is the bytenr of last byte, so we need + 1 here.
5143+
*/
5144+
if (state->state & EXTENT_DELALLOC)
5145+
btrfs_qgroup_free_data(inode, start, end - start + 1);
5146+
51355147
clear_extent_bit(io_tree, start, end,
51365148
EXTENT_LOCKED | EXTENT_DIRTY |
51375149
EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING |
@@ -8646,6 +8658,18 @@ static void btrfs_invalidatepage(struct page *page, unsigned int offset,
86468658
}
86478659
}
86488660

8661+
/*
8662+
* Qgroup reserved space handler
8663+
* Page here will be either
8664+
* 1) Already written to disk
8665+
* In this case, its reserved space is released from data rsv map
8666+
* and will be freed by delayed_ref handler finally.
8667+
* So even we call qgroup_free_data(), it won't decrease reserved
8668+
* space.
8669+
* 2) Not written to disk
8670+
* This means the reserved space should be freed here.
8671+
*/
8672+
btrfs_qgroup_free_data(inode, page_start, PAGE_CACHE_SIZE);
86498673
if (!inode_evicting) {
86508674
clear_extent_bit(tree, page_start, page_end,
86518675
EXTENT_LOCKED | EXTENT_DIRTY |

0 commit comments

Comments
 (0)