From patchwork Wed Oct 19 08:23:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp204926wrs; Wed, 19 Oct 2022 01:47:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4R6pQE9gZZvdyETLfJSL3qmjXAGad2ko1Wo3DGX+y+++N30jkbQC20l2pLLW/g93Q8GSgI X-Received: by 2002:a17:902:a502:b0:184:f2e2:a5ce with SMTP id s2-20020a170902a50200b00184f2e2a5cemr7152786plq.56.1666169271611; Wed, 19 Oct 2022 01:47:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666169271; cv=none; d=google.com; s=arc-20160816; b=DtXIgjTpz7MKcm8SbT+spXsLgtPN8hF0u0pH5BO94ctnehrWgIzg/4r+y9/O93CYKs mrRcD5tDOLPSdv1c6NbIMcyDWizd5P83QexbIGthXPjDzLenUrQQH6u1WSQjx/n5Ok9R aFuHNyT80X1VllmLEOVeMwTUSJeEs54RqATHnZ/ZNPxfXMxMAl5UkUBk1ba84TaKh2M5 dWa2vpgatEOjLeX29Cj2FAht4i86wUmak4y5ASmGhYPJ3voUctrc2j0E+fSorKYPXjeu LZxVWz54QtiMDEK8m7OP5XmG3RupgV9EyzGvE94Nyru/uYCGw8al1B7eHT1t2Q/3Q5qc m17w== 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=e/MyYCzaJwYLLI5OatsnK4a3NNOS5FB4qdGjAjU1RGEOcJs1/ZuSebmM/sHQuIRqXR aing1HOdAvdaN+RqOZ3ztoCvbYs2Gn/v/G93sNq8+fW7ecrs5jLE6QblJTURZs/WQnbi suJrFcXfNyeDj/D7DZXUjxjQkLzdOAnSG67K0rFLMHHlS09Du0zJWL3NWdWnuSEMTEPg DEExegxJyXSWwuTkekaRBRcNXd8ZNRlTBqXqcTfKd1gNaS9OGcxoBN5PjOAmnTp/zVLk SMB2kln/94vjJ4my8R5H4Vt9t2lBybn658hvZJRT2J+SZQPxc8zI3x+XKwNyq37OU4Sh rLFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d36zqZGD; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ip4-20020a17090b314400b00202dbe5fc51si22414100pjb.103.2022.10.19.01.47.39; Wed, 19 Oct 2022 01:47:51 -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=d36zqZGD; 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 S231557AbiJSIrD (ORCPT + 99 others); Wed, 19 Oct 2022 04:47:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231397AbiJSIpw (ORCPT ); Wed, 19 Oct 2022 04:45:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2B0E868B9; Wed, 19 Oct 2022 01:44:15 -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 A3690617AC; Wed, 19 Oct 2022 08:44:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1F63C433D6; Wed, 19 Oct 2022 08:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169055; bh=VtFKGsLaErRVzOB9Z09DPYXE6t91wddQ7M2ZiRFgHpo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d36zqZGDmODF1s5zSqRCAvH+CPB9crylxW+0etX7rV1eDtIBejDmZg4mJvbSDLMJ8 oDEAM+jvwMNGRX6Fo5BHr4LUR3z0RhFAgBQTWRgvvsqh03/94QZr7VwaVuc9SZdydv JSihO+j11E3Af5wWTIiGhm4vL5KSFCG5pIsKwFM0= 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 6.0 142/862] ext4: place buffer head allocation before handle start Date: Wed, 19 Oct 2022 10:23:49 +0200 Message-Id: <20221019083256.258802162@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747105109905931504?= X-GMAIL-MSGID: =?utf-8?q?1747105109905931504?= 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: