All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] bouncebuf: Add static buffer allocation method for SPL.
Date: Tue, 7 May 2019 15:06:35 +0200	[thread overview]
Message-ID: <22733bba-07dd-4ad6-be64-da2f34b89f75@denx.de> (raw)
In-Reply-To: <20190507090936.51687-1-christoph.muellner@theobroma-systems.com>

On 5/7/19 11:09 AM, Christoph Muellner wrote:
> If we are using malloc-simple, we get into the problem, that
> calls to free() won't free any memory. When using bouncebuf
> in SPL with malloc-simple this means, that every allocated buffer
> is lost. This can quickly consume the whole heap.

When does such a scenario happen ?

> This patch addresses this memory wasting by introducing a static
> allocated memory location, which is used instead of dynamically
> allocated buffers.
> 
> Signed-off-by: Christoph Muellner <christoph.muellner@theobroma-systems.com>
> ---
> 
>  common/Kconfig     | 15 +++++++++++++++
>  common/bouncebuf.c | 14 ++++++++++++++
>  2 files changed, 29 insertions(+)
> 
> diff --git a/common/Kconfig b/common/Kconfig
> index 1a1951f874..5fbca1e61a 100644
> --- a/common/Kconfig
> +++ b/common/Kconfig
> @@ -702,6 +702,21 @@ config BOUNCE_BUFFER
>  	  A second possible use of bounce buffers is their ability to
>  	  provide aligned buffers for DMA operations.
>  
> +config SPL_BOUNCE_BUFFER_STATIC
> +	bool "Static bounce buffer in SPL"
> +	depends on SPL && BOUNCE_BUFFER
> +	default n
> +	help
> +	  This option uses a static allocated memory area as
> +	  bounce buffer (i.e. no dynamic allocation).
> +
> +config SPL_BOUNCE_BUFFER_STATIC_SIZE
> +	hex "Size of static bounce buffer in SPL"
> +	depends on SPL_BOUNCE_BUFFER_STATIC
> +	default 0x2800
> +	help
> +	  Size of the static allocated bounce buffer.
> +
>  config BOARD_TYPES
>  	bool "Call get_board_type() to get and display the board type"
>  	help
> diff --git a/common/bouncebuf.c b/common/bouncebuf.c
> index a7098e2caf..92ee10fb93 100644
> --- a/common/bouncebuf.c
> +++ b/common/bouncebuf.c
> @@ -10,6 +10,11 @@
>  #include <errno.h>
>  #include <bouncebuf.h>
>  
> +#if CONFIG_IS_ENABLED(BOUNCE_BUFFER_STATIC)
> +static u8 static_bb[CONFIG_VAL(BOUNCE_BUFFER_STATIC_SIZE)];
> +static const size_t static_bb_size = CONFIG_VAL(BOUNCE_BUFFER_STATIC_SIZE);
> +#endif
> +
>  static int addr_aligned(struct bounce_buffer *state)
>  {
>  	const ulong align_mask = ARCH_DMA_MINALIGN - 1;
> @@ -40,10 +45,19 @@ int bounce_buffer_start(struct bounce_buffer *state, void *data,
>  	state->flags = flags;
>  
>  	if (!addr_aligned(state)) {
> +#if CONFIG_IS_ENABLED(BOUNCE_BUFFER_STATIC)
> +		if (state->len_aligned > static_bb_size) {
> +			debug("Static allocated bounce buffer too small.\n");
> +			return -ENOMEM;
> +		}
> +
> +		state->bounce_buffer = static_bb;
> +#else
>  		state->bounce_buffer = memalign(ARCH_DMA_MINALIGN,
>  						state->len_aligned);
>  		if (!state->bounce_buffer)
>  			return -ENOMEM;
> +#endif
>  
>  		if (state->flags & GEN_BB_READ)
>  			memcpy(state->bounce_buffer, state->user_buffer,
> 


-- 
Best regards,
Marek Vasut

  parent reply	other threads:[~2019-05-07 13:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-07  9:09 [U-Boot] [PATCH 1/2] bouncebuf: Add static buffer allocation method for SPL Christoph Muellner
2019-05-07  9:09 ` [U-Boot] [PATCH 2/2] rockchip: rk3399-puma: Enable SPL_BOUNCE_BUFFER_STATIC Christoph Muellner
2019-05-18 16:07   ` Simon Glass
2019-05-07 13:06 ` Marek Vasut [this message]
2019-05-07 13:45   ` [U-Boot] [PATCH 1/2] bouncebuf: Add static buffer allocation method for SPL Christoph Müllner
2019-05-07 13:52     ` Marek Vasut
2019-05-07 13:55       ` Christoph Müllner
2019-05-07 13:55         ` Marek Vasut
2019-05-07 14:08           ` Christoph Müllner
2019-05-07 14:16             ` Simon Goldschmidt
2019-05-07 14:20               ` Christoph Müllner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22733bba-07dd-4ad6-be64-da2f34b89f75@denx.de \
    --to=marex@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.