Memory Mapped I/O vs Swap? - Linux

This is a discussion on Memory Mapped I/O vs Swap? - Linux ; Dear all, I tried developing a LU Factorization program that makes use of large amount of memory (the matrix size is 8192 x 8192), such that the memory usage (>512MB in this case) is greater than the amount of memory ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Memory Mapped I/O vs Swap?

  1. Memory Mapped I/O vs Swap?

    Dear all,

    I tried developing a LU Factorization program that makes use of large amount
    of memory (the matrix size is 8192 x 8192), such that the memory usage
    (>512MB in this case) is greater than the amount of memory the machine has
    (512MB). I wrote two versions, one is using ordinary malloc(), and the
    second one maps the 512MB matrix to a file through memory mapped I/O. The
    algorithm of the two programs is the same. Results taken show that the
    memory mapped I/O version is 70% faster than the one using malloc(). I'd
    like to ask if there are any reasons behind that makes memory mapped I/O
    working much better than the OS swap in this case? Are they adopting
    different swapping strategies?

    Many thanks in advance!

    Best Regards,
    LaBird (Benny)
    [Email: Please remove all underscores for the correct email.]



  2. Re: Memory Mapped I/O vs Swap?

    On Jul 27, 4:23 am, "LaBird" wrote:

    > I tried developing a LU Factorization program that makes use of large amount
    > of memory (the matrix size is 8192 x 8192), such that the memory usage
    > (>512MB in this case) is greater than the amount of memory the machine has
    > (512MB). I wrote two versions, one is using ordinary malloc(), and the
    > second one maps the 512MB matrix to a file through memory mapped I/O. The
    > algorithm of the two programs is the same. Results taken show that the
    > memory mapped I/O version is 70% faster than the one using malloc(). I'd
    > like to ask if there are any reasons behind that makes memory mapped I/O
    > working much better than the OS swap in this case? Are they adopting
    > different swapping strategies?


    I would say you've encountered an oddity. The only possible rational
    explanation I can think of for this is if the the memory mapped file
    is on a device that is much faster than your swap device. Otherwise, I
    would think profiling the kernel activity in both cases would likely
    show a bug or defect of some kind.

    An anonymous mapped file should be the same as paging through swap. A
    named mapped file should be the same as an anonymous one except on a
    particular device rather than swap.

    DS


  3. Re: Memory Mapped I/O vs Swap?

    Dear David,

    "David Schwartz" wrote in message
    news:1185653009.883506.3860@i38g2000prf.googlegrou ps.com...
    > I would say you've encountered an oddity. The only possible rational
    > explanation I can think of for this is if the the memory mapped file
    > is on a device that is much faster than your swap device. Otherwise, I
    > would think profiling the kernel activity in both cases would likely
    > show a bug or defect of some kind.
    >
    > An anonymous mapped file should be the same as paging through swap. A
    > named mapped file should be the same as an anonymous one except on a
    > particular device rather than swap.
    >
    > DS
    >


    Many thanks, and I believe you are right. I have tried two other
    applications (Matrix Multiply and Red Black SOR), the swap version is faster
    than the MMIO version by 15% and 30% respectively.
    But for LU, the performance of the swap version seems to fluctuate a lot
    while it is much slower than MMIO. Just wonder why this is so? (I am using
    Fedora Core 1).

    Best Regards,
    LaBird (Benny).
    [Email: Please remove all underscores for the correct email.]



  4. Re: Memory Mapped I/O vs Swap?

    "LaBird" writes:

    > Dear David,
    >
    > "David Schwartz" wrote in message
    > news:1185653009.883506.3860@i38g2000prf.googlegrou ps.com...
    >> I would say you've encountered an oddity. The only possible rational
    >> explanation I can think of for this is if the the memory mapped file
    >> is on a device that is much faster than your swap device. Otherwise, I
    >> would think profiling the kernel activity in both cases would likely
    >> show a bug or defect of some kind.
    >>
    >> An anonymous mapped file should be the same as paging through swap. A
    >> named mapped file should be the same as an anonymous one except on a
    >> particular device rather than swap.
    >>
    >> DS
    >>

    >
    > Many thanks, and I believe you are right. I have tried two other
    > applications (Matrix Multiply and Red Black SOR), the swap version is faster
    > than the MMIO version by 15% and 30% respectively.
    > But for LU, the performance of the swap version seems to fluctuate a lot
    > while it is much slower than MMIO. Just wonder why this is so? (I am using
    > Fedora Core 1).


    The OS readahead rules probably differ between these types of
    mappings. Try playing with madvise() and/or posix_madvise().

    --
    Måns Rullgård
    mans@mansr.com

  5. Re: Memory Mapped I/O vs Swap?

    Dear Måns,

    "Måns Rullgård" wrote in message
    news:yw1x7ioh2fuk.fsf@thrashbarg.mansr.com...
    >
    > The OS readahead rules probably differ between these types of
    > mappings. Try playing with madvise() and/or posix_madvise().
    >
    > --
    > Måns Rullgård
    > mans@mansr.com


    Thanks a lot, actually I am also considering madvise() too ... do you mean
    using the info from madvise() to implement one's own swapping / prefetching
    rules at the application level for optimal performance?

    Best Regards,
    (LaBird) Benny.
    [Email: Please remove all underscores for the correct email.]



+ Reply to Thread