From nobody Fri Apr 17 01:43:25 2026 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A485395DB8 for ; Tue, 24 Feb 2026 12:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771937254; cv=none; b=VjLlJ/vICfO2gGY58ZZn1Vola7XiNjHPTmWmRDvJS6lQMUD7CCtNlZt85mXPd+FZnz01KEG5QqXV1xarP0E+K0Ph0McQQANPX9GfUNc+ljP+wrAhWNpU3YPRyudmS1uxO4rFLoe21KMZcx+R7b48hEJf4bsSjam1Q37tlamvuXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771937254; c=relaxed/simple; bh=8SN7zgnwcL0WRqAhSbscCKYgJ9U4F6nvAJBy3/SsDjA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=noJgt0qDvE3KinO87fQ1L8Uv8ebZkXPnvMAqcNhboh0In8ZIGcRS350gLpU0SQzrE5iBseO9BsIUwY8U3RxvIoqmweF+6tuuLjsuO/WwZXEQ/GLVmGHsG/c8gzJBCmiwcsfVv32OD07WcfPhgTPSAZ9ooCFcOYqrCU1Fsyl3hec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Hqc3z5Mq; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hqc3z5Mq" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-c6541e35fc0so3356416a12.3 for ; Tue, 24 Feb 2026 04:47:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771937252; x=1772542052; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=HZCAGkuMPq7tF14SyJvLaSbQCH8XuWyE97stWsPADsk=; b=Hqc3z5Mqukfcc1vy8J7vnQZhSa+Wvrn6u0dHmkpMWEutr9ULHklS1I56Xo3XB1r6ut G+fef8J0HFcJolulsRWpm/p0pW7+xFsKiCRo1a+Exu/2xzKH/Qytp7zvl6Z7SYv7wS67 tEkRfZh/qqgBkMUalpqCL+tA3OOfwNx/27FQUVSyauTedTbl2fPv6RFkPSBq2rd0Hpco l0Jc/8Np5aRtB86efQcQLvw570y4+i2C7AUwY4QZJlHEcfxIBSw7KJEWPF3yam4pZJf4 b4GZ3y/njEdm8kHcPoleEZYNZRw2tsaMF1Gf5OqbiePyieP94ljkX/kbxfisPsYqQPbs 8ODw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771937252; x=1772542052; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=HZCAGkuMPq7tF14SyJvLaSbQCH8XuWyE97stWsPADsk=; b=p7F2dsz161cJkurGjgZgwPW4x8JcVuTCZl6HgPEAX+ypQquoADB3Xv4IfKDhuSUIaC t/5iAIB65MDGwzqDCa18ZU/KcUe9eWmdl+Op+YZkY3P8Zx2Vc18E4zJSWsO6+Il82fFx i3jbRDHfaWG3ErJzZGDjPXX6MErsLzQQP8AiEGYwcveEmMc+ZpknkvKmps2ggG06KeMa vpi4A1qQG1DegRxsYcb30qqSXu40QdNQd2/JFxCiUAcspswu+9WvtzJtKXCnMEJczf3G 4xpUqVdCRcn5x+Ts7qK8jRzg/AGmgKd1Vm5ZStU11fIpjS6vqPrFIrNkh9KTNhw0A8Ix Y56Q== X-Forwarded-Encrypted: i=1; AJvYcCV8SyP+iNxDDi0rkciSPlJdwVkg3fkSJIKJSzkIsl7gZnZlZ2zykW7H+8YG41dMyyWi9EoOTXOgdigi1kA=@vger.kernel.org X-Gm-Message-State: AOJu0YzZvK8PxqzdzS6btKwk2eSK4T08N6bEu85NFcPrzHvGP3YK4Q2b NeHJY+BPv/xbSAwePtx7hVfGuQ+tuERc3k6vPix0AOMr0v9BtSj0u0NUpvk+QCYe X-Gm-Gg: AZuq6aKgheTMhCqfYASyYgFMHZZfLHWwCOdmwsoAdRUs9n8VoBGR/10owdVutTU28dd yxqwkwiI3Wzh98HuTM78IKHTWd8ETTdm3U1LahFOnsQimdYKpmoUJkWgVo4lJI67zhe60OhVEdJ gbD3g5I7q09tZAv2B7tc3Ij2aIj49kx7+T0BmVfaAGTEFI06Qv0S56+mFIaBZM2Udw/PVPZTRSu N+B6LnM6ITtOpCUO4OT95umrRNeQ7J++PVjR4K/gi13iOp19/c6VZwy3W1oCq0u+bjYRKr0nGDE yxmXUTanY5QBT+i/ZAE/4oQp3TqghsQhgOgK7Gx7ACg8A6g7wsLLrJheNSJLc3tBxb6ds4RjuQt JrpI/kTK2TSu6/+iy5f6LpvOauBEOhbyzQReItgkGK7qHfzMie0GBhh4jdcXmF67nYKBN0hshWL 1t8O2659htlpn1CBSzAaKIPp4y29ieNYc= X-Received: by 2002:a05:6a21:330e:b0:375:4426:e78b with SMTP id adf61e73a8af0-39545faf8cemr11008959637.71.1771937252236; Tue, 24 Feb 2026 04:47:32 -0800 (PST) Received: from localhost ([120.235.196.245]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-c70b71814f8sm10318755a12.4.2026.02.24.04.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 04:47:31 -0800 (PST) From: cuiweixie@gmail.com To: dilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Weixie Cui Subject: [PATCH v2] ext4: simplify mballoc preallocation size rounding for small files Date: Tue, 24 Feb 2026 20:47:27 +0800 Message-Id: <20260224124727.56016-1-cuiweixie@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Weixie Cui The if-else ladder in ext4_mb_normalize_request() manually rounds up the preallocation size to the next power of two for files up to 1MB, enumerating each step from 16KB to 1MB individually. Replace this with a single roundup_pow_of_two() call clamped to a 16KB minimum, which is functionally equivalent but much more concise. Also replace raw byte constants with SZ_1M and SZ_16K from for clarity, and remove the stale "XXX: should this table be tunable?" comment that has been there since the original mballoc code. No functional change. Signed-off-by: Weixie Cui --- fs/ext4/mballoc.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 20e9fdaf4301..2caf0633c6d4 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4561,22 +4561,16 @@ ext4_mb_normalize_request(struct ext4_allocation_co= ntext *ac, (req <=3D (size) || max <=3D (chunk_size)) =20 /* first, try to predict filesize */ - /* XXX: should this table be tunable? */ start_off =3D 0; - if (size <=3D 16 * 1024) { - size =3D 16 * 1024; - } else if (size <=3D 32 * 1024) { - size =3D 32 * 1024; - } else if (size <=3D 64 * 1024) { - size =3D 64 * 1024; - } else if (size <=3D 128 * 1024) { - size =3D 128 * 1024; - } else if (size <=3D 256 * 1024) { - size =3D 256 * 1024; - } else if (size <=3D 512 * 1024) { - size =3D 512 * 1024; - } else if (size <=3D 1024 * 1024) { - size =3D 1024 * 1024; + if (size <=3D SZ_1M) { + /* + * For files up to 1MB, round up the preallocation size to + * the next power of two, with a minimum of 16KB. + */ + size =3D roundup_pow_of_two(size); + if (size < (unsigned long)SZ_16K) { + size =3D SZ_16K; + } } else if (NRL_CHECK_SIZE(size, 4 * 1024 * 1024, max, 2 * 1024)) { start_off =3D ((loff_t)ac->ac_o_ex.fe_logical >> (21 - bsbits)) << 21; --=20 2.39.5 (Apple Git-154)