Michael Vogt
2007-01-26 17:20:02 UTC
I have a win32 program running on XP Pro that is using a memory mapped file
to create shared memory. I find that some or all pages of that memory are
being cleared in memory overcommit situations.
The program does not actually need the persistence of a file, so the
CreateFile() is called with flag FILE_FLAG_DELETE_ON_CLOSE. After doing the
CreateFileMapping()and MapViewOfFile() the program does a CloseHandle() on
the file handle and on the handle to the file mapping object but still keeps
"open" the pointer returned from MapViewOfFile().
Here is the relevant initialization code for the memory:
hFilePtr = CreateFile( TCPDRV32FILE,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_HIDDEN |
FILE_ATTRIBUTE_TEMPORARY |
FILE_FLAG_DELETE_ON_CLOSE |
FILE_ATTRIBUTE_NORMAL,
NULL );
hFileMap = CreateFileMapping( (HANDLE)hFilePtr,
NULL,
PAGE_READWRITE,
0,
size,
TCPDRV32SHR );
lpMapAddr = MapViewOfFile( hFileMap,
FILE_MAP_ALL_ACCESS,
0, 0,
0 );
CloseHandle( hFileMap );
CloseHandle( hFilePtr );
In the relevant scenarios, no other application process opens the mapped
memory.
The memory is only getting lost/cleared when I do something like open 20 IE
sessions.
The memory clearing can be prevented by any of the following:
- Don't set FILE_FLAG_DELETE_ON_CLOSE
- don't close the file handle
- frequently read from the memory.
I need to know if this behaviour is expected because I need to rule out that
the program is doing something else wrong.
The reason I suspect something else is going on is because in some
application scenarios, the problem does not occur. That is, there are certain
application scenarios that experience the problem and others that do not. In
at least some of those cases the memory is not being read any more frequently
than a failing case.
See this post in the WinDbg newsgroup for some other background:
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.windbg&tid=89af28e3-2d38-48c5-af7d-e17125ea88fb&m=1&p=1
Thanks for any help or insight.
Michael Vogt
to create shared memory. I find that some or all pages of that memory are
being cleared in memory overcommit situations.
The program does not actually need the persistence of a file, so the
CreateFile() is called with flag FILE_FLAG_DELETE_ON_CLOSE. After doing the
CreateFileMapping()and MapViewOfFile() the program does a CloseHandle() on
the file handle and on the handle to the file mapping object but still keeps
"open" the pointer returned from MapViewOfFile().
Here is the relevant initialization code for the memory:
hFilePtr = CreateFile( TCPDRV32FILE,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_HIDDEN |
FILE_ATTRIBUTE_TEMPORARY |
FILE_FLAG_DELETE_ON_CLOSE |
FILE_ATTRIBUTE_NORMAL,
NULL );
hFileMap = CreateFileMapping( (HANDLE)hFilePtr,
NULL,
PAGE_READWRITE,
0,
size,
TCPDRV32SHR );
lpMapAddr = MapViewOfFile( hFileMap,
FILE_MAP_ALL_ACCESS,
0, 0,
0 );
CloseHandle( hFileMap );
CloseHandle( hFilePtr );
In the relevant scenarios, no other application process opens the mapped
memory.
The memory is only getting lost/cleared when I do something like open 20 IE
sessions.
The memory clearing can be prevented by any of the following:
- Don't set FILE_FLAG_DELETE_ON_CLOSE
- don't close the file handle
- frequently read from the memory.
I need to know if this behaviour is expected because I need to rule out that
the program is doing something else wrong.
The reason I suspect something else is going on is because in some
application scenarios, the problem does not occur. That is, there are certain
application scenarios that experience the problem and others that do not. In
at least some of those cases the memory is not being read any more frequently
than a failing case.
See this post in the WinDbg newsgroup for some other background:
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.windbg&tid=89af28e3-2d38-48c5-af7d-e17125ea88fb&m=1&p=1
Thanks for any help or insight.
Michael Vogt