tags:

views:

42

answers:

1

Is it possible to allocate big chunk (512Mb-1Gb with 4Gb installed) of real memory without dropping it to swap?

My final intention is to free system memory: os x has a problem when free memory is near 0 — it doesn't try hard to put unused memory to swap and everything becomes very slow trying to get memory. So, I decided that if some process grabs some memory (I grab 1/8 to 1/4 of total system memory) by force, and than frees it, than system will become responsible again. I wrote little ruby script which created and filled memory disk (hdiutil is the only way I found to grab real memory using external utils) and now I decided to rewrite it using just C.

+2  A: 

The mlock function will lock pages into physical memory. I'm not sure what the limits are.

You should be extremely sure you really want to do this. It's not a nice thing to do to the rest of the system.

Ken
Already found reading man pages :) But for someone it will be easier to find answer. I'll explain why I did this in question.
tig
Ah. See also /usr/bin/purge. It doesn't do the same thing, but it will typically free up a lot of memory.
Ken
Ouch! purge is hard, it works good (it freed about 1Gb of unused memory), but it unpleasantly totally freezes system for 20-30 seconds. Though thank you for sharing knowledge!
tig