[SOLVED] files created then deleted at every second in tmp directory
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
files created then deleted at every second in tmp directory
By mistake I noticed that in /tmp directory are continuously created some files then immediately deleted. Using a succession of ls -l /tmp I managed to catch the created files:
It's about Ubuntu 18.10 with 4.18.0-16-generic. This is an almost fresh install: I added some server software (nginx, mysql, php7.2-fpm) but even with those closed the problem persists.
What are the files created and why?
How would I stop this behaviour? a very undesirable one on a SSD
Thank you!
Last edited by adrhc; 04-02-2019 at 12:04 PM.
Reason: additional info
you need to find the app doing this. what you got running outside of standard system, if not, then go look at standard system apps. try putting anotime in your fstab for your mounts if it is sdd. man anotime.
You could try running "lsof /tmp" to see if you can capture file names like you did with "ls -l". The lsof otuput will show show you the PID in the second column. You can run "ps -ef |grep <PID>" to see more info about the process that has the specified PID.
By mistake I noticed that in /tmp directory are continuously created some files then immediately deleted.
...
How would I stop this behaviour? a very undesirable one on a SSD
Really, small files that are created and soon deleted are usually never written to the drive. They exist in the kernel buffers, and are then deleted (freeing the buffer) before the dirty buffer is ever flushed out to the drive. For that sort of usage, /tmp in a tmpfs in memory really isn't much different from /tmp on a physical drive. Files in a tmpfs will get pushed out to swap if there is memory pressure, and dirty buffers will be flushed out sooner for the same reason. There is a difference for long-lived files, since unreferenced pages in a tmpfs can sit around for a very long time without being flushed out, whereas the dirty buffer flush is more aggressive.
If they show up in a "ls", are they hitting the SSD, which the OP seems to want to avoid. Personally I always put /tmp on tmpfs.
As for the files themselves, I'd be real interested in finding out what is allocating them. In Fedora I see names like dnf-asdvav or systemd-tmpfiles.gtejgbnb, so the files give an indication themselves.
@adrhc go get fatrace and run it using sudo - it will tell you what process is hitting each file. Very handy for a quick check.
Last edited by syg00; 04-03-2019 at 01:23 AM.
Reason: grammar
Since SSD uses flash memory the benefit to using tmpfs in memory isn't that great from a performance standpoint. It also has the downside of using up system memory for storage that might be used for processes instead. Also of course the same "wear" that would affect SSD drives would affect the DIMMs you're using for tmpfs. Using tmpfs makes sense if you're looking for performance increases on systems that have mechanical drives but not as much if you're using SSD or Flash and none at all if you're using NVMe.
We used SSD disks in a Hitachi disk array for several years and never saw performance degradation. A couple of years back we switched to a Pure Flasharray using flash disks and also haven't seen any degradation.
Hmmm - tmpfs uses kernel cache, and doesn't use a filesystem as generally accepted. It is always ahead of anything else performance wise. Whether any of us can measure such benefit in everyday usage is an entirely different discussion.
Since SSD uses flash memory the benefit to using tmpfs in memory isn't that great from a performance standpoint. It also has the downside of using up system memory for storage that might be used for processes instead. Also of course the same "wear" that would affect SSD drives would affect the DIMMs you're using for tmpfs.
Everything that is read from or written to the SSD is going through the kernel's buffer cache, so the "wear" on the DIMMs (if any) would be the same. For a tmpfs, that's where the data stays unless pushed out to swap because processes need the memory. For a regular filesystem, the data stays in the buffer cache until the kernel gets around to flushing out the dirty buffer, and that can come sooner if there is memory pressure. There really isn't much difference for short-lived files.
if I remember well the tmpfs is much faster than an ssd. Speaking about performance: compiling/building something huge will show you the difference (if compiler uses /tmp). But obviously you need enough RAM to do that.
I suggest installing and running fnotifystat to detect the process that is creating these files:
sudo apt-get install fnotifystat
sudo fnotifystat -i /tmp
You will see process that is doing the open/close/read/write activity something like the following:
Total Open Close Read Write PID Process Pathname
3.0 1.0 1.0 0.0 1.0 5748 firefox /tmp/cubeb-shm-5748-input (deleted)
2.0 0.0 1.0 0.0 1.0 18135 firefox /tmp/cubeb-shm-5748-output (deleted)
1.0 1.0 0.0 0.0 0.0 5748 firefox /tmp/cubeb-shm-5748-output (deleted)
I tried fnotifystat and works really well: it continuously prints the files but after first or second iteration is pretty easy to spot the problem (file & pid). First fnotifystat iteration:
I also tried lsof which I guess should work too but it's very difficult to catch those short lived files; as a matter of fact I never managed to catch one (at least visually if not with a select & copy).
watch --interval=1 'lsof /tmp/'
Code:
Every 1.0s: lsof /tmp/ adrhc.go.ro: Fri Apr 5 09:32:46 2019
lsof: WARNING: can't stat() hugetlbfs file system /var/lib/hugetlbfs/group/www-data/pagesize-2MB
Output information may be incomplete.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 4013 gigi mem REG 0,49 32768 36 /tmp/hsperfdata_adr/4013
clementin 5319 gigi 13uW REG 0,49 0 43 /tmp/qtsingleapp-clemen-d211-3e8-lockfile
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.