Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934482Ab3CUQo2 (ORCPT ); Thu, 21 Mar 2013 12:44:28 -0400 Received: from mail-pb0-f54.google.com ([209.85.160.54]:65013 "EHLO mail-pb0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933845Ab3CUQoW (ORCPT ); Thu, 21 Mar 2013 12:44:22 -0400 From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-aio@kvack.org, akpm@linux-foundation.org Cc: Kent Overstreet , Zach Brown , Felipe Balbi , Greg Kroah-Hartman , Mark Fasheh , Joel Becker , Rusty Russell , Jens Axboe , Asai Thambi S P , Selvan Mani , Sam Bradshaw , Jeff Moyer , Al Viro , Benjamin LaHaise , "Theodore Ts'o" Subject: [PATCH 24/33] aio: percpu ioctx refcount Date: Thu, 21 Mar 2013 09:35:45 -0700 Message-Id: <1363883754-27966-25-git-send-email-koverstreet@google.com> X-Mailer: git-send-email 1.8.1.3 In-Reply-To: <1363883754-27966-1-git-send-email-koverstreet@google.com> References: <1363883754-27966-1-git-send-email-koverstreet@google.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3680 Lines: 125 This just converts the ioctx refcount to the new generic dynamic percpu refcount code. Signed-off-by: Kent Overstreet Cc: Zach Brown Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: Mark Fasheh Cc: Joel Becker Cc: Rusty Russell Cc: Jens Axboe Cc: Asai Thambi S P Cc: Selvan Mani Cc: Sam Bradshaw Cc: Jeff Moyer Cc: Al Viro Cc: Benjamin LaHaise Cc: Theodore Ts'o Signed-off-by: Andrew Morton --- fs/aio.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 603511d..3db2dab 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -65,8 +66,7 @@ struct kioctx_cpu { }; struct kioctx { - atomic_t users; - atomic_t dead; + struct percpu_ref users; /* This needs improving */ unsigned long user_id; @@ -368,7 +368,7 @@ static void free_ioctx(struct kioctx *ctx) static void put_ioctx(struct kioctx *ctx) { - if (unlikely(atomic_dec_and_test(&ctx->users))) + if (percpu_ref_put(&ctx->users)) free_ioctx(ctx); } @@ -409,8 +409,11 @@ static struct kioctx *ioctx_alloc(unsigned nr_events) ctx->max_reqs = nr_events; - atomic_set(&ctx->users, 2); - atomic_set(&ctx->dead, 0); + percpu_ref_init(&ctx->users); + rcu_read_lock(); + percpu_ref_get(&ctx->users); + rcu_read_unlock(); + spin_lock_init(&ctx->ctx_lock); spin_lock_init(&ctx->completion_lock); mutex_init(&ctx->ring_lock); @@ -482,7 +485,7 @@ static void kill_ioctx_rcu(struct rcu_head *head) */ static void kill_ioctx(struct kioctx *ctx) { - if (!atomic_xchg(&ctx->dead, 1)) { + if (percpu_ref_kill(&ctx->users)) { hlist_del_rcu(&ctx->list); /* Between hlist_del_rcu() and dropping the initial ref */ synchronize_rcu(); @@ -528,12 +531,6 @@ void exit_aio(struct mm_struct *mm) struct hlist_node *n; hlist_for_each_entry_safe(ctx, n, &mm->ioctx_list, list) { - if (1 != atomic_read(&ctx->users)) - printk(KERN_DEBUG - "exit_aio:ioctx still alive: %d %d %d\n", - atomic_read(&ctx->users), - atomic_read(&ctx->dead), - atomic_read(&ctx->reqs_available)); /* * We don't need to bother with munmap() here - * exit_mmap(mm) is coming and it'll unmap everything. @@ -544,7 +541,7 @@ void exit_aio(struct mm_struct *mm) */ ctx->mmap_size = 0; - if (!atomic_xchg(&ctx->dead, 1)) { + if (percpu_ref_kill(&ctx->users)) { hlist_del_rcu(&ctx->list); call_rcu(&ctx->rcu_head, kill_ioctx_rcu); } @@ -655,7 +652,7 @@ static struct kioctx *lookup_ioctx(unsigned long ctx_id) hlist_for_each_entry_rcu(ctx, &mm->ioctx_list, list) { if (ctx->user_id == ctx_id){ - atomic_inc(&ctx->users); + percpu_ref_get(&ctx->users); ret = ctx; break; } @@ -867,7 +864,7 @@ static bool aio_read_events(struct kioctx *ctx, long min_nr, long nr, if (ret > 0) *i += ret; - if (unlikely(atomic_read(&ctx->dead))) + if (unlikely(percpu_ref_dead(&ctx->users))) ret = -EINVAL; if (!*i) -- 1.8.1.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/