Buffer Cache Problem

Поиск
Список
Период
Сортировка
От jacktby jacktby
Тема Buffer Cache Problem
Дата
Msg-id 059DE243-F4B0-41CC-84BE-9362FC5FB99A@gmail.com
обсуждение исходный текст
Ответы Re: Buffer Cache Problem  (Matthias van de Meent <boekewurm+postgres@gmail.com>)
Список pgsql-hackers
Hi, postgres hackers, I’m studying postgres buffer cache part. So I open this thread to communicate some buffer cache codes design and try to improve some tricky codes.

For Buffer Cache, we know it’s a buffer array, every bucket of this array is consist of a data page and its header which is used to describe the state of the buffer. 

This is the origin code of buffer header:
typedef struct BufferDesc
{
BufferTag tag; /* ID of page contained in buffer */
int buf_id; /* buffer's index number (from 0) */

/* state of the tag, containing flags, refcount and usagecount */
pg_atomic_uint32 state;

int wait_backend_pgprocno; /* backend of pin-count waiter */
int freeNext; /* link in freelist chain */
LWLock content_lock; /* to lock access to buffer contents */
} BufferDesc;

For field wait_backend_pgprocno, the comment is "backend of pin-count waiter”, I have problems below:
1. it means which processId is waiting this buffer, right? 
2. and if wait_backend_pgprocno is valid, so it says this buffer is in use by one process, right?
3. if one buffer is wait by another process, it means all buffers are out of use, right? So let’s try this: we have 5 buffers with ids (1,2,3,4,5), and they  are all in use, now another process  with processId 8017 is coming, and it choose buffer id 1, so  buffer1’s wait_backend_pgprocno is 8017, but later
buffer4 is released, can process 8017 change to get buffer4? how?
4. wait_backend_pgprocno is a “integer” type, not an array, why can one buffer be wait by only one process?

Hope your reply, thanks!! I’m willing to do contributions after I study buffer cache implementations.

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

Предыдущее
От: Matthias van de Meent
Дата:
Сообщение: Re: 2023-11-09 release announcement draft
Следующее
От: Alexander Lakhin
Дата:
Сообщение: Re: ResourceOwner refactoring