linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ext4: place buffer head allocation before handle start
@ 2022-09-03  1:24 Jinke Han
  2022-09-30  3:19 ` Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Jinke Han @ 2022-09-03  1:24 UTC (permalink / raw)
  To: tytso, adilger.kernel; +Cc: linux-ext4, linux-kernel, yi.zhang, Jinke Han

From: Jinke Han <hanjinke.666@bytedance.com>

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 heand 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.

After commit:cc883236b792, no nore need to do for delay alloc path, just
do it for no delay alloc code.

Signed-off-by: Jinke Han <hanjinke.666@bytedance.com>
---
 fs/ext4/inode.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 601214453c3a..0d6c4ec7c840 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1188,6 +1188,13 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
 	page = grab_cache_page_write_begin(mapping, index);
 	if (!page)
 		return -ENOMEM;
+	/*
+	 * The same as page allocation, we prealloc buffer heads before
+	 * starting the handle.
+	 */
+	if (!page_has_buffers(page))
+		create_empty_buffers(page, inode->i_sb->s_blocksize, 0);
+
 	unlock_page(page);
 
 retry_journal:
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] ext4: place buffer head allocation before handle start
  2022-09-03  1:24 [PATCH v2] ext4: place buffer head allocation before handle start Jinke Han
@ 2022-09-30  3:19 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2022-09-30  3:19 UTC (permalink / raw)
  To: adilger.kernel, hanjinke.666
  Cc: Theodore Ts'o, linux-ext4, linux-kernel, yi.zhang

On Sat, 3 Sep 2022 09:24:29 +0800, Jinke Han wrote:
> From: Jinke Han <hanjinke.666@bytedance.com>
> 
> 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.
> 
> [...]

Applied, thanks!

[1/1] ext4: place buffer head allocation before handle start
      commit: 843b6ee4b8d0d9e7507dad491920db1fbde12439

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-30  3:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-03  1:24 [PATCH v2] ext4: place buffer head allocation before handle start Jinke Han
2022-09-30  3:19 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).