Skip to contentSkip to conversation

f2fs: fix max open zone constraints

PATCH In review Wenjie Qi 2 participants 4 messages Jan 16, 2024 – Jan 17, 2024 F2FS file system

lore
Share & tools
lore

Wenjie Qi

author
#0 lore raw

PATCH 1/1 f2fs: fix max open zone constraints

We can get the number of remaining available zone resources by subtracting the number of active logs from the number of max active zones of zoned devices. We can use these available zone resources to reduce the number of pending bio when switching zones.
If max active zones is 0, there is no limit.

---
 fs/f2fs/data.c  | 32 +++++++++++++++++++++++++-------
 fs/f2fs/f2fs.h  |  2 ++
 fs/f2fs/super.c | 11 +++++++++++
 3 files changed, 38 insertions(+), 7 deletions(-)
fs/f2fs/data.c +25 -7
index dce8defdf4c7..0b62ca296074 100644
@@ -392,6 +392,19 @@ static void f2fs_zone_write_end_io(struct bio *bio)
 	complete(&io->zone_wait);
 	f2fs_write_end_io(bio);
 }
+
+static void f2fs_zone_write_end_io_nowait(struct bio *bio)
+{
+#ifdef CONFIG_F2FS_IOSTAT
+	struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
+	struct f2fs_sb_info *sbi = iostat_ctx->sbi;
+#else
+	struct f2fs_sb_info *sbi = (struct f2fs_sb_info *)bio->bi_private;
+#endif
+
+	atomic_inc(&sbi->available_active_zones);
+	f2fs_write_end_io(bio);
+}
 #endif
 
 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
@@ -1085,14 +1098,19 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
 		goto next;
 out:
 #ifdef CONFIG_BLK_DEV_ZONED
-	if (f2fs_sb_has_blkzoned(sbi) && btype < META &&
+	if (f2fs_sb_has_blkzoned(sbi) && sbi->max_active_zones && btype < META &&
 			is_end_zone_blkaddr(sbi, fio->new_blkaddr)) {
-		bio_get(io->bio);
-		reinit_completion(&io->zone_wait);
-		io->bi_private = io->bio->bi_private;
-		io->bio->bi_private = io;
-		io->bio->bi_end_io = f2fs_zone_write_end_io;
-		io->zone_pending_bio = io->bio;
+		if (!atomic_add_negative(-1, &sbi->available_active_zones)) {
+			io->bio->bi_end_io = f2fs_zone_write_end_io_nowait;
+		} else {
+			atomic_inc(&sbi->available_active_zones);
+			bio_get(io->bio);
+			reinit_completion(&io->zone_wait);
+			io->bi_private = io->bio->bi_private;
+			io->bio->bi_private = io;
+			io->bio->bi_end_io = f2fs_zone_write_end_io;
+			io->zone_pending_bio = io->bio;
+		}
 		__submit_merged_bio(io);
 	}
 #endif
fs/f2fs/f2fs.h +2 -0
index 65294e3b0bef..2aade367ac66 100644
@@ -1551,6 +1551,8 @@ struct f2fs_sb_info {
 
 #ifdef CONFIG_BLK_DEV_ZONED
 	unsigned int blocks_per_blkz;		/* F2FS blocks per zone */
+	unsigned int max_active_zones;		/* max zone resources of the zoned device */
+	atomic_t available_active_zones;	/* remaining zone resources for zone switch */
 #endif
 
 	/* for node-related operations */
fs/f2fs/super.c +11 -0
index 206d03c82d96..6711283ff187 100644
@@ -2385,6 +2385,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 	if (err)
 		goto restore_opts;
 
+#ifdef CONFIG_BLK_DEV_ZONED
+	if (sbi->max_active_zones)
+		atomic_set(&sbi->available_active_zones,
+				sbi->max_active_zones - F2FS_OPTION(sbi).active_logs);
+#endif
+
 	/* flush outstanding errors before changing fs state */
 	flush_work(&sbi->s_error_work);
 
@@ -3932,6 +3938,11 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
 	if (!f2fs_sb_has_blkzoned(sbi))
 		return 0;
 
+	sbi->max_active_zones = bdev_max_active_zones(bdev);
+	if (sbi->max_active_zones)
+		atomic_set(&sbi->available_active_zones,
+				sbi->max_active_zones - F2FS_OPTION(sbi).active_logs);
+
 	zone_sectors = bdev_zone_sectors(bdev);
 	if (!is_power_of_2(zone_sectors)) {
 		f2fs_err(sbi, "F2FS does not support non power of 2 zone sizes\n");
Signature · 1 line
2.34.1
#1 lore raw
Quoted 27 lines · Wenjie Qi

We can get the number of remaining available zone resources by subtracting the number of active logs from the number of max active zones of zoned devices. We can use these available zone resources to reduce the number of pending bio when switching zones.
If max active zones is 0, there is no limit.

---
 fs/f2fs/data.c  | 32 +++++++++++++++++++++++++-------
 fs/f2fs/f2fs.h  |  2 ++
 fs/f2fs/super.c | 11 +++++++++++
 3 files changed, 38 insertions(+), 7 deletions(-)
fs/f2fs/data.c +4 -0
index dce8defdf4c7..0b62ca296074 100644
@@ -392,6 +392,19 @@ static void f2fs_zone_write_end_io(struct bio *bio)
        complete(&io->zone_wait);
        f2fs_write_end_io(bio);
 }
+
+static void f2fs_zone_write_end_io_nowait(struct bio *bio)
+{
+#ifdef CONFIG_F2FS_IOSTAT

fs/f2fs/data.c static void f2fs_zone_write_end_io(struct bio *bio) · line 408

Quoted 10 lines
fs/f2fs/data.c +9 -0
+       struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
+       struct f2fs_sb_info *sbi = iostat_ctx->sbi;
+#else
+       struct f2fs_sb_info *sbi = (struct f2fs_sb_info *)bio->bi_private;
+#endif
+
+       atomic_inc(&sbi->available_active_zones);
+       f2fs_write_end_io(bio);
+}
 #endif

I don't think this works. Let's assume we start with 2 available_active_zones and 4 active logs.
How about 4 active logs reach at the end of the zones at the same time?

Quoted 60 lines
fs/f2fs/data.c +12 -7
 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
@@ -1085,14 +1098,19 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
                goto next;
 out:
 #ifdef CONFIG_BLK_DEV_ZONED
-       if (f2fs_sb_has_blkzoned(sbi) && btype < META &&
+       if (f2fs_sb_has_blkzoned(sbi) && sbi->max_active_zones && btype < META &&
                        is_end_zone_blkaddr(sbi, fio->new_blkaddr)) {
-               bio_get(io->bio);
-               reinit_completion(&io->zone_wait);
-               io->bi_private = io->bio->bi_private;
-               io->bio->bi_private = io;
-               io->bio->bi_end_io = f2fs_zone_write_end_io;
-               io->zone_pending_bio = io->bio;
+               if (!atomic_add_negative(-1, &sbi->available_active_zones)) {
+                       io->bio->bi_end_io = f2fs_zone_write_end_io_nowait;
+               } else {
+                       atomic_inc(&sbi->available_active_zones);
+                       bio_get(io->bio);
+                       reinit_completion(&io->zone_wait);
+                       io->bi_private = io->bio->bi_private;
+                       io->bio->bi_private = io;
+                       io->bio->bi_end_io = f2fs_zone_write_end_io;
+                       io->zone_pending_bio = io->bio;
+               }
                __submit_merged_bio(io);
        }
 #endif
fs/f2fs/f2fs.h +2 -0
index 65294e3b0bef..2aade367ac66 100644
@@ -1551,6 +1551,8 @@ struct f2fs_sb_info {
 
 #ifdef CONFIG_BLK_DEV_ZONED
        unsigned int blocks_per_blkz;           /* F2FS blocks per zone */
+       unsigned int max_active_zones;          /* max zone resources of the zoned device */
+       atomic_t available_active_zones;        /* remaining zone resources for zone switch */
 #endif
 
        /* for node-related operations */
fs/f2fs/super.c +6 -0
index 206d03c82d96..6711283ff187 100644
@@ -2385,6 +2385,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
        if (err)
                goto restore_opts;
 
+#ifdef CONFIG_BLK_DEV_ZONED
+       if (sbi->max_active_zones)
+               atomic_set(&sbi->available_active_zones,
+                               sbi->max_active_zones - F2FS_OPTION(sbi).active_logs);
+#endif
+
        /* flush outstanding errors before changing fs state */
        flush_work(&sbi->s_error_work);
 

fs/f2fs/super.c static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · line 3945

Quoted 8 lines
fs/f2fs/super.c +5 -0
@@ -3932,6 +3938,11 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
        if (!f2fs_sb_has_blkzoned(sbi))
                return 0;
 
+       sbi->max_active_zones = bdev_max_active_zones(bdev);
+       if (sbi->max_active_zones)
+               atomic_set(&sbi->available_active_zones,
+                               sbi->max_active_zones - F2FS_OPTION(sbi).active_logs);
+

Need to make available_active_zones not be negative, right? Hmm, need to make sure active_logs should be equal or less than max_active_zones.

Quoted 12 lines
fs/f2fs/super.c +0 -1
        zone_sectors = bdev_zone_sectors(bdev);
        if (!is_power_of_2(zone_sectors)) {
                f2fs_err(sbi, "F2FS does not support non power of 2 zone sizes\n");
--

2.34.1

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

#2 lore raw
Quoted 35 lines · Daeho Jeong
Quoted 33 lines · Wenjie Qi

We can get the number of remaining available zone resources by subtracting the number of active logs from the number of max active zones of zoned devices. We can use these available zone resources to reduce the number of pending bio when switching zones.
If max active zones is 0, there is no limit.

---
 fs/f2fs/data.c  | 32 +++++++++++++++++++++++++-------
 fs/f2fs/f2fs.h  |  2 ++
 fs/f2fs/super.c | 11 +++++++++++
 3 files changed, 38 insertions(+), 7 deletions(-)
fs/f2fs/data.c +10 -0
index dce8defdf4c7..0b62ca296074 100644
@@ -392,6 +392,19 @@ static void f2fs_zone_write_end_io(struct bio *bio)
        complete(&io->zone_wait);
        f2fs_write_end_io(bio);
 }
+
+static void f2fs_zone_write_end_io_nowait(struct bio *bio)
+{
+#ifdef CONFIG_F2FS_IOSTAT
+       struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
+       struct f2fs_sb_info *sbi = iostat_ctx->sbi;
+#else
+       struct f2fs_sb_info *sbi = (struct f2fs_sb_info *)bio->bi_private;
+#endif
+
Quoted 8 lines

fs/f2fs/data.c static void f2fs_zone_write_end_io(struct bio *bio) · line 408

Quoted 4 lines
fs/f2fs/data.c +3 -0
+       atomic_inc(&sbi->available_active_zones);
+       f2fs_write_end_io(bio);
+}
 #endif

I don't think this works. Let's assume we start with 2 available_active_zones and 4 active logs.
How about 4 active logs reach at the end of the zones at the same time?

Sorry, I was confused. It would work. However, it might be a little clumsy. How about using a data structure like a counting semaphore?
We can decrease it as we open a zone and increase it as we close a zone.

Quoted 86 lines
Quoted 61 lines
fs/f2fs/data.c +12 -7
 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
@@ -1085,14 +1098,19 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
                goto next;
 out:
 #ifdef CONFIG_BLK_DEV_ZONED
-       if (f2fs_sb_has_blkzoned(sbi) && btype < META &&
+       if (f2fs_sb_has_blkzoned(sbi) && sbi->max_active_zones && btype < META &&
                        is_end_zone_blkaddr(sbi, fio->new_blkaddr)) {
-               bio_get(io->bio);
-               reinit_completion(&io->zone_wait);
-               io->bi_private = io->bio->bi_private;
-               io->bio->bi_private = io;
-               io->bio->bi_end_io = f2fs_zone_write_end_io;
-               io->zone_pending_bio = io->bio;
+               if (!atomic_add_negative(-1, &sbi->available_active_zones)) {
+                       io->bio->bi_end_io = f2fs_zone_write_end_io_nowait;
+               } else {
+                       atomic_inc(&sbi->available_active_zones);
+                       bio_get(io->bio);
+                       reinit_completion(&io->zone_wait);
+                       io->bi_private = io->bio->bi_private;
+                       io->bio->bi_private = io;
+                       io->bio->bi_end_io = f2fs_zone_write_end_io;
+                       io->zone_pending_bio = io->bio;
+               }
                __submit_merged_bio(io);
        }
 #endif
fs/f2fs/f2fs.h +2 -0
index 65294e3b0bef..2aade367ac66 100644
@@ -1551,6 +1551,8 @@ struct f2fs_sb_info {
 
 #ifdef CONFIG_BLK_DEV_ZONED
        unsigned int blocks_per_blkz;           /* F2FS blocks per zone */
+       unsigned int max_active_zones;          /* max zone resources of the zoned device */
+       atomic_t available_active_zones;        /* remaining zone resources for zone switch */
 #endif
 
        /* for node-related operations */
fs/f2fs/super.c +6 -0
index 206d03c82d96..6711283ff187 100644
@@ -2385,6 +2385,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
        if (err)
                goto restore_opts;
 
+#ifdef CONFIG_BLK_DEV_ZONED
+       if (sbi->max_active_zones)
+               atomic_set(&sbi->available_active_zones,
+                               sbi->max_active_zones - F2FS_OPTION(sbi).active_logs);
+#endif
+
        /* flush outstanding errors before changing fs state */
        flush_work(&sbi->s_error_work);
 

fs/f2fs/super.c static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · line 3945

Quoted 8 lines
fs/f2fs/super.c +5 -0
@@ -3932,6 +3938,11 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
        if (!f2fs_sb_has_blkzoned(sbi))
                return 0;
 
+       sbi->max_active_zones = bdev_max_active_zones(bdev);
+       if (sbi->max_active_zones)
+               atomic_set(&sbi->available_active_zones,
+                               sbi->max_active_zones - F2FS_OPTION(sbi).active_logs);
+

Need to make available_active_zones not be negative, right? Hmm, need to make sure active_logs should be equal or less than max_active_zones.

Quoted 12 lines
fs/f2fs/super.c +0 -1
        zone_sectors = bdev_zone_sectors(bdev);
        if (!is_power_of_2(zone_sectors)) {
                f2fs_err(sbi, "F2FS does not support non power of 2 zone sizes\n");
--

2.34.1

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

author
#3 lore raw

Do you mean we down the semaphore when we write the first block of the zone and up it when the last bio of the zone finishes? That seems a bit more concise.

Quoted 136 lines · Daeho Jeong
Quoted 35 lines · Daeho Jeong
Quoted 33 lines · Wenjie Qi

We can get the number of remaining available zone resources by subtracting the number of active logs from the number of max active zones of zoned devices. We can use these available zone resources to reduce the number of pending bio when switching zones.
If max active zones is 0, there is no limit.

---
 fs/f2fs/data.c  | 32 +++++++++++++++++++++++++-------
 fs/f2fs/f2fs.h  |  2 ++
 fs/f2fs/super.c | 11 +++++++++++
 3 files changed, 38 insertions(+), 7 deletions(-)
fs/f2fs/data.c +10 -0
index dce8defdf4c7..0b62ca296074 100644
@@ -392,6 +392,19 @@ static void f2fs_zone_write_end_io(struct bio *bio)
        complete(&io->zone_wait);
        f2fs_write_end_io(bio);
 }
+
+static void f2fs_zone_write_end_io_nowait(struct bio *bio)
+{
+#ifdef CONFIG_F2FS_IOSTAT
+       struct bio_iostat_ctx *iostat_ctx = bio->bi_private;
+       struct f2fs_sb_info *sbi = iostat_ctx->sbi;
+#else
+       struct f2fs_sb_info *sbi = (struct f2fs_sb_info *)bio->bi_private;
+#endif
+
Quoted 8 lines

fs/f2fs/data.c static void f2fs_zone_write_end_io(struct bio *bio) · line 408

Quoted 4 lines
fs/f2fs/data.c +3 -0
+       atomic_inc(&sbi->available_active_zones);
+       f2fs_write_end_io(bio);
+}
 #endif

I don't think this works. Let's assume we start with 2 available_active_zones and 4 active logs.
How about 4 active logs reach at the end of the zones at the same time?

Sorry, I was confused. It would work. However, it might be a little clumsy. How about using a data structure like a counting semaphore?
We can decrease it as we open a zone and increase it as we close a zone.

Quoted 86 lines
Quoted 61 lines
fs/f2fs/data.c +12 -7
 struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
@@ -1085,14 +1098,19 @@ void f2fs_submit_page_write(struct f2fs_io_info *fio)
                goto next;
 out:
 #ifdef CONFIG_BLK_DEV_ZONED
-       if (f2fs_sb_has_blkzoned(sbi) && btype < META &&
+       if (f2fs_sb_has_blkzoned(sbi) && sbi->max_active_zones && btype < META &&
                        is_end_zone_blkaddr(sbi, fio->new_blkaddr)) {
-               bio_get(io->bio);
-               reinit_completion(&io->zone_wait);
-               io->bi_private = io->bio->bi_private;
-               io->bio->bi_private = io;
-               io->bio->bi_end_io = f2fs_zone_write_end_io;
-               io->zone_pending_bio = io->bio;
+               if (!atomic_add_negative(-1, &sbi->available_active_zones)) {
+                       io->bio->bi_end_io = f2fs_zone_write_end_io_nowait;
+               } else {
+                       atomic_inc(&sbi->available_active_zones);
+                       bio_get(io->bio);
+                       reinit_completion(&io->zone_wait);
+                       io->bi_private = io->bio->bi_private;
+                       io->bio->bi_private = io;
+                       io->bio->bi_end_io = f2fs_zone_write_end_io;
+                       io->zone_pending_bio = io->bio;
+               }
                __submit_merged_bio(io);
        }
 #endif
fs/f2fs/f2fs.h +2 -0
index 65294e3b0bef..2aade367ac66 100644
@@ -1551,6 +1551,8 @@ struct f2fs_sb_info {
 
 #ifdef CONFIG_BLK_DEV_ZONED
        unsigned int blocks_per_blkz;           /* F2FS blocks per zone */
+       unsigned int max_active_zones;          /* max zone resources of the zoned device */
+       atomic_t available_active_zones;        /* remaining zone resources for zone switch */
 #endif
 
        /* for node-related operations */
fs/f2fs/super.c +6 -0
index 206d03c82d96..6711283ff187 100644
@@ -2385,6 +2385,12 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
        if (err)
                goto restore_opts;
 
+#ifdef CONFIG_BLK_DEV_ZONED
+       if (sbi->max_active_zones)
+               atomic_set(&sbi->available_active_zones,
+                               sbi->max_active_zones - F2FS_OPTION(sbi).active_logs);
+#endif
+
        /* flush outstanding errors before changing fs state */
        flush_work(&sbi->s_error_work);
 

fs/f2fs/super.c static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · line 3945

Quoted 8 lines
fs/f2fs/super.c +5 -0
@@ -3932,6 +3938,11 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
        if (!f2fs_sb_has_blkzoned(sbi))
                return 0;
 
+       sbi->max_active_zones = bdev_max_active_zones(bdev);
+       if (sbi->max_active_zones)
+               atomic_set(&sbi->available_active_zones,
+                               sbi->max_active_zones - F2FS_OPTION(sbi).active_logs);
+

Need to make available_active_zones not be negative, right? Hmm, need to make sure active_logs should be equal or less than max_active_zones.

Quoted 12 lines
fs/f2fs/super.c +0 -1
        zone_sectors = bdev_zone_sectors(bdev);
        if (!is_power_of_2(zone_sectors)) {
                f2fs_err(sbi, "F2FS does not support non power of 2 zone sizes\n");
--

2.34.1

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