Segmented Memory Allocation in Software

So far we’ve talked about the hardware, and having finally explained the hardware basis of segmented memory we can begin to understand the role software plays, and how software allocates memory among the two segments.

From a low-level perspective, video memory management under Windows is the domain of the combination of the operating system and the video drivers. Strictly speaking Windows controls video memory management – this being one of the big changes of Windows Vista and the Windows Display Driver Model – while the video drivers get a significant amount of input in hinting at how things should be laid out.

Meanwhile from an application’s perspective all video memory and its address space is virtual. This means that applications are writing to their own private space, blissfully unaware of what else is in video memory and where it may be, or for that matter where in memory (or even which memory) they are writing. As a result of this memory virtualization it falls to the OS and video drivers to decide where in physical VRAM to allocate memory requests, and for the GTX 970 in particular, whether to put a request in the 3.5GB segment, the 512MB segment, or in the worst case scenario system memory over PCIe.


Virtual Address Space (Image Courtesy Dysprosia)

Without going quite so far to rehash the entire theory of memory management and caching, the goal of memory management in the case of the GTX 970 is to allocate resources over the entire 4GB of VRAM such that high-priority items end up in the fast segment and low-priority items end up in the slow segment. To do this NVIDIA focuses up to the first 3.5GB of memory allocations on the faster 3.5GB segment, and then finally for memory allocations beyond 3.5GB they turn to the 512MB segment, as there’s no benefit to using the slower segment so long as there’s available space in the faster segment.

The complex part of this process occurs once both memory segments are in use, at which point NVIDIA’s heuristics come into play to try to best determine which resources to allocate to which segments. How NVIDIA does this is very much a “secret sauce” scenario for the company, but from a high level identifying the type of resource and when it was last used are good ways to figure out where to send a resource. Frame buffers, render targets, UAVs, and other intermediate buffers for example are the last thing you want to send to the slow segment; meanwhile textures, resources not in active use (e.g. cached), and resources belonging to inactive applications would be great candidates to send off to the slower segment. The way NVIDIA describes the process we suspect there are even per-application optimizations in use, though NVIDIA can clearly handle generic cases as well.

From an API perspective this is applicable towards both graphics and compute, though it’s a safe bet that graphics is the more easily and accurately handled of the two thanks to the rigid nature of graphics rendering. Direct3D, OpenGL, CUDA, and OpenCL all see and have access to the full 4GB of memory available on the GTX 970, and from the perspective of the applications using these APIs the 4GB of memory is identical, the segments being abstracted. This is also why applications attempting to benchmark the memory in a piecemeal fashion will not find slow memory areas until the end of their run, as their earlier allocations will be in the fast segment and only finally spill over to the slow segment once the fast segment is full.

GeForce GTX 970 Addressable VRAM
API Memory
Direct3D 4GB
OpenGL 4GB
CUDA 4GB
OpenCL 4GB

The one remaining unknown element here (and something NVIDIA is still investigating) is why some users have been seeing total VRAM allocation top out at 3.5GB on a GTX 970, but go to 4GB on a GTX 980. Again from a high-level perspective all of this segmentation is abstracted, so games should not be aware of what’s going on under the hood.

Overall then the role of software in memory allocation is relatively straightforward since it’s layered on top of the segments. Applications have access to the full 4GB, and due to the fact that application memory space is virtualized the existence and usage of the memory segments is abstracted from the application, with the physical memory allocation handled by the OS and driver. Only after 3.5GB is requested – enough to fill the entire 3.5GB segment – does the 512MB segment get used, at which point NVIDIA attempts to place the least sensitive/important data in the slower segment.

Diving Deeper: The Maxwell 2 Memory Crossbar & ROP Partitions Practical Performance Possibilities & Closing Thoughts
Comments Locked

398 Comments

