I think I want to use of mmap and perlio

Discussion in 'Perl Misc' started by Mark Seger, Jun 15, 2007.

  1. Mark Seger

    Mark Seger Guest

    I'm trying to find an easy way to hog a large chunk of memory, about
    4GB, thereby reducing the amount available to the rest of the system for
    caches. I know I could do this by physically removing some dimms, but
    the machine is too far away! :cool:

    Anyhow I thought a nifty way to do this might be by using the mmap
    perlio layer. I first created a large file by specifying:

    open FILE, '>:mmap', '/tmp/mmap.dat' or die;

    and wrote a 1GB worth of data to it. Then I opened it with:

    open FILE, '<:mmap', '/tmp/mmap.dat' or die;

    and did $record=<FILE> and sure enough, my mmap'd memory in
    /proc/meminfo went up. However, as soon as the read finished the memory
    was released and I want to hang onto it. Then I just tried playing
    around with sysread on the file handle but not matter what I specified
    for record size or offset it always read 7 bytes. Clearly I don't
    understand the semantics of how this works and couldn't get any more
    details in the documentation.

    So the question is, it is possible to open my mmap file, perform some
    operation on it and hold onto the memory? My intent would then be to do
    a long sleep.

    In addition to trying to figure out how mmap works because it does seem
    to be useful, I also wonder if anyone can suggest a better way to grab
    some memory and if not, so be it.

    -mark
    Mark Seger, Jun 15, 2007
    #1
    1. Advertising

  2. Mark Seger

    Mark Seger Guest

    > In addition to trying to figure out how mmap works because it does seem
    > to be useful, I also wonder if anyone can suggest a better way to grab
    > some memory and if not, so be it.


    If anyone cares, all I had to do was append mem=4g to the kernel line in
    my boot loader. duh!
    -mark
    Mark Seger, Jun 15, 2007
    #2
    1. Advertising

  3. Mark Seger

    Tim S Guest

    Mark Seger wrote:


    > So the question is, it is possible to open my mmap file, perform some
    > operation on it and hold onto the memory? My intent would then be to do
    > a long sleep.
    >
    > In addition to trying to figure out how mmap works because it does seem
    > to be useful, I also wonder if anyone can suggest a better way to grab
    > some memory and if not, so be it.
    >
    > -mark


    Hi

    Simpler:

    malloc() and mlock().

    HTH

    Tim
    Tim S, Jun 15, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gordon

    perlio problem? redhat 9, perl 5.8.0

    gordon, Jun 24, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    123
    gordon
    Jun 27, 2003
  2. Dave
    Replies:
    0
    Views:
    135
  3. Bo Lindbergh

    PerlIO omission

    Bo Lindbergh, Jun 8, 2006, in forum: Perl Misc
    Replies:
    6
    Views:
    112
    Charles DeRykus
    Jun 8, 2006
  4. Replies:
    2
    Views:
    141
  5. Peter J. Holzer

    IO::Select and PerlIO

    Peter J. Holzer, Nov 19, 2012, in forum: Perl Misc
    Replies:
    9
    Views:
    399
    Peter J. Holzer
    Nov 24, 2012
Loading...

Share This Page