Skip site navigation (1) Skip section navigation (2)

Re: memory management suggestion

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>
Cc: pgsql-hackers <pgsql-hackers(at)postgreSQL(dot)org>, Jan Wieck <wieck(at)debis(dot)com>
Subject: Re: memory management suggestion
Date: 2000-09-30 02:47:54
Message-ID: 200009300247.WAA03682@candle.pha.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackers
Where are we on this?


> 
>   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://candle.pha.pa.us
  pgman(at)candle(dot)pha(dot)pa(dot)us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Responses

pgsql-hackers by date

Next:From: Bruce MomjianDate: 2000-09-30 03:05:13
Subject: Re: Database Management/Design terms, glossary of
Previous:From: Bruce MomjianDate: 2000-09-30 02:45:32
Subject: Re: [HACKERS] Re: Join/table alias bug

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group