PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > my code to prove working set larger than virtual bytes
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
my code to prove working set larger than virtual bytes

Réponse
 
LinkBack Outils de la discussion
Vieux 17/01/2008, 14h23   #1
George2
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut my code to prove working set larger than virtual bytes

Hello everyone,


From the definition of working set, it is a subset of virtual pages
resident in physical memory -- from book Windows Internals. It means
working set could not be larger than virtual memory (subset
relationship).

But the following simple code on Windows Server 2003 proves (if you
monitor virtual bytes counter and working set bytes conuter from
perfmon), if we do not unmap the page map file, the working set will
continue to increase (and much larger than virtual bytes) until we
unmap it.

Take a breakpoint before following code section,

<code>
<pre>
// close mapped files to avoid leak
for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex+
+)
{
if (map [sectionIndex])
{
UnmapViewOfFile(map [sectionIndex]);
}
}
</pre>
</code>

Any ideas? Does my code break the definition of working set? Why
working set is much larger than virtual bytes?

<code>
<pre>

int main(int argc, char* argv[])
{
LARGE_INTEGER start,end;
LARGE_INTEGER freq;
QueryPerformanceCounter(&start);
QueryPerformanceFrequency(&freq);
MEMORYSTATUS memstat;
void** map;
int sectionIndex = 0;
memstat.dwLength = sizeof(memstat);
GlobalMemoryStatus(&memstat);

// basic file mapping test (512 MB)
long long size = 512*1024*1024;

HANDLE mapping =
CreateFileMapping(NULL,NULL,PAGE_READWRITE|SEC_COM MIT,(DWORD)(size <<
32),DWORD(size),NULL);
if (mapping)
{
// create and destroy temporary views
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
const int allocSize = sysInfo.dwAllocationGranularity;

GlobalMemoryStatus(&memstat);

void *mem = new char[allocSize];
memset(mem,0x11,allocSize);

map = (void**) new char [sizeof(void*) * size / allocSize];

for (int i=0; i < 10; i++)
{

sectionIndex = 0;
for (long long offset=0; offset&lt;=size-allocSize; offset
+=allocSize)
{
map [sectionIndex] =
MapViewOfFile(mapping,FILE_MAP_WRITE,(DWORD)(offse t<<32),
(DWORD)offset,allocSize);
if (map [sectionIndex])
{
memcpy(map [sectionIndex],mem,allocSize);
// UnmapViewOfFile(map);
}

sectionIndex++;
} // for (long long offset=0; offset<=size-allocSize; offset
+=allocSize)

// close mapped files to avoid leak
for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex+
+)
{
if (map [sectionIndex])
{
UnmapViewOfFile(map [sectionIndex]);
}
}

GlobalMemoryStatus(&memstat);

sectionIndex = 0;
for (long long offset=0; offset <= size-allocSize; offset
+=allocSize)
{
map [sectionIndex] =
MapViewOfFile(mapping,FILE_MAP_READ,(DWORD)(offset << 32),
(DWORD)offset,allocSize);
if (map [sectionIndex])
{
for (int t=0; t < allocSize; t++)
{
if (((char *)(map [sectionIndex]))[t]!=0x11)
{
OutputDebugString("Memory read failed\n");
}
}
}

UnmapViewOfFile(map [sectionIndex]);
}

// close mapped files to avoid leak
/*
for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex+
+)
{
if (map [sectionIndex])
{
UnmapViewOfFile(map [sectionIndex]);
}
}
*/

GlobalMemoryStatus(&memstat);
} // for (int i=0; i < 10; i++)

QueryPerformanceCounter(&end);

GlobalMemoryStatus(&memstat);

printf("Time %.3f\n",
double(end.QuadPart-start.QuadPart)/double(freq.QuadPart));
CloseHandle(mapping);
delete[] mem;
GlobalMemoryStatus(&memstat);
} //if (mapping)

return 0;
}
</pre>
</code>


thanks in advance,
George
  Réponse avec citation
Vieux 17/01/2008, 15h35   #2
Salt_Peter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: my code to prove working set larger than virtual bytes

On Jan 17, 9:23 am, George2 <george4acade...@yahoo.com> wrote:
> Hello everyone,
>
> From the definition of working set, it is a subset of virtual pages
> resident in physical memory -- from book Windows Internals. It means
> working set could not be larger than virtual memory (subset
> relationship).
>
> But the following simple code on Windows Server 2003 proves (if you
> monitor virtual bytes counter and working set bytes conuter from
> perfmon), if we do not unmap the page map file, the working set will
> continue to increase (and much larger than virtual bytes) until we
> unmap it.
>
> Take a breakpoint before following code section,
>
> <code>
> <pre>
> // close mapped files to avoid leak
> for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex+
> +)
> {
> if (map [sectionIndex])
> {
> UnmapViewOfFile(map [sectionIndex]);
> }
> }
> </pre>
> </code>
>
> Any ideas? Does my code break the definition of working set? Why
> working set is much larger than virtual bytes?


Once again, you are off topic. Thats not an idea - its a fact.
Please ask Windows questions in a Windows newsgroup.
Consult the FAQ in order to redirect your quest to the appropriate
newsgroup.

[5.9] Which newsgroup should I post my questions?
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

>
> <code>
> <pre>
>
> int main(int argc, char* argv[])
> {
> LARGE_INTEGER start,end;
> LARGE_INTEGER freq;
> QueryPerformanceCounter(&start);
> QueryPerformanceFrequency(&freq);
> MEMORYSTATUS memstat;
> void** map;
> int sectionIndex = 0;
> memstat.dwLength = sizeof(memstat);
> GlobalMemoryStatus(&memstat);
>
> // basic file mapping test (512 MB)
> long long size = 512*1024*1024;
>
> HANDLE mapping =
> CreateFileMapping(NULL,NULL,PAGE_READWRITE|SEC_COM MIT,(DWORD)(size <<
> 32),DWORD(size),NULL);
> if (mapping)
> {
> // create and destroy temporary views
> SYSTEM_INFO sysInfo;
> GetSystemInfo(&sysInfo);
> const int allocSize = sysInfo.dwAllocationGranularity;
>
> GlobalMemoryStatus(&memstat);
>
> void *mem = new char[allocSize];
> memset(mem,0x11,allocSize);
>
> map = (void**) new char [sizeof(void*) * size / allocSize];
>
> for (int i=0; i < 10; i++)
> {
>
> sectionIndex = 0;
> for (long long offset=0; offset<=size-allocSize; offset
> +=allocSize)
> {
> map [sectionIndex] =
> MapViewOfFile(mapping,FILE_MAP_WRITE,(DWORD)(offse t<<32),
> (DWORD)offset,allocSize);
> if (map [sectionIndex])
> {
> memcpy(map [sectionIndex],mem,allocSize);
> // UnmapViewOfFile(map);
> }
>
> sectionIndex++;
> } // for (long long offset=0; offset<=size-allocSize; offset
> +=allocSize)
>
> // close mapped files to avoid leak
> for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex+
> +)
> {
> if (map [sectionIndex])
> {
> UnmapViewOfFile(map [sectionIndex]);
> }
> }
>
> GlobalMemoryStatus(&memstat);
>
> sectionIndex = 0;
> for (long long offset=0; offset <= size-allocSize; offset
> +=allocSize)
> {
> map [sectionIndex] =
> MapViewOfFile(mapping,FILE_MAP_READ,(DWORD)(offset << 32),
> (DWORD)offset,allocSize);
> if (map [sectionIndex])
> {
> for (int t=0; t < allocSize; t++)
> {
> if (((char *)(map [sectionIndex]))[t]!=0x11)
> {
> OutputDebugString("Memory read failed\n");
> }
> }
> }
>
> UnmapViewOfFile(map [sectionIndex]);
> }
>
> // close mapped files to avoid leak
> /*
> for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex+
> +)
> {
> if (map [sectionIndex])
> {
> UnmapViewOfFile(map [sectionIndex]);
> }
> }
> */
>
> GlobalMemoryStatus(&memstat);
> } // for (int i=0; i < 10; i++)
>
> QueryPerformanceCounter(&end);
>
> GlobalMemoryStatus(&memstat);
>
> printf("Time %.3f\n",
> double(end.QuadPart-start.QuadPart)/double(freq.QuadPart));
> CloseHandle(mapping);
> delete[] mem;
> GlobalMemoryStatus(&memstat);
> } //if (mapping)
>
> return 0;}
>
> </pre>
> </code>
>
> thanks in advance,
> George


  Réponse avec citation
Vieux 17/01/2008, 16h46   #3
red floyd
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: my code to prove working set larger than virtual bytes

Salt_Peter wrote:
> On Jan 17, 9:23 am, George2 <george4acade...@yahoo.com> wrote:
>> [redacted]

>
> Once again, you are off topic. Thats not an idea - its a fact.
> Please ask Windows questions in a Windows newsgroup.
> Consult the FAQ in order to redirect your quest to the appropriate
> newsgroup.
>
> [5.9] Which newsgroup should I post my questions?
> http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
>


I know hope springs eternal, but there's no way this idiot is going to
read the FAQ. He hasn't yet, after being told to multiple times, but
good try anyways.... maybe you'll get him to do it this time.
  Réponse avec citation
Vieux 17/01/2008, 20h06   #4
jalina
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut SPAM was Re: my code to prove working set larger than virtual bytes

