I think I want to use of mmap and perlio

M

Mark Seger

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
 
M

Mark Seger

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
 
T

Tim S

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top