• Stars
    star
    275
  • Rank 148,927 (Top 3 %)
  • Language
    C
  • License
    GNU General Publi...
  • Created almost 6 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

a virtual black hole file system that behaves like /dev/null

nullfsvfs CI on ubuntu-latest

nullfs

A virtual file system that behaves like /dev/null

It can handle regular file operations like mkdir/rmdir/ln but writing to files does not store any data. The file size is however saved, reading from the files behaves like reading from /dev/zero.

Writing and reading is basically an NOOP, so it can be used for performance testing with applications that require directory structures. Implemented as kernel module, instead of using FUSE, there is absolutely no overhead for copying application data from user to kernel space while performing write or read operations.

alt text

# sudo make
make -C /lib/modules/4.18.5/build M=/home/abi/lwnfs modules
make[1]: Entering directory '/usr/src/linux-headers-4.18.5'
  Building modules, stage 2.
  MODPOST 1 modules
make[1]: Leaving directory '/usr/src/linux-headers-4.18.5'

# insmod nullfs.ko 
# mkdir /sinkhole
# mount -t nullfs none /sinkhole/
# mkdir /sinkhole/testdir
# touch /sinkhole/testdir/myfile
# echo foobar > /sinkhole/testdir/myfile
# ls -lah /sinkhole/testdir/myfile
-rw-r--r-- 1 root root 0 Nov  8 20:17 /sinkhole/testdir/myfile
# cat /sinkhole/testdir/myfile
# pv < /dev/zero > /sinkhole/testdir/myfile
11.1GiB 0:00:04 [3.85GiB/s] [     <=>      ] 
# cat /sinkhole/testdir/myfile
# 

File size is preserved to work around applications that do size checks:

# dd if=/dev/zero of=/nullfs/DATA bs=1M count=20
20+0 records in
20+0 records out
20971520 bytes (21 MB, 20 MiB) copied, 0.00392452 s, 5.3 GB/s
# stat -c%s /nullfs/DATA
20971520

Reading from the files does not copy anything to userspace and is an NOOP; makes it behave like reading from /dev/zero:

# dd if=/nullfs/DATA of=/tmp/REALFILE
40960+0 records in
40960+0 records out
20971520 bytes (21 MB, 20 MiB) copied, 0.0455288 s, 461 MB/s
# hexdump -C /tmp/REALFILE
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

installation

manual installation

To install the module for the running linux kernel use:

 # make -C /lib/modules/$(uname -r)/build M=$PWD modules_install INSTALL_MOD_DIR=kernel/fs/nullfs
 # depmod

Running depmod is mandatory. Now the module can be loaded via:

 # modprobe nullfs

To automatically load the module during system boot, create a configuration file suitable for your distribution (usually located in /etc/modules-load.d):

 # echo nullfs > /etc/modules-load.d/nullfs.conf

Example entry for /etc/fstab, mounting the filesystem to /nullfs:

none    /nullfs nullfs auto

debian package

 # apt-get install debhelper dkms
 # dpkg-buildpackage -r fakeroot
 # dpkg -i ../nullfsvfs_<version>_amd64.deb

Usage

Keeping file data

There is the possibility to exclude certain files from being sent into the void. If, for example, the file matching "fstab" should be kept in memory, mount nullfs with the "write=" option.

# mount -t nullfs none /sinkhole/ -o write=fstab
# cp /etc/fstab /sinkhole/
# wc -l /sinkhole/fstab 
14 /sinkhole/fstab
# cp /etc/passwd /sinkhole/
# wc -l /sinkhole/passwd 
0 /sinkhole/passwd

Another option is using the sysfs interface to change the exclude string after the module has been loaded:

 # echo foo  > /sys/fs/nullfs/exclude

Keep in mind that file data is kept in memory and no boundary checks are done, so this might fill up your RAM in case you exclude big files from being nulled.

ACL

It is possible to set POSIX ACL attributes via setfacl so it appears the filesystem supports them, they are not saved.

Works with recent linux kernels (5.x), nullfs builds fine with older kernels (4.x, 3.x) but setting ACL information fails with "Operation not supported".

usecases

See: Use Cases

The module has been used for performance testing with redis, see:

https://www.usenix.org/system/files/atc20-george.pdf

Please report usecases as regular issues!

supported mount options

The following mount options are supported:

 -o mode=      set permissions on mount directory ( mount .. -o mode=777 )
 -o uid=       set uid on mount directory ( mount .. -o uid=1000 )
 -o gid=       set gid on mount directory ( mount .. -o gid=1000 )
 -o write=fn   keep data for specific file ( mount .. -o write=fstab )

todos/ideas

  • replace simple_statfs call with real one, show free space of a directory that can be passed during kernel module load
  • support multiple parameters for write= option
  • allow regex for write= option via trace.h
  • simulate xattr support?

More Repositories

1

virtnbdbackup

Backup utility for Libvirt / qemu / kvm supporting incremental and differential backups + instant recovery (agentless).
Python
253
star
2

qmpbackup

Live Qemu Incremental backup using dirty-bitmaps
Python
58
star
3

github-actions-tune

Speed up your github actions on ubuntu-latest
Shell
15
star
4

ssenv

Exit if environment variables known to be used as access tokens are set.
Go
15
star
5

mifare

mifare m302 rfid card reader playground
Python
9
star
6

getotrs

Download otrs ticket attachments to local folder
Python
7
star
7

issue2mbox

Export github issues to mbox or maildir
Python
5
star
8

kiss-bootstrap

Bootstrap kiss linux into qemu boot image
Shell
4
star
9

nutanix_uefi

how to make nutanix community installation image bootable from uefi
4
star
10

vircpt

Libvirt checkpoint swiss army knife
Python
4
star
11

vagrant-libvirt-dns

How to manage DNS in your vagrant environment the libvirt way
4
star
12

trktor

trktor game
Python
3
star
13

xcbackup

Export all your flights from DHV-XC Portal
Go
3
star
14

xcup

Command line utility for publishing paraglider flights on DHV-XC
Go
2
star
15

xccat

Show latest DHV-XC flights on console
Go
2
star
16

xtdcliconf

Drop into HP Comware switches Extended CLI mode directly
Python
2
star
17

git2skype

Send your git commits to skype group chats
Python
2
star
18

getbandcamp

simple bandcamp downloader in python
Python
1
star
19

tuneme

1
star
20

fm4stream

Simple bottle app frontend for fm4 radio show archive
HTML
1
star
21

plugin.music.fm4

KODI/XBMC plugin for FM4 on Demand streams
Python
1
star
22

packer-omnios

Packer template to build vagrant image for omnios libvirt provider
1
star
23

getfm4

simple script to download fm4 on demand streams
Python
1
star
24

snippets

random code snippets, mostly python, not big enough for having an own repo
Python
1
star
25

winlogon

winlogon
Batchfile
1
star
26

cvs-rhel8

CVS packages for RHEL8
1
star