linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [PATCH 2/3] mkfs.f2fs: set overprovision size more precisely
Date: Mon, 10 Aug 2015 18:23:47 -0700	[thread overview]
Message-ID: <1439256228-8982-2-git-send-email-jaegeuk@kernel.org> (raw)
In-Reply-To: <1439256228-8982-1-git-send-email-jaegeuk@kernel.org>

This patch introduces to set the default overprovision space according to the
partition size in order to provide more space.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 lib/libf2fs.c           |  4 ++--
 mkfs/f2fs_format.c      | 40 ++++++++++++++++++++++++++++++++++++++++
 mkfs/f2fs_format_main.c |  5 -----
 3 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 7fd2550..e8f4d47 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -353,8 +353,8 @@ void f2fs_init_configuration(struct f2fs_configuration *c)
 	c->blks_per_seg = DEFAULT_BLOCKS_PER_SEGMENT;
 
 	/* calculated by overprovision ratio */
-	c->reserved_segments = 48;
-	c->overprovision = 5;
+	c->reserved_segments = 0;
+	c->overprovision = 0;
 	c->segs_per_sec = 1;
 	c->secs_per_zone = 1;
 	c->segs_per_zone = 1;
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index f879bca..21e74fe 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -155,6 +155,33 @@ static void configure_extension_list(void)
 	free(config.extension_list);
 }
 
+static u_int32_t get_best_overprovision(void)
+{
+	u_int32_t reserved, ovp, candidate, end, diff, space;
+	u_int32_t max_ovp = 0, max_space = 0;
+
+	if (get_sb(segment_count_main) < 256) {
+		candidate = 10;
+		end = 95;
+		diff = 5;
+	} else {
+		candidate = 1;
+		end = 10;
+		diff = 1;
+	}
+
+	for (; candidate <= end; candidate += diff) {
+		reserved = 2 * (100 / candidate + 1) + 6;
+		ovp = (get_sb(segment_count_main) - reserved) * candidate / 100;
+		space = get_sb(segment_count_main) - reserved - ovp;
+		if (max_space < space) {
+			max_space = space;
+			max_ovp = candidate;
+		}
+	}
+	return max_ovp;
+}
+
 static int f2fs_prepare_super_block(void)
 {
 	u_int32_t blk_size_bytes;
@@ -310,6 +337,14 @@ static int f2fs_prepare_super_block(void)
 
 	set_sb(segment_count_main, get_sb(section_count) * config.segs_per_sec);
 
+	/* Let's determine the best reserved and overprovisioned space */
+	if (config.overprovision == 0)
+		config.overprovision = get_best_overprovision();
+
+	config.reserved_segments =
+			(2 * (100 / config.overprovision + 1) + 6)
+			* config.segs_per_sec;
+
 	if ((get_sb(segment_count_main) - 2) <
 					config.reserved_segments) {
 		MSG(1, "\tError: Device size is not sufficient for F2FS volume,\
@@ -497,6 +532,11 @@ static int f2fs_write_check_point_pack(void)
 	set_cp(overprov_segment_count, get_cp(overprov_segment_count) +
 			get_cp(rsvd_segment_count));
 
+	MSG(0, "Info: Overprovision ratio = %u%%\n", config.overprovision);
+	MSG(0, "Info: Overprovision segments = %u (GC reserved = %u)\n",
+					get_cp(overprov_segment_count),
+					config.reserved_segments);
+
 	/* main segments - reserved segments - (node + data segments) */
 	set_cp(free_segment_count, get_sb(segment_count_main) - 6);
 	set_cp(user_block_count, ((get_cp(free_segment_count) + 6 -
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 5a9e7e2..fc612d8 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -56,7 +56,6 @@ static void f2fs_show_info()
 
 	if (config.vol_label)
 		MSG(0, "Info: Label = %s\n", config.vol_label);
-	MSG(0, "Info: Overprovision ratio = %u%%\n", config.overprovision);
 	MSG(0, "Info: Segments per section = %d\n", config.segs_per_sec);
 	MSG(0, "Info: Sections per zone = %d\n", config.secs_per_zone);
 	MSG(0, "Info: Trim is %s\n", config.trim ? "enabled": "disabled");
@@ -134,10 +133,6 @@ static void f2fs_parse_options(int argc, char *argv[])
 				config.total_sectors,
 				config.total_sectors * 512);
 	}
-
-	config.reserved_segments  =
-			(2 * (100 / config.overprovision + 1) + 6)
-			* config.segs_per_sec;
 	config.segs_per_zone = config.segs_per_sec * config.secs_per_zone;
 }
 
-- 
2.1.1


------------------------------------------------------------------------------

  reply	other threads:[~2015-08-11  1:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-11  1:23 [PATCH 1/3] mkfs.f2fs: fix wrong documentation Jaegeuk Kim
2015-08-11  1:23 ` Jaegeuk Kim [this message]
2015-08-11  1:23 ` [PATCH 3/3] mkfs.f2fs: don't need to limit MIN_VOLUME SIZE Jaegeuk Kim

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=1439256228-8982-2-git-send-email-jaegeuk@kernel.org \
    --to=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /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).