10 ms·
Tmpfs considered harmful
- forgotusername 14y ago9 times out of 10, tmpfs is explicitly not for use mounted as /tmp. The only obvious exception I can think of are cluster nodes where the workload is specialized and the node has no local storage whatsoever. I guess it only takes one silly person to connect "tmp" in the name to "/tmp", and the rest is history.
- justincormack 14y agosysfs is mounted on /sys debugfs is mounted on /sys/kernel/debug securityfs is mounted on /sys/kernel/security So tmpfs is mounted on /tmp? Can see that...
- alexchamberlain 14y agoIt makes sense in certain cases to use tmpfs for /tmp. However, I'm not sure this is on desktop machines, which (generally) have lower RAM than servers thrashing their /tmp directories.
- noselasd 14y agoEven in that case, using tmpfs on /tmp sounds like band aid. If there are applications that suffer performance because stuff it puts in /tmp , then change those applications - possibly by using an application specific tmpfs , or a new system wide tmpfs that doesn't overload something as ubiquitous /tmp
- rwmj 14y agoThe systemwide tmpfs already exists: /dev/shm.
- praptak 14y agoMinor disagreement about the following: "Everyone must worry about whether their files need to survive a reboot" I believe there was never such expectation of /tmp. On many systems it's being wiped periodically or even when the user's last session ends. The example app(s) that use /tmp for drafts need(s) to be fixed.
- alexchamberlain 14y agoTotally agree, /tmp should be wiped at the end of each session.
- sliverstorm 14y agoAgreed; this prevents establishment of expectations otherwise.
- alexchamberlain 14y agoAlso prevents it filling up your disk.
- dredmorbius 14y agoThe key is that it may be wiped. Files stored in /tmp are not guaranteed to survive boot. Whether or not they are there or not is a bit of a gamble (a regularly losing one should you choose tmpfs).
- mccabe 14y agoSurely thats what /var/tmp is intended for.
- raverbashing 14y ago"Everyone must now be careful never to store a file in /tmp that might grow large" If you're going to trash my /tmp with gigantic files please don't. Really "it’s better to fix the filesystem to make it faster" Yes, let's spend adding more complexity to the file system to work out every /tmp abuser out there. But his original point was avoiding adding complexity in the first place So basically, he contradicts himself. Mounting tmp as a memory backed fs is great (to which there may be better options than tmpfs), avoids (potentially) spinning up disks covered in rust for minor tasks.
- lmm 14y ago>Yes, let's spend adding more complexity to the file system to work out every /tmp abuser out there. But his original point was avoiding adding complexity in the first place Better to add complexity once, in the filesystem, than in every program that writes to it.
- w0utert 14y ago> Mounting tmp as a memory backed fs is great (to which there may be better options than tmpfs), avoids (potentially) spinning up disks covered in rust for minor tasks. I mount /tmp as a tmpfs for almost exactly this reason. I have an always-on home server/HTPC that runs the OS off of a small (40 GB) SSD, and I don't want to wear down the SSD with writes to /tmp, /var/tmp, /var/run, /var/log, etc. In theory, I don't want any writes at all, unless the thing is actually doing something useful. So I simply threw in 2GB extra RAM and mounted all these temporary/logging directories as tmpfs. Periodically (and on reboot) I zip the logs up and copy them to a backup directory just in case something fails. Of course this runs the risk of losing temporary data and logs whenever the server goes down, but that's a trade-off I'm willing to make. It's been running just fine for over 2 years now. I'd do the same thing straight away if I ever need to set up some similar system.
- pezz 14y agoYep - make your box do what you want. Nothing stops you from changing fstab to make any mount tmpfs or disk.
- 14y ago
- gizzlon 14y agoLinkbait headline. Thought it was going to be about a gotcha with tmpfs in general, but it's only about one specific use of tmps in one specific -not even release- version of one linux distribution. I get that the guy want's attention for this life-and-death issue, but linkbaiting is just mean :(
- dmpk2k 14y agoOne of the hardest parts of writing a compiler is register allocation. Not quite. There are many much more difficult problems in a competitive optimizing compiler before hitting that step. You can get reasonable results from even a linear scan allocator, which is simple.
- aidenn0 14y agoIt really depends on the architecture. There are some architectures with only 1 register, and others with many thousands of registers. Current x86 implementations do a good job of being fast even when registers spill. I've seen dual-issue Power cores (32ish registers) that only have 16k of 4-way dcache, which means register spills can easily kill performance.
- asdfaoeu 14y agoWhat's wrong with swapfiles?
- keeperofdakeys 14y agoIt should be mentioned that swapfiles are accessed directly, going around the filesystem. They can suffer from fragmentation if you don't create them when the filesystem is fresh, however.
- buster 14y agoOh, i hope they revert this change! The big trouble for me would be "Everyone must now be careful never to store a file in /tmp that might grow large". I often use /tmp for all kinds of temporary storage. Be it a small text file or a GB big tar file.
- ps2000 14y agoRare use case... I remember CD burning softwares and torrent clients asking for special temp directories to be used for that. Allowing every day applications to create GBs of tmp files would mean you would need to worry once your partition has less than 100 GB free. However, nobody stops you from mounting /tmp anywhere else or even disable tmpfs.
- buster 14y agoVery common for me, not so common for you. ;) And: when is use /tmp on my laptop, it gets cleared after reboot, so that's perfect for _temporary_ files..
- deleted 14y ago[deleted]
- keeperofdakeys 14y ago> "Everyone must now be careful never to store a file in /tmp that might grow large" Be warned that when he says this, he doesn't mean it will eat all your memory, it will only grow upto a maximum size (by default half of your ram). When this is reached, it acts like any other filesystem that is full: you get write errors. There is actually another implementation called ramfs, which doesn't have such a size restriction. However, tmpfs is what is actually being implemented here. The ramfs itself is more of a 'toy' filesystem, also being quite limited, including not being able to use swap space (unlike tmpfs).
- snorkel 14y agoBad title. tmpfs is good. Fedora maintainers assuming that all of /tmp should be in tmpfs is bad. Apps are already in the habit of writing a lot of expendable garbage to /tmp that doesn't require the fast I/O of tmpfs. Clogging RAM with this junk is bad idea.
- segmond 14y agounix noobies!
- peterwwillis 14y agoExample of exactly when to use hard disk and when to use tmpfs: User browsing the web for a month without rebooting. Flash stores temporary files in /tmp/. For a month straight, Pandora is pumping out songs to /tmp/ as a cache. 43829 minutes in a month, imagine an average of 3 minutes per song that's 14609 songs, at an average 1.5 megabytes per song that's 7304 megabytes that's 7.13 gigabytes. Probably shouldn't be stored in RAM. On the other hand, you have ganglia clusters of about 2,000 hosts. You have multiple gmetad's collecting data from different data sources and pooling it into your web interface box. It's updating ~10,000 tiny files every 30 seconds. Your i/o wait and system time is through the roof. You move the place gmetad writes to a tmpfs mount, and rsync to the disk every minute. Suddenly the i/o and system times are at 0.01%. Tmpfs for /tmp/ is considered harmful, but extremely helpful in other cases.
- xxiao 14y agoThis guy knows nothing about embedded and is painting with a wide brush. there are way more use cases where tmpfs is useful/critical than what you know.
- armored_mammal 14y agoMy theory on this is that it's intended as a step to avoid SSDs writes.
- chimeracoder 14y agoExactly - this is a major benefit of using tmpfs on /tmp
- dsr_ 14y agoThe fact is, is that not every app that uses /tmp does so in a safe manner. As long as that is true, it's not a good idea to use tmpfs for /tmp. It's perfectly reasonable, however, to use tmpfs for, say, /var/local/tmp and let individual users point $TMP at that. Want to live fast and dangerously? Set $TMP.
- alexchamberlain 14y agoThis assumes processes use $TMP.
- scotty79 14y agotmpfs is awesome to run rails from (i.e. for development). IO bound becomes CPU bound so you're getting as good speed as you can get.
- spartango 14y agoI'd disagree with the more global point (in the title) that tmpfs is harmful: it's actually quite handy for all sorts of things. As an amusing example, the SHM (shared memory) system in linux is actually implemented on top of tmpfs (/dev/shm is a tmpfs mount). Other uses include CoW shadow mounting (when unioned to an immutable filesystem). That said, the point that /tmp should not be a tmpfs mount is actually a decent one, just because we're used to the idea that /tmp is neither space-constrained (it's scratch space) nor extra performant.
- krakensden 14y agoI'm surprised no one is chanting "CADT" and linking to "What killed Linux on the desktop". This sort of subtle breakage over time is absolutely goddamn maddening.
- notatoad 14y agoWhy on earth would anybody ever use tmpfs for /tmp? If I'm writing a program that deals with a big file, and I want to temporarily write something to the filesystem, it is because I dont want it in memory. Why would you ever write to /tmp for any reason other than to get something out of ram for a while?
- donavanm 14y agoBecause a third party binary expects posix FS semantics for some data that does not require strong durability?
- chimeracoder 14y agoI use /tmp all the time. I find myself needing to interact with things for which the filesystem/shell interface is appropriate, but for which I don't want to worry about having to clean out the directory before it gets too large. Having it sit in RAM is great, because I get the speed without subjecting my disk to unnecessary writes - for certain operations, this can be a huge bonus.
- lostnet 14y agoBecause tmpfs is RAM cached disk (swap) space just like any other filesystem? Is there some better place than swap to accommodate /tmp?
- B-Con 14y agoThis is very popular amongst people just working on desktop setups. They usually don't need /tmp to house anything too large. Arch Linux actually switched recently to mounting /tmp as tmpfs recently.
- rogerbinns 14y agoI have been using tmpfs for /tmp for many years (since 2005 IIRC). Note that I do have large amounts of swap space (typically 64GB). One simple benefit is that files there do not get caught in backups - they are temporary detritus so I don't want backup space wasted by them. The major benefit is that fsync is really slow on Linux. Typically it turns into a sync, and a lot of programs like to ensure you don't lose data by being fsync happy. For temporary stuff that is even more painful - you don't care about data loss - that is why it is in tmp in the first place. TLDR: I prefer filesystem operations on transient/temporary files and data to run at the speed of RAM, and not end up in backups or waiting for syncs.
- donavanm 14y agoHere, let me man 7 hier that for you: /tmp This directory contains temporary files which may be deleted with no notice, such as by a regular job or at system boot up.
- binarycrusader 14y agoSolaris has done this for many years; it's not the end of the world as the author believes.
- tsahyt 14y agoRunning out of swap and memory is one thing, although unlikely considering how much of that stuff we've got nowadays. I for instance have 8gb of main memory and 10gb of swap space. 300mb are used after system boot (still too much). That leaves me with plenty of space to "waste" on temporary files in a tmpfs. The Linux FHS explicitly states "Programs must not assume that any files or directories in /tmp are preserved between invocations of the program." That's not only reboots. It's not meant to be used to store drafts or anything that you might want to reopen at a later time. That's what we've got /var/tmp for. The FHS specifies as follows: "The /var/tmp directory is made available for programs that require temporary files or directories that are preserved between system reboots. Therefore, data stored in /var/tmp is more persistent than data in /tmp". Tmpfs isn't harmful because of this, it's the default mutt configuration which is broken. If developers would have adhered to the standard the problem wouldn't exist. Since programs should adhere to the standard, because decisions like the one in question are made upon it, they should be reviewed and their default configurations should be changed in order to fix this issue.