George2 a écrit :
> Hello everyone,
>
>
> From the definition of working set, it is a subset of virtual pages
> resident in physical memory -- from book Windows Internals. It means
> working set could not be larger than virtual memory (subset
> relationship).
>
> But the following simple code on Windows Server 2003 proves (if you
> monitor virtual bytes counter and working set bytes conuter from
> perfmon), if we do not unmap the page map file, the working set will
> continue to increase (and much larger than virtual bytes) until we
> unmap it.
>
> Take a breakpoint before following code section,
>
> <code>
> <pre>
> // close mapped files to avoid leak
> for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex+
> +)
> {
> if (map [sectionIndex])
> {
> UnmapViewOfFile(map [sectionIndex]);
> }
> }
> </pre>
> </code>
>
> Any ideas? Does my code break the definition of working set? Why
> working set is much larger than virtual bytes?
>
> <code>
> <pre>
>
> int main(int argc, char* argv[])
> {
> LARGE_INTEGER start,end;
> LARGE_INTEGER freq;
> QueryPerformanceCounter(&start);
> QueryPerformanceFrequency(&freq);
> MEMORYSTATUS memstat;
> void** map;
> int sectionIndex = 0;
> memstat.dwLength = sizeof(memstat);
> GlobalMemoryStatus(&memstat);
>
> // basic file mapping test (512 MB)
> long long size = 512*1024*1024;
>
> HANDLE mapping =
> CreateFileMapping(NULL,NULL,PAGE_READWRITE|SEC_COM MIT,(DWORD)(size <<
> 32),DWORD(size),NULL);
> if (mapping)
> {
> // create and destroy temporary views
> SYSTEM_INFO sysInfo;
> GetSystemInfo(&sysInfo);
> const int allocSize = sysInfo.dwAllocationGranularity;
>
> GlobalMemoryStatus(&memstat);
>
> void *mem = new char[allocSize];
> memset(mem,0x11,allocSize);
>
> map = (void**) new char [sizeof(void*) * size / allocSize];
>
> for (int i=0; i < 10; i++)
> {
>
> sectionIndex = 0;
> for (long long offset=0; offset&lt;=size-allocSize; offset
> +=allocSize)
> {
> map [sectionIndex] =
> MapViewOfFile(mapping,FILE_MAP_WRITE,(DWORD)(offse t<<32),
> (DWORD)offset,allocSize);
> if (map [sectionIndex])
> {
> memcpy(map [sectionIndex],mem,allocSize);
> // UnmapViewOfFile(map);
> }
>
> sectionIndex++;
> } // for (long long offset=0; offset<=size-allocSize; offset
> +=allocSize)
>
> // close mapped files to avoid leak
> for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex+
> +)
> {
> if (map [sectionIndex])
> {
> UnmapViewOfFile(map [sectionIndex]);
> }
> }
>
> GlobalMemoryStatus(&memstat);
>
> sectionIndex = 0;
> for (long long offset=0; offset <= size-allocSize; offset
> +=allocSize)
> {
> map [sectionIndex] =
> MapViewOfFile(mapping,FILE_MAP_READ,(DWORD)(offset << 32),
> (DWORD)offset,allocSize);
> if (map [sectionIndex])
> {
> for (int t=0; t < allocSize; t++)
> {
> if (((char *)(map [sectionIndex]))[t]!=0x11)
> {
> OutputDebugString("Memory read failed\n");
> }
> }
> }
>
> UnmapViewOfFile(map [sectionIndex]);
> }
>
> // close mapped files to avoid leak
> /*
> for (sectionIndex = 0; sectionIndex < size/allocSize; sectionIndex+
> +)
> {
> if (map [sectionIndex])
> {
> UnmapViewOfFile(map [sectionIndex]);
> }
> }
> */
>
> GlobalMemoryStatus(&memstat);
> } // for (int i=0; i < 10; i++)
>
> QueryPerformanceCounter(&end);
>
> GlobalMemoryStatus(&memstat);
>
> printf("Time %.3f\n",
> double(end.QuadPart-start.QuadPart)/double(freq.QuadPart));
> CloseHandle(mapping);
> delete[] mem;
> GlobalMemoryStatus(&memstat);
> } //if (mapping)
>
> return 0;
> }
> </pre>
> </code>
>
>
> thanks in advance,
> George

  Réponse avec citation
Vieux 18/01/2008, 07h21   #5
Stuart Redmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: my code to prove working set larger than virtual bytes

red floyd wrote:
> Salt_Peter wrote:
>
>> On Jan 17, 9:23 am, George2 <george4acade...@yahoo.com> wrote:
>>
>>> [redacted]

>>
>>
>> Once again, you are off topic. Thats not an idea - its a fact.
>> Please ask Windows questions in a Windows newsgroup.
>> Consult the FAQ in order to redirect your quest to the appropriate
>> newsgroup.
>>
>> [5.9] Which newsgroup should I post my questions?
>> http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
>>

>
> I know hope springs eternal, but there's no way this idiot is going to
> read the FAQ. He hasn't yet, after being told to multiple times, but
> good try anyways.... maybe you'll get him to do it this time.


Has anyone seens George2 sending a reply to one of his topics? As this guy does
not really look trollish, can't it be that he posts to this newsgroup without
realizing it? Maybe his news client has once been configured to automatically
multi-post to various newsgroups, but he has forgotten about it?

I found out that this guy writes as George to microsoft.public.vc.language, too,
opening the same threads, but contrary to this group he sends replies to the
other newsgroup (even making replies to someone else's threads).

Could it simply be that he doesn't even know that he also posts to this
newsgroup, so he never even sees our complaints about his being off-topic?

Stuart
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h17.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18523 seconds with 13 queries