### Un-pin blocks efficiently

• Solving problem 2: store information to help us perform unpinning on a block

• Recall problem 2:

• When we want to release (clear) a block/record in memory that is being referenced through a virtual memory address:

The block can only be released after all referencing virtual addresses have been unswizzled:

• Pre-requisite to the solution:

• We must maintain information on the locations of all referencing pointers to a given database address

Example:

The location information is necessary to perform the unswizzling operation on all referencing virtual memory addresses

• Assumption:

• Length of a database address 2 × Length of a virtual memory address

Graphically:

• If length of a database address < 2 × Length of a virtual memory address, we will

 allocate extra bytes in the database address field to make its length equal to 2 × length(virtual address)

Reason for doing this:

• We use the first half of the (memory) space of the database address:

 To store the swizzled virtual memory address of the database object in memory

• We use the second half of the (memory) space of the database address:

• The linked list data structure used to store information on the locations of all referencing pointers to a given database address:

Notice that:

• We add an extra field into the translation table:

• The Linked List field contains the start of the linked list

 ``` Before swizzling: +---------------------+---------------------+ | database address of some database object | +---------------------+---------------------+ After swizzling: +---------------------+---------------------+ | Vir Mem Addr of Obj | next field of list | +---------------------+---------------------+ ```

• Unpinning information: How the linked list is constructed

• Initially: the memory is empty

• Read a block with a certain record into memory:

We enter the database address and its corresponding virtual memory address into the translation table

The linked list is initialized to an empty list

• We read in a block containing a database address of the block:

• We read in a another block containing a database address of the block:

• Unpinning a block

• Algorithm to unpin a record located at virtual memory address x:

• Find the entry for x in the translation table

(Use a brute force search in the translation table or use the hash table technique discussed above)

• Traverse the linked list and unpin every virtual address field found in the list:

Before:

After: