Performance boost for most games.

Discussion in 'Games, Gaming & Game-demos' started by harkinsteven, May 11, 2014.

  1. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
  2. bluedevil

    bluedevil Master Guru

    Messages:
    416
    Likes Received:
    28
    GPU:
    Kfa2 RTX 2060 6gb
    Thank you dude it works now. I'm sure there are others that have a whole partition just for games.
    This makes it much easyer to search :).
    Edit:
    I found a bug tho if you type "d:" by mistake instead of "d:\" with the \ it searches but it behaves like the previous version. Hope i'm not being a pest.
    Is there any way to check if gpedit is enabled and the user has the right right to use the policy ?It seems you need to use Method 2 to enable gpedit on Windows 10 Home because it's disabled by default for Lock pages in memory to work https://www.itechtics.com/enable-gpedit-windows-10-home/
    I have found something on microsoft's site thas says you do need to Lock pages.
    https://docs.microsoft.com/en-us/windows/win32/memory/large-page-support
    "To use large-page support
    1. Obtain the SeLockMemoryPrivilege privilege by calling the AdjustTokenPrivileges function. For more information, see Assigning Privileges to an Account and Changing Privileges in a Token.
    2. Retrieve the minimum large-page size by calling the GetLargePageMinimum function.
    3. Include the MEM_LARGE_PAGES value when calling the VirtualAlloc function. The size and alignment must be a multiple of the large-page minimum " -quote

      look for Constant: SeLockMemoryPrivilege here https://docs.microsoft.com/en-us/wi...security-policy-settings/lock-pages-in-memory
     
  3. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
    It is not a bug, app was not developed to search from the root. So people who search from "d:" get punished.

    Still, that can be completely different thing - that text
    https://docs.microsoft.com/en-us/windows/win32/memory/large-page-support
    is about allocating memory by large pages. And the tweak in registry is (most probably) about mapping the executable image using large pages.

    Do you see any references to large or small pages in here
    https://docs.microsoft.com/en-us/wi...security-policy-settings/lock-pages-in-memory
    ?

    People in this thread reported getting boost from this registry tweak without any policies.

    Another doc:
    https://docs.microsoft.com/en-us/wi...gger/load-image-using-large-pages-if-possible
    (
    https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/gflags-flag-table
    https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/gflags-overview
    )
    Also it is possible that the SeLockMemoryPrivilege is needed only on server Windows editions.
     
  4. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
    Maybe I should write a test app with this API
    https://docs.microsoft.com/en-us/windows/win32/api/psapi/nf-psapi-queryworkingsetex
    https://docs.microsoft.com/en-us/windows/win32/api/psapi/ns-psapi-psapi_working_set_ex_information
    https://docs.microsoft.com/en-us/windows/win32/api/psapi/ns-psapi-psapi_working_set_ex_block
    - there are two flags in that structure:
    I will try lately...
     

  5. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
    @bluedevil

    I wrote a test app (x64)
    http://www.mediafire.com/file/ajduc3lopbz43zm/LargePageTest.zip/file
    MD5 hash for zip-file: 3E0489EA828E358DA7D628B6554F6CBF

    Launch it from command prompt or PowerShell.


    This is a console app. It tries following steps:
    - get the minimum large page size;
    - obtain process security token;
    - enumerate privileges assigned to that token (with their states);
    - enumerate memory flags from several locations;
    - allocate memory with large page flag without the SeLockMemoryPrivilege privilege;
    - assign SeLockMemoryPrivilege privilege to process security token;
    - allocate memory with large page flag with the SeLockMemoryPrivilege privilege.

    Here are two outputs from this test app:

    - before I added LargePageTest.exe in LargePage util
    Code:
    Large page test app
    Minimum large page size
            2097152 (or 2048KB or 2MB)
    Retrieving process token
            succeeded
    Retrieving process token privileges and their states:
            'SeLockMemoryPrivilege'  :
            'SeIncreaseQuotaPrivilege'       :
            'SeSecurityPrivilege'    :
            'SeTakeOwnershipPrivilege'       :
            'SeLoadDriverPrivilege'  :
            'SeSystemProfilePrivilege'       :
            'SeSystemtimePrivilege'  :
            'SeProfileSingleProcessPrivilege'        :
            'SeIncreaseBasePriorityPrivilege'        :
            'SeCreatePagefilePrivilege'      :
            'SeBackupPrivilege'      :
            'SeRestorePrivilege'     :
            'SeShutdownPrivilege'    :
            'SeDebugPrivilege'       : enabled
            'SeSystemEnvironmentPrivilege'   :
            'SeChangeNotifyPrivilege'        : enabled by default, enabled
            'SeRemoteShutdownPrivilege'      :
            'SeUndockPrivilege'      :
            'SeManageVolumePrivilege'        :
            'SeImpersonatePrivilege'         : enabled by default, enabled
            'SeCreateGlobalPrivilege'        : enabled by default, enabled
            'SeIncreaseWorkingSetPrivilege'  :
            'SeTimeZonePrivilege'    :
            'SeCreateSymbolicLinkPrivilege'  :
    Retrieving flags of process memory locations:
            code segment : locked=0, large page=0
            data segment : locked=0, large page=0
            stack : locked=0, large page=0
            Win API DLL : locked=0, large page=0
            heap allocation : locked=0, large page=0
            virtual allocation : locked=0, large page=0
            local allocation : locked=0, large page=0
    Trying to allocate memory with large page flag without the 'SeLockMemoryPrivilege' privilege
            failed with error 1314
            A required privilege is not held by the client.
    Assigning process token privilege 'SeLockMemoryPrivilege'
            succeeded
    Trying to allocate memory with large page flag with the 'SeLockMemoryPrivilege' privilege
            succeeded
            allocation : locked=1, large page=1
    

    - after I added LargePageTest.exe in LargePage util
    Code:
    Large page test app
    Minimum large page size
            2097152 (or 2048KB or 2MB)
    Retrieving process token
            succeeded
    Retrieving process token privileges and their states:
            'SeLockMemoryPrivilege'  :
            'SeIncreaseQuotaPrivilege'       :
            'SeSecurityPrivilege'    :
            'SeTakeOwnershipPrivilege'       :
            'SeLoadDriverPrivilege'  :
            'SeSystemProfilePrivilege'       :
            'SeSystemtimePrivilege'  :
            'SeProfileSingleProcessPrivilege'        :
            'SeIncreaseBasePriorityPrivilege'        :
            'SeCreatePagefilePrivilege'      :
            'SeBackupPrivilege'      :
            'SeRestorePrivilege'     :
            'SeShutdownPrivilege'    :
            'SeDebugPrivilege'       : enabled
            'SeSystemEnvironmentPrivilege'   :
            'SeChangeNotifyPrivilege'        : enabled by default, enabled
            'SeRemoteShutdownPrivilege'      :
            'SeUndockPrivilege'      :
            'SeManageVolumePrivilege'        :
            'SeImpersonatePrivilege'         : enabled by default, enabled
            'SeCreateGlobalPrivilege'        : enabled by default, enabled
            'SeIncreaseWorkingSetPrivilege'  :
            'SeTimeZonePrivilege'    :
            'SeCreateSymbolicLinkPrivilege'  :
    Retrieving flags of process memory locations:
            code segment : locked=1, large page=1
            data segment : locked=1, large page=1
            stack : locked=0, large page=0
            Win API DLL : locked=0, large page=0
            heap allocation : locked=0, large page=0
            virtual allocation : locked=0, large page=0
            local allocation : locked=0, large page=0
    Trying to allocate memory with large page flag without the 'SeLockMemoryPrivilege' privilege
            failed with error 1314
            A required privilege is not held by the client.
    Assigning process token privilege 'SeLockMemoryPrivilege'
            succeeded
    Trying to allocate memory with large page flag with the 'SeLockMemoryPrivilege' privilege
            succeeded
            allocation : locked=1, large page=1
    
    

    We can see that
    Code:
    Retrieving flags of process memory locations:
            code segment : locked=0, large page=0
            data segment : locked=0, large page=0
    
    changed to
    Code:
    Retrieving flags of process memory locations:
            code segment : locked=1, large page=1
            data segment : locked=1, large page=1
    
    That proves that with registry large page tweak (offered by LargePage util) the image of the process is loaded with large pages (fixed in memory) - no need for any privileges.

    Also we see that for application to allocate with large page flag the SeLockMemoryPrivilege privilege is necessary, but code can (and should) assign that privilege itself.

    Try test app on your rig. Aside from memory things it will show whether SeLockMemoryPrivilege privilege is assigned to process after your actions with local security policy.

    PS Also I have noticed that the list of assigned privileges is shorter when LargePageTest.exe is started not elevated (not as administrator).
     
    Last edited: Sep 9, 2020
  6. bluedevil

    bluedevil Master Guru

    Messages:
    416
    Likes Received:
    28
    GPU:
    Kfa2 RTX 2060 6gb
    Great job dude you did it !!! You know you win api stuff !!!

    I tested with the LargePageTest.exe added into LargePage_util and then with it removed and got the same results.
    I then went into secpol.msc and removed my account from Lock pages in memory policy but added the admin account then restarted the pc. I did this because my account had admin privileges.
    I then ran LargePageTest.exe again from my account with it active in LargePage_util and it failed to set locked and large page even with SeLockMemoryPrivilege.
    I tried with the compatibility flag Run as Admin from my account and still failed.
    This is the output with test app added in LargePage_util but Lock pages in memory privilege disabled for my account.
    Large page test app
    Minimum large page size
    2097152 (or 2048KB or 2MB)

    Retrieving process token
    succeeded
    Retrieving process token privileges and their states:
    'SeIncreaseQuotaPrivilege' :
    'SeSecurityPrivilege' :
    'SeTakeOwnershipPrivilege' :
    'SeLoadDriverPrivilege' :
    'SeSystemProfilePrivilege' :
    'SeSystemtimePrivilege' :
    'SeProfileSingleProcessPrivilege' :
    'SeIncreaseBasePriorityPrivilege' :
    'SeCreatePagefilePrivilege' :
    'SeBackupPrivilege' :
    'SeRestorePrivilege' :
    'SeShutdownPrivilege' :
    'SeDebugPrivilege' :
    'SeSystemEnvironmentPrivilege' :
    'SeChangeNotifyPrivilege' : enabled by default, enabled
    'SeRemoteShutdownPrivilege' :
    'SeUndockPrivilege' :
    'SeManageVolumePrivilege' :
    'SeImpersonatePrivilege' : enabled by default, enabled
    'SeCreateGlobalPrivilege' : enabled by default, enabled
    'SeIncreaseWorkingSetPrivilege' :
    'SeTimeZonePrivilege' :
    'SeCreateSymbolicLinkPrivilege' :
    'SeDelegateSessionUserImpersonatePrivilege' :

    Retrieving flags of process memory locations:
    code segment : locked=0, large page=0
    data segment : locked=0, large page=0
    stack : locked=0, large page=0
    Win API DLL : locked=0, large page=0
    heap allocation : locked=0, large page=0
    virtual allocation : locked=0, large page=0
    local allocation : locked=0, large page=0

    Trying to allocate memory with large page flag without the 'SeLockMemoryPrivilege' privilege
    failed with error 1314
    A required privilege is not held by the client.

    Assigning process token privilege 'SeLockMemoryPrivilege'
    The token does not have the specified privilege 'SeLockMemoryPrivilege'

    I then logged off and logged in using the hidden windows Administrator account, ran the test and it was a success.

    This behaviour is perfectly fine and expected but it means that if a user that does not have Lock Pages privilege set in secpol.msc tries to use the LargePage_util it will fail to set large pages on.
    The guys at sisoftsandra were right.
    If someone just installs windows then that account's name is added as having admin privileges and automatically has Lock Pages privilege, so for most of us nothing has to be done it will work just fine, but if you make some new account without admin privileges then the app does not work.
    You could modify the LargePage_util to try to assign process token privilege 'SeLockMemoryPrivilege' for itself as a test and if it fails it means that user account is not added to the Lock Pages privileges list,then just pop a messagebox with a message.

    Windows 10 Home Edition does not have gpedit enabled so you need to enable it first then add the user to the Lock Pages privilege list as shown below.
    Use the guide from here : https://www.itechtics.com/enable-gpedit-windows-10-home/
    Use Method 2 or just save the code with a .bat extension and run it (it's the same from the site):

    @Echo off
    pushd "%~dp0"

    dir /b %SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~3*.mum >List.txt
    dir /b %SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~3*.mum >>List.txt

    for /f %%i in ('findstr /i . List.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
    pause

    The next step is to run secpol.msc
    Security settings then Local Policies User Rights Assignment folder.
    The policies will be displayed in the details pane.
    In the pane, double-click Lock pages in memory.
    In the Lock pages in memory dialog box if your username does not appear click Add User or Group, Advanced Find Now and select your username then ok and ok.

    I have Windows 10 Home Edition so gpedit was disabled and had no way of knowing if my account had Lock pages policies enabled.
     
    Last edited: Sep 9, 2020
  7. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
    @bluedevil

    I have not toyed with local security policy and test app succeeded to allocate with large page flag and with privilege - both elevated and not.

    The guys at sisoftsandra were right about the memory VirtualAlloc-functions to fail with large page flag and without 'SeLockMemoryPrivilege' privilege.
    And I was right about the image of tweaked exe-file loaded with large pages (and locked), and about 'SeLockMemoryPrivilege' privilege not needed for that.

    PS Overall you don`t have to fuss with security policies.
     
    Last edited: Sep 10, 2020
  8. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
  9. Anomander

    Anomander Guest

    Messages:
    7
    Likes Received:
    2
    GPU:
    1080ti
    okay, registered specially for this. When I start it I get the following error:
    upload_2020-10-29_19-40-18.png
    and it still loads and seems to work, but it's annoying. So any idea what I'm doing wrong? I'm running it as admin. Is there anything else that's needed? Thanks!
     

    Attached Files:

  10. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070

  11. Anomander

    Anomander Guest

    Messages:
    7
    Likes Received:
    2
    GPU:
    1080ti
    No need to apologize of course. However the error persists and the exe is being added, but if I close the utility and re-open it, then it's missing although it's in the reg file which I also run manually:
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
    "UseLargePages"=dword:00000001

    upload_2020-10-29_21-0-33.png
     
  12. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
    Error persists with new version? And the text of the error stays the same?

    PS Have you checked in registry whether the key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options" is there and you can create any subkey there (manually)?
     
  13. Anomander

    Anomander Guest

    Messages:
    7
    Likes Received:
    2
    GPU:
    1080ti
    It was the same or at least that's what I think I saw, but now double checking it's different. As for the registrykey, it's there. I have a feeling I'm not doing something right. But as I said, it's kinda weird because the notepad.exe is in the registry and some other keys which are not shown in the app.

    upload_2020-10-29_23-17-16.png

    upload_2020-10-29_23-14-0.png
     

    Attached Files:

  14. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
    @Anomander

    That`s very strange because at start app just asks to read the subkeys (names) from that key (pure read access) - which should require much lower level of access than when app creates subkey (write access). I will try to toy with permissions, wait a little...
     
  15. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
    * scratch that one *
     
    Last edited: Oct 29, 2020

  16. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
    @Anomander

    Try this one
    http://www.mediafire.com/download/aiudd2j3at03j12/LargePage_util.zip
    MD5 hash for zip-file: AB952455E8F3930F368062A1F3AD3E4A

    It can be that some subkey of 'Image File Execution Options' key causes that security exception namely at start when app enumerates through all subkeys. So I changed that enumeration code accordingly.

    PS It is deep night here, so I went to bed. Post results with this new version...
     
  17. Anomander

    Anomander Guest

    Messages:
    7
    Likes Received:
    2
    GPU:
    1080ti
    Still getting "Required registry access is not allowed". In the Scurity tab for my specific user the permissions looked like this (if that matters):
    upload_2020-10-30_0-7-25.png

    But even after granting Full control the error persists, but I guess it might not be related to that. However, don't worry too much about it, I'm fine either way. It was just interesting to try it out.
     
  18. Astyanax

    Astyanax Ancient Guru

    Messages:
    17,040
    Likes Received:
    7,381
    GPU:
    GTX 1080ti
    anything that writes into that registry key needs trusted installer, system or administrator elevation.
     
  19. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
    1. Depends on security properties of registry key. Many (office) users can`t elevate their programs but that doesn`t prevent those programs to write data into their registry places. Or Steam, for example, writes data into registry when it installs game, and 99% of users do not elevate Steam.

    2. App in question does not write anything at start (when error pops up), it even opens all keys in read-only mode. So security exception raises simply from enumeration of subkeys.
     
  20. mbk1969

    mbk1969 Ancient Guru

    Messages:
    15,606
    Likes Received:
    13,615
    GPU:
    GF RTX 4070
    Only one method remains for investigation. I am in process...

    PS You can obviously do the large page tweak manually in registry, but some people will fail, so for their sake I am trying to fix the issue.
     

Share This Page