postgresql 的buffer 的clock sweep 算法
typedef struct sbufdesc slock_t buf_hdr_lock; /* protects the above fields */ int buf_id; /* buffer's index number (from 0) */ LWLockId io_in_progress_lock; /* to wait for I/O to complete */ /* Nothing on the freelist,so run the "clock sweep" algorithm */ if (++StrategyControl->nextVictimBuffer >= NBuffers) /* * If the buffer is pinned or has a nonzero usage_count,we cannot use * it; decrement the usage_count (unless pinned) and keep scanning. */ LockBufHdr(buf); if (buf->refcount == 0) { if (buf->usage_count > 0) { buf->usage_count--; trycounter = NBuffers; } else { /* Found a usable buffer */ if (strategy != NULL) AddBufferToRing(strategy,buf); return buf; } } else if (--trycounter == 0) { /* * We've scanned all the buffers without making any state changes,* so all the buffers are pinned (or were when we looked at them). * We could hope that someone will free one eventually,but it's * probably better to fail than to risk getting stuck in an * infinite loop. */ UnlockBufHdr(buf); elog(ERROR,"no unpinned buffers available"); } UnlockBufHdr(buf);} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |