From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp56.i.mail.ru (smtp56.i.mail.ru [217.69.128.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 65C9046970E for ; Mon, 27 Jan 2020 22:41:40 +0300 (MSK) Received: by smtp56.i.mail.ru with esmtpa (envelope-from ) id 1iwAGR-0008S8-W2 for tarantool-patches@dev.tarantool.org; Mon, 27 Jan 2020 22:41:40 +0300 From: Georgy Kirichenko Date: Mon, 27 Jan 2020 22:41:39 +0300 Message-ID: <2545762.mvXUDI8C0e@localhost> In-Reply-To: <20200127193907.34019-1-georgy@tarantool.org> References: <20200127193907.34019-1-georgy@tarantool.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart11483986.O9o76ZdvQC"; micalg="pgp-sha256"; protocol="application/pgp-signature" Subject: Re: [Tarantool-patches] [PATCH] do not keep a slab in cache if new allocation does not fit List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org --nextPart11483986.O9o76ZdvQC Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sorry, I forgot an issue and a branch. Issue: https://github.com/tarantool/tarantool/issues/4736 Branch: https://github.com/tarantool/tarantool/tree/g.kirichenko/gh-4736-region-size-for-gc On Monday, 27 January 2020 22:39:07 MSK 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. > > Follow up 67d7ab44ab09df3356929e3692a03321b31f3ebb > > Fixes #12 > > 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); --nextPart11483986.O9o76ZdvQC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEECXG+Yw5ArYcP8x5wDVHWG5PoUw4FAl4vPPMACgkQDVHWG5Po Uw564AgAnKc7BModArK9IqHQbHtmkaTMgTlFal2ph3Zem/3kmqGHr076atdvibJI C4D2fAPGY5FfzdDSY1MFKwmccQQ73pbnAuHT1OpX60r5hgRpIET0Ue1h2KCaCIJo sFpYUd7q0w7/3Am+jtc+QTLoq0VbMD4u7TBqnItPA55+AUmc3O9/C9GtDHchJ8Fw C1eA2eIWwvlYdDUD4sBgeQyG8CQzVaSYGzxHEaeEfhLDnVY4GQi9D4Jbl+Z/MEDG P8eJC0jjB1rWnXCIouUK+MzSoC4wmC/fXRWzV1J6c8f2MQ8jVPzj7TZWDotd8FKx 0q5SLYHoECYZMfggvxzTHfAdQ0ieSw== =1bCm -----END PGP SIGNATURE----- --nextPart11483986.O9o76ZdvQC--