Why does /tmp show only 2GB instead 4GB on my RPi4?

Running snapshot on my RPi4 4GB RAM

In Luci it shows

But df -h shows:

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                17.5M     17.5M         0 100% /rom
tmpfs                     1.9G    756.6M      1.1G  40% /tmp      <---------------
/dev/loop0               75.7M     60.0K     69.6M   0% /overlay
overlayfs:/overlay       75.7M     60.0K     69.6M   0% /
/dev/mmcblk0p1           63.9M     18.5M     45.4M  29% /boot
tmpfs                   512.0K         0    512.0K   0% /dev

tmpfs supposed to show whole RAM i.e. around 4GB right?

what is in /etc/fstab ?

Nope, half.

1 Like

It's empty.

Why half can I know?

See https://docs.kernel.org/filesystems/tmpfs.html:

size - The limit of allocated bytes for this tmpfs instance. The default is half of your physical RAM without swap. If you oversize your tmpfs instances the machine will deadlock since the OOM handler will not be able to free that memory.

2 Likes

So, is there any way a user can at least use 3.5 GB out of 4GB RAM? Seems like it's a waste of RAM to me in this case :slight_smile:

Let us know when you manage to allocate the 1st half ,)

From my link:

tmpfs puts everything into the kernel internal caches and grows and shrinks to accommodate the files it contains and is able to swap unneeded pages out to swap space. It has maximum size limits which can be adjusted on the fly via ‘mount -o remount …’

maybe read that document?

1 Like

Sorry I was testing DOH package so I missed that part. Anyways thanks for pointing it out Moeller. unfortunately I'm new to this mount, remount commands but lemme dig in and get familiar with it. BTW, can mount -o remount... explicitly expand the tmpfs storage?

Here is what I put in my /etc/rclocal:

# minimize the too large tmpfs (to avoid OOM), this is better handled by adding swap                                                                                                                               
mount tmpfs /tmp -t tmpfs -o remount,size=16000k,nosuid,nodev  

here my goal was to reduce the size as I really did not want this to OOM my router. However tmpfs can be pushed out to swap/paging files, so if you enable a swap partition/file the OOM likelihood is reduced.

However /tmp IMHO rarely need to reach let alone exceed 2 GB... but that is for my use-cases, might be different for yours, though it sounds like you are not doing that based on a specific need.

2 Likes

Alright thanks for the direction. I'll try your command and report back. Also wondering is it possible to change tmpfs size when we build the image?

Honestly no idea. When I looked at this some years ago, I was sufficiently satisfied with the solution above to not bother any further (on my current router with 1GB ram instead of my old router's 64MB I stopped bothering about this, since I consider 512MB way more than /tmp on a rputer should ever require and I assume that my use-cases would not OOM my router even if it only had 512MB ram; also I added a swap partition).

I just started using Aria2 and loved it. Thought I could use the available RAM to download files where servers cap the download speed. It would have been great to use whole RAM (except allocated for the system for fail-safe) to write files :slight_smile:

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                17.5M     17.5M         0 100% /rom
tmpfs                     3.4G     12.0M      3.4G   0% /tmp     <------------
/dev/loop0               75.6M     60.0K     69.5M   0% /overlay
overlayfs:/overlay       75.6M     60.0K     69.5M   0% /
/dev/mmcblk0p1           63.9M     18.5M     45.4M  29% /boot
tmpfs                   512.0K         0    512.0K   0% /dev

Finally did it with mount tmpfs /tmp -t tmpfs -o remount,size=3482M,nosuid,nodev
Thank you!

thought you wanted a smaller /tmp, not a bigger one ... ?

Nope I never said that. I wanted more size so I can write huge chunks of data in /tmp :wink:

Not 100% sure, but IMHO mounting a USB drive (flash or HD) seems like a better fit for filesharing/torrenting needs as it will allow persistent copies of files that survive across reboots, no? For most internet access speeds USB read speed is probably fast enough...

Honestly as of now I'm extremely happy with this setup besides I rarely ever reboot RPi4.
Note: I just noticed an issue with irqbalance not spreading traffic among all 4 cores. IDK if this is normal but I'll make another post on it.

assuming storage wear is a thing, I'd definitely use RAM for temp storage, esp with lots of reads and writes going on + the speed increase.

there's a reason why Gigabyte i-RAM existed - https://en.wikipedia.org/wiki/I-RAM :wink:

1 Like