Hi,
On Tue, 5 Sep 2023 09:52:51 +0800
"wuqiang.matt" [off-list ref] wrote:
quoted hunk ↗ jump to hunk
+/* 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.
quoted hunk ↗ jump to hunk
+ }
+ kfree(head->cpu_slots);
+ head->cpu_slots = NULL;
+ head->slot_sizes = NULL;
+}
...
quoted hunk ↗ jump to hunk
+/* 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) [off-list ref]