IPC shared memory question - Linux

This is a discussion on IPC shared memory question - Linux ; Is there any way to use shared memory without using a file. Or is it possible to turn off the the file system writes for a mmaped file. I'm a little bit scared that the the occasional file writes are ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: IPC shared memory question

  1. IPC shared memory question

    Is there any way to use shared memory without using a file.
    Or is it possible to turn off the the file system writes for a mmaped
    file.

    I'm a little bit scared that the the occasional file writes are
    killing the performance
    i get from shared memory (instead of using a socket).

    By the way there is no child/parent relation between the two
    processes, so i can't
    use "minherit"

  2. Re: IPC shared memory question

    scholz.lothar@gmail.com writes:

    > Is there any way to use shared memory without using a file.


    You could use SYSV shared memory. man shmget and its references.

    > Or is it possible to turn off the the file system writes for a mmaped
    > file.


    Not sure. BSD has the MAP_NOSYNC flag for mmap (and a corresponding
    flag for madvise) but I don't see anything similar for Linux.

    > I'm a little bit scared that the the occasional file writes are
    > killing the performance
    > i get from shared memory (instead of using a socket).
    >
    > By the way there is no child/parent relation between the two
    > processes, so i can't
    > use "minherit"


  3. Re: IPC shared memory question

    On 2008-10-04, scholz.lothar@gmail.com wrote:
    > Is there any way to use shared memory without using a file.


    /dev/shm is shmfs, a ramdisk. as with all ramdisks if ram is all used
    up something will get swapped to disk (including ramdisk contents)
    but other than that it's a ramdisk.

    > Or is it possible to turn off the the file system writes for a mmaped
    > file.


    possibly.

    > I'm a little bit scared that the the occasional file writes are
    > killing the performance
    > i get from shared memory (instead of using a socket).


    it shouldn't have a large effect, it is possible to read the new value
    of the shared memory before it is recorded on the disk.

    > By the way there is no child/parent relation between the two
    > processes, so i can't
    > use "minherit"


    also have a look in LPG for other ways of using shmfs.

    Bye.
    Jasen

  4. Re: IPC shared memory question

    scholz.lothar@gmail.com writes:
    > Is there any way to use shared memory without using a file.


    In addition to the already mentionend SysV IPC facility, there is a
    newer POSIX interface for shared memory (shm_open). A third option
    would be to use a file residing on a tmpfs. I usually prefer the
    latter: It is IMO easier to use then shmget & friends and supported by
    more kernels than the other interface.

    > Or is it possible to turn off the the file system writes for a
    > mmaped file.
    >
    > I'm a little bit scared that the the occasional file writes are
    > killing the performance i get from shared memory (instead of using a
    > socket).


    There is no reason to. When you are not using a file as backing store
    for some set of pages, the kernel will use 'the swapspace' instead,
    should it become necessary to free memory for something else. Ordinary
    disk I/O is done asynchronously by the kernel as it sees fit, trying
    to avoid it as much as possible.

  5. Re: IPC shared memory question

    Jasen Betts writes:
    > On 2008-10-04, scholz.lothar@gmail.com wrote:
    >> Is there any way to use shared memory without using a file.

    >
    > /dev/shm is shmfs, a ramdisk. as with all ramdisks if ram is all used
    > up something will get swapped to disk (including ramdisk contents)
    > but other than that it's a ramdisk.


    The 'shared memory file system' (or 'temporary filesystem') is not 'a
    ramdisk', ie a memory-backed block device which can (among other
    things) contain a filesystem. Objects stored on a shmfs live in the
    various kernel caches for these objects, eg the page cache (for 'file
    contents').

+ Reply to Thread