From nobody Fri Dec 19 17:33:13 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 06AFEC32771 for ; Mon, 26 Sep 2022 11:49:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238923AbiIZLsa (ORCPT ); Mon, 26 Sep 2022 07:48:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238540AbiIZLqE (ORCPT ); Mon, 26 Sep 2022 07:46:04 -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 7D58674CDA; Mon, 26 Sep 2022 03:47:35 -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 6C3C3B80926; Mon, 26 Sep 2022 10:41:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0D9EC433D6; Mon, 26 Sep 2022 10:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188875; bh=nkTo4kgOVzMVNdgbzyC07o/v4i4vF8Ba7SloRGnTvrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S57zn0Fs6JGNZEsatpVB1pyg7X8unU3De+zbPm7vCkOORKhjV8YunUybbX9qybyAJ BSqPHckg1I74qxoB5ZuOj1skG2ITRiAXbqH+x8DNBQ0COnuZYD/N7oNZjlqmOu0vE+ Z28H5qcACEFiA5oaNV/ClmImF3E8n8a3G3NC+MNg= 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.15 148/148] ext4: use locality group preallocation for small closed files Date: Mon, 26 Sep 2022 12:13:02 +0200 Message-Id: <20220926100801.796536949@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100756.074519146@linuxfoundation.org> References: <20220926100756.074519146@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 @@ -5169,6 +5169,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; @@ -5176,25 +5177,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; }