Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Cc: tarantool-patches@freelists.org, kostja@tarantool.org,
	v.shpilevoy@tarantool.org
Subject: Re: [PATCH v5 2/3] box: introduce tuple_chunk infrastructure
Date: Fri, 26 Jul 2019 12:35:19 +0300	[thread overview]
Message-ID: <20190726093519.GS24631@esperanza> (raw)
In-Reply-To: <1936ef07aa32f059b741e0a9862c8bf1d6fca4c8.1564079799.git.kshcherbatov@tarantool.org>

On Thu, Jul 25, 2019 at 09:39:44PM +0300, Kirill Shcherbatov wrote:
> Introduced a new object tuple_chunk: a memory allocation is
> associated with given tuple. tuple_format's vtab is extended
> with few new methods to manage tuple_chunks lifecycle.
> Implemented corresponding methid for memtx engine: a memory
> chunks are allocated with memtx's smalloc allocator.
> 
> Needed for #1260

I wouldn't use a separate patch for this, because this patch introduces
some code which is only used by the following patches and useless
otherwise. It's difficult to review without peeking at the following
patches. It's not important though so never mind.

> ---
>  src/box/tuple.h        | 28 ++++++++++++++++++++++++++++
>  src/box/tuple_format.h |  9 +++++++++
>  src/box/memtx_engine.c | 27 +++++++++++++++++++++++++++
>  src/box/tuple.c        |  8 ++++++++
>  src/box/vy_stmt.c      |  2 ++
>  5 files changed, 74 insertions(+)
> 
> diff --git a/src/box/tuple.h b/src/box/tuple.h
> index 99dfeb82d..60b6fb474 100644
> --- a/src/box/tuple.h
> +++ b/src/box/tuple.h
> @@ -447,6 +447,34 @@ tuple_delete(struct tuple *tuple)
>  	format->vtab.tuple_delete(format, tuple);
>  }
>  
> +/** Tuple chunk memory object. */
> +struct tuple_chunk {
> +	/** The payload size. Needed to perform memory release.*/
> +	uint32_t data_sz;
> +	/** Metadata object payload. */
> +	char data[0];
> +};

Do we really need this level of abstraction? Can't we simply add tuple
format methods to allocate some opaque extra data and free it? Can't
tell without looking at the next patch...

> +
> +/** Calculate the size of tuple_chunk object by given data_sz. */
> +uint32_t
> +tuple_chunk_sz(uint32_t data_sz);
> +
> +/** Allocate a new tuple_chunk for given tuple. */
> +static inline struct tuple_chunk *
> +tuple_chunk_new(struct tuple *tuple, uint32_t data_sz)
> +{
> +	struct tuple_format *format = tuple_format(tuple);
> +	return format->vtab.tuple_chunk_new(format, tuple, data_sz);
> +}
> +
> +/** Free a tuple_chunk is allocated for given tuple. */
> +static inline void
> +tuple_chunk_delete(struct tuple *tuple, struct tuple_chunk *tuple_chunk)
> +{
> +	struct tuple_format *format = tuple_format(tuple);
> +	format->vtab.tuple_chunk_delete(format, tuple_chunk);
> +}

Why pass tuples to these methods? Solely to extract a format?

> diff --git a/src/box/memtx_engine.c b/src/box/memtx_engine.c
> index 428491c2d..fbb3151c9 100644
> --- a/src/box/memtx_engine.c
> +++ b/src/box/memtx_engine.c
> @@ -1126,9 +1126,36 @@ memtx_tuple_delete(struct tuple_format *format, struct tuple *tuple)
>  		smfree_delayed(&memtx->alloc, memtx_tuple, total);
>  }
>  
> +void
> +metmx_tuple_chunk_delete(struct tuple_format *format,
> +			 struct tuple_chunk *tuple_chunk)
> +{
> +	struct memtx_engine *memtx = (struct memtx_engine *)format->engine;
> +	uint32_t sz = tuple_chunk_sz(tuple_chunk->data_sz);
> +	smfree(&memtx->alloc, tuple_chunk, sz);
> +}
> +
> +struct tuple_chunk *
> +memtx_tuple_chunk_new(struct tuple_format *format, struct tuple *tuple,
> +		      uint32_t data_sz)
> +{
> +	struct memtx_engine *memtx = (struct memtx_engine *)format->engine;
> +	uint32_t sz = tuple_chunk_sz(data_sz);
> +	struct tuple_chunk *tuple_chunk =
> +		(struct tuple_chunk *) smalloc(&memtx->alloc, sz);
> +	if (tuple == NULL) {

s/tuple/tuple_chunk

Looks like you don't need 'tuple' here.

> +		diag_set(OutOfMemory, sz, "smalloc", "tuple");
> +		return NULL;
> +	}
> +	tuple_chunk->data_sz = data_sz;
> +	return tuple_chunk;
> +}
> +
>  struct tuple_format_vtab memtx_tuple_format_vtab = {
>  	memtx_tuple_delete,
>  	memtx_tuple_new,
> +	metmx_tuple_chunk_delete,
> +	memtx_tuple_chunk_new,
>  };
>  
>  /**
> diff --git a/src/box/tuple.c b/src/box/tuple.c
> index c0e94d55b..25f85f732 100644
> --- a/src/box/tuple.c
> +++ b/src/box/tuple.c
> @@ -67,6 +67,8 @@ runtime_tuple_new(struct tuple_format *format, const char *data, const char *end
>  static struct tuple_format_vtab tuple_format_runtime_vtab = {
>  	runtime_tuple_delete,
>  	runtime_tuple_new,
> +	NULL,
> +	NULL,
>  };
>  
>  static struct tuple *
> @@ -785,3 +787,9 @@ mp_str(const char *data)
>  		return "<failed to format message pack>";
>  	return buf;
>  }
> +
> +uint32_t
> +tuple_chunk_sz(uint32_t data_sz)
> +{
> +	return sizeof(struct tuple_chunk) + data_sz;
> +}

This function could be inlined.

  reply	other threads:[~2019-07-26  9:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-25 18:39 [PATCH v5 0/3] box: functional indexes Kirill Shcherbatov
2019-07-25 18:39 ` [PATCH v5 1/3] box: introduce opts.is_multikey function option Kirill Shcherbatov
2019-07-26  9:22   ` Vladimir Davydov
2019-07-26  9:55     ` Konstantin Osipov
2019-07-25 18:39 ` [PATCH v5 2/3] box: introduce tuple_chunk infrastructure Kirill Shcherbatov
2019-07-26  9:35   ` Vladimir Davydov [this message]
2019-07-25 18:39 ` [PATCH v5 3/3] box: introduce func_index Kirill Shcherbatov
2019-07-26  9:49   ` Vladimir Davydov
2019-07-26  9:57     ` Konstantin Osipov
2019-07-26 10:10       ` Vladimir Davydov
2019-07-26 19:31         ` [tarantool-patches] " Konstantin Osipov
2019-07-27 11:42           ` Vladimir Davydov
2019-07-28 21:30             ` Konstantin Osipov
2019-07-26  9:43 [PATCH v5 0/3] box: functional indexes Kirill Shcherbatov
2019-07-26  9:43 ` [PATCH v5 2/3] box: introduce tuple_chunk infrastructure Kirill Shcherbatov

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=20190726093519.GS24631@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=kostja@tarantool.org \
    --cc=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [PATCH v5 2/3] box: introduce tuple_chunk infrastructure' \
    /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