Professional Documents
Culture Documents
BUFFER POOL
disk page
free frame
MAIN MEMORY
An approximation of LRU
Arrange frames into a cycle, store one C(1)
reference bit per frame
Can think of this as the 2nd chance bit
When pin count reduces to 0, turn on ref. bit
When replacement necessary
do for each page in cycle {
if (pincount == 0 && ref bit is on)
turn off ref bit;
else if (pincount == 0 && ref bit is off)
choose this page for replacement;
} until a page is chosen;
Code Navigation
ctags
Allows you to use your favorite editor to find declarations
1. cd to
Hw1/MyStuff/MyCode
2. Run ctags -R ../../postgresql-7.2.2/
3. Start vi filename.c
4. ^] - Look up the location of the identifier under
the cursor in the tags file, and move to
that location.
^T - Return to the previous location in the tag stack, i.e.,
pop off one element.
Also Emacs support (ctags). Talk amongst yourselves
Code Debugging
ddd
Two ways to debug postgres
interactive mode
bare backend mode (described here)
Initialize postgres by typing
/local_tmp/$USER/postgresql-7.2.2-
clock/bin/initdb D <data directory>
Startup ddd with the newly complied and
installed version of postgres
ddd /local_tmp/$USER/postgresql-7.2.2-
clock/bin/postgres
You can now examine functions
Type in the search field the name of the function to
be examined (e.g., GetFreeBuffer()).
Then click the Lookup button.
Code Debugging
ddd (contd
Run postgres by hitting F2 or by using the
menu option Program -> Run
A dialog box will appear where you enter
-D <data dir> template1
Click on Run and then the backend
prompt should appears in the upper pane.
Place a breakpoint in GetFreeBuffer() on the first line of the code
in the function (You can either right click your mouse and choose the
set breakpoint menu or click on the line and then click on the Break
button).
Type at the backend prompt
Select * from pg_user; to run your query.
Now you can start debugging your code by either
Looking at the current state of your stack (Status -> Backtrace).
Display local variables (Data -> Display Local Variables) and function
arguments
(Data -> Display Arguments).
Display any expression you want to know about more (highlight the expression
and click on the Display Button).
Stuff About Assignment 3
Methods to know about
AddBufferToFreeList(BufferDesc) and
InitFreeList(bool) can be ignored for implementing the
Clock Algorithm.
BufferDescriptorGetBuffer(BufferDesc) returns
position of a page in buffer.
GetFreeBuffer() method that needs to be re-implemented.
Data structures to know about
BufferDescriptors[] Array representing the buffer pool
of size NBuffers.
BufferDesc represents a buffer page; stores among other
things information like whether the page is currently pinned or
unpinned (struct variable refcount).
Buffer 0 Buffer 1 Buffer 2.. Buffer N-2 Buffer N-1
SharedFreeList
freeNext
0 1 2 3N-2 N-1 N
freePrev
This buffer
freeNext is deleted freeNext freeNext freeNext
from
freelist.
freePrev freePrev freePrev freePrev
SharedFreeList
freelist.c:198, No
free elements left
condition check.
SharedFreeList
0 1 2 3N-2 N-1 N i
This buffer
freeNext is deleted freeNext freeNext freeNext freeNext
from
freelist.
freePrev freePrev freePrev freePrev freePrev
SharedFreeList
0 1 2 3N-2 N-1 N i
This buffer
freeNext is deleted freeNext freeNext freeNext freeNext
from
freelist.
freePrev freePrev freePrev freePrev freePrev
SharedFreeList
N-3
N-2
N-1
0
0 1 1 0
freeNext freeNext
freePrev freePrev
SharedFreeList 0 1 SharedFreeList 1 0