MemFS v2 û A Memory-based File System on HP-UX 11i v2
Introduction
A Memory-based File System (MemFS) is a file system that resides in memory. It does not normally
write data out to stable storage. A MemFS is created from a mount operation, and ceases to exist
when it is un-mounted. The purpose of such a file system is to provide fast access for temporary files
that do not need to be kept for an indeterminate time. Because it does not normally have to do I/O to
stable storage, the MemFS is able to provide extremely high throughput.
Keeping data in memory comes at a cost. It consumes system physical memory. A system or
application that runs out of available memory at a critical time can cause irreparable loss to the user.
That is why most of the Virtual Memory (VM) management systems implement a paging policy,
wherein less frequently used memory pages are paged out to a swap device. This policy has been
extended to the MemFS. Under memory pressure the VM system can de-allocate MemFS pages and
reassign them where needed.
MemFS requires a user process to be associated with each of its instances. The memory allocated in
the process address space of this user process is used to store the data from the reallocated pages.
These user memory pages can be paged out to the system swap device whenever there is system
memory pressure.
This document discusses how MemFS in HP-UX 11i v2 is designed and it differs from a RAMdisk. It
will also cover the performance implications and guidelines to configure MemFS.
Why 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. That is, 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 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 buffer cache. There is a
difference, though. Disk based file systems try to keep the disk copy up to date with the buffer copy.
So, “dirty” buffers (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 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.