Remaking the memory manager

In our case first of all we decided to resign from the fixed buffer size. So, every buffer may contains more than one page. The minimal buffer size we selected from the next considerations. The page size is 2Kb. On our platform we have 64Mb. We are planning to use 3/4 of this memory size, it is about 48Mb. So the memory may contains 24.000 pages. The indentificator of any page is usually 16 byte, and the indentificator table has a maximum size – 384Kb. Thus we took the minimal buffer size 512Kb.

It is null buffer, which contains the indentificator table, has a minimal size. Minimal buffer number is two. That means, the first buffer may be 47Kb size of. The purpose of this decision we shall discuss later.

It is obvious, the system is predestined not for our platform only. We suppose that in every custom case the minimal buffer size should be varied proportionally to the appropriated platform. But the presented discussion shows the way to determine it. The null buffer consists of page indentificator table, which is the key instrument for page finding, locking, account synchronization and other page operations. Page indentificator (ptid) includes:

Page indentificator table compares ptid with the number of buffer, where the page is storing, and the ordinal number of the page in this buffer. In old buffer implementation, the two-direction search was executed. It took a lot of time and was one of the narrow places of the system. Our table is organized as a B-tree, and with the large amount of papers, greatly reduced search time.

In the contrast to the earlier buffer realization buffer-segments number is unrestricted. That means that buffer numbers may be varied in any custom case.

Theoretically, the first buffer may be alone and takes the all memory space, available. But this is inconvenient in the terms of buffer deleting, when memory space is required for others processes than buffer process. On the other hand, large number of any object makes difficult their control and takes large resources. We suggest that buffers number should be in order of ten. It would be varied in accordance with the tests results.

When any transaction send requirement to buffer for some page the buffer process make a search in the ptid table. The process defines the presence of the page in any buffer. If the search is successful, the page was found, it locks, according to the semaphores state. If there is no the page, it looks for the page presence in external memory. If the page wasn’t found the process sends the negative answer, and transaction rollback is executed. If the page is found in the external memory, the process looks for free space in any buffer. When the space was found, the page is loaded to the buffer, ptid – to the ptid table, and page lock executes. If there is no available space, that means all buffers are fulled, the process defines the page with the least priority. With the aim of the least priority page defining buffer creates a priority table in its internal memory. The tables contains the list of ptids have been loaded earlier. The ptid of the locking page is replaced to the bottom of the list. During the process the pages which were not used for a long time are replaced to the top of the list. When the free place is needed, the buffer checks, if the top page is locked. If it is, it is moved to the bottom again, if it isn’t the process checks whether the page has been changed or not. In the first case, the process go to next ptid, else the required page is loaded to the appropriate place.

The problem of synchronization is the most actual in the system. We use the OS semaphores for interprocess synchronization.

Model situation supposes two semaphores for each page. The initial state of semaphores is 1 and 0. Every page may locked as for read only, so for write access. So, the first semaphore opens the page for read lock, and the second, for write lock. The read or write lock may be executed, when semaphore state is more than 0. When any transaction locks the page for read, it increases the semaphore state to 1, so the state of the first semaphore indicates the number of transactions that use the page. With the unlocking of the page, the first semaphore state is diminished to the initial state. Let some transaction is going to execute the write lock. It must be sure that no one transaction has locked the page. Thus if the first semaphore is more than 1, the transaction stands to the waiting status. When the page is finally unlocked, the transaction locks the page. It diminishes the first semaphore to 0, then the second semaphore enlarges to 1. That means that the page may be locked with the write access, and no one page else can lock this page. When the page is unlocked the initial semaphore states is returned.

This model would be optional, but the next problem arises: if we have 48Mb of buffer memory, that means it may keep 24.000 of pages. It is evident that there is too little operation systems, that may support so semaphores. And our task is to diminish the semaphore number in two or three orders. The next mechanism was offered. Semaphore is a massive of integer elements. In the first model we used only two elements. We decided to use one semaphore to maximal page numbers. When the buffer loads some page amount for only one transaction, the one semaphore is used for all these pages. Every two massive elements are corresponds to one page. The initial state of the elements is the same as in the above model. When every another transaction is going to lock one of these pages, the next operations are executed. If all the pages read only locked and all the first elements of massive elements couples are equal 1, the transaction also locks the required page, and the situation mentioned above, take place. If one or more pages is write locked the transaction sends conflict message to buffer, which contains page required ptid and semaphore number, and goes to the waiting state. When pages are unlocked the transaction sends to buffer message that the conflict is solved, and locks the needed page.

The buffer process analyses conflict messages. When the number of conflict related to any semaphore exceed the barrier level, the process splits page pool, controlled by this semaphore.

Certainly, this mechanism reduces the system effectiveness, but we expect the read locked page number is much lager then the write lock page number.

Interfaces:

It must be pointed, that my task was to rebuild the buffer process system, but not the SMDT at all. Thus in terms of external interfaces buffer is to stay unchanged. All external commands were restored. The command “'Optimal number'”, which determines the optimal buffers number, is cut, because it is out of need now.