Re: memory management suggestion

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: memory management suggestion
Дата
Msg-id 200006130007.UAA11564@candle.pha.pa.us
обсуждение исходный текст
Ответы Re: memory management suggestion  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: memory management suggestion  (Karel Zak <zakkr@zf.jcu.cz>)
Список pgsql-hackers
Can anyone comment on this work?  Karel?

> 
>   I start detail study of PG's memory management (because, I want remove
> prepared query-cache to shmem (more is in my old discussion with Jan)).
> 
>  I see current code in the aset.c and I found small non-effective memory 
> usage.
> 
> 
>  Description:
> 
>  The postgresql use blocks for allocation. These blocks are inward
> organized/split via chunks. 
> 
>  If a palloc() wants memory:
>    1) try use some chunk in a freelist of chunks
>    2) try use free space in an actual block
>    3) if wanted space is large - allocate specific one-block-for-one-chunk
>    4) if previous options are not possible allocate new block
>  
>  A problem:
> 
>    - if use option 4) and already exist (old) block (but space in this block 
> is less than wanted space) current algorithm _skip_ and not _use_ this small
> space in old block. For a detail see the 'else' on line 327 in aset.c.
> 
>   I test it and average is 8-10b per a block (but max is 1000b) - large is 
> this space if a palloc() wants bigger space. 
> 
>  A solution:
> 
>   Create from this non-used residual space chunk and remove it into free 
>   chunk list. 
>  
> 
>  Comments?
> 
>                         Karel
> 
> 
> -----> A tested patch (hmm, we are freeze, possible for 7.0.?):
> 
> *** aset.orig.c    Thu Apr 13 18:33:45 2000
> --- aset.c    Thu Apr 20 18:45:50 2000
> ***************
> *** 323,326 ****
> --- 323,346 ----
>           else
>           {
> +             int     oldfree = set->blocks->endptr - set->blocks->freeptr;
> +         
> +             /*
> +              * Try create from residual space in block free chunk
> +              */
> +             if (oldfree > MAXALIGN(1) + ALLOC_CHUNKHDRSZ) {
> +                 
> +                 int x_fidx = AllocSetFreeIndex(oldfree - ALLOC_CHUNKHDRSZ );
> +                 
> +                 chunk = (AllocChunk) (set->blocks->freeptr);
> +                 chunk->size = oldfree - ALLOC_CHUNKHDRSZ;
> +                 
> +                 /* put chunk into freelist */
> +                 chunk->aset = (void *) set->freelist[x_fidx];
> +                 set->freelist[x_fidx] = chunk;
> +                 
> +                 /* unset free space in block */                
> +                 set->blocks->freeptr = set->blocks->endptr;
> +             }
> +         
>               /* Get size of prior block */
>               blksize = set->blocks->endptr - ((char *) set->blocks);
> 
> 
> 
> 


--  Bruce Momjian                        |  http://www.op.net/~candle pgman@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Proposal for fixing intra-query memory leaks
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: memory management suggestion