From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH] mkfs.f2fs: check zeros in first 16MB for Android
Date: Thu, 8 Aug 2019 16:11:08 -0700 [thread overview]
Message-ID: <20190808231108.75599-1-jaegeuk@kernel.org> (raw)
We actually don't need to issue trim on entire disk by checking first
blocks having zeros.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
mkfs/f2fs_format_utils.c | 47 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/mkfs/f2fs_format_utils.c b/mkfs/f2fs_format_utils.c
index 8bf128c..52fedc7 100644
--- a/mkfs/f2fs_format_utils.c
+++ b/mkfs/f2fs_format_utils.c
@@ -110,13 +110,56 @@ static int trim_device(int i)
return 0;
}
+static int f2fs_zero_blocks(int i)
+{
+#ifdef WITH_ANDROID
+ struct device_info *dev = c.devices + i;
+ int fd = dev->fd;
+ char buf[F2FS_BLKSIZE];
+ char *zero_buf;
+ int j, ret;
+ int ret2 = 0;
+
+ zero_buf = calloc(1, F2FS_BLKSIZE);
+ if (zero_buf == NULL) {
+ MSG(1, "\tError: Malloc Failed for zero buf!!!\n");
+ return -1;
+ }
+
+ /* check first 16MB blocks */
+ for (j = 0; j < 4096; j++) {
+ ret = lseek(fd, j * F2FS_BLKSIZE, SEEK_SET);
+ if (ret < 0) {
+ ret2 = -1;
+ break;
+ }
+ ret = read(fd, buf, F2FS_BLKSIZE);
+ if (ret != F2FS_BLKSIZE) {
+ ret2 = -1;
+ break;
+ }
+ if (memcmp(buf, zero_buf, F2FS_BLKSIZE)) {
+ ret2 = -1;
+ break;
+ }
+ }
+ free(zero_buf);
+ if (!ret2)
+ MSG(0, "Info: Skip discarding blocks (found all zeros\n");
+ return ret2;
+#else
+ return -1;
+#endif
+}
+
int f2fs_trim_devices(void)
{
int i;
- for (i = 0; i < c.ndevs; i++)
- if (trim_device(i))
+ for (i = 0; i < c.ndevs; i++) {
+ if (f2fs_zero_blocks(i) && trim_device(i))
return -1;
+ }
c.trimmed = 1;
return 0;
}
--
2.19.0.605.g01d371f741-goog
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next reply other threads:[~2019-08-08 23:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-08 23:11 Jaegeuk Kim [this message]
2019-08-09 15:12 ` [f2fs-dev] [PATCH v2] mkfs.f2fs: check zeros in first 16MB for Android Jaegeuk Kim
[not found] ` <CAD14+f2V=j8o=0sUGMgmJHmwKgm80WyzJC5yW7qmyffL=CBJhw@mail.gmail.com>
2019-08-09 15:39 ` Jaegeuk Kim
2019-08-12 3:26 ` Chao Yu
2019-08-12 2:19 ` Chao Yu
2019-08-15 22:21 ` Jaegeuk Kim
2019-08-16 1:00 ` Chao Yu
2019-08-16 1:02 ` Jaegeuk Kim
2019-08-16 1:23 ` Chao Yu
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=20190808231108.75599-1-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).