Commit a34375ef authored by Tejun Heo's avatar Tejun Heo

percpu-refcount: add @gfp to percpu_ref_init()

Percpu allocator now supports allocation mask.  Add @gfp to
percpu_ref_init() so that !GFP_KERNEL allocation masks can be used
with percpu_refs too.

This patch doesn't make any functional difference.

v2: blk-mq conversion was missing.  Updated.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Nicholas A. Bellinger <nab@linux-iscsi.org>
Cc: Jens Axboe <axboe@kernel.dk>
parent 20ae0079
...@@ -1776,7 +1776,8 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set) ...@@ -1776,7 +1776,8 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
if (!q) if (!q)
goto err_hctxs; goto err_hctxs;
if (percpu_ref_init(&q->mq_usage_counter, blk_mq_usage_counter_release)) if (percpu_ref_init(&q->mq_usage_counter, blk_mq_usage_counter_release,
GFP_KERNEL))
goto err_map; goto err_map;
setup_timer(&q->timeout, blk_mq_rq_timer, (unsigned long) q); setup_timer(&q->timeout, blk_mq_rq_timer, (unsigned long) q);
......
...@@ -819,7 +819,8 @@ int core_tpg_add_lun( ...@@ -819,7 +819,8 @@ int core_tpg_add_lun(
{ {
int ret; int ret;
ret = percpu_ref_init(&lun->lun_ref, core_tpg_lun_ref_release); ret = percpu_ref_init(&lun->lun_ref, core_tpg_lun_ref_release,
GFP_KERNEL);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -666,10 +666,10 @@ static struct kioctx *ioctx_alloc(unsigned nr_events) ...@@ -666,10 +666,10 @@ static struct kioctx *ioctx_alloc(unsigned nr_events)
INIT_LIST_HEAD(&ctx->active_reqs); INIT_LIST_HEAD(&ctx->active_reqs);
if (percpu_ref_init(&ctx->users, free_ioctx_users)) if (percpu_ref_init(&ctx->users, free_ioctx_users, GFP_KERNEL))
goto err; goto err;
if (percpu_ref_init(&ctx->reqs, free_ioctx_reqs)) if (percpu_ref_init(&ctx->reqs, free_ioctx_reqs, GFP_KERNEL))
goto err; goto err;
ctx->cpu = alloc_percpu(struct kioctx_cpu); ctx->cpu = alloc_percpu(struct kioctx_cpu);
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/percpu.h> #include <linux/percpu.h>
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <linux/gfp.h>
struct percpu_ref; struct percpu_ref;
typedef void (percpu_ref_func_t)(struct percpu_ref *); typedef void (percpu_ref_func_t)(struct percpu_ref *);
...@@ -66,7 +67,7 @@ struct percpu_ref { ...@@ -66,7 +67,7 @@ struct percpu_ref {
}; };
int __must_check percpu_ref_init(struct percpu_ref *ref, int __must_check percpu_ref_init(struct percpu_ref *ref,
percpu_ref_func_t *release); percpu_ref_func_t *release, gfp_t gfp);
void percpu_ref_reinit(struct percpu_ref *ref); void percpu_ref_reinit(struct percpu_ref *ref);
void percpu_ref_exit(struct percpu_ref *ref); void percpu_ref_exit(struct percpu_ref *ref);
void percpu_ref_kill_and_confirm(struct percpu_ref *ref, void percpu_ref_kill_and_confirm(struct percpu_ref *ref,
......
...@@ -1628,7 +1628,7 @@ static int cgroup_setup_root(struct cgroup_root *root, unsigned int ss_mask) ...@@ -1628,7 +1628,7 @@ static int cgroup_setup_root(struct cgroup_root *root, unsigned int ss_mask)
goto out; goto out;
root_cgrp->id = ret; root_cgrp->id = ret;
ret = percpu_ref_init(&root_cgrp->self.refcnt, css_release); ret = percpu_ref_init(&root_cgrp->self.refcnt, css_release, GFP_KERNEL);
if (ret) if (ret)
goto out; goto out;
...@@ -4487,7 +4487,7 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss, ...@@ -4487,7 +4487,7 @@ static int create_css(struct cgroup *cgrp, struct cgroup_subsys *ss,
init_and_link_css(css, ss, cgrp); init_and_link_css(css, ss, cgrp);
err = percpu_ref_init(&css->refcnt, css_release); err = percpu_ref_init(&css->refcnt, css_release, GFP_KERNEL);
if (err) if (err)
goto err_free_css; goto err_free_css;
...@@ -4555,7 +4555,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name, ...@@ -4555,7 +4555,7 @@ static int cgroup_mkdir(struct kernfs_node *parent_kn, const char *name,
goto out_unlock; goto out_unlock;
} }
ret = percpu_ref_init(&cgrp->self.refcnt, css_release); ret = percpu_ref_init(&cgrp->self.refcnt, css_release, GFP_KERNEL);
if (ret) if (ret)
goto out_free_cgrp; goto out_free_cgrp;
......
...@@ -40,6 +40,7 @@ static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref) ...@@ -40,6 +40,7 @@ static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref)
* percpu_ref_init - initialize a percpu refcount * percpu_ref_init - initialize a percpu refcount
* @ref: percpu_ref to initialize * @ref: percpu_ref to initialize
* @release: function which will be called when refcount hits 0 * @release: function which will be called when refcount hits 0
* @gfp: allocation mask to use
* *
* Initializes the refcount in single atomic counter mode with a refcount of 1; * Initializes the refcount in single atomic counter mode with a refcount of 1;
* analagous to atomic_set(ref, 1). * analagous to atomic_set(ref, 1).
...@@ -47,11 +48,12 @@ static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref) ...@@ -47,11 +48,12 @@ static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref)
* Note that @release must not sleep - it may potentially be called from RCU * Note that @release must not sleep - it may potentially be called from RCU
* callback context by percpu_ref_kill(). * callback context by percpu_ref_kill().
*/ */
int percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release) int percpu_ref_init(struct percpu_ref *ref, percpu_ref_func_t *release,
gfp_t gfp)
{ {
atomic_set(&ref->count, 1 + PCPU_COUNT_BIAS); atomic_set(&ref->count, 1 + PCPU_COUNT_BIAS);
ref->pcpu_count_ptr = (unsigned long)alloc_percpu(unsigned); ref->pcpu_count_ptr = (unsigned long)alloc_percpu_gfp(unsigned, gfp);
if (!ref->pcpu_count_ptr) if (!ref->pcpu_count_ptr)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment