Memory priorities

Started by BenYeeHua, December 04, 2012, 02:41:35 PM

Previous topic - Next topic

BenYeeHua

Note from Bitsum (not author of this post):

Windows memory page priorities are used to help the virtual memory manager decide what pages should remain in RAM during high memory loads. For cases where there is not much paging going on, they are not really of great importance.

Memory page priorities are 0-7, with 0 being the lowest and 5 being the default (normal). Pages with the highest memory priority will be paged out last, all other factors being equal.

MEMORY_PRIORITY_VERY_LOW 1
MEMORY_PRIORITY_LOW 2
MEMORY_PRIORITY_MEDIUM 3
MEMORY_PRIORITY_BELOW_NORMAL 4
MEMORY_PRIORITY_NORMAL 5
MEMORY_PRIORITY_UNDEFINED_HIGH 6
MEMORY_PRIORITY_UNDEFINED_HIGHEST 7

Technet quote
"Beginning with Windows Vista, each memory page has a priority ranging from 0 to 7.  The Standby List is divided into eight lists that each handle pages of a different priority.  When the Memory Manager wants to take a page from the Standby List, it takes pages from the low-priority lists first. "

Process Lasso can help manage memory priorities by allowing persistent memory priorities to be set for processes, so that their virtual memory pages are set to a specific priority each time run.

Now, back to the previously written thread .....


-------------------------------
Quote from: Hotrod on December 04, 2012, 01:32:29 PM
I may depend greatly on exactly WHAT things you like to do with your browser. If you are visiting a gaming website where the pages are very "busy" ie alot of graphics and sounds and scripts, these will tax your bandwidth to the point that it stalls anything else using the network. I have found that most browsers WANT to have the connection to the page you request at the expense of everything on the system. I have had my browser eat so much bandwidth that nothing else can get a bite.  Or on the opposite side one that completely locks up my PC because it can't get ALL the items on a page and goes into an indefinite "Wait" cycle that grinds everything else to a halt.
About bandwidth, you can use Cfosspeed to control the RWIN for all connection.
The RWIN just like you are telling the servers that, how many data you can give to me.
So it will not cause the ISP is full of buffer and delay your important data ;)
----OT line
With Process Explorer, I see there are 2 strange priority, which is
Background: 4(Low I/O and Memory Priority)
Idle: 4
And windows is completely don't use the "Background"?

Will PL adding the "Background" Priority and adding the strange "Memory Priority", or the answer is this?
QuoteTherefore, Microsoft recommends applications set their I/O priority indirectly by changing either the base process priority class or individual thread priority.
http://bitsum.com/pl_io_priority.php

And it seen like the "Memory Priority" is
QuoteOn Windows Vista, every page of memory has a priority in the range of 0 to 7, and so the Memory Manager divides the Standby List into eight lists that each store pages of a particular priority. When the Memory Manager wants to take a page from the Standby List, it takes pages from low-priority lists first. A page's priority usually reflects that of the thread that first causes its allocation. (If the page is shared, it reflects the highest of memory priorities of the sharing threads.) A thread inherits its page-priority value from the process to which it belongs. The Memory Manager uses low priorities for pages it reads from disk speculatively when anticipating a process's memory accesses.
By default, processes have a page-priority value of 5, but functions allow applications and the system to change process and thread page-priority values. The real power of memory priorities is realized only when the relative priorities of pages are understood at a macro-level, which is the role of SuperFetch.
http://technet.microsoft.com/en-us/magazine/2007.03.vistakernel.aspx

It maybe useful for some heavy work multi-task worker, as they Ram is always nearly full and they want some background software

And I wonder why the PL is having the Memory Priority: 2And it seen like all the software start with Task Schedule will started by Memory Priority: 2, will not it cause the PL push to PageFile when the Ram is nearly full and affect the function of PL?
Maybe it can set to 6-7 to prevent PL is push to PageFile ;)

