drm/amdgpu: increase hmm range get pages timeout
Subsystems (2)
PATCH 1/2 drm/amdgpu: increase hmm range get pages timeout
When application tries to allocate all system memory and cause memory to swap out. Needs more time for hmm_range_fault to validate the remaining page for allocation. To be safe, increase timeout value to 1 second for 64MB range.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +2 -2
@@ -190,8 +190,8 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,pr_debug ("hmm range: start = 0x%lx, end = 0x%lx" , hmm_range->start, hmm_range->end); -/* Assuming 128MB takes maximum 1 second to fault page address */ - timeout =max ((hmm_range->end - hmm_range->start) >>27 ,1UL ); +/* Assuming 64MB takes maximum 1 second to fault page address */ + timeout =max ((hmm_range->end - hmm_range->start) >>26 ,1UL ); timeout *=HMM_RANGE_DEFAULT_TIMEOUT ; timeout = jiffies +msecs_to_jiffies (timeout);
Signature · 1 line
2.25.1
PATCH 2/2 drm/amdgpu: make an improvement on amdgpu_hmm_range_get_pages
Needn't do schedule for each hmm_range_fault, and use cond_resched to replace schedule.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -1
@@ -199,6 +199,7 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier, hmm_range->notifier_seq =mmu_interval_read_begin (notifier); r =hmm_range_fault (hmm_range);if (unlikely (r)) { +cond_resched ();/* * FIXME: This timeout should encompass the retry from * mmu_interval_read_retry() as well.
@@ -212,7 +213,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,break ; hmm_range->hmm_pfns +=MAX_WALK_BYTE >>PAGE_SHIFT ; hmm_range->start = hmm_range->end; -schedule (); }while (hmm_range->end < end); hmm_range->start = start;
Signature · 1 line
2.25.1
Christian König
maintainerRe: [PATCH 2/2] drm/amdgpu: make an improvement on amdgpu_hmm_range_get_pages
Am 09.12.23 um 00:01 schrieb James Zhu:
Quoted 2 lines
Needn't do schedule for each
hmm_range_fault, and usecond_reschedto replace schedule.
cond_resched() is usually NAKed upstream since it is a NO-OP in most situations.
IIRC there was even a patch set to completely remove it.
Christian.
Quoted 26 lines
Signed-off-by James Zhu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1
-1@@ -199,6 +199,7 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier, hmm_range->notifier_seq =mmu_interval_read_begin (notifier); r =hmm_range_fault (hmm_range);if (unlikely (r)) { +cond_resched ();/* * FIXME: This timeout should encompass the retry from * mmu_interval_read_retry() as well. @@ -212,7 +213,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,break ; hmm_range->hmm_pfns +=MAX_WALK_BYTE >>PAGE_SHIFT ; hmm_range->start = hmm_range->end; -schedule (); }while (hmm_range->end < end); hmm_range->start = start;
Re: [PATCH 2/2] drm/amdgpu: make an improvement on amdgpu_hmm_range_get_pages
Quoted 5 lines · Christian König
Am 09.12.23 um 00:01 schrieb James Zhu:
Quoted 2 lines
Needn't do schedule for each
hmm_range_fault, and usecond_reschedto replace schedule.
cond_resched()is usually NAKed upstream since it is a NO-OP in most situations.
[JZ] then let me change back to schedule(); Thanks!
Quoted 33 lines
IIRC there was even a patch set to completely remove it.
Christian.
Quoted 27 lines
Signed-off-by James Zhu <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1
-0@@ -199,6 +199,7 @@ int amdgpu_hmm_range_get_pages(structmmu_interval_notifier *notifier, hmm_range->notifier_seq = mmu_interval_read_begin(notifier); r = hmm_range_fault(hmm_range); if (unlikely(r)) { + cond_resched(); /** FIXME: This timeout should encompass the retry from *
mmu_interval_read_retry()as well.drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +0
-1@@ -212,7 +213,6 @@ int amdgpu_hmm_range_get_pages(structmmu_interval_notifier *notifier, break; hmm_range->hmm_pfns += MAX_WALK_BYTE >> PAGE_SHIFT; hmm_range->start = hmm_range->end; - schedule(); } while (hmm_range->end < end); hmm_range->start = start;
Re: [PATCH 2/2] drm/amdgpu: make an improvement on amdgpu_hmm_range_get_pages
In reply to Christian KönigQuoted 5 lines · Christian König
Am 09.12.23 um 00:01 schrieb James Zhu:
Quoted 2 lines
Needn't do schedule for each
hmm_range_fault, and usecond_reschedto replace schedule.
cond_resched()is usually NAKed upstream since it is a NO-OP in most situations.
That's weird, because https://docs.kernel.org/RCU/stallwarn.html specifically recommends it to resolve RCU stall warnings. I previously told James to use that instead of schedule().
Regards,
Felix
Quoted 33 lines
IIRC there was even a patch set to completely remove it.
Christian.
Quoted 27 lines
Signed-off-by James Zhu <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1
-0@@ -199,6 +199,7 @@ int amdgpu_hmm_range_get_pages(structmmu_interval_notifier *notifier, hmm_range->notifier_seq = mmu_interval_read_begin(notifier); r = hmm_range_fault(hmm_range); if (unlikely(r)) { + cond_resched(); /** FIXME: This timeout should encompass the retry from *
mmu_interval_read_retry()as well.drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +0
-1@@ -212,7 +213,6 @@ int amdgpu_hmm_range_get_pages(structmmu_interval_notifier *notifier, break; hmm_range->hmm_pfns += MAX_WALK_BYTE >> PAGE_SHIFT; hmm_range->start = hmm_range->end; - schedule(); } while (hmm_range->end < end); hmm_range->start = start;
Christian König
maintainerRe: [PATCH 2/2] drm/amdgpu: make an improvement on amdgpu_hmm_range_get_pages
Am 12.12.23 um 00:43 schrieb Felix Kuehling:
Quoted 9 lines · Christian König
Quoted 5 lines
Am 09.12.23 um 00:01 schrieb James Zhu:
Quoted 2 lines
Needn't do schedule for each
hmm_range_fault, and usecond_reschedto replace schedule.
cond_resched()is usually NAKed upstream since it is a NO-OP in most situations.That's weird, because https://docs.kernel.org/RCU/stallwarn.html specifically recommends it to resolve RCU stall warnings. I previously told James to use that instead of
schedule().
I haven't followed the full discussion and rational about that either, could be that the documentation is outdated.
The latest RFC to remove cond_resched() and explaining the background can be found here: https://lwn.net/Articles/950581/
Regards,
Christian.
Quoted 38 lines
Regards,
FelixQuoted 33 lines
IIRC there was even a patch set to completely remove it.
Christian.
Quoted 27 lines
Signed-off-by James Zhu <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1
-0@@ -199,6 +199,7 @@ int amdgpu_hmm_range_get_pages(structmmu_interval_notifier *notifier, hmm_range->notifier_seq = mmu_interval_read_begin(notifier); r = hmm_range_fault(hmm_range); if (unlikely(r)) { + cond_resched(); /** FIXME: This timeout should encompass the retry from *
mmu_interval_read_retry()as well.drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +0
-1@@ -212,7 +213,6 @@ int amdgpu_hmm_range_get_pages(structmmu_interval_notifier *notifier, break; hmm_range->hmm_pfns += MAX_WALK_BYTE >> PAGE_SHIFT; hmm_range->start = hmm_range->end; - schedule(); } while (hmm_range->end < end); hmm_range->start = start;
PATCH v2 2/2 drm/amdgpu: make an improvement on amdgpu_hmm_range_get_pages
In reply to James ZhuOnly schedule when hmm_range_fault returns error.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -1
@@ -199,6 +199,7 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier, hmm_range->notifier_seq =mmu_interval_read_begin (notifier); r =hmm_range_fault (hmm_range);if (unlikely (r)) { +schedule ();/* * FIXME: This timeout should encompass the retry from * mmu_interval_read_retry() as well.
@@ -212,7 +213,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,break ; hmm_range->hmm_pfns +=MAX_WALK_BYTE >>PAGE_SHIFT ; hmm_range->start = hmm_range->end; -schedule (); }while (hmm_range->end < end); hmm_range->start = start;
Signature · 1 line
2.25.1
Ping ...
Quoted 25 lines · James Zhu
When application tries to allocate all system memory and cause memory to swap out. Needs more time for
hmm_range_faultto validate the remaining page for allocation. To be safe, increase timeout value to 1 second for 64MB range.Signed-off-by James Zhu <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +2
-2@@ -190,8 +190,8 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,pr_debug ("hmm range: start = 0x%lx, end = 0x%lx" , hmm_range->start, hmm_range->end); -/* Assuming 128MB takes maximum 1 second to fault page address */ - timeout =max ((hmm_range->end - hmm_range->start) >>27 ,1UL ); +/* Assuming 64MB takes maximum 1 second to fault page address */ + timeout =max ((hmm_range->end - hmm_range->start) >>26 ,1UL ); timeout *=HMM_RANGE_DEFAULT_TIMEOUT ; timeout = jiffies +msecs_to_jiffies (timeout);
Felix Kuehling
Acked-byQuoted 9 lines · James Zhu
Ping ...
Quoted 6 lines · James Zhu
When application tries to allocate all system memory and cause memory to swap out. Needs more time for
hmm_range_faultto validate the remaining page for allocation. To be safe, increase timeout value to 1 second for 64MB range.Signed-off-by James Zhu <[email protected]>
This is not the first time we're incrementing this timeout. Eventually we should get rid of that and find a way to make this work reliably without a timeout. There can always be situations where faults take longer, and we should not fail randomly in those cases.
There are also some FIXMEs in this code that should be addressed at the same time.
That said, as a short-term fix, this patch is
Quoted 19 lines
Quoted 19 lines
---
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +0
-0@@ -190,8 +190,8 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier, pr_debug("hmm range: start = 0x%lx, end = 0x%lx", hmm_range->start, hmm_range->end);- /* Assuming 128MB takes maximum 1 second to fault page address */ - timeout =
max((hmm_range->end - hmm_range->start) >> 27, 1UL); + /* Assuming 64MB takes maximum 1 second to fault page address */
+ timeout =max((hmm_range->end - hmm_range->start) >> 26, 1UL); timeout *=HMM_RANGE_DEFAULT_TIMEOUT;
timeout = jiffies +msecs_to_jiffies(timeout);
Quoted 10 lines · Felix Kuehling
Quoted 8 lines · James Zhu
Ping ...
Quoted 5 lines · James Zhu
When application tries to allocate all system memory and cause memory to swap out. Needs more time for
hmm_range_faultto validate the remaining page for allocation. To be safe, increase timeout value to 1 second for 64MB range.
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Signed-off-by James Zhu <[email protected]>This is not the first time we're incrementing this timeout. Eventually we should get rid of that and find a way to make this work reliably without a timeout. There can always be situations where faults take longer, and we should not fail randomly in those cases.
There are also some FIXMEs in this code that should be addressed at the same time.
That said, as a short-term fix, this patch is
[JZ] Yes, it is just a short-term fix. the root cause is still under study,
Quoted 23 lines
Acked-by Felix Kuehling <[email protected]>Quoted 19 lines
Quoted 19 lines
---
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +0
-0@@ -190,8 +190,8 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier, pr_debug("hmm range: start = 0x%lx, end = 0x%lx", hmm_range->start, hmm_range->end);- /* Assuming 128MB takes maximum 1 second to fault page address */ - timeout =
max((hmm_range->end - hmm_range->start) >> 27, 1UL); + /* Assuming 64MB takes maximum 1 second to fault page address */
+ timeout =max((hmm_range->end - hmm_range->start) >> 26, 1UL); timeout *=HMM_RANGE_DEFAULT_TIMEOUT;
timeout = jiffies +msecs_to_jiffies(timeout);