View All Comments

  • Galidou - Monday, January 26, 2015 - link

    I should have specified that the 8gb is ''usable'' for graphics but will not be totally used so considering the OS, normal usage and so on.

    Let's not forget the Xbox one has 8gb of Hynix H26M42003GMR 8 GB eMMC NAND flash memory for storing OS information, caching memory to give the maximum usage of the 8gb RAM for games. But you already knew that, didn't you? the OS goes on standby when you enter a game, goes to the NAND flash and is then loaded from the flash when it needs to Wake up.
  • hermeslyre@hotmail.com - Monday, January 26, 2015 - link

    Your point is sound, but facts wrong. Both Consoles reserve a whopping 3.5GB or around for OS. You can Google it to confirm if you like. PS4 has 512mb of that reserved pool as flexible. At the most console developers have not a megabyte more than 5GB for use. And that's total system RAM. The only way the developer can dedicate 4GB to VRAM is to have only 1GB for the rest of the game, which is very unlikely, take a look at the system RAM usage in the task manager when playing any modern game. My 8GB system RAM gets very close to filled in many games.

    3GB Of dedicated VRAM would require the devs only use 2GB for general use in the game. A better situation but still skewered. 2 for VRAM leaves 3 for the rest of the game. Most developers are going to chose one of these 2, or something close. Which does not paint as dire a picture as you paint above.
  • hermeslyre@hotmail.com - Monday, January 26, 2015 - link

    Your point is sound, but facts wrong. Both Consoles reserve a whopping 3.5GB or around for OS. You can Google it to confirm if you like. PS4 has 512mb of that reserved pool as flexible. At the most console developers have not a megabyte more than 5GB for use. And that's total system RAM. The only way the developer can dedicate 4GB to VRAM is to have only 1GB for the rest of the game, which is very unlikely, take a look at the system RAM usage in the task manager when playing any modern game. My 8GB system RAM gets very close to filled in many games.

    3GB Of dedicated VRAM would require the devs only use 2GB for general use in the game. A better situation but still skewered. 2 for VRAM leaves 3 for the rest of the game. Most developers are going to chose one of these 2, or something close. Which does not paint as dire a picture as you paint above.
  • hermeslyre@hotmail.com - Monday, January 26, 2015 - link

    Last I checked both consoles reserve around 3.5GB for OS, With the PS4 having 512MB of that reserved pool as flexible. Which leaves not a megabyte more than 5GB available to developers to do their thing. On the PS4 at least.

    That's total available RAM for games, not just vram. The only way a developer can get away with taking 4GB of that RAM for video is to only use 1GB for everything else.
  • Oxford Guy - Tuesday, January 27, 2015 - link

    That's ridiculous. Since when does a console need an OS that hogs 3.5 GB?
  • Galidou - Tuesday, January 27, 2015 - link

    +1 Oxford Guy, my Windows 7 uses 2.41gb of ram and I can guarantee it's WAY heavier than any console OS. Plus the guy didn't read about the Hynix H26M42003GMR 8 GB eMMC NAND flash memory used to cache most of the OS non-usable GUI ressources and such while gaming to alleviate RAM usage during games
  • Mvoigt - Tuesday, January 27, 2015 - link

    What your point... i have an 128gb cache drive in my machine... i like consoles.. but get of your high horse and get your facts straight... show me on game that looks better on console than pc and i will rest my case...
  • Mvoigt - Tuesday, January 27, 2015 - link

    http://www.geek.com/games/ps4-gives-5-5gb-of-ram-t... read the freakin ling boy , and again http://www.eurogamer.net/articles/digitalfoundry-p...

    Why dont you google instead of comming of like an ignorant mofo....
  • Mvoigt - Tuesday, January 27, 2015 - link

    And the xbox one link... http://n4g.com/news/1262357/microsoft-confirms-xbo...
  • OrphanageExplosion - Tuesday, January 27, 2015 - link

    It's actually 3GB on both consoles.

    The consoles are designed with a ten year lifecycle in mind. The reservation is that - a reservation. The OS and overall functionality will grow over the years and both MS and Sony gave themselves the room to expand.

    You can't *increase* the reservation going forward with new features in mind without breaking compatibility with older games.

Log in

Don't have an account? Sign up now