First, I create a RAM disk, like so:
diskutil erasevolume APFS RAM_Disk_4096MB $(hdiutil attach -nomount ram://8388608)
At first it occupies no RAM (system memory), as it is empty. When I copy/move files to it, in
Memory section process
Memory column (usage) becomes exactly what the size of a file I copied is (as verified by
Used: section for that RAM disk volume).
The problem is that when I delete a file from my RAM disk,
Memory used by
diskimages-helper does not go away. The only way to free it up is to either
eject the RAM disk volume or kill the
diskimages-helper process (practically the same thing).
From my research, as I continue to copy/move/remove files to/from my RAM disk the
diskimages-helper memory usage grows untill it hits the 4GB mark (the amount allocated to the RAM disk). Once again, deleting files from RAM disk does not free up any memory used by
The question is then, how can I get my RAM disk/
diskimages-helper process to only use the memory needed? And subsequently release whatever memory used to be allocated to now deleted files? Command line answers are preffered.
Note: RAM disk file system ideally has to be APFS or another sparse file capable file system.
To be clear, I'm not looking for a way to limit
diskimages-helper's memory usage, as I can do so by simply changing my RAM disk size. The intention is to get
diskimages-helper to only use whatever amount of memory is actually occupied by the files currently stored on the RAM disk (similar to how RAM disk/tmpfs works on Linux).
There was a similarly looking question with a key difference though, as this one is solved by simply ejecting the ram disk which frees up allocated memory. How do I get the memory allocated to a ramdisk back?
Potentially unimportant background: I use a streaming app called infuse, and it caches the entire movie/episode of whatever I watch/stream from my server. I do not want my already worn out SSD to carry the burden, so I'm using RAM disk for this app's cache directory. Please refrain from suggesting app-specific fixes, alternative apps, and such, the purpose of this question is to sort out RAM disk and diskimages-helper behaviour.