msync - using MS_SYNC and MS_ASYNC interleaved - Linux

This is a discussion on msync - using MS_SYNC and MS_ASYNC interleaved - Linux ; I've the following situation: A file is mapped using mmap. I must update 2 areas inside the file which are typically mapped into 2 different memory areas (data area + application header). After changing the memory contents a call to ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: msync - using MS_SYNC and MS_ASYNC interleaved

  1. msync - using MS_SYNC and MS_ASYNC interleaved

    I've the following situation:

    A file is mapped using mmap. I must update 2 areas inside the file
    which are typically mapped into 2 different memory areas (data area +
    application header). After changing the memory contents a call to
    msync(MS_SYNC) would guarantee that all data is stored on disc.

    But du to the fact that 1 have 2 separtly mapped areas, I would have
    to call msync twice. When specifying MS_SYNC for both calls I would
    have to wait 2 times for IO completion. So I would prefer to use
    msync( MS_ASYNC) for the data area and a second msync(MS_SYNC) for the
    header. This would cause only one I/O wait.

    I could not find an answer to the following questions:

    a) Is there any gurantee, that after the second msync(MS_SYNC) all
    previous issued msync(MS_ASYNC) are completed too ? (Note: The memory
    is mapped to the same file, but mmaped memory does not really use
    filedescriptors so I do not know whether this fact can be known by the
    kernel. Und note too, that the memory address range for the two msyncs
    will be different)

    b) Is there any defined order to the write operations I could expect
    (Is msync #1 performed before the secon msync ?) ?

    c) alternativly: Is there any service that I can call at a random
    point in time to ensure that all previous issued msync(MS_ASYNC)
    operations have been completed ?

    Thanks for information or pointers to some documentation /
    description.

    Klaus

  2. Re: msync - using MS_SYNC and MS_ASYNC interleaved

    Klaus Klingenbusch writes:
    > A file is mapped using mmap. I must update 2 areas inside the file
    > which are typically mapped into 2 different memory areas (data area +
    > application header). After changing the memory contents a call to
    > msync(MS_SYNC) would guarantee that all data is stored on disc.
    >
    > But du to the fact that 1 have 2 separtly mapped areas, I would have
    > to call msync twice. When specifying MS_SYNC for both calls I would
    > have to wait 2 times for IO completion. So I would prefer to use
    > msync( MS_ASYNC) for the data area and a second msync(MS_SYNC) for the
    > header. This would cause only one I/O wait.
    >
    > I could not find an answer to the following questions:


    [...]

    > c) alternativly: Is there any service that I can call at a random
    > point in time to ensure that all previous issued msync(MS_ASYNC)
    > operations have been completed ?


    Keep the descriptor and use fsync (or fdatasync). For 'current'
    kernels (2.6.23), both fsync and msync end up calling the same
    low-level routine [XX].

    [XX] I have cursory checked this a couple of days
    ago. Consequently, you should either test that it works or
    read the code more thoroughly than I did before really relying
    on this (Linux-only).

+ Reply to Thread