tmpfs little help

I try to understand what exactly is tmpfs. I read on Google but I didn't understand what exactly does and why make Os run faster. Also. What I should write to add tmpfs on fstab? Now the only thing I have done is to add this line
Code:
tmpfs_load="YES"
on loader.conf
 
tmpfs(5) is a very fast version of a regular filesystem on a memory disk. I don't know how optomized it is on FreeBSD, but NetBSD claims it's much much faster than the multi-layered approach of putting a regular (UFS) filesystem on a md(4).

Keep in mind too that when using it for, say, a ports build you don't have to clean your working directories (not that that takes much time anyway), just umount the build directory when done.

The biggest disadvantage is to make data persist across reboots, you have to actively back-up and then restore it. So if you were going to use a tmpfs(5) for your /usr/obj/ you would do something like
Code:
# mount /usr/obj     (as a tmpfs)
# cd /usr/src && make buildworld && make buildkernel
# tar -zcvf /usr/tmp/buildworld_23_10_2010.tar.gz -C /usr/obj
# make installkernel && shutdown -r now
. . .
# mount /usr/obj && tar -zxvf /usr/tmp/buildworld_23_10_2010.tar.gz -C /usr/obj
# cd /usr/src && make installworld && mergemaster && umount /usr/obj
Etc etc.