Solution
QuoteAnyway, even with the scheduled task priority fix, the memory priority of your task is set to 4, which is one notch below the normal setting of 5. When I manually boosted the memory priority of my task up to 5, the performance was on par with running the process interactively.

For info on boosting the priority, see my answer to a related StackOverflow question about IO priority; setting memory priority is done similarly, via NtSetInformationProcess, with PROCESS_INFORMATION_CLASS set to ProcessMemoryPriority (the value of this is 39 or 0x27). I might make a free utility that can be used to set this, if others need it and don't have access to programmer tools.

EDIT: I've gone ahead and written a free utility for querying and setting the memory priority of a task, available here. The download contains both source code and a compiled binary.
http://serverfault.com/questions/151824/process-runs-slower-as-a-scheduled-task-than-it-does-interactively


PS:Some information for the windows 8 new function?
MEMORY_PRIORITY_INFORMATION structure
QuoteThe memory priority of a thread or process serves as a hint to the memory manager when it trims pages from the working set. Other factors being equal, pages with lower memory priority are trimmed before pages with higher memory priority. For more information, see Working Set.
http://msdn.microsoft.com/en-us/library/windows/desktop/hh448387%28v=vs.85%29.aspx

Jeremy Collake

#1
Quote from: BenYeeHua on December 04, 2012, 02:41:35 PM
Will PL adding the "Background" Priority and adding the strange "Memory Priority", or the answer is this?http://bitsum.com/pl_io_priority.php

Background is the same as 'Very Low' in Process Lasso. I should probably change it to 'Background' instead of 'Very Low'. My rationale for using Very Low was simply to make it in line with the other priorities, as 'Background' isn't necessarily clear that it is lowest possible.

The memory page priorities are only important when you are in a high memory load situation (rare in the days of cheap RAM). They are used to help determine which pages should be trimmed first by the virtual memory manager.

When Process Lasso starts via the Task Scheduler, as it always does at user login for Vista or above, it inherits the Task Scheduler's priorities. While Process Lasso adjusts it own CPU and I/O priorities, it does not adjust its own memory priority. Therefore, you end up with a situation where it has a lower memory priority. Again, this doesn't make it run faster or slower in ANY WAY unless you are in a very high memory load situation. Even then, it is unlikely to affect Process Lasso at all because Process Lasso uses so little memory, relatively speaking. In short, the pages it uses are unlikely to be in a state of page out when they are referenced, inducing a page fault, no matter what its memory priority.

That said, I never noticed that the memory priority defaulted to this low value when started by the task scheduler, so I am now adding some code to adjust it. While I'm at it, I will go ahead and display the memory priorities of all processes, and allow them to be changed.

So, this will change in the next minor update, and I appreciate you pointing it out.

To be absolutely clear, it is nothing to worry about since Process Lasso doesn't use much memory, and is unlikely to be affected by paging. At best, it will help keep the memory of that application in RAM, preventing hard page faults in high memory loads. In other words, deter or encourage (but not prevent or mandate) paging of that process. It is NOT the only factor though when it comes to the virtual memory manager's decision on what pages to page out, or in. The text there says "other factors being equal", but all else is hardly ever equal. In example, another important factor is the reference count of the pages.
Software Engineer. Bitsum LLC.

BenYeeHua

QuoteBackground is the same as 'Very Low' in Process Lasso. I should probably change it to 'Background' instead of 'Very Low'. My rationale for using Very Low was simply to make it in line with the other priorities, as 'Background' isn't necessarily clear that it is lowest possible.
Nope, sorry for misleading you.
The "Background" is for the process priority, not I/O priority. :)
So you just change the priority of the process to "Background", and it will change the process to priority(Idle/4), I/O(very low) and Memory Priority(1) ;)
One click, changing all. ;D

I don't know it is support by os, or just the Process Explorer by manual changing all of this.
----
QuoteSo, this will change in the next minor update, and I appreciate you pointing it out.
And I also thank you for the Process Explorer dev, and you for create a useful software. ;)
----
Ya, all is handle by the OS, just devs can changing the priority manual, to prevent the paging.
And so great that, this memory priority is still don't know by many of the other devs.
After they know paging, they just put the memory into the PageFile instead of garbage collector or reduce/improve the code to reduce the memory usage.

So the foreground process memory(5) will not bite by the background process with the highesthigher memory(7) priority. :P
PS:The highest priority is 0, it is using by Nonpaged Pool, Driver Locked etc(the "free" is 0 too, but maybe it means empty priority, not managed by OS, can't paging.)

And this functions is useful for person that multi-task, convert, rendering, photoshop, Chrome(just kidding ::)) ...
Netbook too ;)

Maybe you can provide other function like "increase the memory priority of the foreground process". ;)

Jeremy Collake

#3
Ah, semantics ;). Background is technically the name of the lowest I/O priority, with Idle being the corresponding CPU priority. At least that is how they are specified in MSDN. Though these are just names and they do correlate with each other, so you are also correct. Some process managers have simply used 'background' to indicate using the lowest (for all) priority. It makes sense, and is easier for users to understand simply setting the process as 'Background' to induce the lowest priority for all.

Increasing the memory priority for the foreground application is an interesting idea. I'm not sure it would make a difference since the virtual memory manager considers *a lot* of factors when doing paging, with the memory priority just being one of them. However, it probably wouldn't hurt, and could potentially be useful --- and, if nothing else, seem useful to some people ;p.

I am going to try to get this update issued in a few hours ...





Software Engineer. Bitsum LLC.

Jeremy Collake

#4
Memory priority display now complete. I am implementing the ability to set the memory priority for any process as well, though it isn't done yet. Process Lasso does already set its own memory priority to 5.

The next final version will be an important one, doing some needed maintenance in a variety of areas. Preceding that will be a few betas.
Software Engineer. Bitsum LLC.

BenYeeHua

Good jobs ;)
I will testing it with some person that playing with convert/multi-task after you done.

And it(default memory priority) can be use for other software that start with Task Scheduler too. :)

edkiefer

Quote from: Jeremy Collake on December 08, 2012, 05:34:30 PM
Ah, semantics ;). Background is technically the name of the lowest I/O priority, with Idle being the corresponding CPU priority. At least that is how they are specified in MSDN. Though these are just names and they do correlate with each other, so you are also correct. Some process managers have simply used 'background' to indicate using the lowest (for all) priority. It makes sense, and is easier for users to understand simply setting the process as 'Background' to induce the lowest priority for all.

Increasing the memory priority for the foreground application is an interesting idea. I'm not sure it would make a difference since the virtual memory manager considers *a lot* of factors when doing paging, with the memory priority just being one of them. However, it probably wouldn't hurt, and could potentially be useful --- and, if nothing else, seem useful to some people ;p.

I am going to try to get this update issued in a few hours ...

I would think if a process is raised in priority class the memory would also get higher priority to match, like app going into foreground or what ever reason its raised .
Bitsum QA Engineer

BenYeeHua

Quotelike app going into foreground or what ever reason its raised .
QuoteIncreasing the memory priority for the foreground application is an interesting idea. I'm not sure it would make a difference since the virtual memory manager considers *a lot* of factors when doing paging, with the memory priority just being one of them. However, it probably wouldn't hurt, and could potentially be useful --- and, if nothing else, seem useful to some people ;p.
;D
Maybe increase the game/Media Player memory priority is a good idea, but it maybe also a bad idea, as the game maybe eating too much memory and causing other software paging too.
But it is not a problem for >8GB ram/SSD, as the limit of 32bit process with 64bit system is 4GB. ;D

So, change the memory priority
1.When change the process priority
2.When it is a game/media player
(can be enable/disable)

edkiefer

#8
I just noticed with Palemoon.exe (Firefox browser) and plugin- container.exe is not displaying a value for memory priority .

Edit: Seems like any process after PL is started doesn't show memory priority for me . if I close PL and restart then all process show a value .
Edit2: no its not that either, just seems to be random , I will see if I can find pattern .
Bitsum QA Engineer

BenYeeHua

No problem at here. :)
But will keep an eye on it. 8)

Jeremy Collake

I believe the problem in the current beta is an uninitialized variable, something I simply overlooked in this build. This causes it to fail or succeed based on what that memory happens to be when the variable is first referenced. Thus, it truly is pseudo-random.
Software Engineer. Bitsum LLC.

Jeremy Collake

Software Engineer. Bitsum LLC.

Jeremy Collake

v6.0.1.99 beta is building now. You can set memory priorities this build, though the default memory priorities aren't enabled yet. I may upload another build in just a few hours, but wanted to get this on out due to the string changes and general improvements. It makes a good staging build as I move forward.
Software Engineer. Bitsum LLC.

Jeremy Collake

Due to the crashes identified in the last final, I am issuing a new final prematurely, with the default memory priority support not yet complete. In short, I really screwed the pooch not regression testing the last final better after the change in CRT. Anyway, it is critical to get this update issued asap, so I'm doing that.
Software Engineer. Bitsum LLC.

Jeremy Collake

Default memory support code at about 90% now. Anticipate finishing very shortly.
Software Engineer. Bitsum LLC.

brandon02852

How do the numbers work?  Does zero mean no priority at all while seven is basically "Realtime" priority?

What would the benefits be to increasing memory priority to a process?  Would the process load/run faster than normal?

I don't really understand the concept of memory priority.

Jeremy Collake

Do you want a short answer? They are useless for boosting your PC performance in any way and should be avoided. See above for more complicated discussions.
Software Engineer. Bitsum LLC.

brandon02852

Quote from: Jeremy Collake on December 15, 2012, 10:29:34 PM
Do you want a short answer? They are useless for boosting your PC performance in any way and should be avoided. See above for more complicated discussions.

I read the above and didn't really understand what was being said.  If you could try to explain it to me in simpler terms, I would be greatful.

Why would a feature be included in PL when it is useless and should be avoided?

Jeremy Collake

Memory priorities don't make anything run slower or faster except in very unusual situations that I would have be hard pressed to intentionally try to demonstrate in a test bed, much less in the real world. How is that? ;)
Software Engineer. Bitsum LLC.

BenYeeHua

The best way is buying more RAM. ;D
If you are using the software that can using the Ram until 99% and causing the os push the other software data into the PageFile.(HDD/SSD)
Then it is useful, as it can prevent your other software being push into the PageFile(HDD/SSD) too much, and cause delay when switching to it. ;)

brandon02852

Oh, I think I understand now.  So the priority only comes into play when the resource is being utilized to its fullest.  Like how process priorities are ineffective until the CPU is being fully utilized.

So if I had 1GB ram with Windows 7, memory priorities would come into play much more than if I had 4 or 8GB.

BenYeeHua

Yup, and CPU is depend on the usage in a burst time.
So if you can buy a Ram for it when it is no enough, just buy it.
Except you can't buy it or the slot of the Ram is fully used or the motherboard is not support bigger Ram.
So it is useful for netbook, multi-task/heavy user and maybe small servers too. ;)

Hotrod

I've been testing/playing with memory priorities and I've found that I can't set any process to 6 or 7. I get a error pop up. Is this normal?

edkiefer

have you tried it with other priorities set higher for that process (priority class, i/o priority) , maybe needs one of them higher .

I have not messed with it .
Bitsum QA Engineer

BenYeeHua

I think is yes, just like I/O Priority-Critical, it(0,6,7) is backup by system and you can't use it. :)

Hotrod

Yes Ed I have tried it with a high priority process, but I don't mess with real time. I think maybe Ben is right here, but am waiting for JC's take on the subject. :)

BenYeeHua

You can use RamMap to check which process/file is using 0,6,7, and you will find that it is must in Ram(0), and frequently used file/important process(6,7).

Jeremy Collake

#27
I am just going to skim here, as I'm focused on code - catching up from the holidays. Needless to say, I can't really afford any break!

Setting certain memory priorities may be disallowed. In some cases, you may not have sufficient access to the process. In others, Windows may have a hard-coded block (as BeeYeeHua says). In others, there *may be* a local security policy or account security token relating to this (so it requires you enable this security item for your user security context). It could even be that the 'Increase Scheduling Priority' security right is something that also applies to memory priorities.

Possible solutions:


  • ELEVATION of Process Lasso (see Main Menu, click box in dialog you see there to run as admin).
  • (if exists??) check local security policy and user rights to see if any right or policy exists related to these - I haven't yet explored them all, though am looking now. One exists for 'real-time' priority, for instance. REPEAT - It could even be that the 'Increase Scheduling Priority' security right is something that also applies to memory priorities.
      Run secpol.msc
Software Engineer. Bitsum LLC.

BenYeeHua

QuoteELEVATION of Process Lasso (see Main Menu, click box in dialog you see there to run as admin).
It is always running as Admin. ;)
So this way can't walk.
----
Quote(if exists??) check local security policy and user rights to see if any right or policy exists related to these - I haven't yet explored them all, though am looking now. One exists for 'real-time' priority, for instance. REPEAT - It could even be that the 'Increase Scheduling Priority' security right is something that also applies to memory priorities.
  Run 'secpol.msc'
Windows 8(no Pro) at here, so I can't testing/finding it. :P

Jeremy Collake

I am too, just ran it ;). Simply type 'secpol.msc' into the Search box of the Metro shell. Then hit enter (despite no results being shown). This runs this process. You can try changing the option to allow increasing the scheduling priority in the Local User Rights section (look around).
Software Engineer. Bitsum LLC.

BenYeeHua

Nope, I can't find 'secpol.msc'.

Jeremy Collake

Strange. Maybe it doesn't come with Windows 8 non-Pro? or maybe even non-Enterprise... I forget which I installed since I have MSDN access to both.
Software Engineer. Bitsum LLC.

BenYeeHua

It is a Windows 8 Single Language. :)

Hotrod

I do not have secpol.msc here on Win7 X64 Home Premium either. :(

Jeremy Collake

#34
Update: Yea, searching around confirms a horrid fact given that this is an essential part of your system's security (lets you fine tune it)...


  • Vista: NOT included Home Premium AND below.
  • Windows 7: NOT included in Home Premium AND below.
  • Windows 8: Unclear, but may only be in Enterprise edition if the above report is correct :o. I will verify this in time here...

The MMC snap-in (MSC file) is likely redristributable - perhaps - except for legal issues ;p.
Software Engineer. Bitsum LLC.

edkiefer

secpol.msc comes up in win7 pro 64bit .

didn't run it but found it in search .
Bitsum QA Engineer

BenYeeHua

Just Google awhile, it is just a GUI for changing the registry and apply real-time.
And I think it is another license problem just like the memory limit.

Jeremy Collake

Even if Microsoft's management console snap-in can't be legally transposed, and can't be legally modified, it would be entirely plausible to develop either:


  • An alternative management console snap-in (MSC file). This format may or may not already be documented, I don't know. I am also unsure if the files are signed or if signing is enforced. I would guess it is do-able.
  • A simple application to edit the application registry values.

This needs to be developed, and I already put it in my HUGE idea bucket. Perhaps I will look into doing either at some point if it hasn't already been done. It is very simplistic really, and since it is rarely run, if an application is developed, I see no reason not to use managed code on this one. In fact, it might be a good exercise with managed code myself.
Software Engineer. Bitsum LLC.

BenYeeHua

So research about it first? :)

Jeremy Collake

Definitely. Maybe we can come up with something. Note that it might be part of some 'administrator's toolkit' or something. I also vaguely recall a console mode utility to set similar variables...
Software Engineer. Bitsum LLC.