From nobody Fri Apr 17 01:43:26 2026 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.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 5B982396D07 for ; Tue, 24 Feb 2026 12:29:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771936181; cv=none; b=DyIXYiZGK2wPg6x9JMTpHh7dQ8alccZ1gZQ3OMcKBhHPouU1TrqHhIw9ARIse7bKHluMs6GCxUvtL39E0e+8ch9qY0n4WlvjH+lgzH6X8gX6w3GL7iZ6xde/8NfUVi2vZ+WwUyfkcORzbg7htByG90lncZp8ezGEI8vDPBuB0vw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771936181; c=relaxed/simple; bh=4Nk4brUE9c0cHOHvRjQBQZii34SBzjk+bptrUw+er58=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=F2Zl3Fv+ns4f8HMAkznA+xqjeUyXVbjogWyHJQNs3CfqPRj91q7fhh8PDerRx1jQajDw5f3bZB73WNfoD9Rd5jyhEOiR0Vq6pWvwHE5d6RQf6KHolbxJXuNp6bTZuyB/8QbCJQU3vGVufVD+eB98jg7C0ewtMNtP2rAq886frfg= 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=FKiAaNuG; arc=none smtp.client-ip=209.85.210.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="FKiAaNuG" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-824c9da9928so2755763b3a.3 for ; Tue, 24 Feb 2026 04:29:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771936180; x=1772540980; 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=HjRheRQ3fng1+sf53F1DgV3/ZGdhBv7J7v8XPZ28gGo=; b=FKiAaNuGoOFN7HaW14gypBFEwc/LmtbeeJth7eOQeOxsUSl9yHPG+R9xc13TWe7mCp RL3VUq1T9/V1hjw+bx49DCx26YYMgkXtLOSbienCEcUM1TpI+ANkCNisHUUdfei6kBLq RMm+FMsK+q2y7yr6l3WsRbeWXeyY16ikaIClNsY0x7Li5sbTMU6PuSDVHLLGCHiJ6nrN jpSvjaxye6/dtLPQHl1IlQvr9/3rgY5GKRKKWuP0vmvAFu/jFevw3AGPI+4C9OxMA4rm pMYIbmxthyqrVbE2FVtLeXptYueq9BhGzKExg1xbr9C6sQ9Qfw/8PPkhXIdDJQiYylAj sKew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771936180; x=1772540980; 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=HjRheRQ3fng1+sf53F1DgV3/ZGdhBv7J7v8XPZ28gGo=; b=t7x/nrusWfYNyPWCCXZdinzLghM7VEJyyNaBfzWo0sde8qKXn6DRfhwLRFzyR/QEiE 0qtH3g4oKHvP6cF4p4IK4Qwtc+luVm9e6PZ3utuY3B+Q9H29y0/vAXPWsHQ1NSkbd67q k4DmxM9gKduxy3pkc+6Hrk6Swrs8KgFwZfOH3w8fQyPm5DqVLMzApC1B0w8uYDtlqVv8 bqfB+ee3V/GES9fa8ao1aHGKmfeu9uYOrcToMhdOvF5vbPwKK2M9fFRwIDLu7Uh8VPka pSj6o2tKYCawupc3K9RgMy4dfNkutaDYqrb30Wi1vCZO+PUW2QHbKF80iDaDekKVBlsw fepg== X-Forwarded-Encrypted: i=1; AJvYcCX897rQhsmLpV//AaLbLx46dG5Z0PPqC7EjtJPtgSoqHoKERzn0qvFfvtcMqHAaM9tYr9tRwglVkLIafQI=@vger.kernel.org X-Gm-Message-State: AOJu0YyNCVCG6yDnGro4bqzCvLqZ8qegJvVD6RELlA4qAqwHCivgO1Fr 6J4nmpHzQYUZL7JWFACQO9VzTywAu0HmenWDdoHIIy4IamOY1RJmfWeMIWxysNaa X-Gm-Gg: AZuq6aLcoU8AaAIBW98KMtoTB8krNfixO5u6bVRQApmPwHy5BwbHEAHPr2EIXZpIGOk 9y4OURcUAHPVo9nC4nzvlZmrX7INdACWJs+boYmcMuPKF81wbNXG0NBXowKyA95BoTGCcgAyLlV zexT5p6NTExU+UJLUd8cM/c4fXYHr1xY5hArzinEtP3yvjRHUYO1n7USA1r/xAmXBzKO7Uc5k5J H1lffoCiuPu1aypQM5FGuyHkfE5UXIEUAV9OUzOoh1J3ppmC291v7ISzIdwqLVKT/XcDvqrbRH7 ncZID/dBTBPqovxdwyzdyC5AGqAZF7duPOWH3sW7VAJcR/Qoh/bSKBFQb1Vi7YrQ0hH+ysFbVRy d2YEt8ce354BDk7wwtzOEwC6tx8w0sAM0RboPRZRFlDX2JvtriA0xpfiy13OblVyYZRhFUet5LB 6ut1vAbb9kFq37zFbwz08F9ddtP7K7Fhs= X-Received: by 2002:a05:6a20:3ca7:b0:38d:f8e6:fc8b with SMTP id adf61e73a8af0-39545fac23dmr9717360637.58.1771936179679; Tue, 24 Feb 2026 04:29:39 -0800 (PST) Received: from localhost ([120.235.196.245]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-358af71e797sm9757901a91.5.2026.02.24.04.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Feb 2026 04:29:39 -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] ext4: simplify mballoc preallocation size rounding for small files Date: Tue, 24 Feb 2026 20:29:33 +0800 Message-Id: <20260224122933.27975-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 | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 20e9fdaf4301..dc7a0dee332f 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4561,22 +4561,13 @@ 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 max(roundup_pow_of_two(size), (unsigned long)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)