History

debugobjects: Provide and use free_object_list()

Move the loop to free a list of objects into a helper function so it can be reused later.

Thomas Gleixner committed 2 years ago

Commit 49a5cb81 parent 241463f1 file · +16 −6Browse files

Showing the changes to lib/debugobjects.c (1 of 1 file). Show all

Unified · Split

lib/debugobjects.c+16−6
@@ -125,6 +125,20 @@ static const char *obj_states[ODEBUG_STATE_MAX] = { · 124 unmodified lines
125125 [ODEBUG_STATE_NOTAVAILABLE] = "not available",
126126 };
127127
128+static void free_object_list(struct hlist_head *head)
129+{
130+ struct hlist_node *tmp;
131+ struct debug_obj *obj;
132+ int cnt = 0;
133+
134+ hlist_for_each_entry_safe(obj, tmp, head, node) {
135+ hlist_del(&obj->node);
136+ kmem_cache_free(obj_cache, obj);
137+ cnt++;
138+ }
139+ debug_objects_freed += cnt;
140+}
141+
128142 static void fill_pool(void)
129143 {
130144 gfp_t gfp = __GFP_HIGH | __GFP_NOWARN;
@@ -286,7 +300,6 @@ init_obj: · 155 unmodified lines
286300 */
287301 static void free_obj_work(struct work_struct *work)
288302 {
289− struct hlist_node *tmp;
290303 struct debug_obj *obj;
291304 unsigned long flags;
292305 HLIST_HEAD(tofree);
@@ -323,15 +336,11 @@ free_objs: · 30 unmodified lines
323336 */
324337 if (obj_nr_tofree) {
325338 hlist_move_list(&obj_to_free, &tofree);
326− debug_objects_freed += obj_nr_tofree;
327339 WRITE_ONCE(obj_nr_tofree, 0);
328340 }
329341 raw_spin_unlock_irqrestore(&pool_lock, flags);
330342
331− hlist_for_each_entry_safe(obj, tmp, &tofree, node) {
332− hlist_del(&obj->node);
333− kmem_cache_free(obj_cache, obj);
334− }
343+ free_object_list(&tofree);
335344 }
336345
337346 static void __free_object(struct debug_obj *obj)
@@ -1334,6 +1343,7 @@ static bool __init debug_objects_replace_static_objects(struct kmem_cache *cache · 996 unmodified lines
13341343 }
13351344 return true;
13361345 free:
1346+ /* Can't use free_object_list() as the cache is not populated yet */
13371347 hlist_for_each_entry_safe(obj, tmp, &objects, node) {
13381348 hlist_del(&obj->node);
13391349 kmem_cache_free(cache, obj);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t