[alsa-devel] [PATCH] ALSA: snd-aloop: make preallocated buffer size configurable

Takashi Iwai tiwai at suse.de
Wed Sep 21 16:38:45 CEST 2011


At Wed, 21 Sep 2011 08:26:27 -0500,
Pierre-Louis Bossart wrote:
> 
> > > Default of 2MB of physically-contiguous memory can be
> > > too high for embedded solutions, make the size configurable.
> > 
> > Hm, maybe better to have an option for global limit of preallocation?
> > The problem is not necessarily specific to snd-aloop.
> 
> Not sure I understand the comment. This code is essentially the same as the
> configuration option for HDAudio, and the parameter value defines the amount
> of preallocated memory, with a limit to 32MB.

I meant to have a kconfig option to limit the upper-bound of pre-alloc
buffer sizes for all drivers.  That is, a patch like below (untested)


Takashi

---
diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index 475455c..525ed28 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -204,6 +204,15 @@ config SND_PCM_XRUN_DEBUG
 	  sound clicking when system is loaded, it may help to determine
 	  the process or driver which causes the scheduling gaps.
 
+config SND_PCM_MAX_PREALLOC_SIZE
+	int "Maximum pre-allocated buffer size"
+	range 0 32768
+	default 0
+	depends on EMBEDDED
+	help
+	  Specifies the default upper-limit of PCM pre-allocation
+	  buffer sizes in kB.  Zero means unlimited.
+
 config SND_VMASTER
 	bool
 
diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c
index 150cb7e..a09425c 100644
--- a/sound/core/pcm_memory.c
+++ b/sound/core/pcm_memory.c
@@ -270,6 +270,9 @@ int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
 				  int type, struct device *data,
 				  size_t size, size_t max)
 {
+	if (CONFIG_SND_PCM_MAX_PREALLOC_SIZE &&
+	    max > CONFIG_PCM_SND_MAX_PREALLOC_SIZE * 1024)
+		max = CONFIG_SND_PCM_PREALLOC_SIZE * 1024;
 	substream->dma_buffer.dev.type = type;
 	substream->dma_buffer.dev.dev = data;
 	return snd_pcm_lib_preallocate_pages1(substream, size, max);


More information about the Alsa-devel mailing list