From: Andrei Maxim Date: 2008-04-16T23:38:34+09:00 Subject: Re: ruby memory allocation On 16.04.2008, at 16:50, M. Edward (Ed) Borasky wrote: > Emanuele Ricci wrote: >> I just discovered that ruby allocates memory in 8Mb chunks. >> Forgive my ignorance. >> Is there a way to change this behaviour? Since my app runs in an >> environment with very strict memory constraints, a memory spike of >> 8Mb >> can be lethal... >> I would change it to a lower figure. >> It doesn't matter if I have to patch my ruby source files in order to >> achieve this goal. >> Any clues? >> Thank you in advance, >> Emanuele Ricci. > > That may not be Ruby's fault entirely. In many cases, the size of > memory chunks delivered by "malloc" and its friends is determined by > the compiler or operating system. I've worked on systems where you > got the next higher power of two, for example. If you asked for > 5,000 you got 8192, if you asked for 65 you got 128, etc. And many > modern systems won't give you less than a physical page. > > A physical page on most x86 operating systems is 4096 bytes, so 8 MB > is 2048 pages. There is also an option to run larger pages in Linux. > What OS and architecture are you on? From _why's article "The Fully Upturned Bin" [1] I see that by default Ruby allocates a minimum of 8 MB for the object heap. Isn't this related to the OP's question? [1]: http://whytheluckystiff.net/articles/theFullyUpturnedBin.html