Skip to content

Commit bcbf234

Browse files
committed
Remove investigative code for can't-reattach-to-shared-memory errors.
Revert commits 2307868, 73042b8, ce07aff, f7df804, 6ba0cc4, eb16011, 68e7e97, 63ca350. We still have a problem here, but somebody who's actually a Windows developer will need to spend time on it. Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
1 parent fa94fa6 commit bcbf234

File tree

1 file changed

+1
-97
lines changed

1 file changed

+1
-97
lines changed

src/backend/port/win32_shmem.c

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313
#include "postgres.h"
1414

15-
#include "lib/stringinfo.h"
1615
#include "miscadmin.h"
1716
#include "storage/dsm.h"
1817
#include "storage/ipc.h"
@@ -25,65 +24,6 @@ static Size UsedShmemSegSize = 0;
2524
static bool EnableLockPagesPrivilege(int elevel);
2625
static void pgwin32_SharedMemoryDelete(int status, Datum shmId);
2726

28-
static const char *
29-
mi_type(DWORD code)
30-
{
31-
switch (code)
32-
{
33-
case MEM_IMAGE:
34-
return "img";
35-
case MEM_MAPPED:
36-
return "map";
37-
case MEM_PRIVATE:
38-
return "prv";
39-
}
40-
return "???";
41-
}
42-
43-
static const char *
44-
mi_state(DWORD code)
45-
{
46-
switch (code)
47-
{
48-
case MEM_COMMIT:
49-
return "commit";
50-
case MEM_FREE:
51-
return "free ";
52-
case MEM_RESERVE:
53-
return "reserv";
54-
}
55-
return "???";
56-
}
57-
58-
/*
59-
* Append memory dump to buf. To avoid affecting the memory map mid-run,
60-
* buf should be preallocated to be bigger than needed.
61-
*/
62-
static void
63-
dumpmem(StringInfo buf, const char *reason)
64-
{
65-
char *addr = 0;
66-
MEMORY_BASIC_INFORMATION mi;
67-
68-
appendStringInfo(buf, "%s memory map:\n", reason);
69-
do
70-
{
71-
memset(&mi, 0, sizeof(mi));
72-
if (!VirtualQuery(addr, &mi, sizeof(mi)))
73-
{
74-
if (GetLastError() == ERROR_INVALID_PARAMETER)
75-
break;
76-
appendStringInfo(buf, "VirtualQuery failed: %lu\n", GetLastError());
77-
break;
78-
}
79-
appendStringInfo(buf, "0x%p+0x%p %s (alloc 0x%p) %s\n",
80-
mi.BaseAddress, (void *) mi.RegionSize,
81-
mi_type(mi.Type), mi.AllocationBase,
82-
mi_state(mi.State));
83-
addr += mi.RegionSize;
84-
} while (addr > 0);
85-
}
86-
8727
/*
8828
* Generate shared memory segment name. Expand the data directory, to generate
8929
* an identifier unique for this data directory. Then replace all backslashes
@@ -251,7 +191,6 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port,
251191
SIZE_T largePageSize = 0;
252192
Size orig_size = size;
253193
DWORD flProtect = PAGE_READWRITE;
254-
MEMORY_BASIC_INFORMATION info;
255194

256195
/* Room for a header? */
257196
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
@@ -420,14 +359,6 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port,
420359
/* Register on-exit routine to delete the new segment */
421360
on_shmem_exit(pgwin32_SharedMemoryDelete, PointerGetDatum(hmap2));
422361

423-
/* Log information about the segment's virtual memory use */
424-
if (VirtualQuery(memAddress, &info, sizeof(info)) != 0)
425-
elog(LOG, "mapped shared memory segment at %p, requested size 0x%zx, mapped size 0x%zx",
426-
memAddress, size, info.RegionSize);
427-
else
428-
elog(LOG, "VirtualQuery(%p) failed: error code %lu",
429-
memAddress, GetLastError());
430-
431362
*shim = hdr;
432363
return hdr;
433364
}
@@ -448,55 +379,28 @@ PGSharedMemoryReAttach(void)
448379
{
449380
PGShmemHeader *hdr;
450381
void *origUsedShmemSegAddr = UsedShmemSegAddr;
451-
StringInfoData buf;
452382

453383
Assert(UsedShmemSegAddr != NULL);
454384
Assert(IsUnderPostmaster);
455385

456-
/* Ensure buf is big enough that it won't grow mid-operation */
457-
initStringInfo(&buf);
458-
enlargeStringInfo(&buf, 128 * 1024);
459-
/* ... and let's just be sure all that space is committed */
460-
memset(buf.data, 0, buf.maxlen);
461-
462-
/* Test: see if this lets the process address space quiesce */
463-
pg_usleep(1000000L);
464-
465-
dumpmem(&buf, "before VirtualFree");
466-
467386
/*
468387
* Release memory region reservation that was made by the postmaster
469388
*/
470389
if (VirtualFree(UsedShmemSegAddr, 0, MEM_RELEASE) == 0)
471390
elog(FATAL, "failed to release reserved memory region (addr=%p): error code %lu",
472391
UsedShmemSegAddr, GetLastError());
473392

474-
dumpmem(&buf, "after VirtualFree");
475-
476393
hdr = (PGShmemHeader *) MapViewOfFileEx(UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr);
477394
if (!hdr)
478-
{
479-
DWORD maperr = GetLastError();
480-
481-
dumpmem(&buf, "after failed MapViewOfFileEx");
482-
elog(LOG, "%s", buf.data);
483-
484395
elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): error code %lu",
485-
UsedShmemSegID, UsedShmemSegAddr, maperr);
486-
}
487-
488-
dumpmem(&buf, "after MapViewOfFileEx");
489-
elog(LOG, "%s", buf.data);
490-
396+
UsedShmemSegID, UsedShmemSegAddr, GetLastError());
491397
if (hdr != origUsedShmemSegAddr)
492398
elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)",
493399
hdr, origUsedShmemSegAddr);
494400
if (hdr->magic != PGShmemMagic)
495401
elog(FATAL, "reattaching to shared memory returned non-PostgreSQL memory");
496402
dsm_set_control_handle(hdr->dsm_control);
497403

498-
pfree(buf.data);
499-
500404
UsedShmemSegAddr = hdr; /* probably redundant */
501405
}
502406

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy