From: Ojaswin Mujoo <ojaswin@linux.ibm.com>
To: linux-ext4@vger.kernel.org, "Theodore Ts'o" <tytso@mit.edu>
Cc: Ritesh Harjani <ritesh.list@gmail.com>,
linux-kernel@vger.kernel.org,
"Darrick J . Wong" <djwong@kernel.org>,
linux-block@vger.kernel.org, linux-xfs@vger.kernel.org,
linux-fsdevel@vger.kernel.org,
John Garry <john.g.garry@oracle.com>,
dchinner@redhat.com
Subject: [RFC 2/7] ext4: Factor out size and start prediction from ext4_mb_normalize_request()
Date: Thu, 30 Nov 2023 19:23:11 +0530 [thread overview]
Message-ID: <a6fc4fc33c61be908d4977bcf35e6fb267baca08.1701339358.git.ojaswin@linux.ibm.com> (raw)
In-Reply-To: <cover.1701339358.git.ojaswin@linux.ibm.com>
As a part of trimming down the size of ext4_mb_normalize_request(), factor
out the logic to predict normalized start and size to a separate function
ext4_mb_pa_predict_size().
This is no functional change in this patch.
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
fs/ext4/mballoc.c | 95 ++++++++++++++++++++++++++++-------------------
1 file changed, 56 insertions(+), 39 deletions(-)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 0b0aff458efd..3eb7b639d36e 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4394,6 +4394,58 @@ ext4_mb_pa_adjust_overlap(struct ext4_allocation_context *ac,
*end = new_end;
}
+static void ext4_mb_pa_predict_size(struct ext4_allocation_context *ac,
+ loff_t *start, loff_t *size)
+{
+ struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
+ loff_t new_size = *size;
+ loff_t new_start = *start;
+ int bsbits, max;
+
+ bsbits = ac->ac_sb->s_blocksize_bits;
+ /* max size of free chunks */
+ max = 2 << bsbits;
+
+#define NRL_CHECK_SIZE(req, size, max, chunk_size) \
+ (req <= (size) || max <= (chunk_size))
+
+ if (new_size <= 16 * 1024) {
+ new_size = 16 * 1024;
+ } else if (new_size <= 32 * 1024) {
+ new_size = 32 * 1024;
+ } else if (new_size <= 64 * 1024) {
+ new_size = 64 * 1024;
+ } else if (new_size <= 128 * 1024) {
+ new_size = 128 * 1024;
+ } else if (new_size <= 256 * 1024) {
+ new_size = 256 * 1024;
+ } else if (new_size <= 512 * 1024) {
+ new_size = 512 * 1024;
+ } else if (new_size <= 1024 * 1024) {
+ new_size = 1024 * 1024;
+ } else if (NRL_CHECK_SIZE(new_size, 4 * 1024 * 1024, max, 2 * 1024)) {
+ new_start = ((loff_t)ac->ac_o_ex.fe_logical >>
+ (21 - bsbits)) << 21;
+ new_size = 2 * 1024 * 1024;
+ } else if (NRL_CHECK_SIZE(new_size, 8 * 1024 * 1024, max, 4 * 1024)) {
+ new_start = ((loff_t)ac->ac_o_ex.fe_logical >>
+ (22 - bsbits)) << 22;
+ new_size = 4 * 1024 * 1024;
+ } else if (NRL_CHECK_SIZE(EXT4_C2B(sbi, ac->ac_o_ex.fe_len),
+ (8<<20)>>bsbits, max, 8 * 1024)) {
+ new_start = ((loff_t)ac->ac_o_ex.fe_logical >>
+ (23 - bsbits)) << 23;
+ new_size = 8 * 1024 * 1024;
+ } else {
+ new_start = (loff_t) ac->ac_o_ex.fe_logical << bsbits;
+ new_size = (loff_t) EXT4_C2B(sbi,
+ ac->ac_o_ex.fe_len) << bsbits;
+ }
+
+ *size = new_size;
+ *start = new_start;
+}
+
/*
* Normalization means making request better in terms of
* size and alignment
@@ -4404,7 +4456,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
{
struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
struct ext4_super_block *es = sbi->s_es;
- int bsbits, max;
+ int bsbits;
loff_t size, start_off, end;
loff_t orig_size __maybe_unused;
ext4_lblk_t start;
@@ -4438,47 +4490,12 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
size = i_size_read(ac->ac_inode);
orig_size = size;
- /* max size of free chunks */
- max = 2 << bsbits;
-
-#define NRL_CHECK_SIZE(req, size, max, chunk_size) \
- (req <= (size) || max <= (chunk_size))
-
/* first, try to predict filesize */
/* XXX: should this table be tunable? */
start_off = 0;
- if (size <= 16 * 1024) {
- size = 16 * 1024;
- } else if (size <= 32 * 1024) {
- size = 32 * 1024;
- } else if (size <= 64 * 1024) {
- size = 64 * 1024;
- } else if (size <= 128 * 1024) {
- size = 128 * 1024;
- } else if (size <= 256 * 1024) {
- size = 256 * 1024;
- } else if (size <= 512 * 1024) {
- size = 512 * 1024;
- } else if (size <= 1024 * 1024) {
- size = 1024 * 1024;
- } else if (NRL_CHECK_SIZE(size, 4 * 1024 * 1024, max, 2 * 1024)) {
- start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
- (21 - bsbits)) << 21;
- size = 2 * 1024 * 1024;
- } else if (NRL_CHECK_SIZE(size, 8 * 1024 * 1024, max, 4 * 1024)) {
- start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
- (22 - bsbits)) << 22;
- size = 4 * 1024 * 1024;
- } else if (NRL_CHECK_SIZE(EXT4_C2B(sbi, ac->ac_o_ex.fe_len),
- (8<<20)>>bsbits, max, 8 * 1024)) {
- start_off = ((loff_t)ac->ac_o_ex.fe_logical >>
- (23 - bsbits)) << 23;
- size = 8 * 1024 * 1024;
- } else {
- start_off = (loff_t) ac->ac_o_ex.fe_logical << bsbits;
- size = (loff_t) EXT4_C2B(sbi,
- ac->ac_o_ex.fe_len) << bsbits;
- }
+
+ ext4_mb_pa_predict_size(ac, &start_off, &size);
+
size = size >> bsbits;
start = start_off >> bsbits;
--
2.39.3
next prev parent reply other threads:[~2023-11-30 13:53 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-30 13:53 [RFC 0/7] ext4: Allocator changes for atomic write support with DIO Ojaswin Mujoo
2023-11-30 13:53 ` [RFC 1/7] iomap: Don't fall back to buffered write if the write is atomic Ojaswin Mujoo
2023-11-30 21:10 ` Dave Chinner
2023-12-01 10:42 ` John Garry
2023-12-01 13:27 ` Matthew Wilcox
2023-12-01 19:06 ` John Garry
2023-12-01 22:07 ` Dave Chinner
2023-12-04 9:02 ` John Garry
2023-12-04 18:17 ` Darrick J. Wong
2023-12-04 18:34 ` John Garry
2023-12-07 12:43 ` John Garry
2023-11-30 13:53 ` Ojaswin Mujoo [this message]
2023-11-30 13:53 ` [RFC 3/7] ext4: add aligned allocation support in mballoc Ojaswin Mujoo
2023-11-30 13:53 ` [RFC 4/7] ext4: allow inode preallocation for aligned alloc Ojaswin Mujoo
2023-11-30 13:53 ` [RFC 5/7] block: export blkdev_atomic_write_valid() and refactor api Ojaswin Mujoo
2023-12-01 10:47 ` John Garry
2023-12-11 10:57 ` Ojaswin Mujoo
2023-11-30 13:53 ` [RFC 6/7] ext4: Add aligned allocation support for atomic direct io Ojaswin Mujoo
2023-11-30 13:53 ` [RFC 7/7] ext4: Support atomic write for statx Ojaswin Mujoo
2023-12-04 10:36 ` [RFC 0/7] ext4: Allocator changes for atomic write support with DIO John Garry
2023-12-04 13:38 ` Ojaswin Mujoo
2023-12-04 14:44 ` John Garry
2023-12-11 10:54 ` Ojaswin Mujoo
2023-12-12 7:46 ` John Garry
2023-12-12 13:10 ` Christoph Hellwig
2023-12-12 15:16 ` Theodore Ts'o
2023-12-12 15:19 ` Christoph Hellwig
2023-12-12 16:10 ` John Garry
2023-12-13 5:59 ` Ojaswin Mujoo
2023-12-13 9:17 ` John Garry
2023-12-13 6:42 ` Ojaswin Mujoo
2023-12-13 9:20 ` John Garry
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a6fc4fc33c61be908d4977bcf35e6fb267baca08.1701339358.git.ojaswin@linux.ibm.com \
--to=ojaswin@linux.ibm.com \
--cc=dchinner@redhat.com \
--cc=djwong@kernel.org \
--cc=john.g.garry@oracle.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).