Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6740287rwi; Mon, 24 Oct 2022 05:38:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6U2QscYOU1EQdSpUwYRPAHfOlo33gdyb/M/kgxHkAR7WgjR2P6nLncXzZj1N+B6Mo+cNx3 X-Received: by 2002:a63:b64:0:b0:439:8143:c184 with SMTP id a36-20020a630b64000000b004398143c184mr27665727pgl.22.1666615120654; Mon, 24 Oct 2022 05:38:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615120; cv=none; d=google.com; s=arc-20160816; b=qeF9YbDNzvjavJsEQ25LHwwPEB5DHaXrl2nj5dRMtkFIWYSQg50gAYPlPSOOdlTxEe 4Mx7uksVsG0kbGusBGbsV2nC3yU2RLcU7hwGmsnfoRcbkUPrk5s3b8QwymuWHqYhZdyy r0OTrri5l+B5AXwC1VX7ReyGfQiV6eb4MiGKOsFPPDTsJblU6CxaGv/a9trhltdu0VvO kKpzhn50bSIbC6/r29Rh36nr2inAFyvqOxcjOiehBIK9MXbtgQMy23kh7Qs4i87S59ym cXkWZCs+2Dd/5A/fdFQJVGEA7u5zONDqgzHo3poq338/NQnr10IIMElWS9CMDhujy36+ z7tw== 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=4g+UCgAa4jDAMfNpZkbdRRbnc9I+ZBAsUS8coRv62xA=; b=bNJGp2HM3UO5Vm3AKnd+iYvZcgouXMblFWgwLuMKSBykuyh1FWBYsVz6vxOeHPUhFu M9f7WzCbMPllJ5GycDd1ncpkiUiz8iN4H9Fbbu9jUMfcra2Pxrz0n28lNR0QtGUJFDbz 3imjXg75R00xkiYvbdOmfV7JA1WP54JSD03tcvoa97Nr7tSB3bMp6t8fVAvfg00j6asa XDRvwtrmI112T37gHf+7SiDxNdTFjTiuam/WU9wGlA8t2+svq7G9uUsD+nS76Kg3zuLX zI3b9Rhbm51p8NhQjBC73LnbFT6eCDrQvDNNiObAEuovvRIN6+cYz06BheJ4bXC7hruJ 9LZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SD64py0F; 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 w190-20020a6382c7000000b0043c8ce98a7bsi7639342pgd.802.2022.10.24.05.38.28; Mon, 24 Oct 2022 05:38:40 -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=SD64py0F; 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 S232700AbiJXMGt (ORCPT + 99 others); Mon, 24 Oct 2022 08:06:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232909AbiJXMEh (ORCPT ); Mon, 24 Oct 2022 08:04:37 -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 CC66263D0A; Mon, 24 Oct 2022 04:50:57 -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 17638B811BD; Mon, 24 Oct 2022 11:49:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67101C433D6; Mon, 24 Oct 2022 11:49:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612186; bh=wPT73C7wz0wOnYYzNDbw2GNECMcxZOHB770mS52PGjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SD64py0FAiV7HGu71D0Ebc1MqD9gvn7p1+xn4UN+LGOLzRcowRb/snb9EU3vE5bdK Fw5A4Ja0NWU8qtEYLQmA9iFcwjyGwPePYuceSY0lvX0uL34Ur+7dmym5ZdY6X6zA6t 4pYSrADCtEaVUobGI7Oo0gFOFnuNnquCmj75afNw= 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 4.14 071/210] ext4: place buffer head allocation before handle start Date: Mon, 24 Oct 2022 13:29:48 +0200 Message-Id: <20221024112959.364329797@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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.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 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 @@ -1309,6 +1309,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: