[SLOF] [PATCH] Improve SLOF_alloc_mem_aligned()

Alexey Kardashevskiy aik at ozlabs.ru
Wed Sep 14 15:39:40 AEST 2016


On 05/09/16 19:28, Thomas Huth wrote:
> When loading a file via the spapr-vlan network interface, SLOF
> currently leaks quite a lot of memory, about 12kB each time.
> This happens mainly because veth_init() uses for example
> SLOF_alloc_mem_aligned(8192, 4096) and similar calls to get
> the memory, but the space for the additional alignment is never
> returned anymore later. An easy way to ease this situation is to
> improve SLOF_alloc_mem_aligned() a little bit. We normally get memory
> from SLOF_alloc_mem() which is aligned pretty well already, thanks to
> the buddy allocator in SLOF. So we can try to first get a memory
> block with the exact size first, and only do the alignment dance
> if the first allocation was not aligned yet.
> 
> Signed-off-by: Thomas Huth <thuth at redhat.com>

I do not like it but since the allocated address does not store the size
somewhere nearby, I'll apply this anyway, thanks.


> ---
>  slof/helpers.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/slof/helpers.c b/slof/helpers.c
> index 48c34a6..b049141 100644
> --- a/slof/helpers.c
> +++ b/slof/helpers.c
> @@ -69,9 +69,14 @@ void *SLOF_alloc_mem(long size)
>  
>  void *SLOF_alloc_mem_aligned(long size, long align)
>  {
> -	unsigned long addr = (unsigned long)SLOF_alloc_mem(size + align - 1);
> -	addr = addr + align - 1;
> -	addr = addr & ~(align - 1);
> +	unsigned long addr = (unsigned long)SLOF_alloc_mem(size);
> +
> +	if (addr % align) {
> +		SLOF_free_mem((void *)addr, size);
> +		addr = (unsigned long)SLOF_alloc_mem(size + align - 1);
> +		addr = addr + align - 1;
> +		addr = addr & ~(align - 1);
> +	}
>  
>  	return (void *)addr;
>  }
> 


-- 
Alexey


More information about the SLOF mailing list