-
Notifications
You must be signed in to change notification settings - Fork 9
memcached: use own small's arena #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
33f0b97
test: add tests for memcached instance api
ligurio ca07325
test: add tests for memcached module api
ligurio 78dc98e
memcached: rename internal module function memcached_init()
ligurio 71c9ece
memcached: add alloc.c to build
ligurio 0bf8fda
memcached: remove dead code
ligurio f92475c
memcached: use own slab arena
ligurio 41deb89
memcached: add a new module function with slab info
ligurio eec33c9
github-ci: enable Tarantool 2.10 in integration testing
ligurio 17959b4
github-ci: add Tarantool 2.10 to regular workflow
ligurio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,87 @@ | ||
#include <tarantool/module.h> | ||
#include <small/slab_cache.h> | ||
#include <small/quota.h> | ||
|
||
#include "memcached_persistent.h" | ||
static struct slab_arena arena; | ||
static struct slab_cache slabc; | ||
static struct quota quota; | ||
|
||
void * | ||
box_persistent_malloc(size_t len, size_t *total) | ||
ligurio marked this conversation as resolved.
Show resolved
Hide resolved
|
||
struct slab_arena_info { | ||
uint64_t quota_size; | ||
uint64_t quota_used; | ||
double quota_used_ratio; | ||
}; | ||
|
||
struct slab_arena_info slab_info; | ||
|
||
/* | ||
* Function produce an output with information of total quota size, used quota | ||
* size and quota used ratio. Note that function relies on a fact that | ||
* memcached uses a single slab cache for all allocations it made. | ||
*/ | ||
struct slab_arena_info * | ||
memcached_slab_arena_info() | ||
{ | ||
struct slab *slab = slab_get(cord_slab_cache(), len); | ||
char *ptr = NULL; size_t sz = 0; | ||
if (slab != NULL) { | ||
ptr = slab_data(slab); | ||
sz = slab_capacity(slab); | ||
} | ||
if (total) *total = sz; | ||
return ptr; | ||
/* | ||
* How much quota has been booked - reflects the total | ||
* size of slabs in various slab caches. | ||
*/ | ||
slab_info.quota_used = (uint64_t)quota_used(arena.quota); | ||
|
||
slab_info.quota_size = (uint64_t)quota_total(arena.quota); | ||
slab_info.quota_used_ratio = 100 * ((double) slab_info.quota_used / | ||
((double) slab_info.quota_size + 0.0001)); | ||
|
||
return &slab_info; | ||
} | ||
|
||
void * | ||
box_persistent_malloc0(size_t len, size_t *total) | ||
void | ||
memcached_slab_arena_create() | ||
{ | ||
size_t sz = 0; | ||
char *ptr = box_persistent_malloc(len, &sz); | ||
if (ptr) memset(ptr, 0, sz); | ||
if (total) *total = sz; | ||
return ptr; | ||
static __thread bool inited = false; | ||
if (inited) return; | ||
size_t quota_size = QUOTA_MAX; | ||
quota_init("a, quota_size); | ||
/* Parameters are the same as in src/lib/core/memory.c:memory_init() */ | ||
const size_t SLAB_SIZE = 4 * 1024 * 1024; | ||
slab_arena_create(&arena, "a, 0, SLAB_SIZE, SLAB_ARENA_PRIVATE); | ||
say_info("creating arena with %zu bytes...", quota_size); | ||
inited = 1; | ||
} | ||
|
||
void | ||
box_persistent_free(void *ptr) { | ||
if (ptr) slab_put(cord_slab_cache(), slab_from_data(ptr)); | ||
memcached_slab_arena_destroy() | ||
{ | ||
static __thread bool freed = false; | ||
if (freed) return; | ||
say_info("destroying arena..."); | ||
slab_arena_destroy(&arena); | ||
freed = 1; | ||
} | ||
|
||
void * | ||
box_persistent_realloc(void *ptr, size_t len, size_t *total) | ||
void | ||
memcached_slab_cache_create() | ||
{ | ||
if (len == 0) { | ||
if (ptr) box_persistent_free(ptr); | ||
if (total) *total = 0; | ||
return NULL; | ||
} else if (ptr == NULL) { | ||
return box_persistent_malloc(len, total); | ||
} | ||
struct slab *slab = slab_from_data(ptr); | ||
size_t sz = slab_capacity(slab); | ||
if (len <= sz) { | ||
if (total) *total = sz; | ||
return ptr; | ||
} | ||
char *ptr_new = box_persistent_malloc(len, total); | ||
if (!ptr_new) | ||
return NULL; | ||
memcpy(ptr_new, ptr, sz); | ||
box_persistent_free(ptr); | ||
return ptr_new; | ||
static __thread bool inited = false; | ||
if (inited) return; | ||
slab_cache_set_thread(&slabc); | ||
slab_cache_create(&slabc, &arena); | ||
say_info("allocate slab cache with slab size %u", arena.slab_size); | ||
inited = 1; | ||
} | ||
|
||
void * | ||
box_persistent_strdup(const void *str, size_t *total) | ||
void | ||
memcached_slab_cache_destroy() | ||
{ | ||
size_t strl = strlen(str); | ||
char *ptr = box_persistent_malloc(strl, total); | ||
if (ptr) { | ||
memcpy(ptr, str, strl); | ||
ptr[strl] = 0; | ||
} | ||
return ptr; | ||
static __thread bool freed = false; | ||
if (freed) return; | ||
say_info("destroying slab cache"); | ||
slab_cache_destroy(&slabc); | ||
freed = 1; | ||
} | ||
|
||
void * | ||
box_persistent_strndup(const void *str, size_t len, size_t *total) | ||
struct slab_cache * | ||
memcached_slab_cache() | ||
{ | ||
char *ptr = box_persistent_malloc(len, total); | ||
if (ptr) strncpy(ptr, str, len); | ||
return ptr; | ||
return &slabc; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
#ifndef ALLOC_H_INCLUDED | ||
#define ALLOC_H_INCLUDED | ||
|
||
void * | ||
box_persistent_malloc(size_t len, size_t *total); | ||
void | ||
memcached_slab_arena_create(); | ||
|
||
void * | ||
box_persistent_malloc0(size_t len, size_t *total); | ||
void | ||
memcached_slab_arena_destroy(); | ||
|
||
void | ||
box_persistent_free(void *ptr); | ||
memcached_slab_cache_create(); | ||
|
||
void * | ||
box_persistent_realloc(void *ptr, size_t len, size_t *total); | ||
void | ||
memcached_slab_cache_destroy(); | ||
|
||
void * | ||
box_persistent_strdup(const void *str, size_t *total); | ||
struct slab_cache * | ||
memcached_slab_cache(); | ||
|
||
void * | ||
box_persistent_strndup(const void *str, size_t len, size_t *total); | ||
struct slab_arena_info * | ||
memcached_slab_arena_info(); | ||
|
||
#endif /* ALLOC_H_INCLUDED */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.