[tarantool-patches] Re: [PATCH] Fix static buffer align

Konstantin Osipov kostja at tarantool.org
Mon Apr 9 23:21:24 MSK 2018


* AKhatskevich <avkhatskevich at tarantool.org> [18/04/09 10:35]:

This is OK to push.

> Branch: https://github.com/tarantool/tarantool/tree/kh/align_static_buf
> 
> The length of the TT_STATIC_BUFS was 1025 bytes which lead to unaligned
> allocation.
> The addresses was allocated like this:
>  - 0 0x7ffdd80aaa20
>  - 1 0x7ffdd80aae21
>  - 2 0x7ffdd80ab222
>  - 3 0x7ffdd80ab623
> 
> It may affect the performance and looks wired.
> ---
>  src/trivia/util.h | 2 +-
>  src/tt_uuid.c     | 2 +-
>  src/tt_uuid.h     | 3 ++-
>  3 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/src/trivia/util.h b/src/trivia/util.h
> index 38beff395..8f2075664 100644
> --- a/src/trivia/util.h
> +++ b/src/trivia/util.h
> @@ -489,7 +489,7 @@ static inline char *
>  tt_static_buf(void)
>  {
>  	enum { TT_STATIC_BUFS = 4 };
> -	static __thread char bufs[TT_STATIC_BUFS][TT_STATIC_BUF_LEN + 1];
> +	static __thread char bufs[TT_STATIC_BUFS][TT_STATIC_BUF_LEN];
>  	static __thread int bufno = TT_STATIC_BUFS - 1;
>  
>  	bufno = (bufno + 1) % TT_STATIC_BUFS;
> diff --git a/src/tt_uuid.c b/src/tt_uuid.c
> index f621ba711..530aa31a1 100644
> --- a/src/tt_uuid.c
> +++ b/src/tt_uuid.c
> @@ -86,7 +86,7 @@ tt_uuid_is_equal(const struct tt_uuid *lhs, const struct tt_uuid *rhs);
>  char *
>  tt_uuid_str(const struct tt_uuid *uu)
>  {
> -	assert(TT_STATIC_BUF_LEN >= UUID_STR_LEN);
> +	assert(TT_STATIC_BUF_LEN > UUID_STR_LEN);
>  	char *buf = tt_static_buf();
>  	tt_uuid_to_string(uu, buf);
>  	return buf;
> diff --git a/src/tt_uuid.h b/src/tt_uuid.h
> index 818914b83..00d6de662 100644
> --- a/src/tt_uuid.h
> +++ b/src/tt_uuid.h
> @@ -124,7 +124,8 @@ tt_uuid_compare(const struct tt_uuid *a, const struct tt_uuid *b)
>  inline void
>  tt_uuid_to_string(const struct tt_uuid *uu, char *out)
>  {
> -	sprintf(out, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
> +	snprintf(out, UUID_STR_LEN + 1,
> +		"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
>  		uu->time_low, uu->time_mid, uu->time_hi_and_version,
>  		uu->clock_seq_hi_and_reserved, uu->clock_seq_low, uu->node[0],
>  		uu->node[1], uu->node[2], uu->node[3], uu->node[4], uu->node[5]);
> -- 
> 2.14.1
> 
> 

-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov




More information about the Tarantool-patches mailing list