make the blkcg and blkcg structures private
Subsystems (13)
Christoph Hellwig
maintainerHi all,
this series cleans up various lose end in the blk-cgroup code to make it easier to follow in preparation of reworking the blkcg assignment for bios. The biggest change is that most of <linux/blk-cgroup.h> is now taken private into block/.
Diffstat:
block/Makefile | 1 block/bfq-iosched.h | 4 block/blk-cgroup-fc-appid.c | 57 +++++++++ block/blk-cgroup.c | 154 ++++++++++++++++++++----- block/blk-cgroup.h | 138 +++++++++++++++------- block/blk-throttle.c | 2 drivers/block/loop.c | 12 + drivers/nvme/host/fc.c | 26 +--- drivers/scsi/lpfc/lpfc_scsi.c | 4 include/linux/backing-dev.h | 6 include/linux/blk-cgroup.h | 258 ++---------------------------------------- include/linux/blktrace_api.h | 10 - include/linux/kthread.h | 4 kernel/kthread.c | 1 kernel/trace/blktrace.c | 26 ++-- mm/backing-dev.c | 19 +-- mm/readahead.c | 1 mm/swapfile.c | 1 18 files changed, 343 insertions(+), 381 deletions(-)
Christoph Hellwig
maintainerPATCH 1/15 blk-cgroup: remove __bio_blkcg
Remove the unused and deprecated __bio_blkcg helper.
--- block/blk-cgroup.h | 23 ----------------------- 1 file changed, 23 deletions(-)
block/blk-cgroup.h +0 -23
@@ -139,27 +139,6 @@ static inline struct cgroup_subsys_state *blkcg_css(void)return task_css (current, io_cgrp_id); } -/** -* __bio_blkcg - internal, inconsistent version to get blkcg -* -* DO NOT USE. -* This function is inconsistent and consequently is dangerous to use. The -* first part of the function returns a blkcg where a reference is owned by the -* bio. This means it does not need to be rcu protected as it cannot go away -* with the bio owning a reference to it. However, the latter potentially gets -* it from task_css(). This can race against task migration and the cgroup -* dying. It is also semantically different as it must be called rcu protected -* and is susceptible to failure when trying to get a reference to it. -* Therefore, it is not ok to assume that *_get() will always succeed on the -* blkcg returned here. -*/ -static inline struct blkcg *__bio_blkcg (struct bio *bio) -{ -if (bio && bio->bi_blkg) -return bio->bi_blkg->blkcg; -return css_to_blkcg (blkcg_css ()); -} -/** * bio_issue_as_root_blkg - see if this bio needs to be issued as root blkg * @return: true if this bio needs to be submitted with the root blkg context.
@@ -471,8 +450,6 @@ static inline int blkcg_activate_policy(struct request_queue *q,static inline void blkcg_deactivate_policy (struct request_queue *q,const struct blkcg_policy *pol) { } -static inline struct blkcg *__bio_blkcg (struct bio *bio) {return NULL ; } -static inline struct blkg_policy_data *blkg_to_pd (struct blkcg_gq *blkg,struct blkcg_policy *pol) {return NULL ; }static inline struct blkcg_gq *pd_to_blkg (struct blkg_policy_data *pd) {return NULL ; }
Signature · 1 line
2.30.2
Re: [PATCH 01/15] blk-cgroup: remove __bio_blkcg
Quoted 3 lines · Christoph Hellwig
Remove the unused and deprecated
__bio_blkcghelper.Signed-off-by Christoph Hellwig <[email protected]>
Thanks.
Signature · 1 line
tejun
Christoph Hellwig
maintainerPATCH 2/15 nvme-fc: don't support the appid attribute without CONFIG_BLK_CGROUP_FC_APPID
In reply to Christoph Hellwignvme-fc appid support needs CONFIG_BLK_CGROUP_FC_APPID to work, so disable the whole code if the option is not set.
--- drivers/nvme/host/fc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/nvme/host/fc.c +6 -1
@@ -3831,6 +3831,9 @@ static ssize_t nvme_fc_nvme_discovery_store(struct device *dev,return count; } +static DEVICE_ATTR(nvme_discovery, 0200, NULL, nvme_fc_nvme_discovery_store); + +#ifdef CONFIG_BLK_CGROUP_FC_APPID /* Parse the cgroup id from a buf and return the length of cgrpid */ static int fc_parse_cgrpid (const char *buf,u64 *id) {
@@ -3898,12 +3901,14 @@ static ssize_t fc_appid_store(struct device *dev,return -EINVAL ;return count; } -static DEVICE_ATTR(nvme_discovery, 0200, NULL, nvme_fc_nvme_discovery_store); static DEVICE_ATTR(appid_store, 0200, NULL, fc_appid_store); +#endif /* CONFIG_BLK_CGROUP_FC_APPID */ static struct attribute *nvme_fc_attrs[] = { &dev_attr_nvme_discovery.attr, +#ifdef CONFIG_BLK_CGROUP_FC_APPID &dev_attr_appid_store.attr, +#endifNULL };
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 3/15 nvme-fc: fold t fc_update_appid into fc_appid_store
In reply to Christoph HellwigNo need for this wrapper.
--- drivers/nvme/host/fc.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-)
drivers/nvme/host/fc.c +3 -16
@@ -3857,12 +3857,10 @@ static int fc_parse_cgrpid(const char *buf, u64 *id) }/* -* fc_update_appid: Parse and update the appid in the blkcg associated with -* cgroupid. -* @buf: buf contains both cgrpid and appid info -* @count: size of the buffer +* Parse and update the appid in the blkcg associated with the cgroupid. */ -static int fc_update_appid (const char *buf,size_t count) +static ssize_t fc_appid_store (struct device *dev, +struct device_attribute *attr,const char *buf,size_t count) {u64 cgrp_id;int appid_len =0 ;
@@ -3890,17 +3888,6 @@ static int fc_update_appid(const char *buf, size_t count)return ret;return count; } - -static ssize_t fc_appid_store (struct device *dev, -struct device_attribute *attr,const char *buf,size_t count) -{ -int ret =0 ; - - ret =fc_update_appid (buf, count); -if (ret <0 ) -return -EINVAL ; -return count; -} static DEVICE_ATTR(appid_store, 0200, NULL, fc_appid_store);#endif /* CONFIG_BLK_CGROUP_FC_APPID */
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 4/15 blk-cgroup: move blkcg_{get,set}_fc_appid out of line
In reply to Christoph HellwigNo need to have these helpers inline. Also remove the stubs and just use an IS_ENABLED for the get side (the set side already is only built conditionlly).
--- block/Makefile | 1 + block/blk-cgroup-fc-appid.c | 57 ++++++++++++++++++++++++++++++++++ drivers/scsi/lpfc/lpfc_scsi.c | 4 ++- include/linux/blk-cgroup.h | 58 ++--------------------------------- 4 files changed, 63 insertions(+), 57 deletions(-) create mode 100644 block/blk-cgroup-fc-appid.c
block/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_BLK_DEV_BSG_COMMON) += bsg.o obj-$(CONFIG_BLK_DEV_BSGLIB) += bsg-lib.o obj-$(CONFIG_BLK_CGROUP) += blk-cgroup.o obj-$(CONFIG_BLK_CGROUP_RWSTAT) += blk-cgroup-rwstat.o +obj-$(CONFIG_BLK_CGROUP_FC_APPID) += blk-cgroup-fc-appid.o obj-$(CONFIG_BLK_DEV_THROTTLING) += blk-throttle.o obj-$(CONFIG_BLK_CGROUP_IOPRIO) += blk-ioprio.o obj-$(CONFIG_BLK_CGROUP_IOLATENCY) += blk-iolatency.o
block/blk-cgroup-fc-appid.c new file +57 -0
57 lines not on this page · raw message
drivers/scsi/lpfc/lpfc_scsi.c +3 -1
@@ -5528,7 +5528,9 @@ static char *lpfc_is_command_vm_io(struct scsi_cmnd *cmd) {struct bio *bio =scsi_cmd_to_rq (cmd)->bio; -return bio ?blkcg_get_fc_appid (bio) :NULL ; +if (!IS_ENABLED (CONFIG_BLK_CGROUP_FC_APPID ) || !bio) +return NULL ; +return blkcg_get_fc_appid (bio); }/**
include/linux/blk-cgroup.h +2 -56
63 lines not on this page · raw message
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 5/15 blk-cgroup: move blk_cgroup_congested out line
In reply to Christoph HellwigThere is no urgent need to inline this function, so move it out of line.
--- block/blk-cgroup.c | 20 ++++++++++++++++++++ include/linux/blk-cgroup.h | 20 +------------------- 2 files changed, 21 insertions(+), 19 deletions(-)
block/blk-cgroup.c +20 -0
@@ -1950,6 +1950,26 @@ void blk_cgroup_bio_start(struct bio *bio)put_cpu (); } +bool blk_cgroup_congested (void ) +{ +struct cgroup_subsys_state *css; +bool ret = false; + +rcu_read_lock (); + css =kthread_blkcg (); +if (!css) + css =task_css (current, io_cgrp_id); +while (css) { +if (atomic_read (&css->cgroup->congestion_count)) { + ret = true; +break ; + } + css = css->parent; + } +rcu_read_unlock (); +return ret; +} +static int __init blkcg_init (void ) { blkcg_punt_bio_wq = alloc_workqueue("blkcg_punt_bio",
include/linux/blk-cgroup.h +1 -19
@@ -135,25 +135,7 @@ static inline struct blkcg *bio_blkcg(struct bio *bio)return NULL ; } -static inline bool blk_cgroup_congested (void ) -{ -struct cgroup_subsys_state *css; -bool ret = false; - -rcu_read_lock (); - css =kthread_blkcg (); -if (!css) - css =task_css (current, io_cgrp_id); -while (css) { -if (atomic_read (&css->cgroup->congestion_count)) { - ret = true; -break ; - } - css = css->parent; - } -rcu_read_unlock (); -return ret; -} +bool blk_cgroup_congested (void );/** * blkcg_parent - get the parent of a blkcg
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 6/15 blk-cgroup: move blkcg_{pin,unpin}_online out of line
In reply to Christoph HellwigMove these two functions out of line as there is no good reason to inline them. Also switch to passing a cgroup_subsys_state instead of doing the conversion in the caller to prepare for making the blkcg structure private to blk-cgroup.
--- block/blk-cgroup.c | 88 ++++++++++++++++++++++++++++---------- include/linux/blk-cgroup.h | 46 +------------------- mm/backing-dev.c | 5 +-- 3 files changed, 69 insertions(+), 70 deletions(-)
block/blk-cgroup.c +65 -23
@@ -155,6 +155,17 @@ static void blkg_async_bio_workfn(struct work_struct *work)blk_finish_plug (&plug); } +/** +* blkcg_parent - get the parent of a blkcg +* @blkcg: blkcg of interest +* +* Return the parent blkcg of @blkcg. Can be called anytime. +*/ +static inline struct blkcg *blkcg_parent (struct blkcg *blkcg) +{ +return css_to_blkcg (blkcg->css.parent); +} +/** * blkg_alloc - allocate a blkg * @blkcg: block cgroup the new blkg is associated with
@@ -1015,25 +1026,6 @@ static struct cftype blkcg_legacy_files[] = {* This finally frees the blkcg. */ -/** -* blkcg_css_offline - cgroup css_offline callback -* @css: css of interest -* -* This function is called when @css is about to go away. Here the cgwbs are -* offlined first and only once writeback associated with the blkcg has -* finished do we start step 2 (see above). -*/ -static void blkcg_css_offline (struct cgroup_subsys_state *css) -{ -struct blkcg *blkcg =css_to_blkcg (css); - -/* this prevents anyone from attaching or migrating to this blkcg */ -wb_blkcg_offline (blkcg); - -/* put the base online pin allowing step 2 to be triggered */ -blkcg_unpin_online (blkcg); -} -/** * blkcg_destroy_blkgs - responsible for shooting down blkgs * @blkcg: blkcg of interest
@@ -1045,7 +1037,7 @@ static void blkcg_css_offline(struct cgroup_subsys_state *css)* * This is the blkcg counterpart of ioc_release_fn(). */ -void blkcg_destroy_blkgs (struct blkcg *blkcg) +static void blkcg_destroy_blkgs (struct blkcg *blkcg) {might_sleep ();
@@ -1075,6 +1067,57 @@ void blkcg_destroy_blkgs(struct blkcg *blkcg)spin_unlock_irq (&blkcg->lock); } +/** +* blkcg_pin_online - pin online state +* @blkcg_css: blkcg of interest +* +* While pinned, a blkcg is kept online. This is primarily used to +* impedance-match blkg and cgwb lifetimes so that blkg doesn't go offline +* while an associated cgwb is still active. +*/ +void blkcg_pin_online (struct cgroup_subsys_state *blkcg_css) +{ +refcount_inc (&css_to_blkcg (blkcg_css)->online_pin); +} + +/** +* blkcg_unpin_online - unpin online state +* @blkcg_css: blkcg of interest +* +* This is primarily used to impedance-match blkg and cgwb lifetimes so +* that blkg doesn't go offline while an associated cgwb is still active. +* When this count goes to zero, all active cgwbs have finished so the +* blkcg can continue destruction by calling blkcg_destroy_blkgs(). +*/ +void blkcg_unpin_online (struct cgroup_subsys_state *blkcg_css) +{ +struct blkcg *blkcg =css_to_blkcg (blkcg_css); + +do { +if (!refcount_dec_and_test (&blkcg->online_pin)) +break ; +blkcg_destroy_blkgs (blkcg); + blkcg =blkcg_parent (blkcg); + }while (blkcg); +} + +/** +* blkcg_css_offline - cgroup css_offline callback +* @css: css of interest +* +* This function is called when @css is about to go away. Here the cgwbs are +* offlined first and only once writeback associated with the blkcg has +* finished do we start step 2 (see above). +*/ +static void blkcg_css_offline (struct cgroup_subsys_state *css) +{ +/* this prevents anyone from attaching or migrating to this blkcg */ +wb_blkcg_offline (css_to_blkcg (css)); + +/* put the base online pin allowing step 2 to be triggered */ +blkcg_unpin_online (css); +} +static void blkcg_css_free (struct cgroup_subsys_state *css) {struct blkcg *blkcg =css_to_blkcg (css);
@@ -1163,8 +1206,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)static int blkcg_css_online (struct cgroup_subsys_state *css) { -struct blkcg *blkcg =css_to_blkcg (css); -struct blkcg *parent =blkcg_parent (blkcg); +struct blkcg *parent =blkcg_parent (css_to_blkcg (css));/* * blkcg_pin_online() is used to delay blkcg offline so that blkgs
@@ -1172,7 +1214,7 @@ static int blkcg_css_online(struct cgroup_subsys_state *css)* parent so that offline always happens towards the root. */ if (parent) -blkcg_pin_online (parent); +blkcg_pin_online (css);return 0 ; }
include/linux/blk-cgroup.h +2 -44
58 lines not on this page · raw message
mm/backing-dev.c +2 -3
@@ -390,7 +390,6 @@ static void cgwb_release_workfn(struct work_struct *work) { struct bdi_writeback *wb = container_of(work, struct bdi_writeback, release_work); -struct blkcg *blkcg =css_to_blkcg (wb->blkcg_css);struct backing_dev_info *bdi = wb->bdi;mutex_lock (&wb->bdi->cgwb_release_mutex);
@@ -401,7 +400,7 @@ static void cgwb_release_workfn(struct work_struct *work)mutex_unlock (&wb->bdi->cgwb_release_mutex);/* triggers blkg destruction if no online users left */ -blkcg_unpin_online (blkcg); +blkcg_unpin_online (wb->blkcg_css);fprop_local_destroy_percpu (&wb->memcg_completions);
@@ -511,7 +510,7 @@ static int cgwb_create(struct backing_dev_info *bdi,list_add_tail_rcu (&wb->bdi_node, &bdi->wb_list);list_add (&wb->memcg_node, memcg_cgwb_list);list_add (&wb->blkcg_node, blkcg_cgwb_list); -blkcg_pin_online (blkcg); +blkcg_pin_online (blkcg_css);css_get (memcg_css);css_get (blkcg_css); }
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 7/15 blk-cgroup: move struct blkcg to block/blk-cgroup.h
In reply to Christoph HellwigThere is no real need to expose the blkcg structure to the whole kernel. Move it to the private header an expose a helper to let the writeback code access the cgwb_list member.
--- block/blk-cgroup.c | 9 ++++++++- block/blk-cgroup.h | 28 ++++++++++++++++++++++++++++ include/linux/backing-dev.h | 6 ++---- include/linux/blk-cgroup.h | 32 +------------------------------- mm/backing-dev.c | 13 ++++++------- 5 files changed, 45 insertions(+), 43 deletions(-)
block/blk-cgroup.c +8 -1
@@ -1005,6 +1005,13 @@ static struct cftype blkcg_legacy_files[] = { { }/* terminate */ }; +#ifdef CONFIG_CGROUP_WRITEBACK +struct list_head *blkcg_get_cgwb_list (struct cgroup_subsys_state *css) +{ +return &css_to_blkcg (css)->cgwb_list; +} +#endif +/* * blkcg destruction is a three-stage process. *
@@ -1112,7 +1119,7 @@ void blkcg_unpin_online(struct cgroup_subsys_state *blkcg_css)static void blkcg_css_offline (struct cgroup_subsys_state *css) {/* this prevents anyone from attaching or migrating to this blkcg */ -wb_blkcg_offline (css_to_blkcg (css)); +wb_blkcg_offline (css);/* put the base online pin allowing step 2 to be triggered */ blkcg_unpin_online (css);
block/blk-cgroup.h +28 -0
@@ -17,10 +17,38 @@#include <linux/blk-cgroup.h> #include <linux/blk-mq.h> +struct blkcg_gq ; +struct blkg_policy_data ; + +/* percpu_counter batch for blkg_[rw]stats, per-cpu drift doesn't matter */ #define BLKG_STAT_CPU_BATCH (INT_MAX / 2)#ifdef CONFIG_BLK_CGROUP +struct blkcg { +struct cgroup_subsys_state css; +spinlock_t lock; +refcount_t online_pin; + +struct radix_tree_root blkg_tree; +struct blkcg_gq __rcu *blkg_hint; +struct hlist_head blkg_list; + +struct blkcg_policy_data *cpd[BLKCG_MAX_POLS ]; + +struct list_head all_blkcgs_node; +#ifdef CONFIG_BLK_CGROUP_FC_APPID +char fc_app_id[FC_APPID_LEN ]; +#endif +#ifdef CONFIG_CGROUP_WRITEBACK +struct list_head cgwb_list; +#endif +}; + +static inline struct blkcg *css_to_blkcg (struct cgroup_subsys_state *css) +{ + return css ? container_of(css, struct blkcg, css) : NULL; +}/* * A blkcg_gq (blkg) is association between a block cgroup (blkcg) and a
include/linux/backing-dev.h +2 -4
@@ -17,8 +17,6 @@#include <linux/backing-dev-defs.h> #include <linux/slab.h> -struct blkcg ; -static inline struct backing_dev_info *bdi_get (struct backing_dev_info *bdi) {kref_get (&bdi->refcnt);
@@ -154,7 +152,7 @@ struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi,struct cgroup_subsys_state *memcg_css, gfp_t gfp);void wb_memcg_offline (struct mem_cgroup *memcg); -void wb_blkcg_offline (struct blkcg *blkcg); +void wb_blkcg_offline (struct cgroup_subsys_state *css);/** * inode_cgwb_enabled - test whether cgroup writeback is enabled on an inode
@@ -378,7 +376,7 @@ static inline void wb_memcg_offline(struct mem_cgroup *memcg) { } -static inline void wb_blkcg_offline (struct blkcg *blkcg) +static inline void wb_blkcg_offline (struct cgroup_subsys_state *css) { }
include/linux/blk-cgroup.h +1 -31
@@ -37,29 +37,6 @@ enum blkg_iostat_type { BLKG_IOSTAT_NR, }; -struct blkcg_gq ; -struct blkg_policy_data ; - -struct blkcg { -struct cgroup_subsys_state css; -spinlock_t lock; -refcount_t online_pin; - -struct radix_tree_root blkg_tree; -struct blkcg_gq __rcu *blkg_hint; -struct hlist_head blkg_list; - -struct blkcg_policy_data *cpd[BLKCG_MAX_POLS ]; - -struct list_head all_blkcgs_node; -#ifdef CONFIG_BLK_CGROUP_FC_APPID -char fc_app_id[FC_APPID_LEN ]; -#endif -#ifdef CONFIG_CGROUP_WRITEBACK -struct list_head cgwb_list; -#endif -}; -struct blkg_iostat {u64 bytes[BLKG_IOSTAT_NR ];u64 ios[BLKG_IOSTAT_NR ];
@@ -114,11 +91,6 @@ extern struct cgroup_subsys_state * const blkcg_root_css;void blkcg_schedule_throttle (struct request_queue *q,bool use_memdelay);void blkcg_maybe_throttle_current (void ); -static inline struct blkcg *css_to_blkcg (struct cgroup_subsys_state *css) -{ - return css ? container_of(css, struct blkcg, css) : NULL; -} -/** * bio_blkcg - grab the blkcg associated with a bio * @bio: target bio
@@ -137,12 +109,10 @@ static inline struct blkcg *bio_blkcg(struct bio *bio)bool blk_cgroup_congested (void );void blkcg_pin_online (struct cgroup_subsys_state *blkcg_css);void blkcg_unpin_online (struct cgroup_subsys_state *blkcg_css); +struct list_head *blkcg_get_cgwb_list (struct cgroup_subsys_state *css);#else /* CONFIG_BLK_CGROUP */ -struct blkcg { -}; -struct blkcg_gq { };
mm/backing-dev.c +6 -7
@@ -445,7 +445,6 @@ static int cgwb_create(struct backing_dev_info *bdi, {struct mem_cgroup *memcg;struct cgroup_subsys_state *blkcg_css; -struct blkcg *blkcg;struct list_head *memcg_cgwb_list, *blkcg_cgwb_list;struct bdi_writeback *wb;unsigned long flags;
@@ -453,9 +452,8 @@ static int cgwb_create(struct backing_dev_info *bdi, memcg =mem_cgroup_from_css (memcg_css); blkcg_css =cgroup_get_e_css (memcg_css->cgroup, &io_cgrp_subsys); - blkcg =css_to_blkcg (blkcg_css); memcg_cgwb_list = &memcg->cgwb_list; - blkcg_cgwb_list = &blkcg->cgwb_list; + blkcg_cgwb_list =blkcg_get_cgwb_list (blkcg_css);/* look up again under lock and discard on blkcg mismatch */ spin_lock_irqsave (&cgwb_lock, flags);
@@ -723,18 +721,19 @@ void wb_memcg_offline(struct mem_cgroup *memcg)/** * wb_blkcg_offline - kill all wb's associated with a blkcg being offlined -* @blkcg: blkcg being offlined +* @css: blkcg being offlined * * Also prevents creation of any new wb's associated with @blkcg. */ -void wb_blkcg_offline (struct blkcg *blkcg) +void wb_blkcg_offline (struct cgroup_subsys_state *css) {struct bdi_writeback *wb, *next; +struct list_head *list =blkcg_get_cgwb_list (css);spin_lock_irq (&cgwb_lock); -list_for_each_entry_safe (wb, next, &blkcg->cgwb_list, blkcg_node) +list_for_each_entry_safe (wb, next, list, blkcg_node)cgwb_kill (wb); - blkcg->cgwb_list.next =NULL ;/* prevent new wb's */ + list->next =NULL ;/* prevent new wb's */ spin_unlock_irq (&cgwb_lock); }
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 8/15 blktrace: cleanup the __trace_note_message interface
In reply to Christoph HellwigPass the cgroup_subsys_state instead of a the blkg so that blktrace doesn't need to poke into blk-cgroup internals, and give the name a blk prefix as the current name is way too generic for a public interface.
--- block/bfq-iosched.h | 4 ++-- block/blk-throttle.c | 2 +- include/linux/blktrace_api.h | 10 ++++------ kernel/trace/blktrace.c | 20 ++++++++++---------- 4 files changed, 17 insertions(+), 19 deletions(-)
block/bfq-iosched.h +2 -2
@@ -1102,13 +1102,13 @@ struct bfq_group *bfqq_group(struct bfq_queue *bfqq);break ; \bfq_bfqq_name ((bfqq), pid_str,MAX_BFQQ_NAME_LENGTH ); \ blk_add_cgroup_trace_msg((bfqd)->queue, \ - bfqg_to_blkg(bfqq_group(bfqq))->blkcg, \ + &bfqg_to_blkg(bfqq_group(bfqq))->blkcg->css, \ "%s " fmt, pid_str, ##args); \ } while (0) #define bfq_log_bfqg(bfqd, bfqg, fmt, args...) do { \ blk_add_cgroup_trace_msg((bfqd)->queue, \ - bfqg_to_blkg(bfqg)->blkcg, fmt, ##args); \ + &bfqg_to_blkg(bfqg)->blkcg->css, fmt, ##args); \ } while (0)#else /* CONFIG_BFQ_GROUP_IOSCHED */
block/blk-throttle.c +1 -1
@@ -227,7 +227,7 @@ static unsigned int tg_iops_limit(struct throtl_grp *tg, int rw)break ; \if ((__tg)) { \ blk_add_cgroup_trace_msg(__td->queue, \ - tg_to_blkg(__tg)->blkcg, "throtl " fmt, ##args);\ + &tg_to_blkg(__tg)->blkcg->css, "throtl " fmt, ##args);\ } else { \ blk_add_trace_msg(__td->queue, "throtl " fmt, ##args); \ } \
include/linux/blktrace_api.h +4 -6
@@ -27,12 +27,10 @@ struct blk_trace {atomic_t dropped; }; -struct blkcg ; -extern int blk_trace_ioctl (struct block_device *,unsigned ,char __user *);extern void blk_trace_shutdown (struct request_queue *); -extern __printf(3, 4) -void __trace_note_message(struct blk_trace *, struct blkcg *blkcg, const char *fmt, ...); +__printf(3, 4) void __blk_trace_note_message(struct blk_trace *bt, +struct cgroup_subsys_state *css,const char *fmt, ...);/** * blk_add_trace_msg - Add a (simple) message to the blktrace stream
@@ -47,14 +45,14 @@ void __trace_note_message(struct blk_trace *, struct blkcg *blkcg, const char *f* NOTE: Can not use 'static inline' due to presence of var args... * **/ -#define blk_add_cgroup_trace_msg (q, cg, fmt, ...) \ +#define blk_add_cgroup_trace_msg (q, css, fmt, ...) \ do { \ struct blk_trace *bt; \ \ rcu_read_lock(); \ bt = rcu_dereference((q)->blk_trace); \ if (unlikely(bt)) \ - __trace_note_message(bt, cg, fmt, ##__VA_ARGS__);\ + __blk_trace_note_message(bt, css, fmt, ##__VA_ARGS__);\ rcu_read_unlock(); \ } while (0)#define blk_add_trace_msg (q, fmt, ...) \
kernel/trace/blktrace.c +10 -10
@@ -145,13 +145,14 @@ static void trace_note_time(struct blk_trace *bt)local_irq_restore (flags); } -void __trace_note_message (struct blk_trace *bt,struct blkcg *blkcg, -const char *fmt, ...) +void __blk_trace_note_message (struct blk_trace *bt, +struct cgroup_subsys_state *css,const char *fmt, ...) {int n;va_list args;unsigned long flags;char *buf; +u64 cgid =0 ;if (unlikely (bt->trace_state != Blktrace_running && !blk_tracer_enabled))
@@ -170,17 +171,16 @@ void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg, n =vscnprintf (buf,BLK_TN_MAX_MSG , fmt, args);va_end (args); -if (!(blk_tracer_flags.val &TRACE_BLK_OPT_CGROUP )) - blkcg =NULL ;#ifdef CONFIG_BLK_CGROUP -trace_note (bt, current->pid,BLK_TN_MESSAGE , buf, n, - blkcg ?cgroup_id (blkcg->css.cgroup) :1 ); -#else -trace_note (bt, current->pid,BLK_TN_MESSAGE , buf, n,0 ); +if (css && (blk_tracer_flags.val &TRACE_BLK_OPT_CGROUP )) + cgid =cgroup_id (css->cgroup); +else + cgid =1 ;#endif +trace_note (bt, current->pid,BLK_TN_MESSAGE , buf, n, cgid);local_irq_restore (flags); } -EXPORT_SYMBOL_GPL (__trace_note_message); +EXPORT_SYMBOL_GPL (__blk_trace_note_message);static int act_log_check (struct blk_trace *bt,u32 what,sector_t sector,pid_t pid)
@@ -411,7 +411,7 @@ static ssize_t blk_msg_write(struct file *filp, const char __user *buffer,return PTR_ERR (msg); bt = filp->private_data; -__trace_note_message (bt,NULL ,"%s" , msg); +__blk_trace_note_message (bt,NULL ,"%s" , msg);kfree (msg);return count;
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 9/15 blk-cgroup: replace bio_blkcg with bio_blkcg_css
In reply to Christoph HellwigAll callers of bio_blkcg actually want the CSS, so replace it with an interface that does return the CSS. This now allows to move struct blkcg_gq to block/blk-cgroup.h instead of exposing it in a public header.
--- block/blk-cgroup.c | 18 ++++++++- block/blk-cgroup.h | 67 ++++++++++++++++++++++++++++-- drivers/block/loop.c | 12 +++--- include/linux/blk-cgroup.h | 83 +++----------------------------------- kernel/trace/blktrace.c | 6 ++- 5 files changed, 97 insertions(+), 89 deletions(-)
block/blk-cgroup.c +17 -1
@@ -155,6 +155,22 @@ static void blkg_async_bio_workfn(struct work_struct *work)blk_finish_plug (&plug); } +/** +* bio_blkcg_css - return the blkcg CSS associated with a bio +* @bio: target bio +* +* This returns the CSS for the blkcg associated with a bio, or %NULL if not +* associated. Callers are expected to either handle %NULL or know association +* has been done prior to calling this. +*/ +struct cgroup_subsys_state *bio_blkcg_css (struct bio *bio) +{ +if (!bio || !bio->bi_blkg) +return NULL ; +return &bio->bi_blkg->blkcg->css; +} +EXPORT_SYMBOL_GPL (bio_blkcg_css); +/** * blkcg_parent - get the parent of a blkcg * @blkcg: blkcg of interest
@@ -1938,7 +1954,7 @@ void bio_associate_blkg(struct bio *bio)rcu_read_lock ();if (bio->bi_blkg) - css = &bio_blkcg (bio)->css; + css =bio_blkcg_css (bio);else css =blkcg_css ();
block/blk-cgroup.h +64 -3
85 lines not on this page · raw message
drivers/block/loop.c +7 -5
@@ -1829,12 +1829,14 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx, cmd->blkcg_css =NULL ; cmd->memcg_css =NULL ;#ifdef CONFIG_BLK_CGROUP -if (rq->bio && rq->bio->bi_blkg) { - cmd->blkcg_css = &bio_blkcg (rq->bio)->css; +if (rq->bio) { + cmd->blkcg_css =bio_blkcg_css (rq->bio);#ifdef CONFIG_MEMCG - cmd->memcg_css = -cgroup_get_e_css (cmd->blkcg_css->cgroup, - &memory_cgrp_subsys); +if (cmd->blkcg_css) { + cmd->memcg_css = +cgroup_get_e_css (cmd->blkcg_css->cgroup, + &memory_cgrp_subsys); + }#endif }#endif
include/linux/blk-cgroup.h +5 -78
106 lines not on this page · raw message
kernel/trace/blktrace.c +4 -2
@@ -783,6 +783,7 @@ void blk_trace_shutdown(struct request_queue *q)#ifdef CONFIG_BLK_CGROUP static u64 blk_trace_bio_get_cgid (struct request_queue *q,struct bio *bio) { +struct cgroup_subsys_state *blkcg_css;struct blk_trace *bt;/* We don't use the 'bt' value here except as an optimization... */
@@ -790,9 +791,10 @@ static u64 blk_trace_bio_get_cgid(struct request_queue *q, struct bio *bio)if (!bt || !(blk_tracer_flags.val &TRACE_BLK_OPT_CGROUP ))return 0 ; -if (!bio->bi_blkg) + blkcg_css =bio_blkcg_css (bio); +if (!blkcg_css)return 0 ; - return cgroup_id(bio_blkcg(bio)->css.cgroup); + return cgroup_id(blkcg_css->cgroup); }#else static u64 blk_trace_bio_get_cgid (struct request_queue *q,struct bio *bio)
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 10/15 blk-cgroup: remove pointless CONFIG_BLOCK ifdefs
In reply to Christoph HellwigNo need to make BLK_CGROUP stubs conditional on CONFIG_BLOCK as they can't be used without that.
--- block/blk-cgroup.h | 3 --- include/linux/blk-cgroup.h | 4 ---- 2 files changed, 7 deletions(-)
block/blk-cgroup.h +0 -3
@@ -525,8 +525,6 @@ struct blkcg_policy {struct blkcg { }; -#ifdef CONFIG_BLOCK -static inline struct blkcg_gq *blkg_lookup (struct blkcg *blkcg,void *key) {return NULL ; }static inline struct blkcg_gq *blk_queue_root_blkg (struct request_queue *q) {return NULL ; }
@@ -554,7 +552,6 @@ static inline bool blk_cgroup_mergeable(struct request *rq, struct bio *bio) { r#define blk_queue_for_each_rl (rl, q) \ for ((rl) = &(q)->root_rl; (rl); (rl) = NULL) -#endif /* CONFIG_BLOCK */ #endif /* CONFIG_BLK_CGROUP */ #endif /* _BLK_CGROUP_PRIVATE_H */
include/linux/blk-cgroup.h +0 -4
@@ -44,15 +44,11 @@ struct cgroup_subsys_state *bio_blkcg_css(struct bio *bio);static inline void blkcg_maybe_throttle_current (void ) { }static inline bool blk_cgroup_congested (void ) {return false; } - -#ifdef CONFIG_BLOCK static inline void blkcg_schedule_throttle (struct request_queue *q,bool use_memdelay) { }static inline struct cgroup_subsys_state *bio_blkcg_css (struct bio *bio) {return NULL ; } -#endif /* CONFIG_BLOCK */ -#endif /* CONFIG_BLK_CGROUP */ int blkcg_set_fc_appid (char *app_id,u64 cgrp_id,size_t app_id_len);
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 11/15 blk-cgroup: remove unneeded includes from <linux/blk-cgroup.h>
In reply to Christoph HellwigRemove all the includes that aren't actually needed from <linux/blk-cgroup.h> and push them to the actual source files where needed.
--- block/blk-cgroup.h | 2 ++ include/linux/blk-cgroup.h | 15 +++++---------- mm/backing-dev.c | 1 + mm/readahead.c | 1 + mm/swapfile.c | 1 + 5 files changed, 10 insertions(+), 10 deletions(-)
block/blk-cgroup.h +2 -0
@@ -15,6 +15,8 @@*/ #include <linux/blk-cgroup.h> +#include <linux/cgroup.h> +#include <linux/kthread.h> #include <linux/blk-mq.h> struct blkcg_gq ;
include/linux/blk-cgroup.h +5 -10
@@ -14,16 +14,11 @@* Nauman Rafique <[email protected]> */ -#include <linux/cgroup.h> -#include <linux/percpu.h> -#include <linux/percpu_counter.h> -#include <linux/u64_stats_sync.h> -#include <linux/seq_file.h> -#include <linux/radix-tree.h> -#include <linux/blkdev.h> -#include <linux/atomic.h> -#include <linux/kthread.h> -#include <linux/fs.h> +#include <linux/types.h> + +struct bio ; +struct cgroup_subsys_state ; +struct request_queue ;#define FC_APPID_LEN 129
mm/backing-dev.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0-only +#include <linux/blkdev.h> #include <linux/wait.h> #include <linux/rbtree.h> #include <linux/kthread.h>
mm/readahead.c +1 -0
@@ -113,6 +113,7 @@* ->readpage() which may be less efficient. */ +#include <linux/blkdev.h> #include <linux/kernel.h> #include <linux/dax.h> #include <linux/gfp.h>
mm/swapfile.c +1 -0
@@ -6,6 +6,7 @@* Swap reorganised 29.12.95, Stephen Tweedie */ +#include <linux/blkdev.h> #include <linux/mm.h> #include <linux/sched/mm.h> #include <linux/sched/task.h>
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 12/15 blk-cgroup: move blkcg_css to blk-cgroup.c
In reply to Christoph Hellwigblkcg_css is only used in blk-cgroup.c, so move it there.
--- block/blk-cgroup.c | 17 +++++++++++++++++ block/blk-cgroup.h | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-)
block/blk-cgroup.c +17 -0
@@ -59,6 +59,23 @@ static struct workqueue_struct *blkcg_punt_bio_wq;#define BLKG_DESTROY_BATCH_SIZE 64 +/** +* blkcg_css - find the current css +* +* Find the css associated with either the kthread or the current task. +* This may return a dying css, so it is up to the caller to use tryget logic +* to confirm it is alive and well. +*/ +static struct cgroup_subsys_state *blkcg_css (void ) +{ +struct cgroup_subsys_state *css; + + css =kthread_blkcg (); +if (css) +return css; +return task_css (current, io_cgrp_id); +} +static bool blkcg_policy_enabled (struct request_queue *q,const struct blkcg_policy *pol) {
block/blk-cgroup.h +0 -17
@@ -210,23 +210,6 @@ int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol, char *input, struct blkg_conf_ctx *ctx);void blkg_conf_finish (struct blkg_conf_ctx *ctx); -/** -* blkcg_css - find the current css -* -* Find the css associated with either the kthread or the current task. -* This may return a dying css, so it is up to the caller to use tryget logic -* to confirm it is alive and well. -*/ -static inline struct cgroup_subsys_state *blkcg_css (void ) -{ -struct cgroup_subsys_state *css; - - css =kthread_blkcg (); -if (css) -return css; -return task_css (current, io_cgrp_id); -} -/** * bio_issue_as_root_blkg - see if this bio needs to be issued as root blkg * @return: true if this bio needs to be submitted with the root blkg context.
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 13/15 blk-cgroup: cleanup blk_cgroup_congested
In reply to Christoph HellwigUse blkcg_css instead of open coding it, and switch to a slightly more natural for loop.
--- block/blk-cgroup.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
block/blk-cgroup.c +1 -5
@@ -2038,15 +2038,11 @@ bool blk_cgroup_congested(void)bool ret = false;rcu_read_lock (); - css =kthread_blkcg (); -if (!css) - css =task_css (current, io_cgrp_id); -while (css) { +for (css =blkcg_css (); css; css = css->parent) {if (atomic_read (&css->cgroup->congestion_count)) { ret = true;break ; } - css = css->parent; }rcu_read_unlock ();return ret;
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 14/15 blk-cgroup: cleanup blkcg_maybe_throttle_current
In reply to Christoph HellwigUse blkcg_css instead of opencoding it.
--- block/blk-cgroup.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
block/blk-cgroup.c +1 -7
@@ -1808,7 +1808,6 @@ static void blkcg_maybe_throttle_blkg(struct blkcg_gq *blkg, bool use_memdelay)void blkcg_maybe_throttle_current (void ) {struct request_queue *q = current->throttle_queue; -struct cgroup_subsys_state *css;struct blkcg *blkcg;struct blkcg_gq *blkg;bool use_memdelay = current->use_memdelay;
@@ -1820,12 +1819,7 @@ void blkcg_maybe_throttle_current(void) current->use_memdelay = false;rcu_read_lock (); - css =kthread_blkcg (); -if (css) - blkcg =css_to_blkcg (css); -else - blkcg =css_to_blkcg (task_css (current, io_cgrp_id)); - + blkcg =css_to_blkcg (blkcg_css ());if (!blkcg) goto out; blkg =blkg_lookup (blkcg, q);
Signature · 1 line
2.30.2
Christoph Hellwig
maintainerPATCH 15/15 kthread: unexport kthread_blkcg
In reply to Christoph Hellwigkthread_blkcg is only used by the built-in blk-cgroup code.
--- include/linux/kthread.h | 4 ---- kernel/kthread.c | 1 - 2 files changed, 5 deletions(-)
include/linux/kthread.h +0 -4
@@ -222,9 +222,5 @@ void kthread_associate_blkcg(struct cgroup_subsys_state *css);struct cgroup_subsys_state *kthread_blkcg (void );#else static inline void kthread_associate_blkcg (struct cgroup_subsys_state *css) { } -static inline struct cgroup_subsys_state *kthread_blkcg (void ) -{ -return NULL ; -}#endif #endif /* _LINUX_KTHREAD_H */
kernel/kthread.c +0 -1
@@ -1522,5 +1522,4 @@ struct cgroup_subsys_state *kthread_blkcg(void) }return NULL ; } -EXPORT_SYMBOL (kthread_blkcg);#endif
Signature · 1 line
2.30.2
Tejun Heo
maintainerHello,
Quoted 4 lines · Christoph Hellwig
this series cleans up various lose end in the blk-cgroup code to make it easier to follow in preparation of reworking the blkcg assignment for bios. The biggest change is that most of <
linux/blk-cgroup.h> is now taken private intoblock/.
The patches look all good to me and I'm not against making things more private but can you elaborate on the rationale a bit more? By and large, we have never been shy about putting things in the headers if there's *any* (perceived) gain to be made from doing so, or even just as a way to pick the locations for different things - type defs go on header and so on. Most of the inlines and [un]likely's that we have are rather silly with modern compilers with global optimizations, so it does make sense to get tidier, but if that's the rationale, mentioning that in the commit message, even briefly, would be great - ie. it should explain the benefits of adding these few accessors to keep the definition private.
Thanks.
Signature · 1 line
tejun
Christoph Hellwig
maintainerQuoted 10 lines · Tejun Heo
The patches look all good to me and I'm not against making things more private but can you elaborate on the rationale a bit more? By and large, we have never been shy about putting things in the headers if there's *any* (perceived) gain to be made from doing so, or even just as a way to pick the locations for different things - type defs go on header and so on. Most of the inlines and [un]likely's that we have are rather silly with modern compilers with global optimizations, so it does make sense to get tidier, but if that's the rationale, mentioning that in the commit message, even briefly, would be great - ie. it should explain the benefits of adding these few accessors to keep the definition private.
Mostly to help me understand the code :) between all the moving to and from the css struture it is a bit of a mess, and limiting the scope that deals with the structures greatly helps with that.
Hello,
Quoted 12 lines · Christoph Hellwig
Quoted 10 lines · Tejun Heo
The patches look all good to me and I'm not against making things more private but can you elaborate on the rationale a bit more? By and large, we have never been shy about putting things in the headers if there's *any* (perceived) gain to be made from doing so, or even just as a way to pick the locations for different things - type defs go on header and so on. Most of the inlines and [un]likely's that we have are rather silly with modern compilers with global optimizations, so it does make sense to get tidier, but if that's the rationale, mentioning that in the commit message, even briefly, would be great - ie. it should explain the benefits of adding these few accessors to keep the definition private.
Quoted 3 lines
Mostly to help me understand the code :) between all the moving to and from the css struture it is a bit of a mess, and limiting the scope that deals with the structures greatly helps with that.
Hahaha, yeah, fair enough. I don't see a reason to not apply the patchset given that the code is better organized and easier to follow afterewards. For the series,
Thanks.
Signature · 1 line
tejun
Christoph Hellwig
maintainerping?
Quoted 26 lines · Christoph Hellwig
this series cleans up various lose end in the blk-cgroup code to make it easier to follow in preparation of reworking the blkcg assignment for bios. The biggest change is that most of <
linux/blk-cgroup.h> is now taken private intoblock/.Diffstat:
block/Makefile | 1 block/bfq-iosched.h | 4 block/blk-cgroup-fc-appid.c | 57 +++++++++ block/blk-cgroup.c | 154 ++++++++++++++++++++----- block/blk-cgroup.h | 138 +++++++++++++++------- block/blk-throttle.c | 2 drivers/block/loop.c | 12 + drivers/nvme/host/fc.c | 26 +--- drivers/scsi/lpfc/lpfc_scsi.c | 4 include/linux/backing-dev.h | 6 include/linux/blk-cgroup.h | 258 ++---------------------------------------- include/linux/blktrace_api.h | 10 - include/linux/kthread.h | 4 kernel/kthread.c | 1 kernel/trace/blktrace.c | 26 ++-- mm/backing-dev.c | 19 +-- mm/readahead.c | 1 mm/swapfile.c | 1 18 files changed, 343 insertions(+), 381 deletions(-)
Quoted 1 line
[...]
Applied, thanks!
[01/15] blk-cgroup: remove __bio_blkcg
commit: 2524a5783e7d49e7cd936f582485a2bb4567edd1
[02/15] nvme-fc: don't support the appid attribute without CONFIG_BLK_CGROUP_FC_APPID
commit: 55d7baa371ad90d297daf4250720af77449fdec0
[03/15] nvme-fc: fold t fc_update_appid into fc_appid_store
commit: c814153c83a892dfd42026eaa661ae2c1f298792
[04/15] blk-cgroup: move blkcg_{get,set}_fc_appid out of line
commit: db05628435aa761d30b4eae481a82befe7a8492a
[05/15] blk-cgroup: move blk_cgroup_congested out line
commit: 216889aad362b5b7e998a5371348b5e95d485dd1
[06/15] blk-cgroup: move blkcg_{pin,unpin}_online out of line
commit: 397c9f46ee4d99024c64954b007c1b5762d01cb4
[07/15] blk-cgroup: move struct blkcg to block/blk-cgroup.h
commit: dec223c92a4688f6c9642d640cfe15a99d289dd4
[08/15] blktrace: cleanup the __trace_note_message interface
commit: f4a6a61cb6d40d9ae63e47743d33200f3efe3fe7
[09/15] blk-cgroup: replace bio_blkcg with bio_blkcg_css
commit: bbb1ebe7a909db4de49777fb7676d5bf293f34c9
[10/15] blk-cgroup: remove pointless CONFIG_BLOCK ifdefs
commit: 7f20ba7c42fd899557cef7d001f48711c3066ba5
[11/15] blk-cgroup: remove unneeded includes from <linux/blk-cgroup.h>
commit: c97ab271576dec2170e7b804cb05f7617b30fed9
[12/15] blk-cgroup: move blkcg_css to blk-cgroup.c
commit: bc5fee91f26d8d1428fb744e5ad04b1417a85197
[13/15] blk-cgroup: cleanup blk_cgroup_congested
commit: d200ca143ac6d0b4391b4e811e67e1a36461d501
[14/15] blk-cgroup: cleanup blkcg_maybe_throttle_current
commit: 82778259eb201870d6d4f95ca4162de60a682343
[15/15] kthread: unexport kthread_blkcg
commit: f624506f98b198e65b44da303f44974590fb16c0Best regards,
Signature · 1 line
Jens Axboe