Edata cache small: rewrite.

In previous designs, this was intended to be a sort of cache that couldn't fail.
In the current design, we want to use it just as a contention reduction
mechanism.  Rewrite it with those goals in mind.
This commit is contained in:
David Goldblatt
2020-10-29 05:11:16 -07:00
committed by David Goldblatt
parent c9757d9e3b
commit 03a6047111
3 changed files with 302 additions and 77 deletions

View File

@@ -3,6 +3,16 @@
#include "jemalloc/internal/base.h"
/*
* Public for tests. When we go to the fallback when the small cache is empty,
* we grab up to 8 items (grabbing less only if the fallback is exhausted).
* When we exceed 16, we flush. This caps the maximum memory lost per cache to
* 16 * sizeof(edata_t), a max of 2k on architectures where the edata_t is 128
* bytes.
*/
#define EDATA_CACHE_SMALL_MAX 16
#define EDATA_CACHE_SMALL_FILL 8
/*
* A cache of edata_t structures allocated via base_alloc_edata (as opposed to
* the underlying extents they describe). The contents of returned edata_t
@@ -25,32 +35,23 @@ void edata_cache_prefork(tsdn_t *tsdn, edata_cache_t *edata_cache);
void edata_cache_postfork_parent(tsdn_t *tsdn, edata_cache_t *edata_cache);
void edata_cache_postfork_child(tsdn_t *tsdn, edata_cache_t *edata_cache);
/*
* An edata_cache_small is like an edata_cache, but it relies on external
* synchronization and avoids first-fit strategies.
*/
typedef struct edata_cache_small_s edata_cache_small_t;
struct edata_cache_small_s {
edata_list_inactive_t list;
size_t count;
edata_cache_t *fallback;
bool disabled;
};
/*
* An edata_cache_small is like an edata_cache, but it relies on external
* synchronization and avoids first-fit strategies. You can call "prepare" to
* acquire at least num edata_t objects, and then "finish" to flush all
* excess ones back to their fallback edata_cache_t. Once they have been
* acquired, they can be allocated without failing (and in fact, this is
* required -- it's not permitted to attempt to get an edata_t without first
* preparing for it).
*/
void edata_cache_small_init(edata_cache_small_t *ecs, edata_cache_t *fallback);
/* Returns whether or not an error occurred. */
bool edata_cache_small_prepare(tsdn_t *tsdn, edata_cache_small_t *ecs,
size_t num);
edata_t *edata_cache_small_get(edata_cache_small_t *ecs);
void edata_cache_small_put(edata_cache_small_t *ecs, edata_t *edata);
void edata_cache_small_finish(tsdn_t *tsdn, edata_cache_small_t *ecs,
size_t num);
edata_t *edata_cache_small_get(tsdn_t *tsdn, edata_cache_small_t *ecs);
void edata_cache_small_put(tsdn_t *tsdn, edata_cache_small_t *ecs,
edata_t *edata);
void edata_cache_small_disable(tsdn_t *tsdn, edata_cache_small_t *ecs);
#endif /* JEMALLOC_INTERNAL_EDATA_CACHE_H */