From nobody Tue Dec 16 04:36:35 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21660C32771 for ; Mon, 26 Sep 2022 12:02:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235315AbiIZMCy (ORCPT ); Mon, 26 Sep 2022 08:02:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239129AbiIZMAG (ORCPT ); Mon, 26 Sep 2022 08:00:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54A827C32D; Mon, 26 Sep 2022 03:53:09 -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 F202C60C94; Mon, 26 Sep 2022 10:51:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB653C433C1; Mon, 26 Sep 2022 10:51:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664189509; bh=wKQ2OWT+iKaWQAMG/hdsCIYwXywAu5qK/bsiXG5dHtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MCOz3hd19eOMl2lTfU+SVmbz9fXa/W/6lpWvSWMWcnchpTjkIoYznEUxoe8NT7izu FbgwM5DYl/oP55/za3pSe7vZZz/u73bczykpWCXs0LDAWEG/CGEi4cCRB4rifGKI6j HNWD/jhPZRh0om+Bl7/PlzcL2cb56z5+Yi+gWhMQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Ojaswin Mujoo , "Ritesh Harjani (IBM)" , Jan Kara , Theodore Tso , Stefan Wahren Subject: [PATCH 5.19 205/207] ext4: use locality group preallocation for small closed files Date: Mon, 26 Sep 2022 12:13:14 +0200 Message-Id: <20220926100815.787405954@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Jan Kara commit a9f2a2931d0e197ab28c6007966053fdababd53f upstream. Curently we don't use any preallocation when a file is already closed when allocating blocks (from writeback code when converting delayed allocation). However for small files, using locality group preallocation is actually desirable as that is not specific to a particular file. Rather it is a method to pack small files together to reduce fragmentation and for that the fact the file is closed is actually even stronger hint the file would benefit from packing. So change the logic to allow locality group preallocation in this case. Fixes: 196e402adf2e ("ext4: improve cr 0 / cr 1 group scanning") CC: stable@kernel.org Reported-and-tested-by: Stefan Wahren Tested-by: Ojaswin Mujoo Reviewed-by: Ritesh Harjani (IBM) Signed-off-by: Jan Kara Link: https://lore.kernel.org/all/0d81a7c2-46b7-6010-62a4-3e6cfc1628d6@i2se= .com/ Link: https://lore.kernel.org/r/20220908092136.11770-4-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/mballoc.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -5189,6 +5189,7 @@ static void ext4_mb_group_or_file(struct struct ext4_sb_info *sbi =3D EXT4_SB(ac->ac_sb); int bsbits =3D ac->ac_sb->s_blocksize_bits; loff_t size, isize; + bool inode_pa_eligible, group_pa_eligible; =20 if (!(ac->ac_flags & EXT4_MB_HINT_DATA)) return; @@ -5196,25 +5197,27 @@ static void ext4_mb_group_or_file(struct if (unlikely(ac->ac_flags & EXT4_MB_HINT_GOAL_ONLY)) return; =20 + group_pa_eligible =3D sbi->s_mb_group_prealloc > 0; + inode_pa_eligible =3D true; size =3D ac->ac_o_ex.fe_logical + EXT4_C2B(sbi, ac->ac_o_ex.fe_len); isize =3D (i_size_read(ac->ac_inode) + ac->ac_sb->s_blocksize - 1) >> bsbits; =20 + /* No point in using inode preallocation for closed files */ if ((size =3D=3D isize) && !ext4_fs_is_busy(sbi) && - !inode_is_open_for_write(ac->ac_inode)) { - ac->ac_flags |=3D EXT4_MB_HINT_NOPREALLOC; - return; - } - - if (sbi->s_mb_group_prealloc <=3D 0) { - ac->ac_flags |=3D EXT4_MB_STREAM_ALLOC; - return; - } + !inode_is_open_for_write(ac->ac_inode)) + inode_pa_eligible =3D false; =20 - /* don't use group allocation for large files */ size =3D max(size, isize); - if (size > sbi->s_mb_stream_request) { - ac->ac_flags |=3D EXT4_MB_STREAM_ALLOC; + /* Don't use group allocation for large files */ + if (size > sbi->s_mb_stream_request) + group_pa_eligible =3D false; + + if (!group_pa_eligible) { + if (inode_pa_eligible) + ac->ac_flags |=3D EXT4_MB_STREAM_ALLOC; + else + ac->ac_flags |=3D EXT4_MB_HINT_NOPREALLOC; return; }