]> Pileus Git - ~andy/linux/blobdiff - block/blk-cgroup.h
Merge branch 'fbdev-for-linus' into fbdev-next
[~andy/linux] / block / blk-cgroup.h
index 0b0a176ee00750f2cff14e5fef96766574608e01..8ac457ce7783847522c1340c008d3c7789f3a1b2 100644 (file)
 #include <linux/cgroup.h>
 #include <linux/u64_stats_sync.h>
 #include <linux/seq_file.h>
-
-enum blkio_policy_id {
-       BLKIO_POLICY_PROP = 0,          /* Proportional Bandwidth division */
-       BLKIO_POLICY_THROTL,            /* Throttling */
-
-       BLKIO_NR_POLICIES,
-};
+#include <linux/radix-tree.h>
 
 /* Max limits for throttle policy */
 #define THROTL_IOPS_MAX                UINT_MAX
 
-#ifdef CONFIG_BLK_CGROUP
+/* CFQ specific, out here for blkcg->cfq_weight */
+#define CFQ_WEIGHT_MIN         10
+#define CFQ_WEIGHT_MAX         1000
+#define CFQ_WEIGHT_DEFAULT     500
 
-/* cft->private [un]packing for stat printing */
-#define BLKCG_STAT_PRIV(pol, off)      (((unsigned)(pol) << 16) | (off))
-#define BLKCG_STAT_POL(prv)            ((unsigned)(prv) >> 16)
-#define BLKCG_STAT_OFF(prv)            ((unsigned)(prv) & 0xffff)
+#ifdef CONFIG_BLK_CGROUP
 
 enum blkg_rwstat_type {
        BLKG_RWSTAT_READ,
@@ -44,14 +38,21 @@ enum blkg_rwstat_type {
        BLKG_RWSTAT_TOTAL = BLKG_RWSTAT_NR,
 };
 
-struct blkio_cgroup {
-       struct cgroup_subsys_state css;
-       unsigned int weight;
-       spinlock_t lock;
-       struct hlist_head blkg_list;
+struct blkcg_gq;
+
+struct blkcg {
+       struct cgroup_subsys_state      css;
+       spinlock_t                      lock;
+
+       struct radix_tree_root          blkg_tree;
+       struct blkcg_gq                 *blkg_hint;
+       struct hlist_head               blkg_list;
 
        /* for policies to test whether associated blkcg has changed */
-       uint64_t id;
+       uint64_t                        id;
+
+       /* TODO: per-policy storage in blkcg */
+       unsigned int                    cfq_weight;     /* belongs to cfq */
 };
 
 struct blkg_stat {
@@ -64,138 +65,98 @@ struct blkg_rwstat {
        uint64_t                        cnt[BLKG_RWSTAT_NR];
 };
 
-struct blkio_group_stats {
-       /* number of ios merged */
-       struct blkg_rwstat              merged;
-       /* total time spent on device in ns, may not be accurate w/ queueing */
-       struct blkg_rwstat              service_time;
-       /* total time spent waiting in scheduler queue in ns */
-       struct blkg_rwstat              wait_time;
-       /* number of IOs queued up */
-       struct blkg_rwstat              queued;
-       /* total disk time and nr sectors dispatched by this group */
-       struct blkg_stat                time;
-#ifdef CONFIG_DEBUG_BLK_CGROUP
-       /* time not charged to this cgroup */
-       struct blkg_stat                unaccounted_time;
-       /* sum of number of ios queued across all samples */
-       struct blkg_stat                avg_queue_size_sum;
-       /* count of samples taken for average */
-       struct blkg_stat                avg_queue_size_samples;
-       /* how many times this group has been removed from service tree */
-       struct blkg_stat                dequeue;
-       /* total time spent waiting for it to be assigned a timeslice. */
-       struct blkg_stat                group_wait_time;
-       /* time spent idling for this blkio_group */
-       struct blkg_stat                idle_time;
-       /* total time with empty current active q with other requests queued */
-       struct blkg_stat                empty_time;
-       /* fields after this shouldn't be cleared on stat reset */
-       uint64_t                        start_group_wait_time;
-       uint64_t                        start_idle_time;
-       uint64_t                        start_empty_time;
-       uint16_t                        flags;
-#endif
-};
-
-/* Per cpu blkio group stats */
-struct blkio_group_stats_cpu {
-       /* total bytes transferred */
-       struct blkg_rwstat              service_bytes;
-       /* total IOs serviced, post merge */
-       struct blkg_rwstat              serviced;
-       /* total sectors transferred */
-       struct blkg_stat                sectors;
-};
-
-struct blkio_group_conf {
-       unsigned int weight;
-       u64 iops[2];
-       u64 bps[2];
-};
-
-/* per-blkg per-policy data */
+/*
+ * A blkcg_gq (blkg) is association between a block cgroup (blkcg) and a
+ * request_queue (q).  This is used by blkcg policies which need to track
+ * information per blkcg - q pair.
+ *
+ * There can be multiple active blkcg policies and each has its private
+ * data on each blkg, the size of which is determined by
+ * blkcg_policy->pd_size.  blkcg core allocates and frees such areas
+ * together with blkg and invokes pd_init/exit_fn() methods.
+ *
+ * Such private data must embed struct blkg_policy_data (pd) at the
+ * beginning and pd_size can't be smaller than pd.
+ */
 struct blkg_policy_data {
        /* the blkg this per-policy data belongs to */
-       struct blkio_group *blkg;
-
-       /* Configuration */
-       struct blkio_group_conf conf;
-
-       struct blkio_group_stats stats;
-       /* Per cpu stats pointer */
-       struct blkio_group_stats_cpu __percpu *stats_cpu;
+       struct blkcg_gq                 *blkg;
 
-       /* pol->pdata_size bytes of private data used by policy impl */
-       char pdata[] __aligned(__alignof__(unsigned long long));
+       /* used during policy activation */
+       struct list_head                alloc_node;
 };
 
-struct blkio_group {
+/* association between a blk cgroup and a request queue */
+struct blkcg_gq {
        /* Pointer to the associated request_queue */
-       struct request_queue *q;
-       struct list_head q_node;
-       struct hlist_node blkcg_node;
-       struct blkio_cgroup *blkcg;
-       /* Store cgroup path */
-       char path[128];
+       struct request_queue            *q;
+       struct list_head                q_node;
+       struct hlist_node               blkcg_node;
+       struct blkcg                    *blkcg;
        /* reference count */
-       int refcnt;
+       int                             refcnt;
 
-       struct blkg_policy_data *pd[BLKIO_NR_POLICIES];
+       struct blkg_policy_data         *pd[BLKCG_MAX_POLS];
 
-       /* List of blkg waiting for per cpu stats memory to be allocated */
-       struct list_head alloc_node;
-       struct rcu_head rcu_head;
+       struct rcu_head                 rcu_head;
 };
 
-typedef void (blkio_init_group_fn)(struct blkio_group *blkg);
-
-struct blkio_policy_ops {
-       blkio_init_group_fn *blkio_init_group_fn;
+typedef void (blkcg_pol_init_pd_fn)(struct blkcg_gq *blkg);
+typedef void (blkcg_pol_exit_pd_fn)(struct blkcg_gq *blkg);
+typedef void (blkcg_pol_reset_pd_stats_fn)(struct blkcg_gq *blkg);
+
+struct blkcg_policy {
+       int                             plid;
+       /* policy specific private data size */
+       size_t                          pd_size;
+       /* cgroup files for the policy */
+       struct cftype                   *cftypes;
+
+       /* operations */
+       blkcg_pol_init_pd_fn            *pd_init_fn;
+       blkcg_pol_exit_pd_fn            *pd_exit_fn;
+       blkcg_pol_reset_pd_stats_fn     *pd_reset_stats_fn;
 };
 
-struct blkio_policy_type {
-       struct list_head list;
-       struct blkio_policy_ops ops;
-       enum blkio_policy_id plid;
-       size_t pdata_size;              /* policy specific private data size */
-       struct cftype *cftypes;         /* cgroup files for the policy */
-};
+extern struct blkcg blkcg_root;
 
-extern int blkcg_init_queue(struct request_queue *q);
-extern void blkcg_drain_queue(struct request_queue *q);
-extern void blkcg_exit_queue(struct request_queue *q);
+struct blkcg *cgroup_to_blkcg(struct cgroup *cgroup);
+struct blkcg *bio_blkcg(struct bio *bio);
+struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, struct request_queue *q);
+struct blkcg_gq *blkg_lookup_create(struct blkcg *blkcg,
+                                   struct request_queue *q);
+int blkcg_init_queue(struct request_queue *q);
+void blkcg_drain_queue(struct request_queue *q);
+void blkcg_exit_queue(struct request_queue *q);
 
 /* Blkio controller policy registration */
-extern void blkio_policy_register(struct blkio_policy_type *);
-extern void blkio_policy_unregister(struct blkio_policy_type *);
-extern void blkg_destroy_all(struct request_queue *q, bool destroy_root);
-extern void update_root_blkg_pd(struct request_queue *q,
-                               enum blkio_policy_id plid);
-
-void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
-                      u64 (*prfill)(struct seq_file *, struct blkg_policy_data *, int),
-                      int pol, int data, bool show_total);
+int blkcg_policy_register(struct blkcg_policy *pol);
+void blkcg_policy_unregister(struct blkcg_policy *pol);
+int blkcg_activate_policy(struct request_queue *q,
+                         const struct blkcg_policy *pol);
+void blkcg_deactivate_policy(struct request_queue *q,
+                            const struct blkcg_policy *pol);
+
+void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,
+                      u64 (*prfill)(struct seq_file *,
+                                    struct blkg_policy_data *, int),
+                      const struct blkcg_policy *pol, int data,
+                      bool show_total);
 u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v);
 u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
                         const struct blkg_rwstat *rwstat);
