From patchwork Mon Oct 24 11:30:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8428 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp400767wru; Mon, 24 Oct 2022 04:47:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5q8pymXpJ0zMD2A6hnO+AGur9sk2liWAuBLU33ru8gkrWKbYA82fI5WaMRT+Je2ZkKaE2Y X-Received: by 2002:a05:6402:5507:b0:452:183f:16d1 with SMTP id fi7-20020a056402550700b00452183f16d1mr30980898edb.96.1666612061782; Mon, 24 Oct 2022 04:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612061; cv=none; d=google.com; s=arc-20160816; b=UvwTZhhLvoFhbmc/xJaF+gjmKrxWNBlDjNg2KOyNpRISlpnW4pwLUnFbM1jVrmjmpv 0O7z+H4/IFM1IZ8YSdK7n2+ISm3BQKq4DAxgV+GCuhoM6FXqqdZQ2uwSUywC+IF33KtG F1AL0SI8GzfH2zXyFDGEUpTlM1aKyNu0/iKQB5u9WuNApDWzGQzFXn9F3pKlGnB27dgT SMUxGfuCflfPveRl7I323jVP4TvrbJwl//697az9XXb4r+LEJIwd2lREOgDFbeCNGWV/ QP2GwTUvevsWnw+Z3v18LN+VrlWbad+6w23E00Dcwnm29zsutTeIymU1eWcjP/KT2H6y eQGw== 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=VaxZ90Ayyfbpz0H+c6zD70YVtAmrIXSyx1/W/BKkDCI=; b=Vy1tu04834MJOSYAZMZvyS4k1yTa2aK8jwDi23kPincgXxfWHyeyrC4cwZMLF9+yXf F5pZHRXvqhkhR7P7xFLebi6PSV+YHoCE2TNKhgiDlq3adOzpUSoBmeNgEC62Up/LX5tx DvXeshPOdC3Z/+BE/sak3QPFUsMnuYJIkx2NZhlXZmnc6WvLtgGzHiucZ+RZNt2E5KLN 8zmEixJML14SBvEZ+vkvFlp9zqjWmEO3E4b3guQwZNmAlwZXpr9odVa0qapRgAU5fMix XnKBja5L7mRqyMzZRhlJyQZ6Z1Pm6qkdMLdxSR0R9BN/G2q3uU2r0UPQTS/FfONYKHt8 buig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jidp2Y8n; 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 dz16-20020a0564021d5000b00461c74a07c8si2828323edb.343.2022.10.24.04.47.17; Mon, 24 Oct 2022 04:47:41 -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=Jidp2Y8n; 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 S231419AbiJXLqp (ORCPT + 99 others); Mon, 24 Oct 2022 07:46:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231844AbiJXLog (ORCPT ); Mon, 24 Oct 2022 07:44:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65DF110BE; Mon, 24 Oct 2022 04:42: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 dfw.source.kernel.org (Postfix) with ESMTPS id B93406129E; Mon, 24 Oct 2022 11:40:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9F80C433C1; Mon, 24 Oct 2022 11:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611647; bh=+I0xfy1z0X+lsymIB2vC9bMATzX/t2nZ5Oe46nZnOzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jidp2Y8nsnEnavBQn+EioPMg2cQv9p/mpOPe0XUCePdPln2UZ2Cp1Ldss6cN1Vy5r qc1jba3UIl7MqR1hCTcN23ZkwL9ZO3UEXHn9kXpk+gQ065EovmO4iGXBYLsvLnsIQ3 PhRKMA2FOjW7rtdAQ+lOYIDe4OAyabggSyS9Zvso= 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.9 058/159] ext4: place buffer head allocation before handle start Date: Mon, 24 Oct 2022 13:30:12 +0200 Message-Id: <20221024112951.560021650@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@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?1747569409452053049?= X-GMAIL-MSGID: =?utf-8?q?1747569409452053049?= 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 @@ -1215,6 +1215,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: