<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 2023-08-31 17:29, Chen, Xiaogang
wrote:<br>
</div>
<blockquote type="cite" cite="mid:a83c2317-932b-3a7d-2a54-0ccda4dd77be@amd.com">
<br>
On 8/31/2023 3:59 PM, Felix Kuehling wrote:
<br>
<blockquote type="cite">On 2023-08-31 16:33, Chen, Xiaogang wrote:
<br>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">That said, I'm not actually
sure why we're freeing the DMA address array after
migration to RAM at all. I think we still need it
even when we're using VRAM. We call
svm_range_dma_map in svm_range_validate_and_map
regardless of whether the range is in VRAM or system
memory. So it will just allocate a new array the
next time the range is validated anyway. VRAM pages
use a special address encoding to indicate VRAM
pages to the GPUVM code.
<br>
</blockquote>
<br>
I think we do not need free DMA address array as you
said, it is another thing though.
<br>
<br>
We need unmap dma address(dma_unmap_page) after
migrate from ram to vram because we always do
dma_map_page at svm_range_validate_and_map. If not we
would have multiple dma maps for same sys ram page.
<br>
</blockquote>
<br>
svm_range_dma_map_dev calls dma_unmap_page before
overwriting an existing valid entry in the dma_addr
array. Anyway, dma unmapping the old pages in bulk may
still be cleaner. And it avoids delays in cleaning up
DMA mappings after migrations.
<br>
<br>
Regards,
<br>
Felix
<br>
<br>
<br>
</blockquote>
then we may not need do dma_unmap after migrate from ram
to vram since svm_range_dma_map_dev always do
dma_unmap_page if the address is valid dma address for sys
ram, and after migrate from ram to vram we always do gpu
mapping?
<br>
</blockquote>
<br>
I think with XNACK enabled, the DMA mapping may be delayed
until a page fault. For example on a multi-GPU system, GPU1
page faults and migrates data from system memory to its
VRAM. Immediately afterwards, the page fault handler should
use svm_validate_and_map to update GPU1 page tables. But
GPU2 page tables are not updated immediately. So the now
stale DMA mappings for GPU2 would continue to exist until
the next page fault on GPU2.
<br>
<br>
Regards,
<br>
Felix
<br>
<br>
</blockquote>
If I understand correctly: when user call svm_range_set_attr,
if p->xnack_enabled is true, we can skip call
svm_range_validate_and_map. We postpone the buffer validating
and gpu mapping until page fault or the time the buffer really
got used by a GPU, and only dma map and gpu map for this GPU.
<br>
</blockquote>
<br>
The current implementation of svm_range_set_attr skips the
validation after migration if XNACK is off, because it is
handled by svm_range_restore_work that gets scheduled by the MMU
notifier triggered by the migration.
<br>
<br>
With XNACK on, svm_range_set_attr currently validates and maps
after migration assuming that the data will be used by the
GPU(s) soon. That is something we could change and let page
faults take care of the mappings as needed.
<br>
<br>
</blockquote>
Yes, with xnack on, my understanding is we can skip
svm_range_validate_and_map at svm_range_set_attr after migration,
then page fault handler will do dma and gpu mapping. That would
save the first time dma and gpu mapping which apply to all GPUs
that user ask for access. Then current gpu page fault handler just
does dma and gpu mapping for the GPU that triggered page fault. Is
that ok?
<br>
</blockquote>
<p>With xnack on, after prefetch the range to GPU, need
svm_range_validate_and_map to update the mapping of the GPU
migrated to (also the mapping of GPUs with access_in_place),
because app prefetch to GPU to avoid GPU page fault.</p>
<p>After migrating to VRAM, we only need dma_unmap_page from
prange->dma_addr array, don't need to free the dma_addr array
itself, as it can be reused to store VRAM address to map to GPU. <br>
</p>
<p>Regards,</p>
<p>Philip<br>
</p>
<blockquote type="cite" cite="mid:a83c2317-932b-3a7d-2a54-0ccda4dd77be@amd.com">
<br>
Regards
<br>
<br>
Xiaogang
<br>
<br>
<blockquote type="cite">Regards,
<br>
Felix
<br>
<br>
<br>
</blockquote>
<br>
<blockquote type="cite">
<blockquote type="cite">
<br>
Regards
<br>
<br>
Xiaogang </blockquote>
</blockquote>
</blockquote>
</body>
</html>