Giter Club home page Giter Club logo

nullfsvfs's Introduction

nullfsvfs

a virtual file system that behaves like /dev/null

Mostly based on the ramfs example from the linux kernel and the lwnfs file system.

A virtual filesystem that behaves like /dev/null, but on the VFS layer of the kernel. Existing alternatives are mostly based on FUSE which do not perform good because of user/kernel space mapping operations.

It can handle regular file operations like mkdir/rmdir/ln but writing to files does not store any data.

In my tests i could get up to 3.85 Gib/s so it should be fine for performance tests that need directory operations.

alt text

usage

# 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
# cat /dev/zero | pv > /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:

# stat -c%s proxmox.iso 
641517568
# cp proxmox.iso /sinkhole/
# stat -c%s /sinkhole/proxmox.iso 
641517568

keep data for certain files

There is the possiblity to exclude certain files from beeing sent into the void. For example if the file matching "fstab" should be kept in memory, one can 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 beeing nulled.

todos/ideas

  • replace simple_statfs call with real one, show free space of a directory that can be passed during kernel module load
  • return the size of the files with contents like /dev/zero
  • support multiple parameters for write= option
  • allow regex for write= option via trace.h

nullfsvfs's People

Contributors

abbbi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.