-int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
-                    struct seq_file *sf);
-int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
-                      struct seq_file *sf);
-int blkcg_print_cpu_stat(struct cgroup *cgrp, struct cftype *cft,
-                        struct seq_file *sf);
-int blkcg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
-                          struct seq_file *sf);
+u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd, int off);
+u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
+                      int off);
 
 struct blkg_conf_ctx {
-       struct gendisk          *disk;
-       struct blkio_group      *blkg;
-       u64                     v;
+       struct gendisk                  *disk;
+       struct blkcg_gq                 *blkg;
+       u64                             v;
 };
 
-int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
-                  struct blkg_conf_ctx *ctx);
+int blkg_conf_prep(struct blkcg *blkcg, const struct blkcg_policy *pol,
+                  const char *input, struct blkg_conf_ctx *ctx);
 void blkg_conf_finish(struct blkg_conf_ctx *ctx);
 
 
@@ -206,31 +167,41 @@ void blkg_conf_finish(struct blkg_conf_ctx *ctx);
  *
  * Return pointer to private data associated with the @blkg-@pol pair.
  */
-static inline void *blkg_to_pdata(struct blkio_group *blkg,
-                             struct blkio_policy_type *pol)
+static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg,
+                                                 struct blkcg_policy *pol)
 {
-       return blkg ? blkg->pd[pol->plid]->pdata : NULL;
+       return blkg ? blkg->pd[pol->plid] : NULL;
 }
 
 /**
  * pdata_to_blkg - get blkg associated with policy private data
- * @pdata: policy private data of interest
+ * @pd: policy private data of interest
  *
- * @pdata is policy private data.  Determine the blkg it's associated with.
+ * @pd is policy private data.  Determine the blkg it's associated with.
  */
