[haiku-development] Re: Writing Device Drivers - CRAM - Problem Malloc()

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sat, 20 Aug 2011 14:08:03 +0200

On 2011-08-20 at 05:13:33 [+0200], Rene Gollent <anevilyak@xxxxxxxxx> wrote:
> On Fri, Aug 19, 2011 at 11:03 PM, Earl Pottinger
> <earl_colby_pottinger@xxxxxxxxx> wrote:
> >
> > Does malloc() have a lot of overhead or am I doing something wrong?
> >
> > If I try to create a char[] array that is 1GB or greater on my 2GB laptop 
> > or the 3GB desktop the object code created will no load.
> > I tried to get around this problem by using malloc().  Since the 
> > Data_Tracks were 1MB in I started with 1MB allocations, but even on a 3GB 
> > machine with no applications I get allocation errors after 1.6GB of 
> > allocation.
> > Why?
> 
> You're most likely exhausting your virtual address space. Bear in
> mind, the address space is split in half where 2GB goes to the kernel
> and 2GB to userland, and as such that's the most you'd be able to
> allocate assuming nothing else was taking up the space.  Considering
> that that area is also shared by loaded executable images, various
> bookkeeping structures, etc., in practice you're not going to be able
> to actually allocate all that at once.

Assuming that the question was referring to a driver context, I have to add 
that it is not advisable to do allocations of that order of magnitude. 
Exhausting the kernel address space can lead to the kernel no longer being 
able to allocate memory for essential tasks, which will cause the system to 
go down the drain. To prevent that all caches implemented in kernelland (at 
least all caches of relevant size) should register as low resource handlers 
and free up resources, when requested.

CU, Ingo

Other related posts: