From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Georgy Kirichenko <georgy@tarantool.org>,
tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH] do not keep a slab in cache if new allocation does not fit
Date: Tue, 4 Feb 2020 22:25:14 +0100 [thread overview]
Message-ID: <1a8f199e-4fd6-004e-4d91-bc7a909b242d@tarantool.org> (raw)
In-Reply-To: <20200127193907.34019-1-georgy@tarantool.org>
Hi! Thanks for the patch!
On 27/01/2020 20:39, Georgy Kirichenko wrote:
> Do not allocate a new slab if there is a free slab in a region cache.
> If a cached slab is not big enough then free it.
Please, describe the problem you are trying to solve. The
text above just narrates the code.
> Follow up 67d7ab44ab09df3356929e3692a03321b31f3ebb
>
> Fixes #12
Well, the slabs still are not freed in case there was a spike
which allocated lots of slabs, and then only 1-2 are used, and
all allocations fit into the existing slabs.
>
> Issue: https://github.com/tarantool/small/issues/12
> Branch: https://github.com/tarantool/small/tree/g.kirichenko/gh-12-region-cache
>
> diff --git a/small/region.h b/small/region.h
> index d9be176..58481b0 100644
> --- a/small/region.h
> +++ b/small/region.h
> @@ -157,14 +157,20 @@ region_reserve(struct region *region, size_t size)
> if (size <= rslab_unused(slab))
> return (char *) rslab_data(slab) + slab->used;
> /* Try to get a slab from the region cache. */
> - slab = rlist_last_entry(®ion->slabs.slabs,
> - struct rslab,
> - slab.next_in_list);
> - if (slab->used == 0 && size <= rslab_unused(slab)) {
> - /* Move this slab to the head. */
> + while ((slab = rlist_last_entry(®ion->slabs.slabs,
> + struct rslab,
> + slab.next_in_list))->used == 0) {
> slab_list_del(®ion->slabs, &slab->slab, next_in_list);
> - slab_list_add(®ion->slabs, &slab->slab, next_in_list);
> - return (char *) rslab_data(slab);
> + if (size <= rslab_unused(slab)) {
> + /* Move this slab to the head. */
> + slab_list_add(®ion->slabs, &slab->slab, next_in_list);
> + return (char *) rslab_data(slab);
> + }
> + /*
> + * This cached slab could not be used so free it
> + * and try to use the next one.
> + */
> + slab_put(region->cache, (struct slab *)slab);
> }
> }
> return region_reserve_slow(region, size);
>
prev parent reply other threads:[~2020-02-04 21:25 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-27 19:39 Georgy Kirichenko
2020-01-27 19:41 ` Georgy Kirichenko
2020-01-29 21:48 ` Konstantin Osipov
2020-01-29 21:59 ` Vladislav Shpilevoy
2020-02-04 21:25 ` Vladislav Shpilevoy [this message]
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=1a8f199e-4fd6-004e-4d91-bc7a909b242d@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=georgy@tarantool.org \
--cc=tarantool-patches@dev.tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH] do not keep a slab in cache if new allocation does not fit' \
/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