-static inline struct blkio_group *pdata_to_blkg(void *pdata)
+static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd)
 {
-       if (pdata) {
-               struct blkg_policy_data *pd =
-                       container_of(pdata, struct blkg_policy_data, pdata);
-               return pd->blkg;
-       }
-       return NULL;
+       return pd ? pd->blkg : NULL;
 }
 
-static inline char *blkg_path(struct blkio_group *blkg)
+/**
+ * blkg_path - format cgroup path of blkg
+ * @blkg: blkg of interest
+ * @buf: target buffer
+ * @buflen: target buffer length
+ *
+ * Format the path of the cgroup of @blkg into @buf.
+ */
+static inline int blkg_path(struct blkcg_gq *blkg, char *buf, int buflen)
 {
-       return blkg->path;
+       int ret;
+
+       rcu_read_lock();
+       ret = cgroup_path(blkg->blkcg->css.cgroup, buf, buflen);
+       rcu_read_unlock();
+       if (ret)
+               strncpy(buf, "<unavailable>", buflen);
+       return ret;
 }
 
 /**
@@ -239,14 +210,14 @@ static inline char *blkg_path(struct blkio_group *blkg)
  *
  * The caller should be holding queue_lock and an existing reference.
  */
-static inline void blkg_get(struct blkio_group *blkg)
+static inline void blkg_get(struct blkcg_gq *blkg)
 {
        lockdep_assert_held(blkg->q->queue_lock);
        WARN_ON_ONCE(!blkg->refcnt);
        blkg->refcnt++;
 }
 
-void __blkg_release(struct blkio_group *blkg);
+void __blkg_release(struct blkcg_gq *blkg);
 
 /**
  * blkg_put - put a blkg reference
@@ -254,7 +225,7 @@ void __blkg_release(struct blkio_group *blkg);
  *
  * The caller should be holding queue_lock.
  */
-static inline void blkg_put(struct blkio_group *blkg)
+static inline void blkg_put(struct blkcg_gq *blkg)
 {
        lockdep_assert_held(blkg->q->queue_lock);
        WARN_ON_ONCE(blkg->refcnt <= 0);
@@ -340,7 +311,7 @@ static inline void blkg_rwstat_add(struct blkg_rwstat *rwstat,
  * This function can be called without synchronization and takes care of
  * u64 atomicity.
  */
-static struct blkg_rwstat blkg_rwstat_read(struct blkg_rwstat *rwstat)
+static inline struct blkg_rwstat blkg_rwstat_read(struct blkg_rwstat *rwstat)
 {
        unsigned int start;
        struct blkg_rwstat tmp;
@@ -377,55 +348,38 @@ static inline void blkg_rwstat_reset(struct blkg_rwstat *rwstat)
        memset(rwstat->cnt, 0, sizeof(rwstat->cnt));
 }
 
-#else
+#else  /* CONFIG_BLK_CGROUP */
 
-struct blkio_group {
+struct cgroup;
+
+struct blkg_policy_data {
+};
+
+struct blkcg_gq {
 };
 
-struct blkio_policy_type {
+struct blkcg_policy {
 };
 
+static inline struct blkcg *cgroup_to_blkcg(struct cgroup *cgroup) { return NULL; }
+static inline struct blkcg *bio_blkcg(struct bio *bio) { return NULL; }
+static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg, void *key) { return NULL; }
 static inline int blkcg_init_queue(struct request_queue *q) { return 0; }
 static inline void blkcg_drain_queue(struct request_queue *q) { }
 static inline void blkcg_exit_queue(struct request_queue *q) { }
-static inline void blkio_policy_register(struct blkio_policy_type *blkiop) { }
-static inline void blkio_policy_unregister(struct blkio_policy_type *blkiop) { }
-static inline void blkg_destroy_all(struct request_queue *q,
-                                   bool destory_root) { }
-static inline void update_root_blkg_pd(struct request_queue *q,
-                                      enum blkio_policy_id plid) { }
-
-static inline void *blkg_to_pdata(struct blkio_group *blkg,
-                               struct blkio_policy_type *pol) { return NULL; }
-static inline struct blkio_group *pdata_to_blkg(void *pdata,
-                               struct blkio_policy_type *pol) { return NULL; }
-static inline char *blkg_path(struct blkio_group *blkg) { return NULL; }
-static inline void blkg_get(struct blkio_group *blkg) { }
-static inline void blkg_put(struct blkio_group *blkg) { }
-
-#endif
-
-#define BLKIO_WEIGHT_MIN       10
-#define BLKIO_WEIGHT_MAX       1000
-#define BLKIO_WEIGHT_DEFAULT   500
-
-#ifdef CONFIG_BLK_CGROUP
-extern struct blkio_cgroup blkio_root_cgroup;
-extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
-extern struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio);
-extern struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg,
-                                      struct request_queue *q);
-struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg,
-                                      struct request_queue *q,
-                                      bool for_root);
-#else
-struct cgroup;
-static inline struct blkio_cgroup *
-cgroup_to_blkio_cgroup(struct cgroup *cgroup) { return NULL; }
-static inline struct blkio_cgroup *
-bio_blkio_cgroup(struct bio *bio) { return NULL; }
-
-static inline struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg,
-                                             void *key) { return NULL; }
-#endif
-#endif /* _BLK_CGROUP_H */
+static inline int blkcg_policy_register(struct blkcg_policy *pol) { return 0; }
+static inline void blkcg_policy_unregister(struct blkcg_policy *pol) { }
+static inline int blkcg_activate_policy(struct request_queue *q,
+                                       const struct blkcg_policy *pol) { return 0; }
+static inline void blkcg_deactivate_policy(struct request_queue *q,
+                                          const struct blkcg_policy *pol) { }
+
+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; }
+static inline char *blkg_path(struct blkcg_gq *blkg) { return NULL; }
+static inline void blkg_get(struct blkcg_gq *blkg) { }
+static inline void blkg_put(struct blkcg_gq *blkg) { }
+
+#endif /* CONFIG_BLK_CGROUP */
+#endif /* _BLK_CGROUP_H */