[Tarantool-patches] [PATCH small 2/2] lsregion: provide aligned version of alloc

Aleksandr Lyapunov alyapunov at tarantool.org
Fri May 15 16:03:48 MSK 2020


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.
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.tarantool.org/pipermail/tarantool-patches/attachments/20200515/05ed177e/attachment.html>


More information about the Tarantool-patches mailing list