]> granicus.if.org Git - postgresql/commitdiff
Try to get some info about Windows can't-reattach-to-shared-memory errors.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 28 Apr 2018 01:59:58 +0000 (21:59 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 28 Apr 2018 01:59:58 +0000 (21:59 -0400)
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

src/backend/port/win32_shmem.c

index f8ca52e1afe225cc71778d3dff6e1546e05b93ec..d431e0d036276ee03e4152185226fdd6e9ca2613 100644 (file)
@@ -191,6 +191,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port,
        SIZE_T          largePageSize = 0;
        Size            orig_size = size;
        DWORD           flProtect = PAGE_READWRITE;
+       MEMORY_BASIC_INFORMATION info;
 
        /* Room for a header? */
        Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
@@ -359,6 +360,14 @@ retry:
        /* Register on-exit routine to delete the new segment */
        on_shmem_exit(pgwin32_SharedMemoryDelete, PointerGetDatum(hmap2));
 
+       /* Log information about the segment's virtual memory use */
+       if (VirtualQuery(memAddress, &info, sizeof(info)) != 0)
+               elog(LOG, "mapped shared memory segment at %p, requested size %zu, mapped size %zu",
+                        memAddress, size, info.RegionSize);
+       else
+               elog(LOG, "VirtualQuery(%p) failed: error code %lu",
+                        memAddress, GetLastError());
+
        *shim = hdr;
        return hdr;
 }
@@ -392,8 +401,21 @@ PGSharedMemoryReAttach(void)
 
        hdr = (PGShmemHeader *) MapViewOfFileEx(UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr);
        if (!hdr)
+       {
+               DWORD           maperr = GetLastError();
+               MEMORY_BASIC_INFORMATION info;
+
+               if (VirtualQuery(UsedShmemSegAddr, &info, sizeof(info)) != 0)
+                       elog(LOG, "VirtualQuery(%p) reports region of size %zu, base %p, has state 0x%lx",
+                                UsedShmemSegAddr, info.RegionSize,
+                                info.AllocationBase, info.State);
+               else
+                       elog(LOG, "VirtualQuery(%p) failed: error code %lu",
+                                UsedShmemSegAddr, GetLastError());
+
                elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): error code %lu",
-                        UsedShmemSegID, UsedShmemSegAddr, GetLastError());
+                        UsedShmemSegID, UsedShmemSegAddr, maperr);
+       }
        if (hdr != origUsedShmemSegAddr)
                elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)",
                         hdr, origUsedShmemSegAddr);