Skip to content

Commit d12471b

Browse files
Jinke Hangregkh
authored andcommitted
ext4: place buffer head allocation before handle start
commit d1052d2 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 46e5f47 commit d12471b

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
@@ -1177,6 +1177,13 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
11771177
page = grab_cache_page_write_begin(mapping, index, flags);
11781178
if (!page)
11791179
return -ENOMEM;
1180+
/*
1181+
* The same as page allocation, we prealloc buffer heads before
1182+
* starting the handle.
1183+
*/
1184+
if (!page_has_buffers(page))
1185+
create_empty_buffers(page, inode->i_sb->s_blocksize, 0);
1186+
11801187
unlock_page(page);
11811188

11821189
retry_journal:

0 commit comments

Comments
 (0)