Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Sys::Ramdisk as regular user on Linux

by szabgab (Priest)
on Sep 27, 2015 at 10:29 UTC ( #1143139=perlquestion: print w/replies, xml ) Need Help??

szabgab has asked for the wisdom of the Perl Monks concerning the following question:

I just wrote some code using Sys::Ramdisk. It worked well on OSX, but when I switched to Linux it complained:
Mount command '/bin/mount -t tmpfs -o size=100m tmpfs /tmp/ramdisk' failed: mount: only root can do that
Is there a way to get it working on Linux without running it as root?

Replies are listed 'Best First'.
Re: Sys::Ramdisk as regular user on Linux
by perlron (Pilgrim) on Sep 27, 2015 at 12:27 UTC
    I was just going through the mount documentation on my Debian GNU/Linux instance. ($man mount)
    Non Super User Mounts
    Normally, only the super user can mount filesystem, However when fstab contains the user options on a line, anyone can mount a filesystem.

    The Great Programmer is one who inspires others to code, not just one who writes great code
Re: Sys::Ramdisk as regular user on Linux
by Anonymous Monk on Sep 27, 2015 at 18:24 UTC

    That's a question for the Sys::Ramdisk author, in truth. Could you describe the use case, however? Is the intention in setting a quota-like size limit for a subdirectory?

      Downloading a zip file, unzipping, analyzing content.
      For now I changed it to use a temporary directory on the disk. Later I'll measure if the ramdisk provides a real speedup and then I'll further investigate how to use it.

        Speedup is unlikely. Dirty pages aren't written to disk immediately. Well, if your archives are of considerable size AND your swap is much faster than regular storage, then you'd see benefits.

        I'd advise setting up your whole system to use tmpfs backed /tmp instead of mucking around with userspace options (FUSE, etc.) Incidentally, there are FUSE filesystems to access archived content.

Re: Sys::Ramdisk as regular user on Linux
by Anonymous Monk on Sep 27, 2015 at 10:53 UTC
    ?have root give perms for that?
Re: Sys::Ramdisk as regular user on Linux
by sundialsvc4 (Abbot) on Sep 28, 2015 at 14:23 UTC

    I candidly agree with Anonymous.   Just use a temporary-file, using something like File::Temp or Data::TemporaryBag.   Then, let the filesystem’s caching mechanism do the rest of the work for you.   There are actually compelling reasons to do this.

    “RAM disks” were a great idea in the old days, when a program’s memory was real and disks were slow.   You could manually carve out a chunk of memory and use it as a disk.   There was no concept that the memory you carved-out could be paged-out.   But today’s OSes do not allow you to do that.   User-space memory is virtual, period.

    If you simply use a temporary file, the OS knows that it is a file and may even know that it is temporary.   Systems like Linux will carve out buffer pages as the least-important use of available RAM and will fill-up unused memory with it, “lazy writing” only when necessary.   This works because the OS knows that this memory is being used for file-buffer purposes.   Whereas, if you instead use a ram-disk, one of two things may happen and neither one of them is good:

    1. You will seize a fixed amount of real storage from the operating system, denying it to all other uses, effectively managing itself ... as though your app actually knew how or deserved such expensive privilege.
    2. You will allocate a large chunk of what the OS simply sees as “your process’s virtual memory,” which it may well page-out.   It does not know that you think of that memory as a file or disk.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1143139]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (9)
As of 2020-06-01 17:12 GMT
Find Nodes?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?

    Results (5 votes). Check out past polls.