Re: [PATCH v9 1/5] lib: objpool added: ring-array based lockless MPMC

From: Google
Date: Sun Sep 24 2023 - 10:21:55 EST


Hi,

On Tue, 5 Sep 2023 09:52:51 +0800
"wuqiang.matt" <wuqiang.matt@xxxxxxxxxxxxx> wrote:

> +/* cleanup all percpu slots of the object pool */
> +static void objpool_fini_percpu_slots(struct objpool_head *head)
> +{
> + int i;
> +
> + if (!head->cpu_slots)
> + return;
> +
> + for (i = 0; i < head->nr_cpus; i++) {
> + if (!head->cpu_slots[i])
> + continue;
> + if (head->flags & OBJPOOL_FROM_VMALLOC)
> + vfree(head->cpu_slots[i]);
> + else
> + kfree(head->cpu_slots[i]);

You can use kvfree() for both kmalloc object and vmalloc object.

> + }
> + kfree(head->cpu_slots);
> + head->cpu_slots = NULL;
> + head->slot_sizes = NULL;
> +}

...

> +/* drop the allocated object, rather reclaim it to objpool */
> +int objpool_drop(void *obj, struct objpool_head *head)
> +{
> + if (!obj || !head)
> + return -EINVAL;
> +
> + if (refcount_dec_and_test(&head->ref)) {
> + objpool_free(head);
> + return 0;
> + }
> +
> + return -EAGAIN;
> +}
> +EXPORT_SYMBOL_GPL(objpool_drop);

To make this work correctly, you need to disable the objpool (no more
pop the object from it) and ensure the objpool is disabled.
Also, when disabling the objpool, its refcount must be set to the "active"
number of objects.

Thank you,


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>