Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit73042b8

Browse files
committed
Map and unmap the shared memory block before risking VirtualFree.
The idea here is to get Windows' userspace infrastructure to allocatewhatever space it needs for MapViewOfFileEx() before we release thelocked-down space that we want to map the shared memory block into.This is a fairly brute-force attempt, and would likely (for example)fail with large shared memory on 32-bit Windows. We could perhapsameliorate that by mapping only part of the shared memory block inthis way, but for the moment I just want to see if this approachwill fix dory's problem.Discussion:https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
1 parentce07aff commit73042b8

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

‎src/backend/port/win32_shmem.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ dumpmem(StringInfo buf, const char *reason)
6565
char*addr=0;
6666
MEMORY_BASIC_INFORMATIONmi;
6767

68-
appendStringInfo(buf,"%s memory map:",reason);
68+
appendStringInfo(buf,"%s memory map:\n",reason);
6969
do
7070
{
7171
memset(&mi,0,sizeof(mi));
7272
if (!VirtualQuery(addr,&mi,sizeof(mi)))
7373
{
7474
if (GetLastError()==ERROR_INVALID_PARAMETER)
7575
break;
76-
appendStringInfo(buf,"\nVirtualQuery failed: %lu",GetLastError());
76+
appendStringInfo(buf,"VirtualQuery failed: %lu\n",GetLastError());
7777
break;
7878
}
79-
appendStringInfo(buf,"\n0x%p+0x%p %s (alloc 0x%p) %s",
79+
appendStringInfo(buf,"0x%p+0x%p %s (alloc 0x%p) %s\n",
8080
mi.BaseAddress, (void*)mi.RegionSize,
8181
mi_type(mi.Type),mi.AllocationBase,
8282
mi_state(mi.State));
@@ -457,6 +457,22 @@ PGSharedMemoryReAttach(void)
457457
initStringInfo(&buf);
458458
enlargeStringInfo(&buf,128*1024);
459459

460+
dumpmem(&buf,"beginning PGSharedMemoryReAttach");
461+
462+
hdr= (PGShmemHeader*)MapViewOfFileEx(UsedShmemSegID,FILE_MAP_READ |FILE_MAP_WRITE,0,0,0,NULL);
463+
if (hdr)
464+
{
465+
if (!UnmapViewOfFile(hdr))
466+
elog(LOG,"could not unmap temporary view of shared memory: error code %lu",
467+
GetLastError());
468+
}
469+
else
470+
{
471+
/* This isn't fatal, just unpromising ... */
472+
elog(LOG,"could not attach to shared memory (key=%p) at any address: error code %lu",
473+
UsedShmemSegID,GetLastError());
474+
}
475+
460476
dumpmem(&buf,"before VirtualFree");
461477

462478
/*
@@ -479,6 +495,10 @@ PGSharedMemoryReAttach(void)
479495
elog(FATAL,"could not reattach to shared memory (key=%p, addr=%p): error code %lu",
480496
UsedShmemSegID,UsedShmemSegAddr,maperr);
481497
}
498+
499+
dumpmem(&buf,"after MapViewOfFileEx");
500+
elog(LOG,"%s",buf.data);
501+
482502
if (hdr!=origUsedShmemSegAddr)
483503
elog(FATAL,"reattaching to shared memory returned unexpected address (got %p, expected %p)",
484504
hdr,origUsedShmemSegAddr);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp