From patchwork Mon Oct 24 11:29:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp555998wru; Mon, 24 Oct 2022 10:00:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM46qdTrteHBG3rgc13CiltRJdl4g9rNRUqnI46NKnmihjoI7MhMckwm1vZukA7X4HqDvA5B X-Received: by 2002:a63:9144:0:b0:45f:c9f5:1bb with SMTP id l65-20020a639144000000b0045fc9f501bbmr28088006pge.165.1666630859490; Mon, 24 Oct 2022 10:00:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666630859; cv=none; d=google.com; s=arc-20160816; b=zI9KBQK5toC6zIu9VgQTshxCta+UqqSG+br4/SrEvJFsaGSoOhownQxkGzLWBmCrmx 0k8homu6zBoj/iXDEP7oAGjkSnWrxeoo00L7gPfScxBttMc/FpQsutuSEP8V6EhUMH3l NRrkH7x1+o+5AZJhBQQkB3c7fWyHF1IPC+GYlYIU6FfKVpT0mTwBsyOBuejNmvN0pcRL FKGqsW47yH0b7QmOMCS/tCa+nzzhyxnYUa5idByRkrsShJtkVT5t22XI54Xco35yLgCz Lz29mQYc6uLbgVbV0YmgLIz2ESrirT0mpl8rTfj+N7I1HcZVm56wn3rK0mhmWlt/sdUR S5LA== 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=OoXUJMqtcbWukmRb+zUw2hyrbyKOEynAYk+JXmyg2k0=; b=CXY1r4M1CD/ZZOzHqxnhvf++0Wr/PtUGIwvgJtrovoQ6MQUgiE8jC4+o5xHTXFmUhC EkIy0VjyCjveyfs+3XY6Gs40+xjeO92BhtIuqlR5MUJav+srKEqzc9gj+g1WHEwGa68G YlomjmzwEH70JDZnVCNhBUd749JrWHUosxd00T5o9McmcueZQg8YwUmaJFh184J+7JGr QYFFthcz7lmnUsBwUZU9sQk+koXcvHCwCQiM/QRDBbqCS/AoA2uUOSOZhCzlC64SWpza In/b3lo21uLE931NIY1+7bqt0a074NzwFl/N6lmpkwlj+/opTSzwAKQV37WvGKlkaHkq 3Whg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lqb+dGyy; 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 x6-20020a170902ec8600b0016efde92292si9700plg.255.2022.10.24.10.00.36; Mon, 24 Oct 2022 10:00:59 -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=lqb+dGyy; 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 S235938AbiJXQzV (ORCPT + 99 others); Mon, 24 Oct 2022 12:55:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235671AbiJXQuF (ORCPT ); Mon, 24 Oct 2022 12:50:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48BF64449A; Mon, 24 Oct 2022 08:33:05 -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 ams.source.kernel.org (Postfix) with ESMTPS id 01797B811BC; Mon, 24 Oct 2022 12:06:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59F0CC433D6; Mon, 24 Oct 2022 12:06:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613195; bh=V4IA2J+RiUYh6Wz5OBXXBXbyZirdIwQ3guXguybdpdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lqb+dGyy1wuQ1OY3qZrJ+nN0gfNGffFgeh979bpNWJ3q3jZxVJlTpvDzYVNIEO4c1 y0O7xBkoaSNErdqQlrRzS+UTS0mmc/eQrLSGUrb6AAt5vJJhu8iKpOFYW/rY4vhSSD LS4+xNOxMRL962QHaqYHyCL7AB/HU9GxP695uYUo= 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.4 044/255] ext4: place buffer head allocation before handle start Date: Mon, 24 Oct 2022 13:29:14 +0200 Message-Id: <20221024113003.892320358@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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?1747589120063406393?= X-GMAIL-MSGID: =?utf-8?q?1747589120063406393?= 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 @@ -1317,6 +1317,13 @@ retry_grab: page = grab_cache_page_write_begin(mapping, index, flags); 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: