Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v2 1/1] fiber: extend max fiber name length to 255
Date: Mon, 16 Mar 2020 10:19:27 +0300	[thread overview]
Message-ID: <20200316071927.GZ27301@uranus> (raw)
In-Reply-To: <7720185c4456a63f0d31bfbe11cdb101e864a3c4.1584284911.git.v.shpilevoy@tarantool.org>

On Sun, Mar 15, 2020 at 04:11:14PM +0100, Vladislav Shpilevoy wrote:
...
> diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c
> index ada7972cb..359ef1187 100644
> --- a/src/lib/core/fiber.c
> +++ b/src/lib/core/fiber.c
> @@ -912,8 +912,26 @@ fiber_loop(MAYBE_UNUSED void *data)
>  void
>  fiber_set_name(struct fiber *fiber, const char *name)
>  {
> -	assert(name != NULL);
> -	snprintf(fiber->name, sizeof(fiber->name), "%s", name);
> +	size_t len = strlen(name);
> +	if (len <= FIBER_NAME_INLINE) {
> +		if (fiber->name != fiber->inline_name) {
> +			free(fiber->name);
> +			fiber->name = fiber->inline_name;
> +		}
> +	} else {
> +		if (len > FIBER_NAME_MAX)
> +			len = FIBER_NAME_MAX;
> +		char *new_name;
> +		if (fiber->name != fiber->inline_name)
> +			new_name = realloc(fiber->name, len + 1);
> +		else
> +			new_name = malloc(len + 1);
> +		if (new_name == NULL)
> +			panic("fiber_set_name() failed with OOM");
> +		fiber->name = new_name;
> +	}
> +	memcpy(fiber->name, name, len);
> +	fiber->name[len] = 0;
>  }

Thank, Vlad! I like the patch. There is only one concern I have: for
some reason we has been defining faiber name as

char name[FIBER_NAME_MAX + 1];

where FIBER_NAME_MAX = 32 and finally this expands to "char name[33];"
I'm too lazy to find who exactly introduced this but it is bloody
wrong: compiler alings members to eliminate data access penalty, thus
_actually_ it will be defined as 8 multilier, ie 40 bytes.

Thus, if you don't mind I propose make FIBER_NAME_INLINE = 40
*including* string terminating zero.

Actually we can make it on top then. Up to you. Anyway

Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>

  reply	other threads:[~2020-03-16  7:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-15 15:11 Vladislav Shpilevoy
2020-03-16  7:19 ` Cyrill Gorcunov [this message]
2020-03-16 22:28   ` Vladislav Shpilevoy
2020-03-16 22:31     ` Cyrill Gorcunov
2020-03-16 12:48 ` Nikita Pettik
2020-03-16 22:29   ` Vladislav Shpilevoy
2020-03-18 21:35 ` Vladislav Shpilevoy
2020-03-18 23:57   ` Nikita Pettik
2020-03-19 22:30     ` Vladislav Shpilevoy
2020-03-20  1:59       ` Nikita Pettik

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=20200316071927.GZ27301@uranus \
    --to=gorcunov@gmail.com \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2 1/1] fiber: extend max fiber name length to 255' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox