Most active commenters
  • AdieuToLogic(6)
  • buckle8017(5)
  • pkulak(4)

←back to thread

66 points hiAndrewQuinn | 17 comments | | HN request time: 0s | source | bottom
Show context
hackyhacky ◴[] No.44392515[source]
Rather than re-write your scripts to store temp files into /dev/shm, you can just mount /tmp using the tmpfs file system and get the same benefit for all your programs. Some distros do this by default.

The relevant line from fstab is:

    tmpfs /tmp            tmpfs    noatime 0       2
Now any program that writes to /tmp will be writing to a RAM disk, thus sparing unnecessary wear on my SSD.
replies(7): >>44392526 #>>44392690 #>>44392745 #>>44392789 #>>44392847 #>>44393129 #>>44393836 #
1. pkulak ◴[] No.44392745[source]
I did this for a while, but writing files to ram can be dangerous, since most things assume unlimited disk space. I noticed that updates would fail on machines that had 16 gigs of ram unless I logged out of my window manager and did it from the TTY. Took quite a long time to realize it was because of all the compiles writing to /tmp. Much easier to just let the SSD get used.
replies(1): >>44392802 #
2. buckle8017 ◴[] No.44392802[source]
This is why having swap even when you have plenty of memory for normal usage is good.

Swap on an SSD isn't even that slow.

replies(2): >>44392866 #>>44392886 #
3. pkulak ◴[] No.44392866[source]
You know what, your comment actually reminds me that this happened when I also had a bug in my configuration that was causing me to not actually use swap. I assume running out of tmpfs uses swap like anything else? I might give tmpfs another try.
replies(2): >>44393113 #>>44393717 #
4. ◴[] No.44392886[source]
5. AdieuToLogic ◴[] No.44393113{3}[source]
> I assume running out of tmpfs uses swap like anything else?

This is not the case. RAM-based file system capacities are unrelated to process memory usage, of which "swap space" is for the latter.

replies(3): >>44393245 #>>44393314 #>>44393779 #
6. pkulak ◴[] No.44393245{4}[source]
Interesting, thank you. I stand by my original point, downvotes be damned.
replies(2): >>44393330 #>>44400450 #
7. tatref ◴[] No.44393314{4}[source]
That's why on some configurations (RHEL 7 I think), journald will happily fill up your ram via /run/
replies(1): >>44393476 #
8. AdieuToLogic ◴[] No.44393330{5}[source]
> Interesting, thank you.

Glad to help out. Here[0] is more information regarding Linux swap space as it relates to processes and the VMM subsystem.

> I stand by my original point, downvotes be damned.

:-D

0 - https://phoenixnap.com/kb/swap-space

9. AdieuToLogic ◴[] No.44393476{5}[source]
> That's why on some configurations (RHEL 7 I think), journald will happily fill up your ram via /run/

I do not run systemd-based distros, so cannot relate.

replies(1): >>44401896 #
10. buckle8017 ◴[] No.44393717{3}[source]
Sibling is wrong tmpfs will swap.

Maybe some other ram disk things won't.

11. buckle8017 ◴[] No.44393779{4}[source]
tmpfs will swap.
replies(1): >>44400424 #
12. AdieuToLogic ◴[] No.44400424{5}[source]
> tmpfs will swap.

We are both wrong to a degree, but you are more correct than I was.

According to the docs[0]:

  tmpfs ... is able to swap unneeded pages out to swap
  space, if swap was enabled for the tmpfs mount.
So `tmpfs` does not unconditionally use swap, but can use it if possible. What I was thinking about is `ramfs`, which doesn't support swap, but that is not the topic of the question to which I replied.

0 - https://www.kernel.org/doc/html/latest/filesystems/tmpfs.htm...

replies(1): >>44402971 #
13. AdieuToLogic ◴[] No.44400450{5}[source]
I was wrong in my unconditional assertion that `tmpfs` does not use swap. It can, depending on conditions described here[0].

What I was thinking about is `ramfs`, which does not use/support swap and has other limitations not present in `tmpfs`.

Sorry for confusing the topic.

0 - https://www.kernel.org/doc/html/latest/filesystems/tmpfs.htm...

14. pkulak ◴[] No.44401896{6}[source]
btw
15. buckle8017 ◴[] No.44402971{6}[source]
You have to explicitly disable swap.

Honestly had no idea that was an option because I've never seen it disabled anywhere before.

replies(1): >>44418383 #
16. AdieuToLogic ◴[] No.44418383{7}[source]
> You have to explicitly disable swap.

> Honestly had no idea that was an option because I've never seen it disabled anywhere before.

Disabling swap is common with embedded systems, such as network gateways, routers, and other devices having no intrinsic mass storage devices.

replies(1): >>44508373 #
17. buckle8017 ◴[] No.44508373{8}[source]
No like there's a tmpfs mount flag to not allow swapping.