Linux-kselftest Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] mm/hmm/test: destroy xa_array instead of looping
@ 2020-05-13 21:45 Ralph Campbell
  2020-05-15 23:15 ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Ralph Campbell @ 2020-05-13 21:45 UTC (permalink / raw)
  To: linux-rdma, linux-mm, linux-kselftest, linux-kernel
  Cc: Jerome Glisse, John Hubbard, Christoph Hellwig, Jason Gunthorpe,
	Andrew Morton, Shuah Khan, Ralph Campbell

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.

Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
---

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(+)

diff --git a/lib/test_hmm.c b/lib/test_hmm.c
index 8b36c26b717b..b89852ec3c29 100644
--- a/lib/test_hmm.c
+++ 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.
+	 * 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);
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/hmm/test: destroy xa_array instead of looping
  2020-05-13 21:45 [PATCH] mm/hmm/test: destroy xa_array instead of looping Ralph Campbell
@ 2020-05-15 23:15 ` Jason Gunthorpe
  2020-05-16  0:56   ` Ralph Campbell
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2020-05-15 23:15 UTC (permalink / raw)
  To: Ralph Campbell
  Cc: linux-rdma, linux-mm, linux-kselftest, linux-kernel,
	Jerome Glisse, John Hubbard, Christoph Hellwig, Andrew Morton,
	Shuah Khan

On Wed, May 13, 2020 at 02:45:07PM -0700, Ralph Campbell wrote:
> 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.
> 
> Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
> 
> 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(+)
> 
> diff --git a/lib/test_hmm.c b/lib/test_hmm.c
> index 8b36c26b717b..b89852ec3c29 100644
> +++ 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.
> +	 * 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/hmm/test: destroy xa_array instead of looping
  2020-05-15 23:15 ` Jason Gunthorpe
@ 2020-05-16  0:56   ` Ralph Campbell
  0 siblings, 0 replies; 3+ messages in thread
From: Ralph Campbell @ 2020-05-16  0:56 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: linux-rdma, linux-mm, linux-kselftest, linux-kernel,
	Jerome Glisse, John Hubbard, Christoph Hellwig, Andrew Morton,
	Shuah Khan


On 5/15/20 4:15 PM, Jason Gunthorpe wrote:
> On Wed, May 13, 2020 at 02:45:07PM -0700, Ralph Campbell wrote:
>> 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.
>>
>> Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
>>
>> 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(+)
>>
>> diff --git a/lib/test_hmm.c b/lib/test_hmm.c
>> index 8b36c26b717b..b89852ec3c29 100644
>> +++ 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.
>> +	 * 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
> 

For some reason I had looked at that and rejected it but of course, it works
fine. :-)
Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-13 21:45 [PATCH] mm/hmm/test: destroy xa_array instead of looping Ralph Campbell
2020-05-15 23:15 ` Jason Gunthorpe
2020-05-16  0:56   ` Ralph Campbell

Linux-kselftest Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-kselftest/0 linux-kselftest/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-kselftest linux-kselftest/ https://lore.kernel.org/linux-kselftest \
		linux-kselftest@vger.kernel.org
	public-inbox-index linux-kselftest

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kselftest


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git