Tarantool development patches archive
 help / color / mirror / Atom feed
From: Ilya Kosarev <i.kosarev@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Cc: v.shpilevoy@tarantool.org
Subject: [Tarantool-patches] [PATCH 2/3] memtx: don't reserve extra memory if not needed
Date: Fri, 13 Dec 2019 10:05:10 +0300	[thread overview]
Message-ID: <95c49cb56ed3eb7f2051ee1690f9b28a45210367.1575627361.git.i.kosarev@tarantool.org> (raw)
In-Reply-To: <cover.1575627361.git.i.kosarev@tarantool.org>
In-Reply-To: <cover.1575627361.git.i.kosarev@tarantool.org>

memtx_index_extent_reserve was always being called from
memtx_space_replace_all_keys. It could lead to slab allocator failure
while reaching memtx_memory limit, which is especially distressing on
space:truncate() and space:delete() invocations. we  Now it is not
being called if not needed, including space:truncate() and
space:delete() cases.

Part of #3807
---
 src/box/memtx_space.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c
index 6ef84e04564..1e8759778e7 100644
--- a/src/box/memtx_space.c
+++ b/src/box/memtx_space.c
@@ -260,10 +260,18 @@ memtx_space_replace_all_keys(struct space *space, struct tuple *old_tuple,
 	 * Ensure we have enough slack memory to guarantee
 	 * successful statement-level rollback.
 	 */
-	if (memtx_index_extent_reserve(memtx, new_tuple != NULL ?
-				       RESERVE_EXTENTS_BEFORE_REPLACE :
-				       RESERVE_EXTENTS_BEFORE_DELETE) != 0)
+	if (space->index_count > 1 && new_tuple != NULL) {
+		if (memtx_index_extent_reserve(memtx, new_tuple != NULL ?
+					       RESERVE_EXTENTS_BEFORE_REPLACE :
+					       RESERVE_EXTENTS_BEFORE_DELETE) != 0)
+			return -1;
+	}
+	ERROR_INJECT(ERRINJ_INDEX_ALLOC, {
+		/* same error as in mempool_alloc */
+		diag_set(OutOfMemory, MEMTX_EXTENT_SIZE,
+			 "mempool", "new slab");
 		return -1;
+	});
 
 	uint32_t i = 0;
 
-- 
2.17.1

  parent reply	other threads:[~2019-12-13  7:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-13  7:05 [Tarantool-patches] [PATCH 0/3] Safe allocation on truncation and deletion Ilya Kosarev
2019-12-13  7:05 ` [Tarantool-patches] [PATCH 1/3] b-tree: return NULL on matras_alloc fail Ilya Kosarev
2019-12-19  0:32   ` Vladislav Shpilevoy
2019-12-13  7:05 ` Ilya Kosarev [this message]
2019-12-19  0:31   ` [Tarantool-patches] [PATCH 2/3] memtx: don't reserve extra memory if not needed Vladislav Shpilevoy
2019-12-13  7:05 ` [Tarantool-patches] [PATCH 3/3] tuple: use calloc for service truncation tuples Ilya Kosarev
2019-12-19  0:31   ` 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=95c49cb56ed3eb7f2051ee1690f9b28a45210367.1575627361.git.i.kosarev@tarantool.org \
    --to=i.kosarev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 2/3] memtx: don'\''t reserve extra memory if not needed' \
    /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