Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions | Variables

buf_init.c File Reference

#include "postgres.h"
#include "storage/bufmgr.h"
#include "storage/buf_internals.h"
Include dependency graph for buf_init.c:

Go to the source code of this file.

Functions

void InitBufferPool (void)
void InitBufferPoolAccess (void)
Size BufferShmemSize (void)

Variables

BufferDescBufferDescriptors
char * BufferBlocks
int32PrivateRefCount

Function Documentation

Size BufferShmemSize ( void   ) 

Definition at line 164 of file buf_init.c.

References add_size(), mul_size(), NBuffers, and StrategyShmemSize().

Referenced by CreateSharedMemoryAndSemaphores().

{
    Size        size = 0;

    /* size of buffer descriptors */
    size = add_size(size, mul_size(NBuffers, sizeof(BufferDesc)));

    /* size of data pages */
    size = add_size(size, mul_size(NBuffers, BLCKSZ));

    /* size of stuff controlled by freelist.c */
    size = add_size(size, StrategyShmemSize());

    return size;
}

void InitBufferPool ( void   ) 

Definition at line 73 of file buf_init.c.

References Assert, buf, sbufdesc::buf_hdr_lock, sbufdesc::buf_id, BufferBlocks, CLEAR_BUFFERTAG, sbufdesc::content_lock, sbufdesc::flags, sbufdesc::freeNext, i, sbufdesc::io_in_progress_lock, LWLockAssign(), NBuffers, sbufdesc::refcount, ShmemInitStruct(), SpinLockInit, StrategyInitialize(), sbufdesc::tag, sbufdesc::usage_count, and sbufdesc::wait_backend_pid.

Referenced by CreateSharedMemoryAndSemaphores().

{
    bool        foundBufs,
                foundDescs;

    BufferDescriptors = (BufferDesc *)
        ShmemInitStruct("Buffer Descriptors",
                        NBuffers * sizeof(BufferDesc), &foundDescs);

    BufferBlocks = (char *)
        ShmemInitStruct("Buffer Blocks",
                        NBuffers * (Size) BLCKSZ, &foundBufs);

    if (foundDescs || foundBufs)
    {
        /* both should be present or neither */
        Assert(foundDescs && foundBufs);
        /* note: this path is only taken in EXEC_BACKEND case */
    }
    else
    {
        BufferDesc *buf;
        int         i;

        buf = BufferDescriptors;

        /*
         * Initialize all the buffer headers.
         */
        for (i = 0; i < NBuffers; buf++, i++)
        {
            CLEAR_BUFFERTAG(buf->tag);
            buf->flags = 0;
            buf->usage_count = 0;
            buf->refcount = 0;
            buf->wait_backend_pid = 0;

            SpinLockInit(&buf->buf_hdr_lock);

            buf->buf_id = i;

            /*
             * Initially link all the buffers together as unused. Subsequent
             * management of this list is done by freelist.c.
             */
            buf->freeNext = i + 1;

            buf->io_in_progress_lock = LWLockAssign();
            buf->content_lock = LWLockAssign();
        }

        /* Correct last entry of linked list */
        BufferDescriptors[NBuffers - 1].freeNext = FREENEXT_END_OF_LIST;
    }

    /* Init other shared buffer-management stuff */
    StrategyInitialize(!foundDescs);
}

void InitBufferPoolAccess ( void   ) 

Definition at line 145 of file buf_init.c.

References calloc, ereport, errcode(), errmsg(), FATAL, NBuffers, and PrivateRefCount.

Referenced by BaseInit().

{
    /*
     * Allocate and zero local arrays of per-buffer info.
     */
    PrivateRefCount = (int32 *) calloc(NBuffers, sizeof(int32));
    if (!PrivateRefCount)
        ereport(FATAL,
                (errcode(ERRCODE_OUT_OF_MEMORY),
                 errmsg("out of memory")));
}


Variable Documentation

char* BufferBlocks

Definition at line 22 of file buf_init.c.

Referenced by InitBufferPool().