From patchwork Mon Oct 24 11:27:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 10166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp640448wru; Mon, 24 Oct 2022 13:32:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4qFMN7c2ajbqHBnb621rrnbRrQBbyi/QQHdD1AUiHG5vJxw3UT2XjOW2ZEkKAkUeM4w1Va X-Received: by 2002:a50:c387:0:b0:461:3ae6:8cdf with SMTP id h7-20020a50c387000000b004613ae68cdfmr18668345edf.131.1666643562091; Mon, 24 Oct 2022 13:32:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666643562; cv=none; d=google.com; s=arc-20160816; b=bmgXyoGS4X0vdXWkssi6HOrsmIgEYDB34a3hbzFpeIc3+brbR4WhU0M/W1WoVcKKon kVhDDDNbGeuq04OToDPKSJU3TkCUrqRSlnWzG+ywI7aLba7P8C2vb/L5ahbGgGRAa+R7 9UzYN1deXklp8l4FPZf7UJQmaeNXBAKxIprkSEEHPpsVtGs0wZ2NrTLvqquAER13dYnX Fzuq0nddi/vOH8zEbZSRKTDBPLmemcyWKjWkkS38C/bz7DtNAyz6pxeIUVUDBMvB7QIX NiEk6VmduU2xuKywu+MmKJKop8EBvga+1O3gA4NXz3pEfkFBP17kA5KY6gaV9kjKIuLH sMhA== 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=9Cd82BAJ0LxGQiNOsNbvyQ0yqL0e0q92ONsYVTZ8lx8=; b=f3g8SJFvk42HmMuoZ4HNuqS3o//JpIfC2KUbkUqIl9GiGTWtkeSleDQyu9XHUo2Fqu J8g88J8coCSmEg2spbogF9KQYyrVFoBYdZapiIQ/8G/SVdK3GAOe/Grv1Ar+OV6iMwgA V29YMb9A27K9Fqy4RC9qxHeJ4CZDK5rQB1y35JWKtPRDGAKM8IY8nRCUx8xxAPtWWki9 fzMnxlQEFebRCsBx846rrrZ8BxSC2qm7AOx6n0HK6uPE8qEXhh/z6c97RuRohtPIvztj gOFt69+QKGyjMrKk1KOh3LXx71Dm6R5nqokScXh0kWnZu5+C+QLr0IFeonVDSOfOr9Wi ONhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="RRg/8gh1"; 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 r28-20020a50c01c000000b0045fca739593si751128edb.188.2022.10.24.13.32.17; Mon, 24 Oct 2022 13:32:42 -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="RRg/8gh1"; 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 S234038AbiJXUPB (ORCPT + 99 others); Mon, 24 Oct 2022 16:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233984AbiJXUNv (ORCPT ); Mon, 24 Oct 2022 16:13:51 -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 B78CB9C21E; Mon, 24 Oct 2022 11:32:00 -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 32EC5B8136B; Mon, 24 Oct 2022 12:18:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DCE0C433D6; Mon, 24 Oct 2022 12:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613923; bh=Mvez4XHFuHfJYqsWpKqrKcQB1U/xD2vMwrvXbRgd0Z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RRg/8gh1LB6CmXm2a/SY4fwHl0lYgGWqsPVl4vtUfoqCWpF2gHZaQ0IFXNu90+fah 11fU8J5YFkCDPVGobOD3YYjsrUCsQPFJeooVr+88wMpAx5VqrvQkcPp9eMDedooXlg vEPJfOdNQp34GtsdIxptDcpWBv0KjvS50kOqHyK4= 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.10 066/390] ext4: place buffer head allocation before handle start Date: Mon, 24 Oct 2022 13:27:43 +0200 Message-Id: <20221024113025.428180726@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747602439888939195?= X-GMAIL-MSGID: =?utf-8?q?1747602439888939195?= 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 @@ -1175,6 +1175,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: