From nobody Fri Apr 17 01:43:25 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 2B77F38E108 for ; Tue, 24 Feb 2026 12:51:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771937504; cv=none; b=BiJCPvjj5gxnGFTYxzz0XxCFP8k76ysxkABwr59uSVeIMna94ji9VUPTDoPrJMIqjtx3fw7blf2cF9aMAXxvw8t1y9vJPmr8bcFn6nc+ImMjv+qoyG+pkhhwIR3/xG0XAmQ0aPIQQ/XmlmLzkCAz8+teBVjEDrt0ng8WyOasHdU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771937504; c=relaxed/simple; bh=lYi1KK3NNKr+5+DganXnGOweKJXI1vyqHpOospYsA74=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=tOqLGYqGiO7RiP9cy3VY1mu+0PXqRwgu2hBeSuxJl7CIy/jMlRP+7pKGbCDux0TKVIWCqa+W+s0YFSlR3LKEDTUkIfP9JRKS+OFaLAPZCKUby9z6VX6KArkef8R2XrTgOnVZUt4AC5twPxTwkrmSoWumXT9dvtDlZmRjW1eGyP8= 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=F+r1tUU6; arc=none smtp.client-ip=209.85.214.176 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="F+r1tUU6" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2adae92249eso3576065ad.0 for ; Tue, 24 Feb 2026 04:51:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771937501; x=1772542301; 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=ntm/m5QpJaDRn+h1w7VU33hlplXMfVuCtDhq2BfS2fU=; b=F+r1tUU6MN75MHQL9q3xHgY8kunLimUikuyr/Us4/3PD+0V1GbvjYUWwElyt7mfSIP eGMwCPN9H/BWKC6IPfuh7Xs04/SOFwYUlutsuTneNoJsZ67aMcNU22oSMABtp3Yb7P9e ofl2yXeN6R0DpD3KvL4I/GMZj7h8AEPJJl77kK0OyFlCcKTtz7Dal/KIrbGILSvvGKmY cs8v90S9guTpxkokddJJE8Zo69Z0CoxnIYD/WU11AVQdkRFeRDc3x+ceNBFM1wxRmboM SVbt3+AtbkrbZilh08wvP7P6Yg+VMffh5isxoNj2CULf2vXJkLrln7ZPPShgMZlCe18R 1KgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771937501; x=1772542301; 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=ntm/m5QpJaDRn+h1w7VU33hlplXMfVuCtDhq2BfS2fU=; b=AFUurGrvfBHnGhNU63IoklXJx07yyoiONmWugezGBqiAdOL7EY7QhaGWOkZKCYaczL Rr8oyLoPwLYaY87sKPsQn55zXPoKICqs6VGka6Exdk7z9KBAD/WU5loghc3iLcS5CImI bSe8rGP5NV6odlggoDOJ7ZHGAESRwU8VxjaSErD6pNfueewGLWT7qTn4ziAvJjs5o9z2 lVV8W0USwnIwwi+1Xe1AsTrmNHYs+aHV3IzWGXiDiTHxoydd7aBmZSadf5AKQmrPVxmw yddhzIZDMUEHcW67GXTt7a5jiu/usdTCc+PVVaQEbMk4UGsfexIxfuypsTnZkjhY0l21 2+Tw== X-Forwarded-Encrypted: i=1; AJvYcCUg+WT/pMrVxDd5fwkkdjL7/G2mwz4RZFrYnFikD96KGv35JstkxpowQWuCH7EZDj7Hj8cNltTF/gx92j0=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8clCaJcQSt1JX7Ps9EawOsJMAeUKVsfcuNh5G9Lpvd5IRX7/M jdDlU/X7F93J1GOZo3ugkGGDz/AqaLZ2EqZd6fP4L5+M0AAifeHwLnBBHwoxJvB5 X-Gm-Gg: ATEYQzzlx4INVmicj92g1ISdAHYBOOqjG58Gnvu7et8VGonSOZM/t+jaPQoD6lbPJm2 c8wUFhMF3Gwg99OsSDlV3zRX3k/v1J3IF/YNdTiz2VGtUn941kPQC7Lfi5U8/IQaKPh/wmOAsD+ 7Yd52XL7grfgJdo5wuPBrrX1RvHyd/zqFhkGzIMPrvZsxCFw37SqGSiHfFsx6aKv71FYmzMf0z2 sU+5Qka6yteR/lDV2kVU4OBWNizvf5TAsHqqc+BJwyCv1lbTAEU/jpxQBoJhxNeLKdAmRwjkHkg P9gjIJnhNhH/Ge9ZdcUcKRMIeb7hxwvPzqb1FBPKX2QpuNsriPzFAogbEMZpv+AxDfu+Q1mR32U gajpQetY42fHIjAkfLHfqnOrQhkqTRmdk2+epCvQh72wD87/56scFL42VJvB5VzR2XssGhKDSmz lFsh7srsz0NcFLjZe5+xNLNfO+SIg6bKM= X-Received: by 2002:a17:903:32c8:b0:2aa:f0d6:bf3b with SMTP id d9443c01a7336-2ad7455d873mr119212625ad.53.1771937501421; Tue, 24 Feb 2026 04:51:41 -0800 (PST) Received: from localhost ([120.235.196.245]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-2ad75321543sm107484905ad.72.2026.02.24.04.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 04:51:40 -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 v3] ext4: simplify mballoc preallocation size rounding for small files Date: Tue, 24 Feb 2026 20:51:36 +0800 Message-Id: <20260224125136.62551-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 Reviewed-by: Andreas Dilger > --- fs/ext4/mballoc.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 20e9fdaf4301..a5c51daaba78 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4561,22 +4561,17 @@ 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. + */ + if (size <=3D (unsigned long)SZ_16K) { + size =3D SZ_16K; + } else { + size =3D roundup_pow_of_two(size); + } } 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)