For your fstab(5)
Code:
tmpfs /your/mountpoint/here tmpfs rw,size=469762048 0 0
AFIK, you must have a size= argument(I'm wrong about this), size= can also be in things like 448m or 5g(no, it can't, I'm wrong about this, too).

I'm pretty sure it's a good idea to leave pass and dump numbers as 0, I think the only other argument in the options field is noauto.
 
Ok. I start understand some things. Can someone help me setup it?
Code:
tmpfs /your/mountpoint/here tmpfs rw,size=469762048 0 0
/your/mountpoint/here... What mountpoint?
AFIK, you must have a size= argument, size= can also be in things like 448m or 5g.
I have 2 Giga Ram and 4 giga swap. I don't know if is needed information.
 
sk8harddiefast said:
Now the only thing I have done is to add this line
Code:
tmpfs_load="YES"
on loader.conf
You can remove it. tmpfs.ko will be loaded automatically once the tmpfs is mounted during startup (or when you mount it manually).

sk8harddiefast said:
/your/mountpoint/here... What mountpoint?
Any mountpoint you want, just like a second internal disk, external USB disk/pendrive, etc. Just create some directory somewhere and mount the tmpfs on it.


~~~~


fronclynne said:
AFIK, you must have a size= argument
I have been using tmpfs since it was first implemented without any size limit and I never had any problem.
 
I can create a folder named tmpfs into /tmp and add this line on fstab?
Code:
tmpfs /tmp/tmpfs tmpfs rw 0 0
Remove
Code:
tmpfs_load="YES"
from loader.conf , reboot and that's it?
 
Beastie said:
I have been using tmpfs since it was first implemented without any size limit and I never had any problem.

Ah, I see, yes, thank you for that hint. The size= argument must be in bytes or it is ignored. With ~15G of swap and 4G RAM my machine uses a 17G tmpfs by default. I'll have to fiddle with the inodes= argument to see what that does.
 
sk8harddiefast said:
I can create a folder named tmpfs into /tmp and add this line on fstab?
Code:
tmpfs /tmp/tmpfs tmpfs rw 0 0
Remove
Code:
tmpfs_load="YES"
from loader.conf , reboot and that's it?
Yes. Or simply # mount /tmp/tmpfs.
 
sk8harddiefast said:
I can create a folder named tmpfs into /tmp and add this line on fstab?
Code:
tmpfs /tmp/tmpfs tmpfs rw 0 0
Remove
Code:
tmpfs_load="YES"
from loader.conf , reboot and that's it?

Yes, but do let me know how large of a filesystem it allocates without a size argument.

Ah, from /usr/src/sys/fs/tmpfs/tmpfs.h
Code:
Therefore, the amount of memory to be
 * used is either the limit imposed by the user during mount time or the
 * amount of available memory, whichever is lower.  To avoid consuming all
 * the memory for a given mount point, the system will always reserve a
 * minimum of TMPFS_PAGES_RESERVED pages, which is also taken into account
 * by this macro (see above).
So there's that.
 
Top output:
Code:
last pid: 27060;  load averages:  0.33,  0.34,  0.26                                                                          up 0+00:12:37  04:01:41
89 processes:  1 running, 88 sleeping
CPU:  2.0% user,  0.0% nice,  2.1% system,  0.2% interrupt, 95.8% idle
Mem: 107M Active, 145M Inact, 195M Wired, 2956K Cache, 180M Buf, 1513M Free
Swap: 3972M Total, 3972M Free

  PID USERNAME     THR PRI NICE   SIZE    RES STATE   C   TIME   WCPU COMMAND
 1779 emberdaemon    1  47    0   859M 26920K select  2   0:39  4.20% Xorg
 1786 emberdaemon    1  45    0 32508K  5540K select  0   0:02  0.78% conky
26800 emberdaemon    1  45    0 80016K 15484K select  3   0:00  0.68% urxvt
 1823 emberdaemon    2  44    0   738M 58536K kqread  2   0:01  0.10% chrome
 1813 emberdaemon   20  44    0   201M 84276K ucond   1   0:17  0.00% chrome
 1822 emberdaemon    2  44    0   744M 64452K kqread  1   0:09  0.00% chrome
 1787 emberdaemon    2  44    0 24176K  4796K select  1   0:02  0.00% ipager
 1479 root           1  44    0  6896K  1304K select  3   0:01  0.00% powerd
 1824 emberdaemon    2  44    0   743M 62616K kqread  0   0:01  0.00% chrome
  845 root           1  44    0  8044K  1396K select  0   0:01  0.00% moused
 1781 emberdaemon    1  44    0 38216K  7700K select  1   0:00  0.00% fluxbox
 1692 haldaemon      2  51    0 27540K  5540K piperd  1   0:00  0.00% hald
 1875 emberdaemon    1  44    0 80016K 15468K select  0   0:00  0.00% urxvt
 1815 emberdaemon    1  44    0   141M 26376K sbwait  0   0:00  0.00% chrome
 1814 emberdaemon    1  44    0   139M 22284K select  1   0:00  0.00% chrome
 1877 emberdaemon    1  64    0 10220K  2944K ttyin   2   0:00  0.00% bash
27060 emberdaemon    1  44    0  9336K  2472K CPU0    1   0:00  0.00% top
 1696 root           1  76    0 17944K  3052K select  2   0:00  0.00% hald-runner
 1600 root           1  44    0 12096K  3640K select  3   0:00  0.00% sendmail
  990 root           1  44    0  3204K   740K select  1   0:00  0.00% devd
 1680 root           1  45    0 21676K  2056K wait    0   0:00  0.00% login
 1540 messagebus     1  44    0  8092K  2184K select  3   0:00  0.00% dbus-daemon
  886 root           6  45  r1F 17680K  3852K cuse-s  0   0:00  0.00% webcamd
 1247 root           1  44    0  7024K  1588K select  1   0:00  0.00% syslogd
 1695 root          17  44    0 28536K  5156K waitvt  2   0:00  0.00% console-kit-daemon
 1758 emberdaemon    1  44    0 10220K  2744K wait    0   0:00  0.00% bash
 1739 root           1  76    0 16624K  2692K kqread  0   0:00  0.00% hald-addon-mouse-sy
 1722 root           1  76    0 16624K  2692K kqread  1   0:00  0.00% hald-addon-mouse-sy
 1611 root           1  44    0  7952K  1628K nanslp  2   0:00  0.00% cron
26821 emberdaemon    1  45    0 10220K  2944K wait    0   0:00  0.00% bash
 1760 emberdaemon    1  76    0  8264K  1836K wait    2   0:00  0.00% sh
 1876 emberdaemon    1  46    0 72020K  8600K sbwait  3   0:00  0.00% urxvt
 1778 emberdaemon    1  52    0 13340K  2096K wait    3   0:00  0.00% xinit
26809 emberdaemon    1  45    0 72020K  8600K sbwait  3   0:00  0.00% urxvt
 1682 root           1  76    0  6892K  1300K ttyin   3   0:00  0.00% getty
 1687 root           1  76    0  6892K  1300K ttyin   2   0:00  0.00% getty
 1684 root           1  76    0  6892K  1300K ttyin   1   0:00  0.00% getty
 1685 root           1  76    0  6892K  1300K ttyin   3   0:00  0.00% getty
 1686 root           1  76    0  6892K  1300K ttyin   1   0:00  0.00% getty
 1683 root           1  76    0  6892K  1300K ttyin   0   0:00  0.00% getty
 1681 root           1  76    0  6892K  1300K ttyin   2   0:00  0.00% getty
 1604 smmsp          1  76    0 12096K  3864K pause   2   0:00  0.00% sendmail
  126 root           1  76    0  2744K  1068K pause   0   0:00  0.00% adjkerntz
[...]
 
It does not really "merge" them. They are already one as far as the OS is concerned. tmpfs is a memory filesystem and your (virtual) memory is made of physical memory plus swap space.
 
sk8harddiefast said:
Tmpfs merge swap and ram on a specific mountpoint or is my idea?

Sort of. I'd assume it's also somewhat like the virtual mountpoints in zfs that draw from a common pool of storage. So the sum of the used space in all of your tmpfs mounts can't exceed your available swap+RAM. If that makes any sense.
 
Here we go, a small test:
Code:
> df -h /home/tmp/tmpfs*
Filesystem         Size    Used   Avail Capacity  Mounted on
tmpfs               17G    4.0K     17G     0%    /home/tmp/tmpfs0
tmpfs               17G    4.0K     17G     0%    /home/tmp/tmpfs1
tmpfs               17G    4.0K     17G     0%    /home/tmp/tmpfs2
tmpfs               17G    4.0K     17G     0%    /home/tmp/tmpfs3
. . . copy some junk into them . . .
> df -h /home/tmp/tmpfs*
Filesystem         Size    Used   Avail Capacity  Mounted on
tmpfs               17G    698M     16G     4%    /home/tmp/tmpfs0
tmpfs               16G    4.0K     16G     0%    /home/tmp/tmpfs1
tmpfs               16G    4.0K     16G     0%    /home/tmp/tmpfs2
tmpfs               16G    4.0K     16G     0%    /home/tmp/tmpfs3
. . . more junk . . .
> df -h /home/tmp/tmpfs*
Filesystem         Size    Used   Avail Capacity  Mounted on
tmpfs               15G    698M     15G     4%    /home/tmp/tmpfs0
tmpfs               15G    4.0K     15G     0%    /home/tmp/tmpfs1
tmpfs               16G    1.1G     15G     7%    /home/tmp/tmpfs2
tmpfs               15G    579M     15G     4%    /home/tmp/tmpfs3
So, it just dynamically reallocates as stuff fills up. It just does it kinda weirdly from the perspective of df(1).
 
If I open to see a video on youtube. The video normally been saved on /tmp and is not deleted after reboot. Now will be saved on /tmp/tmpfs and will be deleted after reboot? A youtube video saved on /tmp is a kind of junk. right? So tmpfs is "collecting" all this junks and delete them on reboot. Like Ram do?
 
for zsh, cat /dev/urandom >> .zshrc

sk8harddiefast said:
If I open to see a video on youtube. The video normally been saved on /tmp and is not deleted after reboot. Now will be saved on /tmp/tmpfs and will be deleted after reboot? A youtube video saved on /tmp is a kind of junk. right?

If you want things to use /tmp/tmpfs/ for temporary storage, set TMPDIR in your shell startup. For [t]csh [cmd=""]echo "setenv TMPDIR /tmp/tmpfs" >> .cshrc[/cmd]; for bash [cmd=""]echo "export TMPDIR=/tmp/tmpfs" >> .profile[/cmd].
 
Back
Top