? rtfree.diff Index: route.c =================================================================== RCS file: /cvsroot/src/sys/net/route.c,v retrieving revision 1.202 diff -u -u -r1.202 route.c --- route.c 5 Jan 2018 01:53:15 -0000 1.202 +++ route.c 6 Jan 2018 09:48:38 -0000 @@ -255,7 +255,7 @@ struct workqueue *wq; struct work wk; kmutex_t lock; - struct rtentry *queue[10]; + SLIST_HEAD(, rtentry) queue; } rt_free_global __cacheline_aligned; /* psref for rtentry */ @@ -458,6 +458,8 @@ #endif mutex_init(&rt_free_global.lock, MUTEX_DEFAULT, IPL_SOFTNET); + SLIST_INIT(&rt_free_global.queue); + rt_psref_class = psref_class_create("rtentry", IPL_SOFTNET); error = workqueue_create(&rt_free_global.wq, "rt_free", @@ -687,20 +689,19 @@ rt_free_work(struct work *wk, void *arg) { -restart: - mutex_enter(&rt_free_global.lock); - for (size_t i = 0; i < __arraycount(rt_free_global.queue); i++) { - if (rt_free_global.queue[i] == NULL) - continue; - struct rtentry *rt = rt_free_global.queue[i]; - rt_free_global.queue[i] = NULL; - mutex_exit(&rt_free_global.lock); + for (;;) { + struct rtentry *rt; + mutex_enter(&rt_free_global.lock); + if ((rt = SLIST_FIRST(&rt_free_global.queue)) == NULL) { + mutex_exit(&rt_free_global.lock); + return; + } + SLIST_REMOVE_HEAD(&rt_free_global.queue, rt_free); + mutex_exit(&rt_free_global.lock); atomic_dec_uint(&rt->rt_refcnt); _rt_free(rt); - goto restart; } - mutex_exit(&rt_free_global.lock); } void @@ -714,16 +715,9 @@ return; } - size_t i; mutex_enter(&rt_free_global.lock); - for (i = 0; i < __arraycount(rt_free_global.queue); i++) { - if (rt_free_global.queue[i] == NULL) - break; - } - - KASSERT(i < __arraycount(rt_free_global.queue)); - rt_free_global.queue[i] = rt; rt_ref(rt); + SLIST_INSERT_HEAD(&rt_free_global.queue, rt, rt_free); mutex_exit(&rt_free_global.lock); workqueue_enqueue(rt_free_global.wq, &rt_free_global.wk, NULL); } Index: route.h =================================================================== RCS file: /cvsroot/src/sys/net/route.h,v retrieving revision 1.116 diff -u -u -r1.116 route.h --- route.h 18 Dec 2017 04:11:13 -0000 1.116 +++ route.h 6 Jan 2018 09:48:38 -0000 @@ -124,7 +124,8 @@ struct sockaddr *rt_tag; /* route tagging info */ #ifdef _KERNEL kcondvar_t rt_cv; - struct psref_target rt_psref; + struct psref_target rt_psref; + SLIST_ENTRY(rtentry) rt_free; /* queue of deferred frees */ #endif };