All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: memalloc: use __GFP_RETRY_MAYFAIL for DMA mem allocs
@ 2022-09-23 15:35 Kai Vehmanen
  2022-09-26  6:57 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Kai Vehmanen @ 2022-09-23 15:35 UTC (permalink / raw)
  To: alsa-devel, tiwai; +Cc: peter.ujfalusi, Pierre-Louis Bossart, kai.vehmanen

Use __GFP_RETRY_MAYFAIL instead of __GFP__NORETRY in
snd_dma_dev_alloc(), snd_dma_wc_alloc() and friends, to allocate pages
for device memory. The MAYFAIL flag retains the semantics of not
triggering the OOM killer, but lowers the risk of alloc failure.

MAYFAIL flag was added in commit dcda9b04713c3 ("mm, tree wide: replace
__GFP_REPEAT by __GFP_RETRY_MAYFAIL with more useful semantic").

This change addresses recurring failures with SOF audio driver in test
cases where a system suspend-resume stress test is run, combined with an
active high memory-load use-case. The failure typically shows up as:

[ 379.480229] sof-audio-pci-intel-tgl 0000:00:1f.3: booting DSP firmware
[ 379.484803] sof-audio-pci-intel-tgl 0000:00:1f.3: error: memory alloc failed: -12
[ 379.484810] sof-audio-pci-intel-tgl 0000:00:1f.3: error: dma prepare for ICCMAX stream failed

Multiple fixes to reduce the memory usage of DSP boot have been
identified in SOF driver, but even with those fixes, debug on affected
systems has shown that even a single page alloc may fail with
__GFP_NORETRY. When this occurs, system is under significant load on
physical memory, but a lot of reclaimable pages are available, so the
system has not run out of memory. With __GFP_RETRY_MAYFAIL, the errors
are not hit in these stress tests.

The alloc failure is severe as audio capability is completely lost if
alloc failure is hit at system resume.

An alternative solution was considered where the resources for DSP boot
would be kept allocated until driver is unbound. This would avoid the
allocation failure, but consume memory that is only needed temporarily
at probe and resume time. It seems better to not hang on to the memory,
but rather work a bit harder for allocating the pages at resume.

BugLink: https://github.com/thesofproject/linux/issues/3844
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 sound/core/memalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 2c11413bea61..03cffe771366 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -21,7 +21,7 @@
 #define DEFAULT_GFP \
 	(GFP_KERNEL | \
 	 __GFP_COMP |    /* compound page lets parts be mapped */ \
-	 __GFP_NORETRY | /* don't trigger OOM-killer */ \
+	 __GFP_RETRY_MAYFAIL | /* don't trigger OOM-killer */ \
 	 __GFP_NOWARN)   /* no stack trace print - this call is non-critical */
 
 static const struct snd_malloc_ops *snd_dma_get_ops(struct snd_dma_buffer *dmab);

base-commit: db3ffa8e4f3ce1f910e337b4d8a8518c69420b65
-- 
2.37.3


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

* Re: [PATCH] ALSA: memalloc: use __GFP_RETRY_MAYFAIL for DMA mem allocs
  2022-09-23 15:35 [PATCH] ALSA: memalloc: use __GFP_RETRY_MAYFAIL for DMA mem allocs Kai Vehmanen
@ 2022-09-26  6:57 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2022-09-26  6:57 UTC (permalink / raw)
  To: Kai Vehmanen; +Cc: alsa-devel, peter.ujfalusi, Pierre-Louis Bossart

On Fri, 23 Sep 2022 17:35:01 +0200,
Kai Vehmanen wrote:
> 
> Use __GFP_RETRY_MAYFAIL instead of __GFP__NORETRY in
> snd_dma_dev_alloc(), snd_dma_wc_alloc() and friends, to allocate pages
> for device memory. The MAYFAIL flag retains the semantics of not
> triggering the OOM killer, but lowers the risk of alloc failure.
> 
> MAYFAIL flag was added in commit dcda9b04713c3 ("mm, tree wide: replace
> __GFP_REPEAT by __GFP_RETRY_MAYFAIL with more useful semantic").
> 
> This change addresses recurring failures with SOF audio driver in test
> cases where a system suspend-resume stress test is run, combined with an
> active high memory-load use-case. The failure typically shows up as:
> 
> [ 379.480229] sof-audio-pci-intel-tgl 0000:00:1f.3: booting DSP firmware
> [ 379.484803] sof-audio-pci-intel-tgl 0000:00:1f.3: error: memory alloc failed: -12
> [ 379.484810] sof-audio-pci-intel-tgl 0000:00:1f.3: error: dma prepare for ICCMAX stream failed
> 
> Multiple fixes to reduce the memory usage of DSP boot have been
> identified in SOF driver, but even with those fixes, debug on affected
> systems has shown that even a single page alloc may fail with
> __GFP_NORETRY. When this occurs, system is under significant load on
> physical memory, but a lot of reclaimable pages are available, so the
> system has not run out of memory. With __GFP_RETRY_MAYFAIL, the errors
> are not hit in these stress tests.
> 
> The alloc failure is severe as audio capability is completely lost if
> alloc failure is hit at system resume.
> 
> An alternative solution was considered where the resources for DSP boot
> would be kept allocated until driver is unbound. This would avoid the
> allocation failure, but consume memory that is only needed temporarily
> at probe and resume time. It seems better to not hang on to the memory,
> but rather work a bit harder for allocating the pages at resume.
> 
> BugLink: https://github.com/thesofproject/linux/issues/3844
> Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
> Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

Thanks, applied.


Takashi

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

end of thread, other threads:[~2022-09-26  6:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-23 15:35 [PATCH] ALSA: memalloc: use __GFP_RETRY_MAYFAIL for DMA mem allocs Kai Vehmanen
2022-09-26  6:57 ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.