Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Aleksandr Lyapunov <alyapunov@tarantool.org>,
	tarantool-patches@dev.tarantool.org, korablev@tarantool.org,
	tsafin@tarantool.org, gorcunov@gmail.com
Subject: Re: [Tarantool-patches] [PATCH small 2/2] lsregion: provide aligned version of alloc
Date: Sat, 16 May 2020 01:24:05 +0200	[thread overview]
Message-ID: <099effc3-4bfb-dba7-e479-29b4187ce7b9@tarantool.org> (raw)
In-Reply-To: <e2ba34fa-76e3-9776-b553-4b175da7d6fb@tarantool.org>

Thanks for the review!

On 15/05/2020 15:03, Aleksandr Lyapunov wrote:
> On 5/15/20 2:31 AM, Vladislav Shpilevoy wrote:
>> +static inline void *
>> +lsregion_aligned_alloc(struct lsregion *lsregion, size_t size, size_t alignment,
>> +		       int64_t id)
>> +{
>> +	void *unaligned = lsregion_reserve(lsregion, size + alignment - 1);
> I do not like this change. It will work, but it's not optimal.

It is optimal in terms of code simplicity and speed. The worst what can happen
is that the slab size becomes basically 7 bytes smaller. But taking into account
slab minimal size 65KB, this tail does not matter.

However yeah, it is not optimal in terms of space, strictly speaking. I firstly
wanted to keep the current implementation, but then out of curiosity tried your
way, and it looks fine I think. Not too complex. But the patchset is changed
significantly. Now there is only one commit (since the aligned allocs rewrite all
the diff of the first patch, about reserve() function), and much more changes.

> We don't need to reserve more than size if lslab_pos(slab) is already aligned.
> It could lead to new slab allocation in cases we actually have enough aligned space in current.
> 
> If we really need aligned alloc, I'm sure we should implement it more carefully.
> I think it should start with something like:
>  static inline size_t
> -lslab_unused(const struct lslab *slab)
> +lslab_unused(const struct lslab *slab, size_t align)
>  {
> -       assert(slab->slab_size >= slab->slab_used);
> -       return slab->slab_size - slab->slab_used;
> +       assert(slab->slab_size >= small_align(slab->slab_used, align));
> +       return slab->slab_size - small_align(slab->slab_used, align);
>  }
> 
> Note also we should remove small_align call from lslab_sizeof method.

Eww. This looks really bad. lslab_unused() becomes too complex. And moreover,
it can overflow. Because small_align() can return something bigger than
slab->slab_size. Also this does not return aligned unused, in a common case.
Because the slab itself may be not aligned enough for the requested alignment.
I wrote a test for that.

But I got the idea. I sent v2 in a new thread.

  reply	other threads:[~2020-05-15 23:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 23:31 [Tarantool-patches] [PATCH small 0/2] Aligned lsregion Vladislav Shpilevoy
2020-05-14 23:31 ` [Tarantool-patches] [PATCH small 1/2] lsregion: introduce lsregion_reserve() Vladislav Shpilevoy
2020-05-15 12:35   ` Aleksandr Lyapunov
2020-05-14 23:31 ` [Tarantool-patches] [PATCH small 2/2] lsregion: provide aligned version of alloc Vladislav Shpilevoy
2020-05-15 13:03   ` Aleksandr Lyapunov
2020-05-15 23:24     ` Vladislav Shpilevoy [this message]
2020-05-15 12:26 ` [Tarantool-patches] [PATCH small 0/2] Aligned lsregion Aleksandr Lyapunov
2020-05-15 23:22   ` Vladislav Shpilevoy
2020-05-16 19:09     ` Aleksandr Lyapunov
2020-05-17 13:56       ` Vladislav Shpilevoy

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=099effc3-4bfb-dba7-e479-29b4187ce7b9@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=alyapunov@tarantool.org \
    --cc=gorcunov@gmail.com \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=tsafin@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH small 2/2] lsregion: provide aligned version of alloc' \
    /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