unable to resize mmap object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fabiano Sidler

    #1

    unable to resize mmap object

    Hi folks!

    I created an mmap object like so:
    --- snip ---
    from mmap import mmap,MAP_ANONYM OUS,MAP_PRIVATE
    fl = file('/dev/zero','rw')
    mm = mmap(fl.fileno( ), 1, MAP_PRIVATE|MAP _ANONYMOUS)
    --- snap ---

    Now, when I try to resize mm to 10 byte
    --- snip ---
    mm.resize(10)
    --- snap ---
    I get an EnvironmentErro r:[Errno 22] Invalid argument.

    How can I implement a resizeable anonymous memory mapping?
    Thanks for your reply!

    F. Sidler
  • Serge Orlov

    #2
    Re: unable to resize mmap object


    Fabiano Sidler wrote:[color=blue]
    > Hi folks!
    >
    > I created an mmap object like so:
    > --- snip ---
    > from mmap import mmap,MAP_ANONYM OUS,MAP_PRIVATE
    > fl = file('/dev/zero','rw')
    > mm = mmap(fl.fileno( ), 1, MAP_PRIVATE|MAP _ANONYMOUS)
    > --- snap ---
    >
    > Now, when I try to resize mm to 10 byte
    > --- snip ---
    > mm.resize(10)
    > --- snap ---
    > I get an EnvironmentErro r:[Errno 22] Invalid argument.[/color]

    Just a guess: try a new size argument that is multiple of page size.

    Comment

    • Fabiano Sidler

      #3
      Re: unable to resize mmap object

      On Sunday 30 April 2006 21:06, Serge Orlov wrote:[color=blue]
      > Fabiano Sidler wrote:[color=green]
      >> Now, when I try to resize mm to 10 byte
      >> --- snip ---
      >> mm.resize(10)
      >> --- snap ---
      >> I get an EnvironmentErro r:[Errno 22] Invalid argument.[/color]
      >
      > Just a guess: try a new size argument that is multiple of page size.[/color]

      No, doesn't work neitzer. :(

      Thank you anyway for the idea!

      Comment

      • Carl Banks

        #4
        Re: unable to resize mmap object

        Fabiano Sidler wrote:[color=blue]
        > Hi folks!
        >
        > I created an mmap object like so:
        > --- snip ---
        > from mmap import mmap,MAP_ANONYM OUS,MAP_PRIVATE
        > fl = file('/dev/zero','rw')
        > mm = mmap(fl.fileno( ), 1, MAP_PRIVATE|MAP _ANONYMOUS)
        > --- snap ---
        >
        > Now, when I try to resize mm to 10 byte
        > --- snip ---
        > mm.resize(10)
        > --- snap ---
        > I get an EnvironmentErro r:[Errno 22] Invalid argument.
        >
        > How can I implement a resizeable anonymous memory mapping?
        > Thanks for your reply![/color]

        Bug in Python. Here's the reason (from the changelog):

        - Bug #728515: mmap.resize() now resizes the file on Unix as it did
        on Windows.

        The mmap module resizes the file in question by calling ftruncate.
        Only problem is, you can't truncate /dev/zero. I'm going to file this
        as a bug; probably on Unix mmap should only resize the file if it's a
        regular file (so fstat it first).

        Frankly, I'm not so sure matching Windows behavior is a great idea.
        mmap module seems to be having an identity crisis. Is it a low-level
        system call, or a high-level, OS-independent way to access files as
        blocks of memory? The modules is moving towards the latter (what with
        Unix mmap accepting ACCESS-style flags, and now this file-resizing
        behavior). I actually favor a two-level approach similar to file I/O:
        there would low-level system calls in the os module, and high-level
        mmap object. (The high-level object would go all the way. It would
        accept a filename rather than a file descriptor, anonymous blocks would
        be handled OS-independently, rather than mapping /dev/zero, and so on.)

        Carl Banks

        Comment

        • Georg Brandl

          #5
          Re: unable to resize mmap object

          Carl Banks wrote:
          [color=blue]
          > Frankly, I'm not so sure matching Windows behavior is a great idea.
          > mmap module seems to be having an identity crisis. Is it a low-level
          > system call, or a high-level, OS-independent way to access files as
          > blocks of memory? The modules is moving towards the latter (what with
          > Unix mmap accepting ACCESS-style flags, and now this file-resizing
          > behavior). I actually favor a two-level approach similar to file I/O:
          > there would low-level system calls in the os module, and high-level
          > mmap object. (The high-level object would go all the way. It would
          > accept a filename rather than a file descriptor, anonymous blocks would
          > be handled OS-independently, rather than mapping /dev/zero, and so on.)[/color]

          I'm sure that we will gladly accept a patch implementing this approach.

          Cheers,
          Georg

          Comment

          Working...