Re: [PATCH 1/1] rcu/tree: add emergency pool for headless case

From: Matthew Wilcox
Date: Fri Apr 03 2020 - 14:16:58 EST


On Fri, Apr 03, 2020 at 07:30:51PM +0200, Uladzislau Rezki (Sony) wrote:
> @@ -2877,6 +2885,12 @@ struct kfree_rcu_cpu {
> bool initialized;
> // Number of objects for which GP not started
> int count;
> +
> + /*
> + * Reserved emergency pool for headless variant.
> + */
> + int nr_emergency;
> + void **emergency;

This is a pretty expensive way to maintain an emergency pool.

Try something like this ...

struct emergency_pool_object {
union {
struct whatever foo;
struct {
int remaining;
void *next;
};
};
};

struct kfree_rcu_cpu {
...
struct emergency_pool_object *epo;
};

struct whatever *get_emergency_object(struct kfree_rcu_cpu *krc)
{
struct emergency_pool_object *epo = krc->epo;
if (epo)
krc->epo = epo->next;
return &epo->foo;
}

void alloc_emergency_objects(struct kfree_rcu_cpu *krc, int n)
{
int i = 0;

if (krc->epo)
i = krc->epo->remaining;

while (++i < n) {
struct emergency_pool_object *epo = kmalloc(sizeof(epo), GFP);
epo->remaining = i;
epo->next = krc->epo;
krc->epo = epo;
}
}