From: Amit Kapila [mailto:[email protected]] > > Hmm, the large-page requires contiguous memory for each page, so this > error could occur on a long-running system where the memory is heavily > fragmented. For example, please see the following page and check the memory > with RAMMap program referred there. > > > > I don't have RAMMap and it might take some time to investigate what is going > on, but I think in such a case even if it works we should keep the default > value of huge_pages as off on Windows. I request somebody else having > access to Windows m/c to test this patch and if it works then we can move > forward.
You are right. I modified the patch so that the code falls back to the
non-huge page when CreateFileMapping() fails due to the shortage of large
pages. That's what the Linux version does.
The other change is to parameterize the Win32 function names in the messages in
EnableLockPagePrivileges(). This is to avoid adding almost identical messages
unnecessarily. I followed Alvaro's comment. I didn't touch the two existing
sites that embed Win32 function names. I'd like to leave it up to the
committer to decide whether to change as well, because changing them might make
it a bit harder to apply some bug fixes to earlier releases.
FYI, I could reproduce the same error as Amit on 32-bit Win7, where the total
RAM is 3.5 GB and available RAM is 2 GB. I used the attached largepage.c.
Immediately after the system boot, I could only allocate 8 large pages. When I
first tried to allocate 32 large pages, the test program produced:
large page size = 2097152
allocating 32 large pages...
CreateFileMapping failed: error code = 1450
You can build the test program as follows:
cl largepage.c advapi32.lib
Regards
Takayuki Tsunakawa
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
static void EnableLockPagesPrivilege(void);
void main(int argc, char *argv[])
{
SIZE_T largePageSize = 0;
HANDLE hmap;
int pages = 1;
largePageSize = GetLargePageMinimum();
printf("large page size = %u\n", largePageSize);
EnableLockPagesPrivilege();
if (argc > 1)
pages = atoi(argv[1]);
printf("allocating %d large pages...\n", pages);
hmap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL,
PAGE_READWRITE | SEC_COMMIT | SEC_LARGE_PAGES,
0, largePageSize * pages,
"myshmem");
if (hmap)
printf("allocated large pages successfully\n");
else
printf("CreateFileMapping failed: error code = %u",
GetLastError());
}
static void
EnableLockPagesPrivilege(void)
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES |
TOKEN_QUERY, &hToken))
{
printf("OpenProcessToken failed: error code = %u",
GetLastError());
exit(1);
}
if (!LookupPrivilegeValue(NULL, SE_LOCK_MEMORY_NAME, &luid))
{
printf("LookupPrivilegeValue failed: error code = %u",
GetLastError());
exit(1);
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL))
{
printf("AdjustTokenPrivileges failed: error code = %u",
GetLastError());
exit(1);
}
if (GetLastError() != ERROR_SUCCESS)
{
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
printf("could not enable Lock Pages in Memory user
right");
else
printf("AdjustTokenPrivileges failed: error code = %u",
GetLastError());
exit(1);
}
CloseHandle(hToken);
}
win_large_pages_v8.patch
Description: win_large_pages_v8.patch
-- Sent via pgsql-hackers mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
