/* * 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; }
/* * 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); alreadyInShmem = false; segmentVmemQuotaChunks = (int32 *) ShmemInitStruct(SHMEM_DYNAMIC_VMEM_QUOTA, sizeof(int32), &alreadyInShmem); Assert(alreadyInShmem || !IsUnderPostmaster); Assert(NULL != segmentVmemQuotaChunks); if(!IsUnderPostmaster) { chunkSizeInBits = BITS_IN_MB; physicalMemQuotaInMB = VmemTracker_GetPhysicalMemQuotaInMB(); physicalMemQuotaInChunks = physicalMemQuotaInMB; int32 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(physicalMemQuotaInChunks > (16 * 1024)) { chunkSizeInBits++; physicalMemQuotaInChunks >>= 1; vmemChunksQuota >>= 1; } /* There is at least one chunk if memory enforcement is enabled */ if (gp_vmem_protect_limit > 0) { vmemChunksQuota = Max(vmemChunksQuota, (int32)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; /* Initialize memory enforcement for dynamic resource manager */ *segmentVmemQuotaChunks = vmemChunksQuota; }