Skip to content

Commit d1052d2

Browse files
Jinke Hantytso
authored andcommitted
ext4: place buffer head allocation before handle start
In our product environment, we encounter some jbd hung waiting handles to stop while several writters were doing memory reclaim for buffer head allocation in delay alloc write path. Ext4 do buffer head allocation with holding transaction handle which may be blocked too long if the reclaim works not so smooth. According to our bcc trace, the reclaim time in buffer head allocation can reach 258s and the jbd transaction commit also take almost the same time meanwhile. Except for these extreme cases, we often see several seconds delays for cgroup memory reclaim on our servers. This is more likely to happen considering docker environment. One thing to note, the allocation of buffer heads is as often as page allocation or more often when blocksize less than page size. Just like page cache allocation, we should also place the buffer head allocation before startting the handle. Cc: [email protected] Signed-off-by: Jinke Han <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0b73284 commit d1052d2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/ext4/inode.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,13 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
11881188
page = grab_cache_page_write_begin(mapping, index);
11891189
if (!page)
11901190
return -ENOMEM;
1191+
/*
1192+
* The same as page allocation, we prealloc buffer heads before
1193+
* starting the handle.
1194+
*/
1195+
if (!page_has_buffers(page))
1196+
create_empty_buffers(page, inode->i_sb->s_blocksize, 0);
1197+
11911198
unlock_page(page);
11921199

11931200
retry_journal:

0 commit comments

Comments
 (0)