# Any experiences with F2FS compression?

## Antikapitalista

The partition can be formatted (without support for encryption) and mounted properly, using zstd compression, which is enabled in the kernel; everything seemingly works, the compression attribute can be set and is correctly inherited,etc., but there are no noticeable space savings; I have tested it with plain text files as well as object code files.

So far, f2fs compression seems like snake oil to me.

What are your experiences with it?

----------

## BruceG

I have been trying to test out F2FS but I am hitting the same problem you are. The FS was created with the compression options, the kernel is built with compression support, it is mounted with compression enabled, it is set to compress everything, and yet no compression is happening.

```

# zgrep F2FS /proc/config.gz

CONFIG_F2FS_FS=m

CONFIG_F2FS_STAT_FS=y

CONFIG_F2FS_FS_XATTR=y

CONFIG_F2FS_FS_POSIX_ACL=y

CONFIG_F2FS_FS_SECURITY=y

# CONFIG_F2FS_CHECK_FS is not set

# CONFIG_F2FS_IO_TRACE is not set

# CONFIG_F2FS_FAULT_INJECTION is not set

CONFIG_F2FS_FS_COMPRESSION=y

CONFIG_F2FS_FS_LZO=y

CONFIG_F2FS_FS_LZ4=y

CONFIG_F2FS_FS_ZSTD=y

CONFIG_F2FS_FS_LZORLE=y

# mkfs.f2fs -O inode_checksum,compression,sb_checksum,extra_attr,encrypt -f /dev/vg/testf2fs 

   F2FS-tools: mkfs.f2fs Ver: 1.14.0 (2020-08-24)

Info: Disable heap-based policy

Info: Debug level = 0

Info: Trim is enabled

Info: [/dev/vg/testf2fs] Disk Model: Samsung SSD 860 

Info: Segments per section = 1

Info: Sections per zone = 1

Info: sector size = 512

Info: total sectors = 33554432 (16384 MB)

Info: zone aligned segment0 blkaddr: 512

Info: format version with

  "Linux version 5.10.10 (portage@localhost) (x86_64-pc-linux-gnu-gcc (Gentoo 9.3.0-r2 p4) 9.3.0, GNU ld (Gentoo 2.34 p6) 2.34.0) #1 SMP Sun Jan 24 14:00:53 CST 2021"

Info: [/dev/vg/testf2fs] Discarding device

Info: This device doesn't support BLKSECDISCARD

Info: Discarded 16384 MB

Info: Overprovision ratio = 1.570%

Info: Overprovision segments = 260 (GC reserved = 135)

Info: format successful

# mount -o compress_algorithm=zstd,compress_extension=\* /dev/vg/testf2fs /mnt/test

# dd if=/dev/zero of=/mnt/test/dummy bs=1024k count=8000

8000+0 records in

8000+0 records out

8388608000 bytes (8.4 GB, 7.8 GiB) copied, 3.82504 s, 2.2 GB/s

# sync

# df -h /mnt/test

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/vg-testf2fs   16G  8.5G  7.6G  53% /mnt/test

```

----------

## molletts

I played with it over Christmas to see if I could use it to squeeze a bootable-on-most-PCs diagnostic installation onto a barely-large-enough USB flash drive after my old one wore out and had the same result. In the end, I decided it was time to buy a big, fast new drive anyway as my main USB drive is getting a bit elderly and this was the excuse I had been waiting for!

I'd probably have another go at it if I could figure out how to get compression to work, just for the satisfaction of doing it.

----------

## holdengreen

I'm attempting to do a fresh install with a zstd compressed f2fs partition as root.

To format (no issues as far as I can tell):

- 'mkfs.f2fs -l rootfs -O extra_attr,inode_checksum,sb_checksum,compression /dev/sda4 -f'

some output:

'Info: [/dev/sda4] Discarding device'

'Info: This device doesn't support BLKSECDISCARD'

'Info: Discarded 97607'

'Info: format successful'

I mount with:

- 'mount -o compress_algorithm=zstd(or any other) /dev/sda4 /mnt/root0'

'dmesg' gives me this:

'F2FS-fs (sda4): compression options not supported'

So I think it doesn't work.

----------

## Marlo

 *holdengreen wrote:*   

> 
> 
> So I think it doesn't work.

 

It works:

```

tux ~ # mkfs.f2fs -f -l test -O extra_attr,inode_checksum,sb_checksum,compression,encrypt  /dev/sda5 

        F2FS-tools: mkfs.f2fs Ver: 1.14.0 (2020-08-24)

Info: Disable heap-based policy

Info: Debug level = 0

Info: Label = test

Info: Trim is enabled

Info: [/dev/sda5] Disk Model: Samsung SSD 860 

Info: Segments per section = 1

Info: Sections per zone = 1

Info: sector size = 512

Info: total sectors = 137873408 (67321 MB)

Info: zone aligned segment0 blkaddr: 512

Info: format version with

  "Linux version 5.14.9-gentoo-97-kspp-lock (root@tux) (gcc (Gentoo Hardened 11.2.0 p1) 11.2.0, GNU ld (Gentoo 2.37_p1 p0) 2.37) #1 SMP Fri Oct 1 23:56:48 CEST 2021"

Info: [/dev/sda5] Discarding device

Info: This device doesn't support BLKSECDISCARD

Info: Discarded 67321 MB

Info: Overprovision ratio = 0.770%

Info: Overprovision segments = 522 (GC reserved = 267)

Info: format successful

```

```

tux /mnt # mkdir sda5-f2fs

tux /mnt #  mount -O extra_attr,inode_checksum,sb_checksum,encrypt,compress_algorithm=lzo,compress_extension=txt  /dev/sda5 /mnt/sda5-f2fs/ 
```

