Skip to content

Commit d866dbf

Browse files
htejunaxboe
authored andcommitted
blkcg: rename blkcg->cgwb_refcnt to ->online_pin and always use it
blkcg->cgwb_refcnt is used to delay blkcg offlining so that blkgs don't get offlined while there are active cgwbs on them. However, it ends up making offlining unordered sometimes causing parents to be offlined before children. To fix it, we want child blkcgs to pin the parents' online states turning the refcnt into a more generic online pinning mechanism. In prepartion, * blkcg->cgwb_refcnt -> blkcg->online_pin * blkcg_cgwb_get/put() -> blkcg_pin/unpin_online() * Take them out of CONFIG_CGROUP_WRITEBACK Signed-off-by: Tejun Heo <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 1a323ea commit d866dbf

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

block/blk-cgroup.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,8 @@ static void blkcg_css_offline(struct cgroup_subsys_state *css)
883883
/* this prevents anyone from attaching or migrating to this blkcg */
884884
wb_blkcg_offline(blkcg);
885885

886-
/* put the base cgwb reference allowing step 2 to be triggered */
887-
blkcg_cgwb_put(blkcg);
886+
/* put the base online pin allowing step 2 to be triggered */
887+
blkcg_unpin_online(blkcg);
888888
}
889889

890890
/**
@@ -983,11 +983,11 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
983983
}
984984

985985
spin_lock_init(&blkcg->lock);
986+
refcount_set(&blkcg->online_pin, 1);
986987
INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_NOWAIT | __GFP_NOWARN);
987988
INIT_HLIST_HEAD(&blkcg->blkg_list);
988989
#ifdef CONFIG_CGROUP_WRITEBACK
989990
INIT_LIST_HEAD(&blkcg->cgwb_list);
990-
refcount_set(&blkcg->cgwb_refcnt, 1);
991991
#endif
992992
list_add_tail(&blkcg->all_blkcgs_node, &all_blkcgs);
993993

include/linux/blk-cgroup.h

+13-26
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct blkcg_gq;
4646
struct blkcg {
4747
struct cgroup_subsys_state css;
4848
spinlock_t lock;
49+
refcount_t online_pin;
4950

5051
struct radix_tree_root blkg_tree;
5152
struct blkcg_gq __rcu *blkg_hint;
@@ -56,7 +57,6 @@ struct blkcg {
5657
struct list_head all_blkcgs_node;
5758
#ifdef CONFIG_CGROUP_WRITEBACK
5859
struct list_head cgwb_list;
59-
refcount_t cgwb_refcnt;
6060
#endif
6161
};
6262

@@ -412,47 +412,34 @@ static inline struct blkcg *cpd_to_blkcg(struct blkcg_policy_data *cpd)
412412

413413
extern void blkcg_destroy_blkgs(struct blkcg *blkcg);
414414

415-
#ifdef CONFIG_CGROUP_WRITEBACK
416-
417415
/**
418-
* blkcg_cgwb_get - get a reference for blkcg->cgwb_list
416+
* blkcg_pin_online - pin online state
419417
* @blkcg: blkcg of interest
420418
*
421-
* This is used to track the number of active wb's related to a blkcg.
419+
* While pinned, a blkcg is kept online. This is primarily used to
420+
* impedance-match blkg and cgwb lifetimes so that blkg doesn't go offline
421+
* while an associated cgwb is still active.
422422
*/
423-
static inline void blkcg_cgwb_get(struct blkcg *blkcg)
423+
static inline void blkcg_pin_online(struct blkcg *blkcg)
424424
{
425-
refcount_inc(&blkcg->cgwb_refcnt);
425+
refcount_inc(&blkcg->online_pin);
426426
}
427427

428428
/**
429-
* blkcg_cgwb_put - put a reference for @blkcg->cgwb_list
429+
* blkcg_unpin_online - unpin online state
430430
* @blkcg: blkcg of interest
431431
*
432-
* This is used to track the number of active wb's related to a blkcg.
433-
* When this count goes to zero, all active wb has finished so the
432+
* This is primarily used to impedance-match blkg and cgwb lifetimes so
433+
* that blkg doesn't go offline while an associated cgwb is still active.
434+
* When this count goes to zero, all active cgwbs have finished so the
434435
* blkcg can continue destruction by calling blkcg_destroy_blkgs().
435-
* This work may occur in cgwb_release_workfn() on the cgwb_release
436-
* workqueue.
437436
*/
438-
static inline void blkcg_cgwb_put(struct blkcg *blkcg)
437+
static inline void blkcg_unpin_online(struct blkcg *blkcg)
439438
{
440-
if (refcount_dec_and_test(&blkcg->cgwb_refcnt))
439+
if (refcount_dec_and_test(&blkcg->online_pin))
441440
blkcg_destroy_blkgs(blkcg);
442441
}
443442

444-
#else
445-
446-
static inline void blkcg_cgwb_get(struct blkcg *blkcg) { }
447-
448-
static inline void blkcg_cgwb_put(struct blkcg *blkcg)
449-
{
450-
/* wb isn't being accounted, so trigger destruction right away */
451-
blkcg_destroy_blkgs(blkcg);
452-
}
453-
454-
#endif
455-
456443
/**
457444
* blkg_path - format cgroup path of blkg
458445
* @blkg: blkg of interest

mm/backing-dev.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ static void cgwb_release_workfn(struct work_struct *work)
491491
css_put(wb->blkcg_css);
492492
mutex_unlock(&wb->bdi->cgwb_release_mutex);
493493

494-
/* triggers blkg destruction if cgwb_refcnt becomes zero */
495-
blkcg_cgwb_put(blkcg);
494+
/* triggers blkg destruction if no online users left */
495+
blkcg_unpin_online(blkcg);
496496

497497
fprop_local_destroy_percpu(&wb->memcg_completions);
498498
percpu_ref_exit(&wb->refcnt);
@@ -592,7 +592,7 @@ static int cgwb_create(struct backing_dev_info *bdi,
592592
list_add_tail_rcu(&wb->bdi_node, &bdi->wb_list);
593593
list_add(&wb->memcg_node, memcg_cgwb_list);
594594
list_add(&wb->blkcg_node, blkcg_cgwb_list);
595-
blkcg_cgwb_get(blkcg);
595+
blkcg_pin_online(blkcg);
596596
css_get(memcg_css);
597597
css_get(blkcg_css);
598598
}

0 commit comments

Comments
 (0)