|
11 | 11 | * Portions Copyright (c) 1994, Regents of the University of California
|
12 | 12 | *
|
13 | 13 | * IDENTIFICATION
|
14 |
| - * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.52 2003/08/04 02:40:08 momjian Exp $ |
| 14 | + * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.53 2003/09/13 22:25:38 tgl Exp $ |
15 | 15 | *
|
16 | 16 | * NOTE:
|
17 | 17 | *This is a new (Feb. 05, 1999) implementation of the allocation set
|
@@ -650,32 +650,29 @@ AllocSetAlloc(MemoryContext context, Size size)
|
650 | 650 | }
|
651 | 651 | else
|
652 | 652 | {
|
653 |
| -/* Get size of prior block */ |
654 |
| -blksize=set->blocks->endptr- ((char*)set->blocks); |
655 |
| - |
656 | 653 | /*
|
657 |
| - * Special case: if very first allocation was for a large |
658 |
| - * chunk (or we have a small "keeper" block), could have an |
659 |
| - * undersized top block. Do something reasonable. |
| 654 | + * Use first power of 2 that is larger than previous block, |
| 655 | + * but not more than the allowed limit. (We don't simply double |
| 656 | + * the prior block size, because in some cases this could be a |
| 657 | + * funny size, eg if very first allocation was for an odd-sized |
| 658 | + * large chunk.) |
660 | 659 | */
|
661 |
| -if (blksize<set->initBlockSize) |
662 |
| -blksize=set->initBlockSize; |
663 |
| -else |
664 |
| -{ |
665 |
| -/* Crank it up, but not past max */ |
| 660 | +Sizepblksize=set->blocks->endptr- ((char*)set->blocks); |
| 661 | + |
| 662 | +blksize=set->initBlockSize; |
| 663 | +while (blksize <=pblksize) |
666 | 664 | blksize <<=1;
|
667 |
| -if (blksize>set->maxBlockSize) |
668 |
| -blksize=set->maxBlockSize; |
669 |
| -} |
| 665 | +if (blksize>set->maxBlockSize) |
| 666 | +blksize=set->maxBlockSize; |
670 | 667 | }
|
671 | 668 |
|
672 | 669 | /*
|
673 | 670 | * If initBlockSize is less than ALLOC_CHUNK_LIMIT, we could need
|
674 |
| - * more space... |
| 671 | + * more space... but try to keep it a power of 2. |
675 | 672 | */
|
676 | 673 | required_size=chunk_size+ALLOC_BLOCKHDRSZ+ALLOC_CHUNKHDRSZ;
|
677 |
| -if (blksize<required_size) |
678 |
| -blksize=required_size; |
| 674 | +while (blksize<required_size) |
| 675 | +blksize<<=1; |
679 | 676 |
|
680 | 677 | /* Try to allocate it */
|
681 | 678 | block= (AllocBlock)malloc(blksize);
|
|