Can you throttle the bandwidth to a tmpfs based ramdisk

bandwidthcgroupsiolimitramdisk

I created a ramdisk using tmpfs as follows:

sudo mount -t tmpfs -o size=1024m tmpfs /myramdisk

I was looking into cgroup blkio subsystem bandwidth limits "read_bps_device" and "write_bps_device" but they seem to require the major and minor number of your block device that you want to throttle access to.

Is there any way to achieve a similar bandwidth limit to the in-memory tmpfs ramdisk?

UPDATE: I found a roundabout hacky way of accomplishing this. I first nfs export the ramdisk mount. Then nfs mount it over loopback on the same machine. I then use linux network traffic shaping to set bandwidth limits. This seems to provide what I need. I'm in the process of performing some measurements to see the penalty this hideous layering entails. I'll update info on that in a few days.

Best Answer

stat or /proc/[PID]/mountinfo should still tell you what the device numbers are:

[root@XXXlin01 block]# stat --printf="%d" /tmp/mnt; echo
24
[root@XXXlin01 block]# stat --printf="%d" /tmp/mnt2; echo
25
[root@XXXlin01 block]# grep "/tmp/mnt" /proc/22195/mountinfo
40 20 0:24 / /tmp/mnt rw,relatime - tmpfs none rw
41 20 0:25 / /tmp/mnt2 rw,relatime - tmpfs none rw

Both outputs show 0:25 and 0:24 as the device numbers in question. The "0" device number is used for "unnamed" mounts (such as tmpfs, sysfs, nfs, procfs, etc). For example, here is an NFS mount:

[root@XXXlin01 block]# grep "/LinuxHome" /proc/22195/mountinfo
39 36 0:23 / /home/jad87 rw,relatime - nfs duhsnas-xxx:/ifs/Application\040File\040Shares/DUHS/LinuxHomeDir_fs/jad87 rw,vers=3,rsize=4096,wsize=4096,namlen=255,soft,proto=tcp,timeo=14,retrans=2,sec=sys,mountaddr=10.1x.92.106,mountvers=3,mountport=300,mountproto=udp,local_lock=none,addr=10.1x.92.106
42 36 0:26 / /home/tsa20 rw,relatime - nfs 10.1x.92.117:/ifs/Application\040File\040Shares/DUHS/LinuxHomeDir_fs/tsa20 rw,vers=3,rsize=4096,wsize=4096,namlen=255,soft,proto=tcp,timeo=14,retrans=2,sec=sys,mountaddr=10.1x.92.117,mountvers=3,mountport=300,mountproto=udp,local_lock=none,addr=10.1x.92.117

The NFS mounts above are 0:23 and 0:26 respectively.

Related Question