Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Aug 1997 13:50:26 +1000
From:      Stephen McKay <syssgm@dtir.qld.gov.au>
To:        freebsd-hackers@freebsd.org
Cc:        syssgm@dtir.qld.gov.au
Subject:   Re: special malloc needs... 
Message-ID:  <199708260350.NAA25140@ogre.dtir.qld.gov.au>
In-Reply-To: <19970825222008.PD53308@uriah.heep.sax.de> from J Wunsch at "Mon, 25 Aug 1997 20:20:08 %2B0000"
References:  <199708251630.JAA18241@dragon.awen.com> <19970825222008.PD53308@uriah.heep.sax.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Monday, 25th August 1997, J Wunsch wrote:

>As Mike Burgett wrote:
>
>> Is there any way to malloc memory (from userland code) that is at
>> specific offsets from each other in physical memory (i.e. 2 chunks
>> exactly XXM apart in physical RAM) or failing that, to allocate a
>> very large (>32M) chunk of contig physical RAM? (again, from
>> userland?)
>
>No, you can't do this.  You get virtual memory, nothing else.  It's
>not even backed with physical memory at all when you've got it.
>
>What the h*ck would you need this in a userland program?

I can think of a cache related reason.  Accessing 2 arrays in parallel
can thrash the L2 cache depending on how far apart they are (as well as
the cache size and cache organisation).  Mainframe Fortran programmers
think about this stuff.  Normally I don't.

John Dyson's page colouring code should automatically help if the arrays
are spaced properly in *virtual* memory, but it is no iron-clad guarantee.
I think this is the best that can be done in FreeBSD if I'm right about why
Mike wants this feature.

>> Browsing the kernel/dd sources, I found contigmalloc, but it doesn't
>> appear to be available in any of the libs... (kernel only?)
>
>Kernel only, and only likely to succeed when being called at kernel
>init time.  This is natural, if you think about it.  Once the physical
>memory is fragmented, you cannot get a guarantee for contiguous memory
>at all.

It's the wired down pages that are the problem (as far as I can see).
The pageable stuff can just be paged out to make room if a long enough
stretch can be found.  I can't think off hand how it would be possible
in general to move wired pages, or even a useful subset of wired pages.

Luckily, physically contiguous memory isn't necessary for optimising
cache use.  Lots of pages map to the same part of the cache, and can be
used instead of the next physically adjacent page.

Stephen.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199708260350.NAA25140>