|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.40 2004/02/06 19:36:18 wieck Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/storage/buffer/freelist.c,v 1.41 2004/02/12 15:06:56 wieck Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -662,51 +662,44 @@ void
|
662 | 662 | StrategyInvalidateBuffer(BufferDesc *buf)
|
663 | 663 | {
|
664 | 664 | int cdb_id;
|
665 |
| -#ifdef USE_ASSERT_CHECKING |
666 |
| - int buf_id; |
667 |
| -#endif |
668 | 665 | BufferStrategyCDB *cdb;
|
669 | 666 |
|
670 | 667 | /* The buffer cannot be dirty or pinned */
|
671 | 668 | Assert(!(buf->flags & BM_DIRTY));
|
672 | 669 | Assert(buf->refcount == 0);
|
673 | 670 |
|
674 | 671 | /*
|
675 |
| - * If we have the buffer somewhere in the directory, remove it, |
676 |
| - * add the CDB to the list of unused CDB's. and the buffer to |
677 |
| - * the list of free buffers |
| 672 | + * Lookup the cache directory block for this buffer |
678 | 673 | */
|
679 | 674 | cdb_id = BufTableLookup(&(buf->tag));
|
680 |
| - if (cdb_id >= 0) |
681 |
| - { |
682 |
| - cdb = &StrategyCDB[cdb_id]; |
683 |
| - BufTableDelete(&(cdb->buf_tag)); |
684 |
| - STRAT_LIST_REMOVE(cdb); |
685 |
| - cdb->buf_id = -1; |
686 |
| - cdb->next = StrategyControl->listUnusedCDB; |
687 |
| - StrategyControl->listUnusedCDB = cdb_id; |
688 |
| - |
689 |
| - buf->bufNext = StrategyControl->listFreeBuffers; |
690 |
| - StrategyControl->listFreeBuffers = buf->buf_id; |
691 |
| - return; |
692 |
| - } |
| 675 | + if (cdb_id < 0) |
| 676 | + elog(ERROR, "StrategyInvalidateBuffer() buffer %d not in directory", |
| 677 | + buf->buf_id); |
| 678 | + cdb = &StrategyCDB[cdb_id]; |
693 | 679 |
|
694 |
| -#ifdef USE_ASSERT_CHECKING |
695 | 680 | /*
|
696 |
| - * Check that we have this buffer in the freelist already. |
| 681 | + * Remove the CDB from the hashtable and the ARC queue it is |
| 682 | + * currently on. |
697 | 683 | */
|
698 |
| - buf_id = StrategyControl->listFreeBuffers; |
699 |
| - while (buf_id >= 0) |
700 |
| - { |
701 |
| - if (buf == &BufferDescriptors[buf_id]) |
702 |
| - return; |
| 684 | + BufTableDelete(&(cdb->buf_tag)); |
| 685 | + STRAT_LIST_REMOVE(cdb); |
703 | 686 |
|
704 |
| - buf_id = BufferDescriptors[buf_id].bufNext; |
705 |
| - } |
| 687 | + /* |
| 688 | + * Clear out the CDB's buffer tag and association with the buffer |
| 689 | + * and add it to the list of unused CDB's |
| 690 | + */ |
| 691 | + CLEAR_BUFFERTAG(&(cdb->buf_tag)); |
| 692 | + cdb->buf_id = -1; |
| 693 | + cdb->next = StrategyControl->listUnusedCDB; |
| 694 | + StrategyControl->listUnusedCDB = cdb_id; |
706 | 695 |
|
707 |
| - elog(ERROR, "StrategyInvalidateBuffer() buffer %d not in directory or freelist", |
708 |
| - buf->buf_id); |
709 |
| -#endif |
| 696 | + /* |
| 697 | + * Clear out the buffers tag and add it to the list of |
| 698 | + * currently unused buffers. |
| 699 | + */ |
| 700 | + CLEAR_BUFFERTAG(&(buf->tag)); |
| 701 | + buf->bufNext = StrategyControl->listFreeBuffers; |
| 702 | + StrategyControl->listFreeBuffers = buf->buf_id; |
710 | 703 | }
|
711 | 704 |
|
712 | 705 |
|
@@ -869,12 +862,6 @@ PinBuffer(BufferDesc *buf)
|
869 | 862 | {
|
870 | 863 | int b = BufferDescriptorGetBuffer(buf) - 1;
|
871 | 864 |
|
872 |
| - if (buf->refcount == 0) |
873 |
| - { |
874 |
| - /* mark buffer as no longer free */ |
875 |
| - buf->flags &= ~BM_FREE; |
876 |
| - } |
877 |
| - |
878 | 865 | if (PrivateRefCount[b] == 0)
|
879 | 866 | buf->refcount++;
|
880 | 867 | PrivateRefCount[b]++;
|
@@ -917,12 +904,7 @@ UnpinBuffer(BufferDesc *buf)
|
917 | 904 | if (PrivateRefCount[b] == 0)
|
918 | 905 | buf->refcount--;
|
919 | 906 |
|
920 |
| - if (buf->refcount == 0) |
921 |
| - { |
922 |
| - /* buffer is now unpinned */ |
923 |
| - buf->flags |= BM_FREE; |
924 |
| - } |
925 |
| - else if ((buf->flags & BM_PIN_COUNT_WAITER) != 0 && |
| 907 | + if ((buf->flags & BM_PIN_COUNT_WAITER) != 0 && |
926 | 908 | buf->refcount == 1)
|
927 | 909 | {
|
928 | 910 | /* we just released the last pin other than the waiter's */
|
@@ -953,70 +935,3 @@ refcount = %ld, file: %s, line: %d\n",
|
953 | 935 | #endif
|
954 | 936 |
|
955 | 937 |
|
956 |
| -/* |
957 |
| - * print out the free list and check for breaks. |
958 |
| - */ |
959 |
| -#ifdef NOT_USED |
960 |
| -void |
961 |
| -DBG_FreeListCheck(int nfree) |
962 |
| -{ |
963 |
| - int i; |
964 |
| - BufferDesc *buf; |
965 |
| - |
966 |
| - buf = &(BufferDescriptors[SharedFreeList->freeNext]); |
967 |
| - for (i = 0; i < nfree; i++, buf = &(BufferDescriptors[buf->freeNext])) |
968 |
| - { |
969 |
| - if (!(buf->flags & (BM_FREE))) |
970 |
| - { |
971 |
| - if (buf != SharedFreeList) |
972 |
| - printf("\tfree list corrupted: %d flags %x\n", |
973 |
| - buf->buf_id, buf->flags); |
974 |
| - else |
975 |
| - printf("\tfree list corrupted: too short -- %d not %d\n", |
976 |
| - i, nfree); |
977 |
| - } |
978 |
| - if ((BufferDescriptors[buf->freeNext].freePrev != buf->buf_id) || |
979 |
| - (BufferDescriptors[buf->freePrev].freeNext != buf->buf_id)) |
980 |
| - printf("\tfree list links corrupted: %d %ld %ld\n", |
981 |
| - buf->buf_id, buf->freePrev, buf->freeNext); |
982 |
| - } |
983 |
| - if (buf != SharedFreeList) |
984 |
| - printf("\tfree list corrupted: %d-th buffer is %d\n", |
985 |
| - nfree, buf->buf_id); |
986 |
| -} |
987 |
| -#endif |
988 |
| - |
989 |
| -#ifdef NOT_USED |
990 |
| -/* |
991 |
| - * PrintBufferFreeList - |
992 |
| - * prints the buffer free list, for debugging |
993 |
| - */ |
994 |
| -static void |
995 |
| -PrintBufferFreeList() |
996 |
| -{ |
997 |
| - BufferDesc *buf; |
998 |
| - |
999 |
| - if (SharedFreeList->freeNext == Free_List_Descriptor) |
1000 |
| - { |
1001 |
| - printf("free list is empty.\n"); |
1002 |
| - return; |
1003 |
| - } |
1004 |
| - |
1005 |
| - buf = &(BufferDescriptors[SharedFreeList->freeNext]); |
1006 |
| - for (;;) |
1007 |
| - { |
1008 |
| - int i = (buf - BufferDescriptors); |
1009 |
| - |
1010 |
| - printf("[%-2d] (%s, %d) flags=0x%x, refcnt=%d %ld, nxt=%ld prv=%ld)\n", |
1011 |
| - i, buf->blind.relname, buf->tag.blockNum, |
1012 |
| - buf->flags, buf->refcount, PrivateRefCount[i], |
1013 |
| - buf->freeNext, buf->freePrev); |
1014 |
| - |
1015 |
| - if (buf->freeNext == Free_List_Descriptor) |
1016 |
| - break; |
1017 |
| - |
1018 |
| - buf = &(BufferDescriptors[buf->freeNext]); |
1019 |
| - } |
1020 |
| -} |
1021 |
| - |
1022 |
| -#endif |
0 commit comments