Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Nov 2023 11:23:06 -0800
From:      John Baldwin <jhb@FreeBSD.org>
To:        Alexander Motin <mav@FreeBSD.org>, src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   Re: git: 7c566d6cfc7b - main - uma: Micro-optimize memory trashing
Message-ID:  <bf902537-88f6-459d-957c-44d705c61c90@FreeBSD.org>
In-Reply-To: <202311091821.3A9ILlAJ044944@gitrepo.freebsd.org>
References:  <202311091821.3A9ILlAJ044944@gitrepo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 11/9/23 10:21 AM, Alexander Motin wrote:
> The branch main has been updated by mav:
> 
> URL: https://cgit.FreeBSD.org/src/commit/?id=7c566d6cfc7bfb913bad89d87386fa21dce8c2e6
> 
> commit 7c566d6cfc7bfb913bad89d87386fa21dce8c2e6
> Author:     Alexander Motin <mav@FreeBSD.org>
> AuthorDate: 2023-11-09 18:07:46 +0000
> Commit:     Alexander Motin <mav@FreeBSD.org>
> CommitDate: 2023-11-09 18:07:46 +0000
> 
>      uma: Micro-optimize memory trashing
>      
>      Use u_long for memory accesses instead of uint32_t.  On my tests on
>      amd64 this by ~30% reduces time spent in those functions thanks to
>      bigger 64bit accesses.  i386 still uses 32bit accesses.
>      
>      MFC after:      1 month
> ---
>   sys/vm/uma_dbg.c | 62 ++++++++++++++++++++++++--------------------------------
>   1 file changed, 26 insertions(+), 36 deletions(-)
> 
> diff --git a/sys/vm/uma_dbg.c b/sys/vm/uma_dbg.c
> index 36567f3b3968..76dd2bfde2fe 100644
> --- a/sys/vm/uma_dbg.c
> +++ b/sys/vm/uma_dbg.c
> @@ -64,27 +64,20 @@ static const uint32_t uma_junk = 0xdeadc0de;
>   int
>   trash_ctor(void *mem, int size, void *arg, int flags)
>   {
> -	int cnt;
> -	uint32_t *p;
> +	u_long *p = mem, *e;
>   
>   #ifdef DEBUG_MEMGUARD
>   	if (is_memguard_addr(mem))
>   		return (0);
>   #endif
>   
> -	cnt = size / sizeof(uma_junk);
> -
> -	for (p = mem; cnt > 0; cnt--, p++)
> -		if (*p != uma_junk) {
> -#ifdef INVARIANTS
> -			panic("Memory modified after free %p(%d) val=%x @ %p\n",
> -			    mem, size, *p, p);
> -#else
> -			printf("Memory modified after free %p(%d) val=%x @ %p\n",
> -			    mem, size, *p, p);
> -#endif
> -			return (0);
> -		}
> +	e = p + size / sizeof(*p);
> +	for (; p < e; p++) {
> +		if (__predict_true(*p == uma_junk))
> +			continue;
> +		panic("Memory modified after free %p(%d) val=%lx @ %p\n",
> +		    mem, size, *p, p);
> +	}
>   	return (0);

For future reference, switching from printf to panic here for the !INVARIANTS case
is a good change I think, but it was probably worth calling out in the commit log
(or possibly doing as a separate commit before/after this one).

-- 
John Baldwin




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bf902537-88f6-459d-957c-44d705c61c90>