8

I'm wondering if there is any way to specify the size of RAM cache used to store ramfs, tmpfs?

When I look at /proc/, I can't find anything about ramfs size.

Nick
  • 89
  • 1
  • 1
  • 2
  • did you checked #cat /proc/meminfo –  Jan 28 '13 at 06:44
  • I already check /proc/meminfo and /proc/vmstat but there are no field about ramfs. –  Jan 28 '13 at 07:09
  • `ramfs` and `tmpfs` dynamically use/acquire RAM based on need. They do not have a fixed or hard allocation of RAMemory. Hence there is no way to specify any allocation size like `ramdisk` has. – sawdust Jan 28 '13 at 10:04
  • You can simply use `df` or `du`, have a look to my answer below. – jaume Feb 06 '13 at 19:01
  • A good talk about ramdisk(initrd), vs ramfs(initramfs), vs tmpfs and their various behavior in terms of memory allocation and usage can be found at the following article written by the guys from the Tin Hat and Tor-ramdisk projects: http://opensource.dyc.edu/ramdisk-vs-ramfs – dustymabe Oct 03 '13 at 17:35

1 Answers1

7

From http://www.kernel.org/doc/Documentation/filesystems/tmpfs.txt:

Further on you can check the actual RAM+swap use of a tmpfs instance with df(1) and du(1).

So simply use df or du (you can also use them for ramfs):

$ df | grep tmpfs
tmpfs             205032      1136    203896   1% /run

so 1136 KB is in use.

$ sudo du -s /run
[sudo] password for jaume: 
1416    /run

so 1416 KB is in use.

Thats's interesting... df and du report different sizes. What is happening here and which one is right?

/run has a subfolder called /run/shm, which is itself a separate tmpfs filesytem (although shown as none):

$ df | grep run
tmpfs             205032      1136    203896   1% /run
none                5120         0      5120   0% /run/lock
none              512572       280    512292   1% /run/shm

Adding both amounts you get the size reported by du:

$ expr 1136 + 280
1416

So the whole story is that 2 tmpfs filesystems use 1416 KB.

(Here's another reason why du and df outputs may differ.)

jaume
  • 5,487
  • 1
  • 26
  • 33
  • `tmpfs` will be backed by swap in case of running low on RAM. Is there some simple way to figure out how much RAM / swap is used by tmpfs? – Mikko Rantalainen May 10 '23 at 18:34
  • 1
    @MikkoRantalainen Not that I know of, but it's possible there's indeed a simple way, you may want to ask a new question. – jaume May 10 '23 at 19:39