Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3884017rwi; Sat, 22 Oct 2022 01:31:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7XqTWgHtIXg+yDPopPOPxW0l2wDztBjHrSDHrVmlmUtzeB3AjV5+trpXhcWatwqnjWu/Md X-Received: by 2002:a05:6a00:15c8:b0:565:bc96:1c5b with SMTP id o8-20020a056a0015c800b00565bc961c5bmr23204820pfu.52.1666427495390; Sat, 22 Oct 2022 01:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427495; cv=none; d=google.com; s=arc-20160816; b=VkrYGYIKKKmM2M16JXq2YsmB0wBRfwy66iE7T1KKe10npBhXarj9LF/m84f+psbTm5 29xCZ0DP5u2ZSgyFa7r4ioysrNcUsNgBsw85xUD0yID/Uw8AfxTcU9yAVKJxbkDpF84C M1JZTiEfEx5ZDr0Pbol4AjA2J0WPluxDdMe9D8ghxNpqlHVgRJ8i5iC6QTrVOfr3rU97 wb89ats4E/LTRNMw20m2XSFRU+vETr6yTpoBR7orahTq4vBvHN9h3mwmC8D6R89KBiS/ +yQCu5e05aQL5HpiqwMhD3wljH71+VnjPPgFZE0cKIFSn37+gT50NmqCVRoKxoZf5Hbv 4tLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zg+v+Gl5dyw2REddJ1ixjdeL+pks3AHEObS0bRzHaPU=; b=jm+WeB0RzOAex6juZTCX8g3nVZBk0YtS6KaeBNJvtzPFhBTo8flqy6orIchhBicGJE 6n7VBIaeq3esI/zL30ZqLd+5n107/FMD7IXhVJlbLp45yANV7BANuO0cyPXx58IitMPT RGxXPXxINjGtSsNXJ+Zf0bmkwOSv20aDY/jpEKRvS+5qU0vJLAQ9lfd0g/bEy71LxUQX qaWOGWxOpyeTkAmEEBGWi0r/b0RtGc5aYTeHq0AU+rUjD28dUhcBRVXn8sDJwDoVqQHM YfdS9lrqJO4a1GbrDJLQ1OGcP3I/lQF6lKD9cOJe5VdiYM+xtyp1PjvRNePdRuCAhYLb n8qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vD7ZVQVZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d1-20020a170902cec100b00176be2315dcsi32823671plg.260.2022.10.22.01.31.23; Sat, 22 Oct 2022 01:31:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vD7ZVQVZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231985AbiJVH5V (ORCPT + 99 others); Sat, 22 Oct 2022 03:57:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232011AbiJVHxd (ORCPT ); Sat, 22 Oct 2022 03:53:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D6C82CA7EA; Sat, 22 Oct 2022 00:46:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 52A3260B4D; Sat, 22 Oct 2022 07:40:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 665A8C433C1; Sat, 22 Oct 2022 07:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424415; bh=VtFKGsLaErRVzOB9Z09DPYXE6t91wddQ7M2ZiRFgHpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vD7ZVQVZsjP6YZJ7OdY4yS28R6z9DnKkjDJlp18MoI7TpU+7DCSC8n/NCdF/a2l6g VTA+xUmpa13cWqjK4SguPRYthyMUE3O2iDRYN8+DdRKEs9Jnsk5s4qXxU8yE3T7oKZ Msg85GJzIx8eLpBDt2RFOlYVsDKAkKH8US7tkUtA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Jinke Han , Theodore Tso Subject: [PATCH 5.19 130/717] ext4: place buffer head allocation before handle start Date: Sat, 22 Oct 2022 09:20:09 +0200 Message-Id: <20221022072438.491425100@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jinke Han commit d1052d236eddf6aa851434db1897b942e8db9921 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: stable@kernel.org Signed-off-by: Jinke Han Link: https://lore.kernel.org/r/20220903012429.22555-1-hanjinke.666@bytedance.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1188,6 +1188,13 @@ retry_grab: 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: