Memory File System (MemFS) 1.0 for HP-UX 11i v3
Introducing HP-UX Memory File System (MemFS) 1.0
Need for a Memory-Based File System
Chapter 18
Need for a Memory-Based File System
A memory-based file system is typically used as storage for temporary files. By keeping as
much data as possible in memory, it avoids having to perform disk I/O and the associated
overhead. Traditional file systems manage two types of data. One is the file content (called
data), which an application accesses through the read, write and mmap mechanisms. The
other, called metadata is the information related to file attributes and the file system
structure.
Most file systems implement a buffering mechanism for data. This implies that a copy of the
disk data blocks is maintained in memory (buffer cache or page cache, based on the
implementation). This buffer is used to service the reads from a disk, and to implement a
"delayed write" mechanism. Using a buffer helps the file systems avoid disk I/O to some
extent and improve the file system performance. Structural and attribute changes are
buffered to a lesser extent, and will usually cause disk I/O to be done.
A memory-based file system goes a bit further to avoid disk I/O. Metadata is always kept in
memory, so the overhead of writing structural changes to the disk is totally avoided. MemFS
data blocks are treated mostly at par with other file system blocks and can be swapped out of
the cache. There is a difference, though. Disk based file systems try to keep the disk copy up to
date with the cache copy. So, "dirty" buffers/pages (those that have been modified) are
periodically written back to the disk. This is important since these file systems are expected to
preserve data across system shutdown and reboot. A memory-based file system has no such
requirement, so data is written to the disk only if that buffer/page is being paged out.
Before memory-based file systems became popular, the concept of a "RAM disk" existed. A
RAM disk reserves a range of memory and makes it available through a block device interface
using a pseudo driver. The block device interface permits a file system to be created on it, in
effect providing a memory-based file system. However, RAM disks have certain drawbacks.
Since memory is reserved at the time of the disk creation, it is locked from shared system use,
whether actually in use or not. Most RAM disks do not support paging of their memory,
resulting in very poor system response in cases where the system is running low on free
physical memory. Since the system sees a RAM disk as a device rather than a file system, any
access to a file stored on it results in a second copy of the data being kept in the file system
buffer. Some of the implementations of a RAM disk may provide an improved interface and
some of these shortcomings may not be present.
As attractive as the performance aspects sound, a memory-based file system only works
efficiently under certain circumstances. The biggest disadvantage is that it does not preserve
data across mounts. It cannot be used to replace file systems that store persistent data. Since
it uses memory which is a shared resource, excessive use can adversely affect other memory
consumers. A typical use of a memory file system is for storing temporary files that are