```

tux /sys/fs/f2fs/sda5/feature_list # cat *

unsupported

unsupported

supported

supported

supported

unsupported

supported

unsupported

unsupported

unsupported

unsupported

unsupported

supported

unsupported

tux /sys/fs/f2fs/sda5/feature_list # cat compression 

supported

tux /sys/fs/f2fs/sda5/feature_list # cat encryption 

supported

tux /sys/fs/f2fs/sda5/feature_list # cat extra_attr 

supported

tux /sys/fs/f2fs/sda5/feature_list # cat inode_checksum 

supported

tux /sys/fs/f2fs/sda5/feature_list # cat sb_checksum 

supported

```

Greetings

Ma

```

tux /mnt # cat /usr/src/linux/.config | grep F2FS

CONFIG_F2FS_FS=y

CONFIG_F2FS_STAT_FS=y

CONFIG_F2FS_FS_XATTR=y

CONFIG_F2FS_FS_POSIX_ACL=y

CONFIG_F2FS_FS_SECURITY=y

# CONFIG_F2FS_CHECK_FS is not set

# CONFIG_F2FS_FAULT_INJECTION is not set

CONFIG_F2FS_FS_COMPRESSION=y

CONFIG_F2FS_FS_LZO=y

CONFIG_F2FS_FS_LZ4=y

CONFIG_F2FS_FS_LZ4HC=y

CONFIG_F2FS_FS_ZSTD=y

CONFIG_F2FS_FS_LZORLE=y

```

https://www.kernel.org/doc/Documentation/filesystems/f2fs.txt

https://wiki.gentoo.org/wiki/F2FS

https://wiki.archlinux.org/title/F2FS

https://www.funtoo.org/F2FS_Install_Guide

----------

## Perfect Gentleman

```
 ~ $ mount | grep -i f2fs

/dev/sde1 on /home/VM type f2fs (rw,noatime,lazytime,background_gc=on,discard,no_heap,user_xattr,inline_xattr,acl,

inline_data,inline_dentry,flush_merge,extent_cache,mode=adaptive,active_logs=6,alloc_mode=default,

checkpoint_merge,fsync_mode=posix,compress_algorithm=zstd:7,compress_log_size=2,compress_mode=fs)

```

[Moderator edit: broke long whitespace-free lines in code tags to fix thread layout. -Hu]

----------

## holdengreen

-O got rid of the dmesg

'mount | grep -i f2fs'

has no mention of compression.

Also not sure how to correctly copy root / over to this new f2fs partition.

----------

## figueroa

Restore from a backup. Search the forums for recent discussion about stage4. And this link is good.

https://wiki.archlinux.org/index.php/rsync#Full_system_backup

----------

## Marlo

 *holdengreen wrote:*   

> 
> 
> Also not sure how to correctly copy root / over to this new f2fs partition.

 

I don't know how to do it right either.

In principle I did it like this:

I have 2 gentoo installations

> openrc with kde-plasma

and

> systemd with gnome

so i can boot into one system and edit the other.

https://wiki.archlinux.org/title/F2FS

```
Warning: The data contained on F2FS partitions can become unusable if the kernel version on the running machine is

          older than the kernel version used to create the partition. For example, this limitation can manifest if the F2FS partition

          was created on a mainline kernel provided by linux yet the system has a need to downgrade to an older series of kernels

          provided by linux-lts. See FS#69363.
```

        I created linux-5.10.61-gentoo for formatting and worked with this.

```
    Pitfall: I didn't just install the f2fs over the old ext4. I deleted the old partition and installed

                a new partition with a fresh f2fs. So in this case the uuid has changed.

                If you absolutely need root=, it is safer with root=/dev/sdxx.

                You can go back to root=uuid= if your system works safely after changing the filesystem.

                Check exactly "root=" in /etc/fstab or kernel CONFIG_CMDLINE="root=UUID=xxx" or

                /etc/dracut.conf.d/xxx.xxx with kernel_cmdline="root=UUID=xxx".
```

      Note: I use the rEFInd Boot Manager and here f2fs is not allowed for /boot.

https://www.rodsbooks.com/refind/drivers.html#selecting

        my mount point for /:  # mount /dev/sda4 /mnt/gentoo

```

         Into the fuse:         (cd /mnt/gentoo/ ; tar cf - .) | (cd  /My/path/to/backup ; tar xvf -)

        umount /mnt/gentoo

        Delete old partition

        Create new partition

        Formatting with f2fs

        Control with fsck.f2fs

        mount /mnt/gentoo

        Back from the fuse:    (cd /My/path/to/backup ; tar cf - .) | (cd /mnt/gentoo/ ; tar xvf -)
```

        Change the /etc/fstab:

        Filesystem / to f2fs and at the end 0 0 <--important!

        So I switched both systems from ext4 to f2fs with a total of 6 partitions.

Ma

----------

## M95D

From kernel.org: f2fs compression does not (yet) recover the space saved by compression. It means that compression will not increase available disk space; it will only write less data, which is faster and decreases wear on flash storage devices.

In my opinion, F2FS is *very* unsafe to use because:

- It needs the superblock to work. If it gets erased or corrupted, the filesystem is lost.

- If compression is used, not even raw data can be recovered.

- The superblock is in the first partition sector! It gets erased immediately if you make any mistake formatting, dd-ing or trimming. No time to hit ctrl+c.

- There is a *single* backup of the superblock. Just one. And it is stored in the *second sector*. That means it gets erased immediately after the main superblock if you make any mistake, and it's in the same flash erase block as the main superblock. If that block goes bad, you lost everything.

----------

