[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Why SetProcessWorkingSetSize() fails when called second time

Posted on 2006-05-05
13
Medium Priority
?
910 Views
Last Modified: 2012-06-27
I try to allocate as much as possible physical RAM on 2 GB notebook.

So I:

1. Determine how much memory can I use.

mem_size = phys_mem_size - commited bytes ("Commited Bytes" of "Memory" object - performance counter)

2. Call SetProcessWorkingSetSize() with original limits increased by mem_size.
SetProcessWorkingSetSize() succeeds.

3. Call VirtualAlloc() with "commit" flag starting from mem_size.
After some iterations (decreasing size) function succeeds.

4. Call VirtualLock() to force pages being in RAM. It succeeds also.

5. Call VirtualUnlock()

6. Call VirtualFree()

7. Call SetProcessWorkingSetSize() with original limits.

8. SetProcessWorkingSetSize() again and this time it fails.

Let's say that when called for the first time it succeeded for 700 MB, but for the second time succeeded for 70 MB. Why ?

Unterforunately I do not have acceess to this laptop (it is over the ocean) so I cannot debug it.
I never noticed such problem eralier on 512 MB PC (W2K) nor my current 256 MB PC (XP).
0
Comment
Question by:mrblue
12 Comments
 
LVL 2

Expert Comment

by:htang_us
ID: 16617539
After step 6, you might need to check how much memory you have. The free process might take some time.
0
 
LVL 2

Expert Comment

by:bachra04
ID: 16617540
Please have a look at this link, it may help

http://support.microsoft.com/?kbid=823684

B.T
0
 
LVL 2

Expert Comment

by:bachra04
ID: 16617586
What are the parameters that you pass to SetProcessWorkingSetSize  when it fails.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 8

Author Comment

by:mrblue
ID: 16618293
What are the parameters that you pass to SetProcessWorkingSetSize()

MIN = ORG_MIN + estimated_mem_size + 30 MB
MAX= ORG_MAX + estimated_mem_size + 30 MB

where

estimated_mem_size = total_phys_mem_size - commited_bytes - 70 MB

Memory is allocated by application process (Admin user).

Process privilege SE_INC_BASE_PRIORITY_NAME is enabled (AdjustTokenPrivileges() with SE_PRIVELEGE_ENABLED).

The same parameters (if I am not mistaken) are used for the first time when SetProcessWorkingSetSize() succeeds and for the second time when it fails.

After step 8 steps are repeated starting from step 1 (on interactive request).

"estimated_mem_size" in second iteration is similar but just SetProcessWorkingSetSize() fails.
0
 
LVL 8

Author Comment

by:mrblue
ID: 16618306
I should say steps 1-7 step 8 is just element of next 1-7 steps
0
 
LVL 2

Expert Comment

by:bachra04
ID: 16618371
I think the only way when SetProcessWorkingSetSize fail is when MIN = MAX. this may happen if estimated_mem_size is negative i.e total_physical_mem_size - commited_bytes is less than 70 MB.
0
 
LVL 8

Author Comment

by:mrblue
ID: 16618497
No, I test if total_physical_mem_size > commited_bytes + 70 MB
It cannot be negative. Apart from that I use unsigned variables and also should't it happen in the first iteration also ?
0
 
LVL 8

Author Comment

by:mrblue
ID: 16620644
I have latest news:
  After removing 1 GB memory module from notebook all works fine.
0
 
LVL 22

Expert Comment

by:grg99
ID: 16637993
It's usually a poor idea to set the working set size.   The system or some other app or service may try to start up and need some memory, and there may not be any available since you're hogging it.

Normally Windows does a good job of allocating memory-- why not let it do it's thing?

0
 
LVL 8

Author Comment

by:mrblue
ID: 16638338
"It's usually a poor idea to set the working set size" - I know.
In the first place I wanted it to work least harmfull way possible - to correctly estimate amount of memory I can alloc & lock without interferring currently running software (system & applications).
I want it to be in physical memory before this memory is to be written in round-robin manner sometimes for long hours till some event will happen. Hence I don't want some memory pages to be page out to hard disk (saving disk & performance also are issues).
By the way what can limit parameters passed to SetProcessWorkingSetSize() ?
I know that VirtualAlloc() requires contiguous range of addresses in virtual address space. I am not sure if memory can be compacted some way by Memory Manager.
0
 
LVL 8

Author Comment

by:mrblue
ID: 16638351
It should be:

"I want it to be in physical memory because"
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 16831078
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question