Re: Memory mapped file pages getting cleared when memory overcommi

Tech-Archive recommends: Fix windows errors by optimizing your registry




I don't think the file should even be really closed. Even though the
program dose a close of the file handle and the mapping object, it never did
the UnmapViewOfFile. Should not the system keep the file open because of
that.


"Alexander Grigoriev" wrote:

I guess, that the underlying backing file becomes deleted and inaccessible
for page-out. Thus, any pageout discards the page. I don't like this
behavior, but it could be by design. If it is, it should better be
documented.

"Michael Vogt" <MichaelVogt@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E14D5FFD-DF41-40D9-A694-05D1CB9010D0@xxxxxxxxxxxxxxxx

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



.



Relevant Pages

  • Re: Slow performance
    ... once the program opens up. ... memory is too low. ... Windows Live Once Care, and I usually notice improvement after I run the ... A visit to Event Viewer. ...
    (microsoft.public.windowsxp.perform_maintain)
  • RE: 2003 xls wont open in 200
    ... The backup is to protect against that .001% rare occurrance. ... chance it has of finding memory errors. ... "Newtie" wrote: ... opens fine on my laptop in compatibility mode. ...
    (microsoft.public.excel.misc)
  • Re: The document name or path is not valid
    ... was the hard disk ... When Word opens a document, ... If you don't properly shut down a memory stick using the control on the ... Windows Explorer to copy it from the memory stick to the hard drive of your ...
    (microsoft.public.word.docmanagement)
  • Re: Cant fix random freeze/lockup problems
    ... Since you have the case open, remove the memory and then reseat the memory. ... load Windows and perform a Scandisk. ... for Scandisk opens up, Select both check boxes. ... Running scandisk will identify this sector ...
    (microsoft.public.windowsxp.general)
  • Re: Memory leak in the Driver
    ... if the following application is used then, there is no memory leak. ... you are building a driver for? ... opens the device, ...
    (microsoft.public.windowsce.platbuilder)