[comp.sys.encore] share_malloc under UMAX V

ajk@goanna.cs.rmit.oz.au (Alan Kent) (07/09/90)

I give up. I am trying to use the share_malloc_init(), share_malloc(),
spin_create() and semaphore_create() functions to set everything
up for a parallel index rebuild program (for a research database
system).  My problem is that I calculate the total amount of memory
that I will need and pass this to share_malloc_init(), but
share_malloc() fails near the end of all the allocation code. I
assume it is running out of shared memory to allocate. I am positive
there are no array overflows or that sort of thing - I am simply
doing a series of share_malloc() calls.

For every share_malloc() call, I allocate an additional 16 bytes
for any structures share_malloc() may need internally. I even add an
extra 10k on at the end. But this still does not work reliably
(sometimes it does, sometimes it doesn't). I do not like the solution
of simply adding another 10k again as it might fix the problem for
now, but at some time in the future it will still fail again.

So, can anyone tell me how to calculate the number to pass to
share_malloc_init() given that you know the number of calls to
share_malloc() and the exact amount that needs to be allocated for
each call?

Any help would be much appreciated.

Ps: the code works perfectly when the mallocs suceed. I dont really want
to have to rewrite several thousand lines of code to switch over to the
threads package (not that I know anything about the threads package).

-------------------------------------------------------------------------------
Dr. Alan Kent,                    ACSNET: ajk@goanna.cs.rmit.OZ
Key Center for Knowl. Based Sys., INTERNET: ajk@goanna.cs.rmit.OZ.AU
RMIT Dept. of Comp. Sci.,         JANET: ajk%au.oz.goanna@uk.ac.ukc
GPO BOX 2476 V,                   BITNET: ajk%goanna.cs.rmit.OZ.AU@relay.cs.net
Melbourne, 3001, AUSTRALIA        UUCP: ..!uunet!goanna.cs.rmit.OZ.AU!ajk
Phone: +61 3 660 2992             Fax:   +61 3 662 1617        

maretz@maxzilla.encore.com (Andy Maretz) (07/11/90)

In article <3389@goanna.cs.rmit.oz.au> ajk@goanna.cs.rmit.oz.au (Alan Kent) writes:
>So, can anyone tell me how to calculate the number to pass to
>share_malloc_init() given that you know the number of calls to
>share_malloc() and the exact amount that needs to be allocated for
>each call?

The amount of overhead due to fragmentation will vary depending on
the above information, and also on the order in which requests are
given to share_malloc().  There isn't an easy formula to use without
building into it deep understanding about the algorithm which
share_malloc() uses, and I'm sure that no program will want to do
this.

I'd suggest adding a percentage of extra memory to the pool rather
than adding a fixed constant, which is to say, request 15% or 20%
more than the real need rather than 10K more.  In practice, I've
never seen an application that suffered more than about 20%
fragmentation with share_malloc().  The cost of overestimating the
share_malloc() pool is very low in terms of impact on real and
virtual memory, so I think you'd be OK padding pretty generously.

Andy Maretz