Skip to content

Commit

Permalink
Cache config : Reimplement using psutil
Browse files Browse the repository at this point in the history
This means we can also limit usage to 75% of total RAM on Windows.
  • Loading branch information
johnhaddon committed Dec 6, 2023
1 parent 4d2022e commit 358b7b5
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions startup/Gaffer/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,13 @@
#
##########################################################################

import os
import psutil

import Gaffer

# Set cache memory limit to 8 gigs, capped at 3/4 of the total
# physical memory.

cacheLimit = 1024**3 * 8 # 8 Gigs

if os.name != "nt" :
physicalMemory = os.sysconf( "SC_PAGE_SIZE" ) * os.sysconf( "SC_PHYS_PAGES" )
cacheLimit = min( cacheLimit, physicalMemory * 3 // 4 )
else :
# No native Python API for querying physical memory on Windows.
# And surely nobody is brave enough to use Windows with less
# than 8 gigs ;)
pass

Gaffer.ValuePlug.setCacheMemoryLimit( cacheLimit )
Gaffer.ValuePlug.setCacheMemoryLimit(
min( 1024**3 * 8, psutil.virtual_memory().total * 3 // 4 )
)

0 comments on commit 358b7b5

Please sign in to comment.