What Is CUDA Unified Memory Page Migration? Diagnose and Reduce Stalls
Page migration is the movement of a managed-memory page’s backing data between CPU and GPU memory while its virtual address stays the same. A program can keep using the pointer returned by `cudaMallocManaged`, yet an access may be delayed when the needed page is elsewhere. Not every remote access causes migration: the behavior depends on the GPU, operating system, driver, and Unified Memory support model.
What Is CUDA Unified Memory Page Migration? Diagnose and Reduce Stalls
Page migration is the movement of a managed-memory page’s backing data between CPU and GPU memory while its virtual address stays the same. A program can keep using the pointer returned by cudaMallocManaged, yet an access may be delayed when the needed page is elsewhere. Not every remote access causes migration: the behavior depends on the GPU, operating system, driver, and Unified Memory support model.
This guide covers managed memory in NVIDIA CUDA C++, the current CUDA Runtime API 13.5, and the current Nsight Systems documentation. For the address-space and pointer-location concept, see CUDA UVA; for choosing Unified Memory and checking its support model, see the CUDA Unified Memory overview. This article focuses on explaining and diagnosing latency caused by changes in page location.
Page migration changes physical placement, not the virtual address
A virtual address is the address a program uses through a pointer; a physical page is a unit of CPU or GPU memory that holds the data for that address. Unified Memory lets CPU and GPU code use the same pointer for a managed allocation, but that does not mean every page is always present in both physical memories or is equally cheap to access from either processor. On a supporting device, cudaMallocManaged asks the runtime to manage access, placement, and coherence for that allocation.
On a software-coherent system, a processor that accesses a page owned by another processor can cause a page fault and pause that work. The system can revoke or update the former owner’s mapping, establish a valid mapping for the requester, and move the page’s physical contents when needed. If a GPU requests a page that was in host memory, the transfer may appear as host-to-device; if the CPU requests a page resident on a GPU, it may appear as device-to-host.
CPU and GPU using the same managed pointer
Page resides in CPU memory
│ GPU requests the page
▼
Page fault → adjust access/mappings → migrate page if needed
│
▼
GPU work resumes
│ CPU reads or writes later
└→ remote access or GPU → CPU transfer, depending on the system
The virtual pointer may stay the same while page location and access cost changeThis is a conceptual diagram of a software-coherent path. On a hardware-coherent system, the CPU may directly access GPU-resident data without moving the page. Other supported configurations may allow remote memory access or migrate pages. Therefore, pointer equality or the fact that both processors can read a buffer does not establish whether migration occurs. NVIDIA describes four Unified Memory paradigms and explains that behavior varies with the operating system, Linux kernel, GPU, and interconnect. CUDA Programming Guide — Unified and System Memory CUDA Programming Guide — Unified Memory
A page is a range of memory, not one individual variable. Even when a processor touches one element, the runtime may handle access at page granularity. Page sizes and mappings vary across hardware and operating systems; moving a larger page can mean more data and more latency. Sparse access or frequent ownership changes between CPU and GPU can therefore spend more time on page handling than useful computation. Do not apply a page size documented for one system to another. CUDA Programming Guide — Memory Paging and Page Sizes
Some systems can be slow without migrating a page
Unified Memory does not use one fixed policy. Support for GPU page faults, hardware coherence, and GPU access to system memory differs by configuration. Some devices can fault in host pages on the GPU; limited-support configurations may instead copy managed data to the GPU before a kernel starts and may not support oversubscription of GPU memory. With multiple GPUs, peer compatibility can also affect placement.
For each target device, query the following attributes with cudaDeviceGetAttribute and compare the results with the guide for the matching toolkit/driver. These values help identify the available Unified Memory paradigm; they do not directly measure migration counts or performance.
| Device attribute | What it indicates | How to use it in diagnosis |
|---|---|---|
cudaDevAttrConcurrentManagedAccess | A key condition for concurrent CPU/GPU access to managed memory | If it is 0, do not assume concurrent access or GPU page faults; check the platform rules. A nonzero value is also required for cudaMemPrefetchAsync to a GPU. |
cudaDevAttrPageableMemoryAccess | Whether ordinary system allocations can be accessed as Unified Memory | Do not assume malloc or mmap memory is usable by a kernel. |
cudaDevAttrPageableMemoryAccessUsesHostPageTables | Whether host page tables are used; a clue about hardware versus software coherence | Use it to understand possible differences between remote access and migration. |
cudaDevAttrDirectManagedMemAccessFromHost | Whether the CPU can directly access GPU-resident managed memory | For fault-free direct access to cudaMallocManaged memory, the documented host cudaMemAdviseSetAccessedBy hint is also required. Measure access cost separately. |
For example, after the CPU initializes a cudaMallocManaged buffer, the first GPU kernel that reads it may incur a delay while pages move from host memory closer to the GPU on some configurations. If the kernel completes, the CPU synchronizes and scans the same buffer, and a later GPU stage uses it again, pages may move back and forth on a software-coherent system. In contrast, on a hardware-coherent system where cudaDevAttrDirectManagedMemAccessFromHost is 1, a correctly configured host-access hint may allow CPU reads without page migration. This is an illustrative scenario that suggests what to check; it does not predict results for every GPU. CUDA Programming Guide — CPU and GPU Page Tables CUDA Programming Guide — Unified Memory on Windows, WSL, and Tegra
How can you inspect actual transfers and delays in Nsight Systems?
Start with the Managed Memory lane in a CUDA trace and inspect HtoD, DtoH, and PtoP transfers over time. These events help distinguish a GPU request for a host-resident page, a CPU request for a GPU-resident page, and a request involving another GPU’s page. Enable detailed page-fault collection only when you need it. The Nsight Systems guide warns that CPU/GPU page-fault collection increased runtime by as much as 70% in testing. That describes possible profiler overhead; it is not a measurement of the application’s migration cost.
Here is a Linux example using the current Nsight Systems CLI. Replace ./app and <app-args> with the program and arguments you want to profile.
nsys profile --trace=cuda \
--cuda-um-cpu-page-faults=true \
--cuda-um-gpu-page-faults=true \
-o um-profile ./app <app-args>First inspect the Managed Memory transfer timeline from the CUDA trace, then enable CPU/GPU page-fault options only if needed to locate a cause. Check nsys profile --help because option availability can vary by Nsight Systems version and edition. Repeated HtoD and DtoH transfers between CPU work and GPU kernels are evidence worth investigating as possible ownership ping-pong. If transfers are rare but a kernel is still slow, inspect the access pattern, TLB misses, synchronization, and computation too. Do not use a run with page-fault tracing as the final performance number; compare separate runs with the same input and synchronization but without that instrumentation. NVIDIA Nsight Systems User Guide — Unified Memory Transfer Trace and Page Faults
| Observation | First question | Interpretation or next check |
|---|---|---|
Repeated HtoD transfers | Is the same CPU-initialized input fetched to the GPU on every iteration? | Check whether CPU preprocessing can be batched and the data reused across GPU work. |
Repeated DtoH transfers | Does the CPU read or modify the entire managed buffer after each kernel? | Consider returning only the needed results or reducing CPU-stage frequency. |
PtoP transfers | Are several GPUs repeatedly taking ownership of the same managed data? | Compare partitioning the data, per-GPU local buffers, and peer copies. |
| Few transfers but a slow kernel | Are accesses scattered, synchronization frequent, or TLB/bandwidth limited? | Profile the memory access pattern, kernel, and synchronization separately. |
Do not conclude that Unified Memory is the cause just because the profiler shows transfers. Check whether they lie on the critical path, whether work stalls while they happen, and whether they repeat. Then compare a specific change. Nsight Systems can show Unified Memory transfers in a CUDA trace; detailed CPU/GPU fault collection adds overhead, so keep diagnosis runs separate from final timing. Nsight Systems User Guide — Unified Memory
How can you reduce repeated page movement?
First arrange the work by data locality. If the CPU prepares the full input and the GPU performs several operations before the CPU reads results, reduce steps where both processors touch the entire buffer in turn. You can also compare copying back only the small result the CPU needs or dividing data into ranges with clearer ownership. Record correctness and end-to-end time under the same conditions before changing the design.
When the next processor is known in advance, cudaMemPrefetchAsync can request that a range be placed closer to it. This is an asynchronous, stream-ordered operation: it starts after prior work in the stream and completes before later work in that stream. A Runtime API 13.5 request to prefetch to a GPU requires a nonzero cudaDevAttrConcurrentManagedAccess on the destination device. Check the attribute first and handle the API’s return value. Prefetch is a placement request or hint, not a command that guarantees movement or a speedup on every platform.
#include <cuda_runtime.h>
#include <cstddef>
// data is an existing cudaMallocManaged allocation; update is defined by the application.
cudaError_t prefetchAndUpdate(float* data, std::size_t bytes, int count,
dim3 grid, dim3 block) {
if (data == nullptr || bytes == 0 || count <= 0) return cudaErrorInvalidValue;
int device = 0;
cudaError_t err = cudaGetDevice(&device);
if (err != cudaSuccess) return err;
cudaMemLocation gpuLocation{};
gpuLocation.type = cudaMemLocationTypeDevice;
gpuLocation.id = device;
cudaStream_t stream = 0;
err = cudaMemPrefetchAsync(data, bytes, gpuLocation, 0, stream);
if (err != cudaSuccess) return err;
update<<<grid, block, 0, stream>>>(data, count);
err = cudaGetLastError();
if (err != cudaSuccess) return err;
return cudaStreamSynchronize(stream);
}This function prefetches an existing managed range in the default stream before GPU work and returns errors to its caller, which must record failures and clean up resources. If the GPU uses the data multiple times, check whether it is reused after one migration in the profiler. Synchronize before the CPU reads or writes the buffer again. cudaMemAdviseSetPreferredLocation is a separate hint about a preferred location; it does not guarantee placement. A hint can also make the default behavior slower, so measure before and after applying it. CUDA Programming Guide — Data Prefetching and Usage Hints CUDA Runtime API 13.5 — Memory Management
| Option | May fit when | Caution |
|---|---|---|
cudaMemPrefetchAsync | The next device and data range are known and the work can be ordered in a stream | If it cannot overlap with other work, it may only move the cost earlier; a platform may not perform a physical move. |
cudaMemAdvise | You can describe expected use, such as a preferred location or read-mostly access | This is advice, not a placement or performance guarantee. A poor hint can be worse than the default. |
| Batch CPU/GPU work or partition data | The same pages repeatedly change ownership as CPU and GPU modify them | This can change result latency or program structure; verify correctness. |
| Pinned-host staging with explicit copies | Transfer is predictable and managed-page ping-pong is a measured bottleneck | You must manage copy calls and buffer lifetime; avoid excessive pinned memory. |
Use this diagnostic sequence:
**Record the support model.** Check `cudaDevAttrConcurrentManagedAccess`, `cudaDevAttrPageableMemoryAccess`, and `cudaDevAttrPageableMemoryAccessUsesHostPageTables` per GPU, along with CUDA, driver, and OS versions.
**Choose a reproducible workload segment.** Separate setup, initialization, result checking, and the repeated section you intend to time; keep data size and GPU work constant.
**Capture the basic transfer trace.** In the CUDA trace, note when `HtoD`, `DtoH`, and `PtoP` occur and how they overlap with CPU and GPU work.
**Enable fault details only when needed.** Locate page faults and investigate their cause, but do not judge performance from this instrumented run.
**Compare one placement change.** Try batching, prefetch, a usage hint, or explicit copies; then recheck result correctness and end-to-end time including synchronization.
Page migration is one way managed memory adjusts data placement; it is not identical across CUDA systems and is not an automatic performance optimization. If traces show migration on the critical path, try keeping data with one processor longer, prefetching before a known phase, or comparing explicit pinned-memory transfers. If hardware supports remote access or migration is outside the critical path, adding hints may not help. Base the final choice on the current system’s trace and end-to-end measurements that control for instrumentation overhead.
References
[NVIDIA CUDA Programming Guide — Unified and System Memory](https://docs.nvidia.com/cuda/cuda-programming-guide/02-basics/understanding-memory.html)
[NVIDIA CUDA Programming Guide — Unified Memory](https://docs.nvidia.com/cuda/cuda-programming-guide/04-special-topics/unified-memory.html)
[NVIDIA CUDA Runtime API 13.5 — Memory Management](https://docs.nvidia.com/cuda/cuda-runtime-api/cuda_runtime_api/group__CUDART__MEMORY.html)
[NVIDIA Nsight Systems User Guide — CLI Options and Unified Memory Trace](https://docs.nvidia.com/nsight-systems/UserGuide/index.html)