[Tarantool-patches] [PATCH v2 small 1/1] lsregion: introduce aligned alloc

Timur Safin tsafin at tarantool.org
Tue May 19 19:21:38 MSK 2020


Other than small note below it's looking great, but please keep in mind...

: From: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>
: Subject: [PATCH v2 small 1/1] lsregion: introduce aligned alloc
: 


: @@ -32,59 +32,62 @@
:  #include "lsregion.h"
: 
:  void *
: -lsregion_alloc_slow(struct lsregion *lsregion, size_t size, int64_t id)
: +lsregion_aligned_reserve_slow(struct lsregion *lsregion, size_t size,
: +			      size_t alignment, void **unaligned)
:  {
: -	struct lslab *slab = NULL;
: -	size_t slab_size = lsregion->arena->slab_size;
: +	void *pos;
: +	struct lslab *slab;
: +	struct slab_arena *arena = lsregion->arena;
: +	size_t slab_size = arena->slab_size;
: 
:  	/* If there is an existing slab then try to use it. */
:  	if (! rlist_empty(&lsregion->slabs.slabs)) {
:  		slab = rlist_last_entry(&lsregion->slabs.slabs, struct lslab,
:  					next_in_list);
:  		assert(slab != NULL);
: +		*unaligned = lslab_pos(slab);
: +		pos = (void *)small_align((size_t)*unaligned, alignment);
: +		if (pos + size <= lslab_end(slab))
: +			return pos;

Void* pointer arithmetic is non-standard, gcc extension, and I'd 
avoid to use it in a longer run. There are compilers is which still 
not support it. 

Timur



More information about the Tarantool-patches mailing list