Skip to contentSkip to conversation

Revert "f2fs-tools: do not support user-space cache"

PATCH In review Jaegeuk Kim 2 participants 4 messages Oct 16, 2023 – Nov 15, 2023 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Revert "f2fs-tools: do not support user-space cache"

This reverts commit 2835107ae3908576b41ff5f6a4e63ba7ec9a6246.

There's a report that the impact was true.

---
 fsck/main.c       |  18 ++-
 include/f2fs_fs.h |  18 +++
 lib/libf2fs_io.c  | 329 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 363 insertions(+), 2 deletions(-)
fsck/main.c +16 -2
index 2100394b144c..6d48d404d83c 100644
@@ -10,6 +10,9 @@
  *   Liu Shuoran <[email protected]>
  *   Jaegeuk Kim <[email protected]>
  *  : add sload.f2fs
+ * Copyright (c) 2019 Google Inc.
+ *   Robin Hsu <[email protected]>
+ *  : add cache layer
  * Copyright (c) 2020 Google Inc.
  *   Robin Hsu <[email protected]>
  *  : add sload compression support
@@ -23,6 +26,7 @@
 #include <ctype.h>
 #include <time.h>
 #include <getopt.h>
+#include <stdbool.h>
 #include "quotaio.h"
 #include "compress.h"
 
@@ -55,6 +59,10 @@ void fsck_usage()
 	MSG(0, "\nUsage: fsck.f2fs [options] device\n");
 	MSG(0, "[options]:\n");
 	MSG(0, "  -a check/fix potential corruption, reported by f2fs\n");
+	MSG(0, "  -c <num-cache-entry>  set number of cache entries"
+			" (default 0)\n");
+	MSG(0, "  -m <max-hash-collision>  set max cache hash collision"
+			" (default 16)\n");
 	MSG(0, "  -C encoding[:flag1,flag2] Set options for enabling"
 			" casefolding\n");
 	MSG(0, "  -d debug level [default:0]\n");
@@ -72,6 +80,7 @@ void fsck_usage()
 	MSG(0, "  --dry-run do not really fix corruptions\n");
 	MSG(0, "  --no-kernel-check skips detecting kernel change\n");
 	MSG(0, "  --kernel-check checks kernel change\n");
+	MSG(0, "  --debug-cache to debug cache when -c is used\n");
 	exit(1);
 }
 
@@ -232,6 +241,8 @@ void f2fs_parse_options(int argc, char *argv[])
 		};
 
 		c.func = FSCK;
+		c.cache_config.max_hash_collision = 16;
+		c.cache_config.dbg_en = false;
 		while ((option = getopt_long(argc, argv, option_string,
 						long_opt, &opt)) != EOF) {
 			switch (option) {
@@ -248,15 +259,18 @@ void f2fs_parse_options(int argc, char *argv[])
 				MSG(0, "Info: Do Kernel Check\n");
 				break;
 			case 4:
-				MSG(0, "Info: Deprecated option \"debug-cache\"\n");
+				c.cache_config.dbg_en = true;
 				break;
 			case 'a':
 				c.auto_fix = 1;
 				MSG(0, "Info: Automatic fix mode enabled.\n");
 				break;
 			case 'c':
+				c.cache_config.num_cache_entry = atoi(optarg);
+				break;
 			case 'm':
-				MSG(0, "Info: Deprecated option \'%c\'\n", option);
+				c.cache_config.max_hash_collision =
+						atoi(optarg);
 				break;
 			case 'g':
 				if (!strcmp(optarg, "android")) {
include/f2fs_fs.h +18 -0
index 3c7451c833a2..772a6a59d47e 100644
@@ -3,6 +3,8 @@
  *
  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  *             http://www.samsung.com/
+ * Copyright (c) 2019 Google Inc.
+ *             http://www.google.com/
  * Copyright (c) 2020 Google Inc.
  *   Robin Hsu <[email protected]>
  *  : add sload compression support
@@ -450,6 +452,16 @@ struct device_info {
 	size_t *zone_cap_blocks;
 };
 
+typedef struct {
+	/* Value 0 means no cache, minimum 1024 */
+	long num_cache_entry;
+
+	/* Value 0 means always overwrite (no collision allowed). maximum 16 */
+	unsigned max_hash_collision;
+
+	bool dbg_en;
+} dev_cache_config_t;
+
 /* f2fs_configration for compression used for sload.f2fs */
 typedef struct  {
 	void (*init)(struct compress_ctx *cc);
@@ -1533,6 +1545,9 @@ struct f2fs_configuration {
 	/* precomputed fs UUID checksum for seeding other checksums */
 	uint32_t chksum_seed;
 
+	/* cache parameters */
+	dev_cache_config_t cache_config;
+
 	/* compression support for sload.f2fs */
 	compress_config_t compress;
 
@@ -1584,6 +1599,9 @@ extern void f2fs_release_sparse_resource(void);
 extern int f2fs_finalize_device(void);
 extern int f2fs_fsync_device(void);
 
+extern void dcache_init(void);
+extern void dcache_release(void);
+
 extern int dev_read(void *, __u64, size_t);
 #ifdef POSIX_FADV_WILLNEED
 extern int dev_readahead(__u64, size_t);
lib/libf2fs_io.c +329 -0

365 lines not on this page · raw message

Signature · 8 lines
2.42.0.655.g421f12c284-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw

PATCH 2/2 fsck.f2fs: fix cache offset for multiple partitions

The cache offset should have been considered multiple partitions per fd. Let's fix.

---
 lib/libf2fs_io.c | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)
lib/libf2fs_io.c +25 -20
index 74e5f3ac49ba..39d377777259 100644
@@ -246,7 +246,7 @@ static inline long dcache_relocate(long entry, int n)
 			dcache_config.num_cache_entry;
 }
 
-static long dcache_find(off_t blk)
+static long dcache_find(__u64 blk)
 {
 	register long n = dcache_config.num_cache_entry;
 	register unsigned m = dcache_config.max_hash_collision;
@@ -267,8 +267,13 @@ static long dcache_find(off_t blk)
 }
 
 /* Physical read into cache */
-static int dcache_io_read(int fd, long entry, off_t offset, off_t blk)
+static int dcache_io_read(long entry, __u64 offset, off_t blk)
 {
+	int fd = __get_device_fd(&offset);
+
+	if (fd < 0)
+		return fd;
+
 	if (lseek(fd, offset, SEEK_SET) < 0) {
 		MSG(0, "\n lseek fail.\n");
 		return -1;
@@ -297,12 +302,11 @@ static int dcache_io_read(int fd, long entry, off_t offset, off_t blk)
  *       1: cache not available (uninitialized)
  *      -1: error
  */
-static int dcache_update_rw(int fd, void *buf, off_t offset,
+static int dcache_update_rw(void *buf, __u64 offset,
 		size_t byte_count, bool is_write)
 {
-	off_t blk;
+	__u64 blk, start;
 	int addr_in_blk;
-	off_t start;
 
 	if (!dcache_initialized)
 		dcache_init(); /* auto initialize */
@@ -337,7 +341,7 @@ static int dcache_update_rw(int fd, void *buf, off_t offset,
 				if (dcache_valid[entry])
 					++dcache_rreplace;
 				/* read: physical I/O read into cache */
-				err = dcache_io_read(fd, entry, start, blk);
+				err = dcache_io_read(entry, start, blk);
 				if (err)
 					return err;
 			}
@@ -366,15 +370,15 @@ static int dcache_update_rw(int fd, void *buf, off_t offset,
  * return value: 1: cache not available
  *               0: success, -1: I/O error
  */
-int dcache_update_cache(int fd, void *buf, off_t offset, size_t count)
+int dcache_update_cache(void *buf, __u64 offset, size_t count)
 {
-	return dcache_update_rw(fd, buf, offset, count, true);
+	return dcache_update_rw(buf, offset, count, true);
 }
 
 /* handles read into cache + read into buffer  */
-int dcache_read(int fd, void *buf, off_t offset, size_t count)
+int dcache_read(void *buf, __u64 offset, size_t count)
 {
-	return dcache_update_rw(fd, buf, offset, count, false);
+	return dcache_update_rw(buf, offset, count, false);
 }
 
 /*
@@ -517,15 +521,15 @@ int dev_read(void *buf, __u64 offset, size_t len)
 		return sparse_read_blk(offset / F2FS_BLKSIZE,
 					len / F2FS_BLKSIZE, buf);
 
-	fd = __get_device_fd(&offset);
-	if (fd < 0)
-		return fd;
-
 	/* err = 1: cache not available, fall back to non-cache R/W */
 	/* err = 0: success, err=-1: I/O error */
-	err = dcache_read(fd, buf, (off_t)offset, len);
+	err = dcache_read(buf, offset, len);
 	if (err <= 0)
 		return err;
+
+	fd = __get_device_fd(&offset);
+	if (fd < 0)
+		return fd;
 	if (lseek(fd, (off_t)offset, SEEK_SET) < 0)
 		return -1;
 	if (read(fd, buf, len) < 0)
@@ -561,16 +565,17 @@ int dev_write(void *buf, __u64 offset, size_t len)
 		return sparse_write_blk(offset / F2FS_BLKSIZE,
 					len / F2FS_BLKSIZE, buf);
 
-	fd = __get_device_fd(&offset);
-	if (fd < 0)
-		return fd;
-
 	/*
 	 * dcache_update_cache() just update cache, won't do I/O.
 	 * Thus even no error, we need normal non-cache I/O for actual write
 	 */
-	if (dcache_update_cache(fd, buf, (off_t)offset, len) < 0)
+	if (dcache_update_cache(buf, offset, len) < 0)
 		return -1;
+
+	fd = __get_device_fd(&offset);
+	if (fd < 0)
+		return fd;
+
 	if (lseek(fd, (off_t)offset, SEEK_SET) < 0)
 		return -1;
 	if (write(fd, buf, len) < 0)
Signature · 8 lines
2.42.0.655.g421f12c284-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Reviewed-by on v1 2/2
#2 lore raw

Re: [f2fs-dev] [PATCH 2/2] fsck.f2fs: fix cache offset for multiple partitions

Quoted 4 lines · Jaegeuk Kim

The cache offset should have been considered multiple partitions per fd. Let's fix.

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reviewed-by on v1 1/2
#3 lore raw
In reply to Jaegeuk Kim
Quoted 5 lines · Jaegeuk Kim

This reverts commit 2835107ae3908576b41ff5f6a4e63ba7ec9a6246.

There's a report that the impact was true.

Sorry for delay reply, feel free to add:

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel