f2fs-tools: prefer physical over logical block size
PATCH 1/1 f2fs-tools: prefer physical over logical block size
Some drives operate in "512e" configuration with their logical block size set to 512 bytes for legacy compatibility reasons while providing a more optimal 4096 byte value as the physical block size.
Since the physical block size is the smallest unit a physical storage device can write atomically, prefer it over the logical block size.
--- lib/libf2fs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
lib/libf2fs.c +7 -2
@@ -933,10 +933,15 @@ void get_kernel_uname_version(__u8 *version)#define BLKSSZGET _IO(0x12,104)#endif +#if defined(__linux__) && defined(_IO) && !defined(BLKPBSZGET ) +#define BLKPBSZGET _IO(0x12,123) +#endif +#if defined(__APPLE__)#include <sys/disk.h> #define BLKGETSIZE DKIOCGETBLOCKCOUNT#define BLKSSZGET DKIOCGETBLOCKCOUNT +#define BLKPBSZGET DKIOCGETBLOCKCOUNT#endif /* APPLE_DARWIN */ #ifndef _WIN32
@@ -1050,8 +1055,8 @@ int get_device_info(int i) }else if (S_ISREG (stat_buf->st_mode)) { dev->total_sectors = stat_buf->st_size / dev->sector_size; }else if (S_ISBLK (stat_buf->st_mode)) { -#ifdef BLKSSZGET -if (ioctl (fd,BLKSSZGET , §or_size) <0 ) +#if defined(BLKPBSZGET ) && defined(BLKSSZGET ) +if ((ioctl (fd,BLKPBSZGET , §or_size) <0 ) && (ioctl (fd,BLKSSZGET , §or_size) <0 ))MSG (0 ,"\tError: Using the default sector size\n" );else if (dev->sector_size < sector_size) dev->sector_size = sector_size;
Signature · 8 lines
2.49.0 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 8 lines · On 4/25/25 09:36, nl6720 via Linux-f2fs-devel wrote:
Some drives operate in "512e" configuration with their logical block size set to 512 bytes for legacy compatibility reasons while providing a more optimal 4096 byte value as the physical block size.
Since the physical block size is the smallest unit a physical storage device can write atomically, prefer it over the logical block size.
f2fs uses PAGE_SIZE as block size, commonly it's 4096 rather than 512?
Thanks,
Quoted 27 lines
Signed-off-by nl6720 <[email protected]>--- lib/libf2fs.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)lib/libf2fs.c +5
-0@@ -933,10 +933,15 @@ void get_kernel_uname_version(__u8 *version)#define BLKSSZGET _IO(0x12,104)#endif +#if defined(__linux__) && defined(_IO) && !defined(BLKPBSZGET ) +#define BLKPBSZGET _IO(0x12,123) +#endif +#if defined(__APPLE__)#include <sys/disk.h> #define BLKGETSIZE DKIOCGETBLOCKCOUNT#define BLKSSZGET DKIOCGETBLOCKCOUNT +#define BLKPBSZGET DKIOCGETBLOCKCOUNT#endif /* APPLE_DARWIN */ #ifndef _WIN32
lib/libf2fs.c int get_device_info(int i) · line 1062
Quoted 10 lines
lib/libf2fs.c +2
-2@@ -1050,8 +1055,8 @@ int get_device_info(int i) }else if (S_ISREG (stat_buf->st_mode)) { dev->total_sectors = stat_buf->st_size / dev->sector_size; }else if (S_ISBLK (stat_buf->st_mode)) { -#ifdef BLKSSZGET -if (ioctl (fd,BLKSSZGET , §or_size) <0 ) +#if defined(BLKPBSZGET ) && defined(BLKSSZGET ) +if ((ioctl (fd,BLKPBSZGET , §or_size) <0 ) && (ioctl (fd,BLKSSZGET , §or_size) <0 ))MSG (0 ,"\tError: Using the default sector size\n" );else if (dev->sector_size < sector_size) dev->sector_size = sector_size;
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 11 lines · On Sunday, 27 April 2025 11:45:59 EEST Chao Yu wrote:
Quoted 8 lines · On 4/25/25 09:36, nl6720 via Linux-f2fs-devel wrote:
Some drives operate in "512e" configuration with their logical block size set to 512 bytes for legacy compatibility reasons while providing a more optimal 4096 byte value as the physical block size.
Since the physical block size is the smallest unit a physical storage device can write atomically, prefer it over the logical block size.
f2fs uses
PAGE_SIZEas block size, commonly it's 4096 rather than 512?
The thing mkfs.f2fs calls "sector size" in its output is 512 on 512e drives instead of 4096.
E.g.:
F2FS-tools: mkfs.f2fs Ver: 1.16.0 (2023-04-11)
Info: Disable heap-based policy
Info: Debug level = 0
Info: Trim is enabled
Info: [/dev/disk/by-partlabel/512e] Disk Model: QEMU HARDDISK
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 124997632 (61034 MB)
Info: zone aligned segment0 blkaddr: 512
Info: format version with
"Linux version 6.13.8-arch1-1 (linux@archlinux) (gcc (GCC) 14.2.1 20250207, GNU ld (GNU Binutils) 2.44) #1 SMP PREEMPT_DYNAMIC Sun, 23 Mar 2025 17:17:30 +0000"
Info: [/dev/disk/by-partlabel/512e] Discarding device
Info: This device doesn't support BLKSECDISCARD
Info: Discarded 61034 MB
Info: Overprovision ratio = 0.590%
Info: Overprovision segments = 179 (GC reserved = 176)
Info: format successful
nl6720
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 9 lines · On 4/27/25 17:30, nl6720 wrote:
Quoted 8 lines · On Sunday, 27 April 2025 11:45:59 EEST Chao Yu wrote:
Quoted 7 lines · On 4/25/25 09:36, nl6720 via Linux-f2fs-devel wrote:
Some drives operate in "512e" configuration with their logical block size set to 512 bytes for legacy compatibility reasons while providing a more optimal 4096 byte value as the physical block size.
Since the physical block size is the smallest unit a physical storage device can write atomically, prefer it over the logical block size.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
f2fs uses
PAGE_SIZEas block size, commonly it's 4096 rather than 512?The thing mkfs.f2fs calls "sector size" in its output is 512 on 512e drives instead of 4096.
How about printing block size of f2fs as below:
output of mkfs.f2fs:
Info: sector size = 512
Info: total sectors = 16777216 (8192 MB)
Info: block size = 4096
Thanks,
Quoted 23 lines
E.g.:
F2FS-tools: mkfs.f2fs Ver: 1.16.0 (2023-04-11)Info: Disable heap-based policy
Info: Debug level = 0
Info: Trim is enabled
Info: [/dev/disk/by-partlabel/512e] Disk Model: QEMU HARDDISK
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 124997632 (61034 MB)
Info: zone aligned segment0 blkaddr: 512
Info: format version with
"Linux version 6.13.8-arch1-1 (linux@archlinux) (gcc (GCC) 14.2.1 20250207, GNU ld (GNU Binutils) 2.44) #1 SMPPREEMPT_DYNAMICSun, 23 Mar 2025 17:17:30 +0000"
Info: [/dev/disk/by-partlabel/512e] Discarding device
Info: This device doesn't support BLKSECDISCARD
Info: Discarded 61034 MB
Info: Overprovision ratio = 0.590%
Info: Overprovision segments = 179 (GC reserved = 176)
Info: format successful
Quoted 3 lines
nl6720
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Quoted 7 lines · On Monday, 28 April 2025 10:33:18 EEST Chao Yu wrote:
How about printing block size of f2fs as below:
output of mkfs.f2fs:
Info: sector size = 512
Info: total sectors = 16777216 (8192 MB)
Info: block size = 4096
mkfs.f2fs printing it would be nice.
I'm still confused by the "sector size" in mkfs.f2fs output. Is it simply the drive's logical sector size and not a fundamental part of the file system like with xfs?
nl6720
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel