/* * Allocate and initialize walsender-related shared memory. */ void ReplicationSlotsShmemInit(void) { bool found; if (max_replication_slots == 0) return; ReplicationSlotCtl = (ReplicationSlotCtlData *) ShmemInitStruct("ReplicationSlot Ctl", ReplicationSlotsShmemSize(), &found); LWLockRegisterTranche(LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS, "replication_slot_io"); if (!found) { int i; /* First time through, so initialize */ MemSet(ReplicationSlotCtl, 0, ReplicationSlotsShmemSize()); for (i = 0; i < max_replication_slots; i++) { ReplicationSlot *slot = &ReplicationSlotCtl->replication_slots[i]; /* everything else is zeroed by the memset above */ SpinLockInit(&slot->mutex); LWLockInitialize(&slot->io_in_progress_lock, LWTRANCHE_REPLICATION_SLOT_IO_IN_PROGRESS); ConditionVariableInit(&slot->active_cv); } } }
static void allocShmem(void) { bool found; if (prev_shmem_startup_hook) prev_shmem_startup_hook(); LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); memstats = ShmemInitStruct("contrib/memstat", getMemstatSize(), &found); if (!found) { int32 i; LWLockPadded *LockPadded = GetNamedLWLockTranche("memstat"); for(i=0; i<PROCARRAY_MAXPROCS; i++) { NthBMS(i)->pid = -1; NthBMS(i)->lock = &(LockPadded[i].lock); } } LWLockRelease(AddinShmemInitLock); }
void DistributedLog_ShmemInit(void) { bool found; /* Set up SLRU for the distributed log. */ DistributedLogCtl->PagePrecedes = DistributedLog_PagePrecedes; SimpleLruInit(DistributedLogCtl, "DistributedLogCtl", NUM_DISTRIBUTEDLOG_BUFFERS, DistributedLogControlLock, DISTRIBUTEDLOG_DIR); /* Create or attach to the shared structure */ DistributedLogShared = (DistributedLogShmem *) ShmemInitStruct( "DistributedLogShmem", DistributedLog_SharedShmemSize(), &found); if (!DistributedLogShared) elog(FATAL, "could not initialize Distributed Log shared memory"); if (!found) { DistributedLogShared->oldestXid = InvalidTransactionId; DistributedLogShared->knowHighestUnusedPage = false; DistributedLogShared->highestUnusedPage = -1; } }
/* * LatchShmemInit * Allocate and initialize shared memory needed for latches */ void LatchShmemInit(void) { Size size = LatchShmemSize(); bool found; sharedHandles = ShmemInitStruct("SharedEventHandles", size, &found); /* If we're first, initialize the struct and allocate handles */ if (!found) { int i; SECURITY_ATTRIBUTES sa; /* * Set up security attributes to specify that the events are * inherited. */ ZeroMemory(&sa, sizeof(sa)); sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; SpinLockInit(&sharedHandles->mutex); sharedHandles->maxhandles = NumSharedLatches(); sharedHandles->nfreehandles = sharedHandles->maxhandles; for (i = 0; i < sharedHandles->maxhandles; i++) { sharedHandles->handles[i] = CreateEvent(&sa, TRUE, FALSE, NULL); if (sharedHandles->handles[i] == NULL) elog(ERROR, "CreateEvent failed: error code %d", (int) GetLastError()); } } }
/* * Initialize CommitTs at system startup (postmaster start or standalone * backend) */ void CommitTsShmemInit(void) { bool found; CommitTsCtl->PagePrecedes = CommitTsPagePrecedes; SimpleLruInit(CommitTsCtl, "commit_timestamp", CommitTsShmemBuffers(), 0, CommitTsControlLock, "pg_commit_ts", LWTRANCHE_COMMITTS_BUFFERS); commitTsShared = ShmemInitStruct("CommitTs shared", sizeof(CommitTimestampShared), &found); if (!IsUnderPostmaster) { Assert(!found); commitTsShared->xidLastCommit = InvalidTransactionId; TIMESTAMP_NOBEGIN(commitTsShared->dataLastCommit.time); commitTsShared->dataLastCommit.nodeid = InvalidRepOriginId; commitTsShared->commitTsActive = false; } else Assert(found); }
/* * Allocate and initialize walsender-related shared memory. */ void ReplicationSlotsShmemInit(void) { bool found; if (max_replication_slots == 0) return; ReplicationSlotCtl = (ReplicationSlotCtlData *) ShmemInitStruct("ReplicationSlot Ctl", ReplicationSlotsShmemSize(), &found); if (!found) { int i; /* First time through, so initialize */ MemSet(ReplicationSlotCtl, 0, ReplicationSlotsShmemSize()); for (i = 0; i < max_replication_slots; i++) { ReplicationSlot *slot = &ReplicationSlotCtl->replication_slots[i]; /* everything else is zeroed by the memset above */ SpinLockInit(&slot->mutex); slot->io_in_progress_lock = LWLockAssign(); } } }
/* * BTreeShmemInit --- initialize this module's shared memory */ void BTreeShmemInit(void) { bool found; btvacinfo = (BTVacInfo *) ShmemInitStruct("BTree Vacuum State", BTreeShmemSize(), &found); if (!IsUnderPostmaster) { /* Initialize shared memory area */ Assert(!found); /* * It doesn't really matter what the cycle counter starts at, but * having it always start the same doesn't seem good. Seed with * low-order bits of time() instead. */ btvacinfo->cycle_ctr = (BTCycleId) time(NULL); btvacinfo->num_vacuums = 0; btvacinfo->max_vacuums = MaxBackends; } else Assert(found); }
/* * SIBufferInit * Create and initialize a new SI message buffer */ void SIBufferInit(void) { SISeg *segP; int i; bool found; /* Allocate space in shared memory */ shmInvalBuffer = segP = (SISeg *) ShmemInitStruct("shmInvalBuffer", SInvalShmemSize(), &found); if (found) return; /* Clear message counters, save size of procState array */ segP->minMsgNum = 0; segP->maxMsgNum = 0; segP->lastBackend = 0; segP->maxBackends = MaxBackends; segP->freeBackends = MaxBackends; /* The buffer[] array is initially all unused, so we need not fill it */ /* Mark all backends inactive */ for (i = 0; i < segP->maxBackends; i++) { segP->procState[i].nextMsgNum = -1; /* inactive */ segP->procState[i].resetState = false; } }
/* * Initialize metadata hdfs block array */ bool MetadataCacheHdfsBlockArrayInit(void) { Insist(MetadataCacheSharedDataInstance != NULL); int i = 0; bool found; MetadataBlockArray = (MetadataHdfsBlockInfo *)ShmemInitStruct("Metadata Cache HDFS Block Array", metadata_cache_block_capacity * sizeof(MetadataHdfsBlockInfo), &found); if (NULL == MetadataBlockArray) { return false; } FREE_BLOCK_NUM = metadata_cache_block_capacity; FREE_BLOCK_HEAD = 0; for (i=0;i<FREE_BLOCK_NUM;i++) { NEXT_BLOCK_ID(i) = i + 1; } NEXT_BLOCK_ID(FREE_BLOCK_NUM - 1) = END_OF_BLOCK; return true; }
/* * Initialize the shared-memory for this module. */ void PersistentFilespace_ShmemInit(void) { bool found; bool ok; /* Create the shared-memory structure. */ persistentFilespaceSharedData = (PersistentFilespaceSharedData *) ShmemInitStruct("Persistent Filespace Data", PersistentFilespace_SharedDataSize(), &found); if (!found) { PersistentFileSysObj_InitShared( &persistentFilespaceSharedData->fileSysObjSharedData); } /* Create or find our shared-memory hash table. */ ok = PersistentFilespace_HashTableInit(); if (!ok) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("Not enough shared memory for persistent filespace hash table"))); PersistentFileSysObj_Init( &persistentFilespaceData.fileSysObjData, &persistentFilespaceSharedData->fileSysObjSharedData, PersistentFsObjType_FilespaceDir, PersistentFilespace_ScanTupleCallback); Assert(persistentFilespaceSharedData != NULL); Assert(persistentFilespaceSharedHashTable != NULL); }
/* * Initialize the shared-memory for this module. */ void PersistentRelfile_ShmemInit(void) { bool found; /* Create the shared-memory structure. */ persistentRelfileSharedData = (PersistentRelfileSharedData *) ShmemInitStruct("Mirrored Rel File Data", PersistentRelfile_SharedDataSize(), &found); if (!found) { PersistentFileSysObj_InitShared( &persistentRelfileSharedData->fileSysObjSharedData); } PersistentFileSysObj_Init( &persistentRelfileData.fileSysObjData, &persistentRelfileSharedData->fileSysObjSharedData, PersistentFsObjType_RelationFile, /* scanTupleCallback */ NULL); Assert(persistentRelfileSharedData != NULL); }
/* * StrategyInitialize -- initialize the buffer cache replacement * strategy. * * Assumes: All of the buffers are already built into a linked list. * Only called by postmaster and only during initialization. */ void StrategyInitialize(bool init) { bool found; /* * Initialize the shared buffer lookup hashtable. * * Since we can't tolerate running out of lookup table entries, we must be * sure to specify an adequate table size here. The maximum steady-state * usage is of course NBuffers entries, but BufferAlloc() tries to insert * a new entry before deleting the old. In principle this could be * happening in each partition concurrently, so we could need as many as * NBuffers + NUM_BUFFER_PARTITIONS entries. */ InitBufTable(NBuffers + NUM_BUFFER_PARTITIONS); /* * Get or create the shared strategy control block */ StrategyControl = (BufferStrategyControl *) ShmemInitStruct("Buffer Strategy Status", sizeof(BufferStrategyControl), &found); if (!found) { /* * Only done once, usually in postmaster */ Assert(init); /* * Grab the whole linked list of free buffers for our strategy. We * assume it was previously set up by InitBufferPool(). */ StrategyControl->firstFreeBuffer = 0; StrategyControl->lastFreeBuffer = NBuffers - 1; /* Initialize the clock sweep pointer */ StrategyControl->nextVictimBuffer = 0; /* Clear statistics */ StrategyControl->completePasses = 0; StrategyControl->numBufferAllocs = 0; /* No pending notification */ StrategyControl->bgwriterLatch = NULL; StrategyControl->lastUnpinned = NULL; StrategyControl->firstUnpinned = NULL; StrategyControl->a1Head = NULL; StrategyControl->a1Tail = NULL; } else Assert(!init); }
/* * ProcSignalShmemInit * Allocate and initialize procsignal's shared memory */ void ProcSignalShmemInit(void) { Size size = ProcSignalShmemSize(); bool found; ProcSignalSlots = (ProcSignalSlot *) ShmemInitStruct("ProcSignalSlots", size, &found); /* If we're first, set everything to zeroes */ if (!found) MemSet(ProcSignalSlots, 0, size); }
void WalSendServerShmemInit(void) { bool found; /* Create or attach to the SharedSnapshot shared structure */ WalSendServerShared = (WalSendServerShmem *) ShmemInitStruct("WAL Send Server", WalSendServerShmemSize(), &found); if (!WalSendServerShared) elog(FATAL, "could not initialize WAL Send server shared memory"); if (!found) WalSendServerShared->listenerPort = -1; }
PROC_QUEUE * ProcQueueAlloc(char *name) { bool found; PROC_QUEUE *queue = (PROC_QUEUE *) ShmemInitStruct(name, sizeof(PROC_QUEUE), &found); if (!queue) return NULL; if (!found) ProcQueueInit(queue); return queue; }
/* * Initialize dsm config for arrays */ void init_dsm_config() { bool found; dsm_cfg = ShmemInitStruct("pathman dsm_array config", sizeof(DsmConfig), &found); if (!found) { dsm_cfg->segment_handle = 0; dsm_cfg->block_size = 0; dsm_cfg->blocks_count = INITIAL_BLOCKS_COUNT; dsm_cfg->first_free = 0; } }
/* * PMSignalShmemInit - initialize during shared-memory creation */ void PMSignalShmemInit(void) { bool found; PMSignalState = (PMSignalData *) ShmemInitStruct("PMSignalState", PMSignalShmemSize(), &found); if (!found) { MemSet(PMSignalState, 0, PMSignalShmemSize()); PMSignalState->num_child_flags = MaxLivePostmasterChildren(); } }
/* * InitShmemDynAllocator */ void ShmemDynAllocShmemInit(void) { bool found; ShemDynAllocShmem = (ShemDynAllocShmemStruct *) ShmemInitStruct("ShemDynAllocState", sizeof(ShemDynAllocShmemStruct) , &found); if (!found) { ShemDynAllocShmem->head = NULL; ShemDynAllocShmem->tail = NULL; SpinLockInit(&ShemDynAllocShmem->mutex); } }
/* * NodeTablesInit * Initializes shared memory tables of Coordinators and Datanodes. */ void NodeTablesShmemInit(void) { bool found; /* * Initialize the table of Coordinators: first sizeof(int) bytes are to * store actual number of Coordinators, remaining data in the structure is * array of NodeDefinition that can contain up to MaxCoords entries. * That is a bit weird and probably it would be better have these in * separate structures, but I am unsure about cost of having shmem structure * containing just single integer. */ shmemNumCoords = ShmemInitStruct("Coordinator Table", sizeof(int) + sizeof(NodeDefinition) * MaxCoords, &found); /* Have coDefs pointing right behind shmemNumCoords */ coDefs = (NodeDefinition *) (shmemNumCoords + 1); /* Mark it empty upon creation */ if (!found) *shmemNumCoords = 0; /* Same for Datanodes */ shmemNumDataNodes = ShmemInitStruct("Datanode Table", sizeof(int) + sizeof(NodeDefinition) * MaxDataNodes, &found); /* Have coDefs pointing right behind shmemNumDataNodes */ dnDefs = (NodeDefinition *) (shmemNumDataNodes + 1); /* Mark it empty upon creation */ if (!found) *shmemNumDataNodes = 0; }
/* Allocates the shared memory SessionStateArray */ void SessionState_ShmemInit() { bool found = false; Size shmemSize = SessionState_ShmemSize(); AllSessionStateEntries = (SessionStateArray *) ShmemInitStruct(SHMEM_SESSION_STATE_ARRAY, shmemSize, &found); Assert(found || !IsUnderPostmaster); if (!IsUnderPostmaster) { MemSet(AllSessionStateEntries, 0, shmemSize); /* * We're the first - initialize. */ AllSessionStateEntries->numSession = 0; AllSessionStateEntries->maxSession = SessionStateArrayEntryCount; AllSessionStateEntries->sessions = (SessionState *)&AllSessionStateEntries->data; /* Every entry of the array is free at this time */ AllSessionStateEntries->freeList = AllSessionStateEntries->sessions; AllSessionStateEntries->usedList = NULL; /* * Set all the entries' sessionId to invalid. Also, set the next pointer * to point to the next entry in the array. */ SessionState *prev = &AllSessionStateEntries->sessions[0]; prev->sessionId = INVALID_SESSION_ID; prev->cleanupCountdown = CLEANUP_COUNTDOWN_BEFORE_RUNAWAY; for (int i = 1; i < AllSessionStateEntries->maxSession; i++) { SessionState *cur = &AllSessionStateEntries->sessions[i]; cur->sessionId = INVALID_SESSION_ID; cur->cleanupCountdown = CLEANUP_COUNTDOWN_BEFORE_RUNAWAY; prev->next = cur; prev = cur; } prev->next = NULL; } }
void FSCredShmemInit(void) { bool found; server_ticket_last_renew = (int64 *)ShmemInitStruct( "FileSystem credentials server ticket last renew time", sizeof(int64), &found); if (!server_ticket_last_renew) elog(FATAL, "could not initialize server kerberos ticket share memory"); if (IsUnderPostmaster) *server_ticket_last_renew = 0; }
/** * Initialize global sate of backoff scheduler. This is called during creation * of shared memory and semaphores. */ void BackoffStateInit() { bool found = false; /* Create or attach to the shared array */ backoffSingleton = (BackoffState *) ShmemInitStruct("Backoff Global State", sizeof(BackoffState), &found); if (!found) { bool ret = false; /* * We're the first - initialize. */ MemSet(backoffSingleton, 0, sizeof(BackoffState)); backoffSingleton->numEntries = MaxBackends; backoffSingleton->backendEntries = (BackoffBackendSharedEntry *) ShmemInitStruct("Backoff Backend Entries", mul_size(sizeof(BackoffBackendSharedEntry), backoffSingleton->numEntries), &ret); backoffSingleton->sweeperInProgress = false; Assert(!ret); } on_shmem_exit(BackoffStateAtExit, 0); }
/* * Initialize all the data structure in the share memory for metadata cache * - Metadata cache shared data structure * - Metadata cache hash table * - Metadata cache block info hash tables (3 types) * - Metadata hdfs block array */ void MetadataCache_ShmemInit(void) { bool found; MetadataCacheSharedDataInstance = (MetadataCacheSharedData *)ShmemInitStruct("Metadata Cache Shared Data", sizeof(MetadataCacheSharedData), &found); if (found && MetadataCacheSharedDataInstance) { return; } if (NULL == MetadataCacheSharedDataInstance) { elog(FATAL, "[MetadataCache] fail to allocate share memory for metadata cache shared data"); } MetadataCacheSharedDataInstance->free_block_num = metadata_cache_block_capacity; MetadataCacheSharedDataInstance->free_block_head = 0; MetadataCacheSharedDataInstance->cur_hosts_idx = 0; MetadataCacheSharedDataInstance->cur_names_idx = 0; MetadataCacheSharedDataInstance->cur_topologyPaths_idx = 0; if (!MetadataCacheHashTableInit()) { elog(FATAL, "[MetadataCache] fail to allocate share memory for metadata cache hash table"); } if (!MetadataBlockInfoTablesInit()) { elog(FATAL, "[MetadataCache] fail to allocate share memory for metadata cache block info hash tables"); } if (!MetadataRevertBlockInfoTablesInit()) { elog(FATAL, "[MetadataCache] fail to allocate share memory for metadata cache revert block info hash tables"); } if (!MetadataCacheHdfsBlockArrayInit()) { elog(FATAL, "[MetadataCache] fail to allocate share memory for metadata cache hdfs block array"); } elog(LOG, "[MetadataCache] Metadata cache initialize successfully. block_capacity:%d", metadata_cache_block_capacity); return; }
static void DtmInitialize() { bool found; static HASHCTL info; LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); dtm = ShmemInitStruct("dtm", sizeof(DtmState), &found); if (!found) { dtm->hashLock = LWLockAssign(); dtm->xidLock = LWLockAssign(); dtm->nReservedXids = 0; dtm->minXid = InvalidTransactionId; dtm->nNodes = MMNodes; dtm->disabledNodeMask = 0; pg_atomic_write_u32(&dtm->nReceivers, 0); dtm->initialized = false; BgwPoolInit(&dtm->pool, MMExecutor, MMDatabaseName, MMQueueSize); RegisterXactCallback(DtmXactCallback, NULL); RegisterSubXactCallback(DtmSubXactCallback, NULL); } LWLockRelease(AddinShmemInitLock); info.keysize = sizeof(TransactionId); info.entrysize = sizeof(TransactionId); info.hash = dtm_xid_hash_fn; info.match = dtm_xid_match_fn; xid_in_doubt = ShmemInitHash( "xid_in_doubt", DTM_HASH_SIZE, DTM_HASH_SIZE, &info, HASH_ELEM | HASH_FUNCTION | HASH_COMPARE ); info.keysize = sizeof(TransactionId); info.entrysize = sizeof(LocalTransaction); info.hash = dtm_xid_hash_fn; info.match = dtm_xid_match_fn; local_trans = ShmemInitHash( "local_trans", DTM_HASH_SIZE, DTM_HASH_SIZE, &info, HASH_ELEM | HASH_FUNCTION | HASH_COMPARE ); MMDoReplication = true; TM = &DtmTM; }
/* Allocate and initialize walreceiver-related shared memory */ void WalRcvShmemInit(void) { bool found; WalRcv = (WalRcvData *) ShmemInitStruct("Wal Receiver Ctl", WalRcvShmemSize(), &found); if (!found) { /* First time through, so initialize */ MemSet(WalRcv, 0, WalRcvShmemSize()); WalRcv->walRcvState = WALRCV_STOPPED; SpinLockInit(&WalRcv->mutex); } }
/* * Allocates the shared control for the cache, or attach to * an existing one in the memory. This includes the freelist. */ static void Cache_InitSharedMem(CacheCtl *cacheCtl, Cache *cache) { Assert(NULL != cache); Size entrySize = CACHE_ENTRY_HEADER_SIZE + MAXALIGN(cacheCtl->entrySize); Size cacheTotalSize = MAXALIGN(sizeof(CacheHdr)) + cacheCtl->maxSize * entrySize; bool attach = false; /* Allocate or attach to existing cache header */ cache->cacheHdr = (CacheHdr *) ShmemInitStruct(cache->cacheName, cacheTotalSize, &attach); if (!attach) { /* * If freelist was never allocated, allocate it here. * Set up links. * Identify the HEAD. */ cache->cacheHdr->entryArray = (void *) (((char *) cache->cacheHdr) + MAXALIGN(sizeof(CacheHdr))); cache->cacheHdr->nEntries = cacheCtl->maxSize; cache->cacheHdr->keySize = cacheCtl->keySize; cache->cacheHdr->keyOffset = cacheCtl->keyOffset; cache->cacheHdr->entrySize = cacheCtl->entrySize; SpinLockInit(&cache->cacheHdr->spinlock); Cache_InitReplacementPolicy(cache); Cache_ResetStats(&cache->cacheHdr->cacheStats); cache->cacheHdr->cacheStats.noFreeEntries = cacheCtl->maxSize; /* Initialize freeList linked list */ CacheEntry *firstEntry = (CacheEntry *) cache->cacheHdr->entryArray; CacheEntry *prevEntry = NULL; CacheEntry *tmpEntry = firstEntry; int i=0; for (i=0;i<cacheCtl->maxSize;i++) { Cache_InitCacheEntry(cache, tmpEntry); tmpEntry->nextEntry = prevEntry; prevEntry = tmpEntry; tmpEntry = (CacheEntry *) (((char *) tmpEntry) + entrySize); } cache->cacheHdr->freeList = prevEntry; } }
/* * Probably the most important part - allocates the shared segment * with space for all the rules (and process info), loads the rules * from file and performs all the initialization necessary. */ static void pg_limits_shmem_startup() { bool found = FALSE; char *segment = NULL; if (prev_shmem_startup_hook) prev_shmem_startup_hook(); /* Create or attach to the shared memory state (for the rules). */ LWLockAcquire(AddinShmemInitLock, LW_EXCLUSIVE); segment = ShmemInitStruct(SEGMENT_NAME, SEGMENT_SIZE, &found); #if (PG_VERSION_NUM < 90000) /* since 9.0, it always throws an error */ if (segment == NULL) elog(ERROR, "a call to ShmemInitStruct failed (connection_limits)"); #endif /* rules are placed first, then the cached backend info */ rules = (rules_t*)(segment); backends = (BackendInfo*)(segment + offsetof(rules_t, rules) + sizeof(rule_t) * MAX_RULES); elog(DEBUG1, "initializing segment with connection limit rules (size: %lu B)", SEGMENT_SIZE); /* Perform initialization if this is the first time we see the segment. */ if (! found) { /* * make sure the segment is empty (no rules, ...) * * load_rules() resets only the part where the rules are stored, * and we need to reset the whole segment (including backend info) */ memset(rules, 0, SEGMENT_SIZE); load_rules(); elog(DEBUG1, "shared memory segment successfully created, %d rules loaded", rules->n_rules); } LWLockRelease(AddinShmemInitLock); }
void DistributedXidMapShmemInit(void) { bool found; DISTRIBUTEDXIDMAP_SHARED *shared; shared = (DISTRIBUTEDXIDMAP_SHARED *) ShmemInitStruct("DistributedXidMap Shared", DistributedXidMapShmemSize(), &found); if (!shared) elog(FATAL, "Could not initialize Distributed XIP Map shared memory"); if (!found) { MemSet(shared, 0, sizeof(DISTRIBUTEDXIDMAP_SHARED)); } shmDistributedXidMapHighestPageNo = &shared->DistributedXidMapHighestPageNo; shmMaxDistributedXid = &shared->MaxDistributedXid; }
/* * ProcQueueAlloc -- alloc/attach to a shared memory process queue * * Returns: a pointer to the queue or NULL * Side Effects: Initializes the queue if we allocated one */ PROC_QUEUE * ProcQueueAlloc(char *name) { bool found; PROC_QUEUE *queue = (PROC_QUEUE *) ShmemInitStruct(name,(unsigned)sizeof(PROC_QUEUE),&found); if (! queue) { return(NULL); } if (! found) { ProcQueueInit(queue); } return(queue); }
/* * Initializes the shared memory states of the vmem tracker. This * will also initialize the shared memory states of event version * provider, red zone handler and idle tracker. */ void VmemTracker_ShmemInit() { Assert(!vmemTrackerInited); trackedVmemChunks = 0; maxVmemChunksTracked = 0; trackedBytes = 0; bool alreadyInShmem = false; segmentVmemChunks = (int32 *) ShmemInitStruct(SHMEM_AVAILABLE_VMEM, sizeof(int32), &alreadyInShmem); Assert(alreadyInShmem || !IsUnderPostmaster); Assert(NULL != segmentVmemChunks); if(!IsUnderPostmaster) { Assert(chunkSizeInBits == BITS_IN_MB); vmemChunksQuota = gp_vmem_protect_limit; /* * If vmem is larger than 16GB (i.e., 16K MB), we make the chunks bigger * so that the vmem limit in chunks unit is not larger than 16K. */ while(vmemChunksQuota > (16 * 1024)) { chunkSizeInBits++; vmemChunksQuota >>= 1; } /* * gp_vmem_limit_per_query is in kB. So, first convert it to MB, and then shift it * to adjust for cases where we enlarged our chunk size */ maxChunksPerQuery = ceil(gp_vmem_limit_per_query / (1024.0 * (1 << (chunkSizeInBits - BITS_IN_MB)))); /* Initialize the sub-systems */ EventVersion_ShmemInit(); RedZoneHandler_ShmemInit(); IdleTracker_ShmemInit(); *segmentVmemChunks = 0; }