Tmpfs: Mounting a RAM filesystem on Solaris
Introduction
TmpFS (Temporary File System) is the generic name given to any temporary Unix file system. Any file created in such a filesystem disappears when the system is shut down.
The default implementation of tmpfs in Linux 2.6.x kernels is based on ramfs, which uses the caching mechanism to optimize memory management. It is also available on Solaris 10.
However, tmpfs additionally offers a memory size limit that is set at mount time and can be modified on-the-fly with the “remount” option for security purposes. Tmpfs also allows the system to use swap space when necessary, which provides an additional guarantee.
Unlike a RAM Disk, it allocates memory dynamically to avoid excessive usage and offers better performance due to its extreme simplicity.
Usage
Prerequisites
We will create a mount point at /media/montmpfs
.
First, create the directory:
|
|
Then change the permissions on this directory so everyone can read/write/execute:
|
|
Mounting
Once the prerequisites are completed, we can mount the partition:
|
|
- -o size=2048m: specify the desired size. If none is defined, it will be the size of RAM + swap.
- /media/montmpfs: mount point for tmpfs
To have this mount persist across reboots, add it to the vfstab file (/etc/vfstab
):
|
|
Expanding the Partition
You didn’t plan enough space for your partition? We can expand it - it’s not simple, but it’s feasible.
WARNING: Performing this operation in production can be very risky
Retrieving Information
First, let’s check the available space:
|
|
Let’s retrieve the memory address used for our tmpfs:
|
|
Here’s the allocation address: ffffffffbd1e10c0.
Now, let’s retrieve the address of the tm_anonmax variable so we can change its value later:
|
|
Here tm_anonmax (number of pages) is equal to 0x80000 (512kb) at memory address ffffffffbfb42068.
Applying the New Value
We will now change its value. Let’s say we want to increase it to 3GB. First, we need to retrieve the default block size allocated for swap:
|
|
So I have 4kb blocks.
If I want to change to 3GB, I need to calculate the value in hexadecimal:
Desired size => desired size in kb / block size in kb = size in Kb = size in hexadecimal
3G => 3145728Kb / 4kb = 786432Kb = 0xC0000
Now let’s use these values and apply them to the current memory address to expand it:
|
|
Let’s verify that our changes were applied correctly:
|
|
or
|
|
And check the result:
|
|
Resources
Last updated 19 Feb 2012, 09:07 +0200.