mm/hmm/test: destroy xa_array instead of looping
Subsystems (5)
PATCH 1/1 mm/hmm/test: destroy xa_array instead of looping
The test driver uses an xa_array to store virtual to physical address translations for a simulated hardware device. The MMU notifier invalidation callback is used to keep the table consistent with the CPU page table and is frequently called only for a page or two. However, if the test process exits unexpectedly or is killed, the range can be [0..ULONG_MAX] in which case calling xa_erase() for every possible PFN results in CPU timeouts. Munmap() can result in a large range being invalidated but in that case, the xa_array is likely to contain entries that need to be invalidated.
Check for [0..ULONG_MAX] explicitly and just destroy the whole table.
---
This patch is based on Jason Gunthorpe's hmm tree and should be folded into the ("mm/hmm/test: add selftest driver for HMM") patch once this patch is reviewed, etc.
lib/test_hmm.c | 6 ++++++ 1 file changed, 6 insertions(+)
lib/test_hmm.c +6 -0
@@ -201,7 +201,13 @@ static void dmirror_do_update(struct dmirror *dmirror, unsigned long start,* The XArray doesn't hold references to pages since it relies on * the mmu notifier to clear page pointers when they become stale. * Therefore, it is OK to just clear the entry. +* However, if the entire address space is being invalidated, it +* takes too long to clear them one at a time so destroy the array. */ +if (start ==0 && end ==ULONG_MAX ) { +xa_destroy (&dmirror->pt); +return ; + }for (pfn = start >>PAGE_SHIFT ; pfn < (end >>PAGE_SHIFT ); pfn++)xa_erase (&dmirror->pt, pfn); }
Signature · 1 line
2.20.1
Quoted 27 lines · Ralph Campbell
The test driver uses an
xa_arrayto store virtual to physical address translations for a simulated hardware device. The MMU notifier invalidation callback is used to keep the table consistent with the CPU page table and is frequently called only for a page or two. However, if the test process exits unexpectedly or is killed, the range can be [0..ULONG_MAX] in which case callingxa_erase()for every possible PFN results in CPU timeouts.Munmap()can result in a large range being invalidated but in that case, thexa_arrayis likely to contain entries that need to be invalidated.
Check for [0..ULONG_MAX] explicitly and just destroy the whole table.Signed-off-by Ralph Campbell <[email protected]>This patch is based on Jason Gunthorpe's hmm tree and should be folded into the ("
mm/hmm/test: add selftest driver for HMM") patch once this patch is reviewed, etc.lib/test_hmm.c | 6 ++++++ 1 file changed, 6 insertions(+)lib/test_hmm.c +1
-0+++ b/lib/test_hmm.c@@ -201,7 +201,13 @@ static void dmirror_do_update(struct dmirror *dmirror, unsigned long start,* The XArray doesn't hold references to pages since it relies on * the mmu notifier to clear page pointers when they become stale. * Therefore, it is OK to just clear the entry.
lib/test_hmm.c static void dmirror_do_update(struct dmirror *dmirror, unsigned long start, · line 213
Quoted 10 lines
lib/test_hmm.c +6
-0+* However, if the entire address space is being invalidated, it +* takes too long to clear them one at a time so destroy the array. */ +if (start ==0 && end ==ULONG_MAX ) { +xa_destroy (&dmirror->pt); +return ; + }for (pfn = start >>PAGE_SHIFT ; pfn < (end >>PAGE_SHIFT ); pfn++)xa_erase (&dmirror->pt, pfn); }
Just use xa_for_each_range() instead of the naive loop, it already optimizes against membership and avoids the need for the xa_destroy hack
Jason
Quoted 43 lines · Jason Gunthorpe
Quoted 27 lines · Ralph Campbell
The test driver uses an
xa_arrayto store virtual to physical address translations for a simulated hardware device. The MMU notifier invalidation callback is used to keep the table consistent with the CPU page table and is frequently called only for a page or two. However, if the test process exits unexpectedly or is killed, the range can be [0..ULONG_MAX] in which case callingxa_erase()for every possible PFN results in CPU timeouts.Munmap()can result in a large range being invalidated but in that case, thexa_arrayis likely to contain entries that need to be invalidated.
Check for [0..ULONG_MAX] explicitly and just destroy the whole table.Signed-off-by Ralph Campbell <[email protected]>This patch is based on Jason Gunthorpe's hmm tree and should be folded into the ("
mm/hmm/test: add selftest driver for HMM") patch once this patch is reviewed, etc.lib/test_hmm.c | 6 ++++++ 1 file changed, 6 insertions(+)lib/test_hmm.c +1
-0+++ b/lib/test_hmm.c@@ -201,7 +201,13 @@ static void dmirror_do_update(struct dmirror *dmirror, unsigned long start,* The XArray doesn't hold references to pages since it relies on * the mmu notifier to clear page pointers when they become stale. * Therefore, it is OK to just clear the entry. lib/test_hmm.c static void dmirror_do_update(struct dmirror *dmirror, unsigned long start, · line 213
Quoted 10 lines
lib/test_hmm.c +6
-0+* However, if the entire address space is being invalidated, it +* takes too long to clear them one at a time so destroy the array. */ +if (start ==0 && end ==ULONG_MAX ) { +xa_destroy (&dmirror->pt); +return ; + }for (pfn = start >>PAGE_SHIFT ; pfn < (end >>PAGE_SHIFT ); pfn++)xa_erase (&dmirror->pt, pfn); }Just use
xa_for_each_range()instead of the naive loop, it already optimizes against membership and avoids the need for thexa_destroyhack
Quoted 2 lines
Jason
For some reason I had looked at that and rejected it but of course, it works fine. :-)
Thanks!