Skip to content

Commit 42ec57a

Browse files
htejunaxboe
authored andcommitted
block: misc ioc cleanups
* int return from put_io_context() wasn't used by anybody. Make it return void like other put functions and docbook-fy the function comment. * Reorder dummy declarations for !CONFIG_BLOCK case a bit. * Make alloc_ioc_context() use __GFP_ZERO allocation, take init out of if block and drop 0'ing. * Docbook-fy current_io_context() comment. This patch doesn't introduce any functional change. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent a73f730 commit 42ec57a

2 files changed

Lines changed: 39 additions & 45 deletions

File tree

‎block/blk-ioc.c‎

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,28 @@ static void cfq_dtor(struct io_context *ioc)
2727
}
2828
}
2929

30-
/*
31-
* IO Context helper functions. put_io_context() returns 1 if there are no
32-
* more users of this io context, 0 otherwise.
30+
/**
31+
* put_io_context - put a reference of io_context
32+
* @ioc: io_context to put
33+
*
34+
* Decrement reference count of @ioc and release it if the count reaches
35+
* zero.
3336
*/
34-
int put_io_context(struct io_context *ioc)
37+
void put_io_context(struct io_context *ioc)
3538
{
3639
if (ioc == NULL)
37-
return 1;
40+
return;
3841

39-
BUG_ON(atomic_long_read(&ioc->refcount) == 0);
42+
BUG_ON(atomic_long_read(&ioc->refcount) <= 0);
4043

41-
if (atomic_long_dec_and_test(&ioc->refcount)) {
42-
rcu_read_lock();
43-
cfq_dtor(ioc);
44-
rcu_read_unlock();
44+
if (!atomic_long_dec_and_test(&ioc->refcount))
45+
return;
4546

46-
kmem_cache_free(iocontext_cachep, ioc);
47-
return 1;
48-
}
49-
return 0;
47+
rcu_read_lock();
48+
cfq_dtor(ioc);
49+
rcu_read_unlock();
50+
51+
kmem_cache_free(iocontext_cachep, ioc);
5052
}
5153
EXPORT_SYMBOL(put_io_context);
5254

@@ -84,33 +86,31 @@ struct io_context *alloc_io_context(gfp_t gfp_flags, int node)
8486
{
8587
struct io_context *ioc;
8688

87-
ioc = kmem_cache_alloc_node(iocontext_cachep, gfp_flags, node);
88-
if (ioc) {
89-
atomic_long_set(&ioc->refcount, 1);
90-
atomic_set(&ioc->nr_tasks, 1);
91-
spin_lock_init(&ioc->lock);
92-
ioc->ioprio_changed = 0;
93-
ioc->ioprio = 0;
94-
ioc->last_waited = 0; /* doesn't matter... */
95-
ioc->nr_batch_requests = 0; /* because this is 0 */
96-
INIT_RADIX_TREE(&ioc->radix_root, GFP_ATOMIC | __GFP_HIGH);
97-
INIT_HLIST_HEAD(&ioc->cic_list);
98-
ioc->ioc_data = NULL;
99-
#if defined(CONFIG_BLK_CGROUP) || defined(CONFIG_BLK_CGROUP_MODULE)
100-
ioc->cgroup_changed = 0;
101-
#endif
102-
}
89+
ioc = kmem_cache_alloc_node(iocontext_cachep, gfp_flags | __GFP_ZERO,
90+
node);
91+
if (unlikely(!ioc))
92+
return NULL;
93+
94+
/* initialize */
95+
atomic_long_set(&ioc->refcount, 1);
96+
atomic_set(&ioc->nr_tasks, 1);
97+
spin_lock_init(&ioc->lock);
98+
INIT_RADIX_TREE(&ioc->radix_root, GFP_ATOMIC | __GFP_HIGH);
99+
INIT_HLIST_HEAD(&ioc->cic_list);
103100

104101
return ioc;
105102
}
106103

107-
/*
108-
* If the current task has no IO context then create one and initialise it.
109-
* Otherwise, return its existing IO context.
104+
/**
105+
* current_io_context - get io_context of %current
106+
* @gfp_flags: allocation flags, used if allocation is necessary
107+
* @node: allocation node, used if allocation is necessary
110108
*
111-
* This returned IO context doesn't have a specifically elevated refcount,
112-
* but since the current task itself holds a reference, the context can be
113-
* used in general code, so long as it stays within `current` context.
109+
* Return io_context of %current. If it doesn't exist, it is created with
110+
* @gfp_flags and @node. The returned io_context does NOT have its
111+
* reference count incremented. Because io_context is exited only on task
112+
* exit, %current can be sure that the returned io_context is valid and
113+
* alive as long as it is executing.
114114
*/
115115
struct io_context *current_io_context(gfp_t gfp_flags, int node)
116116
{

‎include/linux/iocontext.h‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,14 @@ static inline struct io_context *ioc_task_link(struct io_context *ioc)
7676

7777
struct task_struct;
7878
#ifdef CONFIG_BLOCK
79-
int put_io_context(struct io_context *ioc);
79+
void put_io_context(struct io_context *ioc);
8080
void exit_io_context(struct task_struct *task);
8181
struct io_context *get_io_context(gfp_t gfp_flags, int node);
8282
struct io_context *alloc_io_context(gfp_t gfp_flags, int node);
8383
#else
84-
static inline void exit_io_context(struct task_struct *task)
85-
{
86-
}
87-
8884
struct io_context;
89-
static inline int put_io_context(struct io_context *ioc)
90-
{
91-
return 1;
92-
}
85+
static inline void put_io_context(struct io_context *ioc) { }
86+
static inline void exit_io_context(struct task_struct *task) { }
9387
#endif
9488

9589
#endif

0 commit comments

Comments
 (0)