Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 63ca350

Browse files
committed
Try to get some info about Windows can't-reattach-to-shared-memory errors.
Add some debug printouts focused on the idea that MapViewOfFileEx might be rounding its virtual memory allocation up more than we expect (and, in particular, more than VirtualAllocEx does). Once we've seen what this reports in one of the failures on buildfarm members dory or jacana, we might revert this ... or perhaps just decrease the log level. Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
1 parent 2e83e6b commit 63ca350

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/backend/port/win32_shmem.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port,
191191
SIZE_T largePageSize = 0;
192192
Size orig_size = size;
193193
DWORD flProtect = PAGE_READWRITE;
194+
MEMORY_BASIC_INFORMATION info;
194195

195196
/* Room for a header? */
196197
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
@@ -359,6 +360,14 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port,
359360
/* Register on-exit routine to delete the new segment */
360361
on_shmem_exit(pgwin32_SharedMemoryDelete, PointerGetDatum(hmap2));
361362

363+
/* Log information about the segment's virtual memory use */
364+
if (VirtualQuery(memAddress, &info, sizeof(info)) != 0)
365+
elog(LOG, "mapped shared memory segment at %p, requested size %zu, mapped size %zu",
366+
memAddress, size, info.RegionSize);
367+
else
368+
elog(LOG, "VirtualQuery(%p) failed: error code %lu",
369+
memAddress, GetLastError());
370+
362371
*shim = hdr;
363372
return hdr;
364373
}
@@ -392,8 +401,21 @@ PGSharedMemoryReAttach(void)
392401

393402
hdr = (PGShmemHeader *) MapViewOfFileEx(UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr);
394403
if (!hdr)
404+
{
405+
DWORD maperr = GetLastError();
406+
MEMORY_BASIC_INFORMATION info;
407+
408+
if (VirtualQuery(UsedShmemSegAddr, &info, sizeof(info)) != 0)
409+
elog(LOG, "VirtualQuery(%p) reports region of size %zu, base %p, has state 0x%lx",
410+
UsedShmemSegAddr, info.RegionSize,
411+
info.AllocationBase, info.State);
412+
else
413+
elog(LOG, "VirtualQuery(%p) failed: error code %lu",
414+
UsedShmemSegAddr, GetLastError());
415+
395416
elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): error code %lu",
396-
UsedShmemSegID, UsedShmemSegAddr, GetLastError());
417+
UsedShmemSegID, UsedShmemSegAddr, maperr);
418+
}
397419
if (hdr != origUsedShmemSegAddr)
398420
elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)",
399421
hdr, origUsedShmemSegAddr);

0 commit comments

Comments
 (0)