From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933845AbcLHB3g (ORCPT ); Wed, 7 Dec 2016 20:29:36 -0500 Received: from mail-wj0-f172.google.com ([209.85.210.172]:36061 "EHLO mail-wj0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932372AbcLHB3e (ORCPT ); Wed, 7 Dec 2016 20:29:34 -0500 From: Rasmus Villemoes To: Tejun Heo , Andrew Morton Cc: linux-kernel@vger.kernel.org, Lai Jiangshan , Jens Axboe , Greg Kroah-Hartman , Rasmus Villemoes Subject: [RFC 05/10] kernel/workqueue.c: replace id allocator ida with tida Date: Thu, 8 Dec 2016 02:23:00 +0100 Message-Id: <1481160187-9652-6-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1481160187-9652-1-git-send-email-linux@rasmusvillemoes.dk> References: <1481160187-9652-1-git-send-email-linux@rasmusvillemoes.dk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The implementation of the id allocator ida causes about 14 KB of unused memory to sit around in the embedded struct idr. Even if one could get rid of that, ida would still use at least one idr_layer worth 2 KB of memory as well as one idr_bitmap worth another 128 bytes, which is all a bit much if we only create, say, a few 100 workers. Using the much simpler tida saves around 100 KB of memory. Signed-off-by: Rasmus Villemoes --- kernel/workqueue.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 479d840db286..6fef51ac1ad7 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -171,7 +171,7 @@ struct worker_pool { struct list_head workers; /* A: attached workers */ struct completion *detach_completion; /* all workers detached */ - struct ida worker_ida; /* worker IDs for task name */ + struct tida worker_ida; /* worker IDs for task name */ struct workqueue_attrs *attrs; /* I: worker attributes */ struct hlist_node hash_node; /* PL: unbound_pool_hash node */ @@ -1757,7 +1757,7 @@ static struct worker *create_worker(struct worker_pool *pool) char id_buf[16]; /* ID is needed to determine kthread name */ - id = ida_simple_get(&pool->worker_ida, 0, 0, GFP_KERNEL); + id = tida_get(&pool->worker_ida, GFP_KERNEL); if (id < 0) goto fail; @@ -1796,7 +1796,7 @@ static struct worker *create_worker(struct worker_pool *pool) fail: if (id >= 0) - ida_simple_remove(&pool->worker_ida, id); + tida_put(&pool->worker_ida, id); kfree(worker); return NULL; } @@ -2186,7 +2186,7 @@ static int worker_thread(void *__worker) worker->task->flags &= ~PF_WQ_WORKER; set_task_comm(worker->task, "kworker/dying"); - ida_simple_remove(&pool->worker_ida, worker->id); + tida_put(&pool->worker_ida, worker->id); worker_detach_from_pool(worker, pool); kfree(worker); return 0; @@ -3207,7 +3207,7 @@ static int init_worker_pool(struct worker_pool *pool) mutex_init(&pool->attach_mutex); INIT_LIST_HEAD(&pool->workers); - ida_init(&pool->worker_ida); + tida_init(&pool->worker_ida); INIT_HLIST_NODE(&pool->hash_node); pool->refcnt = 1; @@ -3236,7 +3236,7 @@ static void rcu_free_pool(struct rcu_head *rcu) { struct worker_pool *pool = container_of(rcu, struct worker_pool, rcu); - ida_destroy(&pool->worker_ida); + tida_destroy(&pool->worker_ida); free_workqueue_attrs(pool->attrs); kfree(pool); } -- 2.1.4