[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Moving /tmp to tmpfs makes it useless



On Sat, May 26, 2012 at 10:59:06PM -0400, Joey Hess wrote:
> Adam Borowski wrote:
> > I think that box had jfs, but other filesystems are no different: for
> > example, ext* will fsync() during a rename() call behind your back even if
> > you don't request it, forcing every file to hit the disk platters even
> > though they'll immediately get changed again.  For files outside /tmp/ that
> > makes sense: the system has to guarantee you won't lose data during a crash.
> > But why should I care about not losing temp files?
> 
> In practice, it's rare for anything that uses libc's interfaces to /tmp
> (or TMPDIR directly) to rename files in /tmp. Files in /tmp are opened,
> unlinked, written, read, and closed. Renaming files in /tmp is thus not
> likely to be a major source of system load. My charge of premature
> optimisation stands.

Ok, so let's benchmark typical workloads on /tmp, ie:

    for (1..$n)
    {
        open F, ">", $_;
        syswrite F, $data;
        close F;
    }

    for (1..$n)
    {
        open F, "<", $_;
        sysread F, $dummy, $len;
        close F;
        unlink $_;
    }

(Best of three runs:)

5000 byte files:
           tmpfs       btrfs         jfs       ext4
real    0m1.430s   0m20.421s   1m35.687s  0m14.498s
user    0m0.416s    0m0.576s    0m0.772s   0m0.604s
sys     0m0.928s    0m7.528s    0m4.812s   0m0.604s
5000000 byte files:
           tmpfs       btrfs         jfs       ext4
real    0m0.548s    0m5.062s    0m5.246s   0m5.351s
user    0m0.004s    0m0.008s    0m0.008s   0m0.004s
sys     0m0.540s    0m0.640s    0m0.612s   0m0.696s


This is without even hitting the disk, ie, strictly in-memory, nullifying
the biggest advantage of tmpfs.  It still acts over an order of magnitude
faster.

If any operation would trigger a fsync(), tmpfs gains additional three
orders of magnitude of an edge¹.


[1]. Ok, somewhat less with jfs, but that's because instead of 6.6 times
slower than ext4, with fsync() it suddenly became consistently 3.4 times
faster.  That's the perils of relative comparisons, but hey, it doesn't
matter that much if tmpfs is 1000 or 10000 faster :p

-- 
I was born an ugly, dumb and work-loving child, then an evil midwife
replaced me in the crib.

Attachment: signature.asc
Description: Digital signature


Reply to: