0

I am wondering how to set the following value within .NET 4.0 (it has a getter, but not a setter):

Process.GetCurrentProcess().PeakWorkingSet64();

Update:

I would like to set this to a very high value, to reduce soft page faults which are caused by the increase in the programs working set. This may help with latency issues we have identified with a profiler.

Update:

As Yuxiu pointed out, you can't set the peak (its rather an observation). What I really want to do is set the working set for a 64-bit process:

Process.GetCurrentProcess().WorkingSet64() = xxx;

Update:

The correct answer to this question is at How to set MinWorkingSet and MaxWorkingSet in a 64-bit .NET process?

Community
  • 1
  • 1
Contango
  • 76,540
  • 58
  • 260
  • 305
  • That's a bit like setting the odometer on your car. – phoog Aug 30 '12 at 18:53
  • var setDiff = new byte[Math.Max(0,targetsWS - Process.GetCurrentProcess().PeakWorkingSet64())]; – Alois Kraus Aug 30 '12 at 18:55
  • 1
    The peak working set is an observation, not a configuration. You can't change observations just by changing a number. You have to change the underlying phenomenon itself. For your latency issue, the right way to fix is to load everything you need to memory on initialization. – Todd Li Aug 30 '12 at 19:41
  • @Yuxiu Yes, you are right - it should be WorkingSet64 not PeakWorkingSet64. – Contango Aug 30 '12 at 20:28
  • possible duplicate of [How to set MinWorkingSet and MaxWorkingSet in a 64-bit .NET process?](http://stackoverflow.com/questions/12203969/how-to-set-minworkingset-and-maxworkingset-in-a-64-bit-net-process) – Contango Aug 31 '12 at 14:56

1 Answers1

1

You are after SetProcessWorkingSetSize which is present in .NET via

Process.GetCurrentProcess().MinWorkingSet = xxx;

this way you can ensure that (nearly) all of your pages are not paged out. Paging is only one issue when you deal with latency. If you have a big object graph the GC times will also negativly impact latency times. In essence size does matter. If you decrease the overall memory consumption you will get shorter GC times and less working set which is then more unlikely to be paged out.

Alois Kraus
  • 13,229
  • 1
  • 38
  • 64
  • I can do this, but unfortunately it doesn't affect WorkingSet64. – Contango Aug 30 '12 at 20:37
  • I think this Windows API does nothing. Can't find the reference right now. – usr Aug 30 '12 at 20:39
  • This works to set the value, however, to set the 64-bit working set, see http://stackoverflow.com/questions/12203969/how-to-set-minworkingset-and-maxworkingset-in-a-64-bit-net-process – Contango Aug 31 '12 at 14:58