1

I have an application for linux I use quite frequently which loves to make a lot of temporary files while it does its work. Basically its software which routes circuit boards automatically and during its routing procedures, it creates and deletes alot of temporary files.

My strace output when scanning for the open command looks like this:

  12:09:52.677525 open("/tmp/e000134A.tmp", O_RDWR|O_CREAT|O_APPEND, 0666) = 8
  12:09:52.677777 open("/tmp/e000134A.tmp", O_RDWR|O_CREAT|O_TRUNC, 0666) = 8
  12:09:52.871198 open("/tmp/e000134B.tmp", O_RDWR|O_CREAT|O_APPEND, 0666) = 8
  12:09:52.871342 open("/tmp/e000134B.tmp", O_RDWR|O_CREAT|O_TRUNC, 0666) = 8
  12:09:53.092441 open("/tmp/e000134C.tmp", O_RDWR|O_CREAT|O_APPEND, 0666) = 8
  12:09:53.092563 open("/tmp/e000134C.tmp", O_RDWR|O_CREAT|O_TRUNC, 0666) = 8
  12:09:53.292663 open("/tmp/e000134D.tmp", O_RDWR|O_CREAT|O_APPEND, 0666) = 8
  12:09:53.292779 open("/tmp/e000134D.tmp", O_RDWR|O_CREAT|O_TRUNC, 0666) = 8
  12:09:53.452220 open("/tmp/e000134E.tmp", O_RDWR|O_CREAT|O_APPEND, 0666) = 8
  12:09:53.452310 open("/tmp/e000134E.tmp", O_RDWR|O_CREAT|O_TRUNC, 0666) = 8
  12:09:53.630176 open("/tmp/e000134F.tmp", O_RDWR|O_CREAT|O_APPEND, 0666) = 8
  12:09:53.630275 open("/tmp/e000134F.tmp", O_RDWR|O_CREAT|O_TRUNC, 0666) = 8
  12:09:53.797461 open("/tmp/e0001350.tmp", O_RDWR|O_CREAT|O_APPEND, 0666) = 8
  12:09:53.797566 open("/tmp/e0001350.tmp", O_RDWR|O_CREAT|O_TRUNC, 0666) = 8
  12:09:53.968627 open("/tmp/e0001351.tmp", O_RDWR|O_CREAT|O_APPEND, 0666) = 8
  12:09:53.968727 open("/tmp/e0001351.tmp", O_RDWR|O_CREAT|O_TRUNC, 0666) = 8
  12:09:54.145310 open("/tmp/e0001352.tmp", O_RDWR|O_CREAT|O_APPEND, 0666) = 8
  12:09:54.145417 open("/tmp/e0001352.tmp", O_RDWR|O_CREAT|O_TRUNC, 0666) = 8

and the calls keeps repeating until I stop the operation.

I noticed in my temp folder that one created file was about 90K but most of the time they are 0 bytes.

I have tried to increase the speed of operations in the following ways:

I adjusted my boot parameters to allow for larger ram drives then I added these two lines before starting anything that needs the /tmp folder:

mke2fs -cc -b 1024 -m 0 /dev/ram0 50000
mount -o async,nodev,noatime,nodiratime,noiversion,nomand,norelatime /dev/ram0 /tmp

I also executed the application with ionice:

ionice -c1 -n0 appname

Here is more of my strace in relation to how it deals with a temp file from creation to deletion:

  12:17:02.905620 stat64("/tmp/", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=1024, ...}) = 0
  12:17:02.905719 access("/tmp/", R_OK|W_OK|X_OK) = 0
  12:17:02.905782 open("/tmp/e0001C6D.tmp", O_RDWR|O_CREAT|O_APPEND, 0666) = 8
  12:17:02.905851 close(8)                = 0
  12:17:02.905886 open("/tmp/e0001C6D.tmp", O_RDWR|O_CREAT|O_TRUNC, 0666) = 8
  12:17:02.905933 fstat64(8, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
  12:17:02.905994 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7c5c000
  12:17:02.906044 write(8, "\1\0\224\10\30\206\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 1024
  12:17:02.906117 write(8, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 63488) = 63488
  12:17:02.906305 write(8, "@\0\221\0\221\0\221\0\221\0\221\0\263\0\263\0\263\0\242\0\263\0\263\0\263\0Q\0Q\0b\0Q"..., 1024) = 1024
  12:17:02.906361 write(8, "Q\0Q\0\242\0b\0\21\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 33792) = 33792
  12:17:02.924577 gettimeofday({1519233422, 924592}, NULL) = 0
  12:17:02.935856 gettimeofday({1519233422, 935870}, NULL) = 0
  12:17:02.947417 gettimeofday({1519233422, 947430}, NULL) = 0
  12:17:02.947453 write(8, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 544) = 544
  12:17:02.947523 _llseek(8, 0, [0], SEEK_SET) = 0
  12:17:02.947558 read(8, "\1\0\224\10\30\206\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 1024
  12:17:02.947616 read(8, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 63488) = 63488
  12:17:02.947727 read(8, "@\0\221\0\221\0\221\0\221\0\221\0\263\0\263\0\263\0\242\0\263\0\263\0\263\0Q\0Q\0b\0Q"..., 1024) = 1024
  12:17:02.947781 read(8, "Q\0Q\0\242\0b\0\21\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 33792) = 33792
  12:17:02.947864 read(8, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 544
  12:17:02.948680 close(8)                = 0
  12:17:02.948713 munmap(0xb7c5c000, 4096) = 0
  12:17:02.948751 unlink("/tmp/e0001C6D.tmp") = 0

So is there any way I can reduce or speed up these calls?

2
  • is the application open source? if so, see if all that I/O can be replaced with a pipe (this is probably why compilers have a -pipe flag...) – thrig Feb 21 '18 at 18:08
  • no its not open source – Mike -- No longer here Feb 21 '18 at 18:35
0

An ext2 filesystem backed by RAM is a lot less efficient than a ramfs or tmpfs. This is one of the reasons why the kernel switched from initrd to initramfs. Try replacing your /tmp mountpoint with a tmpfs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.