Skip to contentSkip to conversation

percpu_ida: support to export allocation/free information

PATCH In review Ming Lei 1 participant 5 messages Apr 29, 2014 – May 5, 2014

Subsystems (3)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

cover percpu_ida: support to export allocation/free information

Hi,

These patches support to export percpu_ida allocation/free information via sysfs, so that percpu_ida performance can be monitored, and at least two use cases:

- some parameters(such as percpu_max_size) from its users are very sensitive to performance

- the data is helpful for verifying patches which try to improve percpu_ida

Thanks,
--
Ming Lei

author
#1 lore raw

PATCH 1/3 percpu_ida: introduce kobject for percpu_ida pool

So that we can export some allocation/free information for monitoring percpu_ida performance.

---
 include/linux/percpu_ida.h |   16 ++++++++++++++++
 lib/percpu_ida.c           |   21 ++++++++++++++++++---
 2 files changed, 34 insertions(+), 3 deletions(-)
include/linux/percpu_ida.h +16 -0
index f5cfdd6..463e3b3 100644
@@ -8,6 +8,7 @@
 #include <linux/spinlock_types.h>
 #include <linux/wait.h>
 #include <linux/cpumask.h>
+#include <linux/kobject.h>
 
 struct percpu_ida_cpu;
 
@@ -52,6 +53,8 @@ struct percpu_ida {
 		unsigned		nr_free;
 		unsigned		*freelist;
 	} ____cacheline_aligned_in_smp;
+
+	struct kobject kobj;
 };
 
 /*
@@ -79,4 +82,17 @@ int percpu_ida_for_each_free(struct percpu_ida *pool, percpu_ida_cb fn,
 	void *data);
 
 unsigned percpu_ida_free_tags(struct percpu_ida *pool, int cpu);
+
+static inline int percpu_ida_kobject_add(struct percpu_ida *pool,
+		struct kobject *parent, const char *name)
+{
+	if (pool->kobj.state_initialized)
+		return kobject_add(&pool->kobj, parent, name);
+	return 0;
+}
+static inline void percpu_ida_kobject_del(struct percpu_ida *pool)
+{
+	if (pool->kobj.state_in_sysfs)
+		kobject_del(&pool->kobj);
+}
 #endif /* __PERCPU_IDA_H__ */
lib/percpu_ida.c +18 -3
index 93d145e..56ae350 100644
@@ -260,6 +260,20 @@ void percpu_ida_free(struct percpu_ida *pool, unsigned tag)
 }
 EXPORT_SYMBOL_GPL(percpu_ida_free);
 
+static void percpu_ida_release(struct kobject *kobj)
+{
+	struct percpu_ida *pool = container_of(kobj,
+			struct percpu_ida, kobj);
+
+	free_percpu(pool->tag_cpu);
+	free_pages((unsigned long) pool->freelist,
+		   get_order(pool->nr_tags * sizeof(unsigned)));
+}
+
+static struct kobj_type percpu_ida_ktype = {
+	.release        = percpu_ida_release,
+};
+
 /**
  * percpu_ida_destroy - release a tag pool's resources
  * @pool: pool to free
@@ -268,9 +282,8 @@ EXPORT_SYMBOL_GPL(percpu_ida_free);
  */
 void percpu_ida_destroy(struct percpu_ida *pool)
 {
-	free_percpu(pool->tag_cpu);
-	free_pages((unsigned long) pool->freelist,
-		   get_order(pool->nr_tags * sizeof(unsigned)));
+	if (pool->kobj.state_initialized)
+		kobject_put(&pool->kobj);
 }
 EXPORT_SYMBOL_GPL(percpu_ida_destroy);
 
@@ -324,6 +337,8 @@ int __percpu_ida_init(struct percpu_ida *pool, unsigned long nr_tags,
 	for_each_possible_cpu(cpu)
 		spin_lock_init(&per_cpu_ptr(pool->tag_cpu, cpu)->lock);
 
+	kobject_init(&pool->kobj, &percpu_ida_ktype);
+
 	return 0;
 err:
 	percpu_ida_destroy(pool);
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH 2/3 percpu_ida: support exporting allocation/free info via sysfs

In reply to Ming Lei

With this information, it is easy to monitor percpu_ida performance.

---
 include/linux/percpu_ida.h |   24 ++++++++
 lib/Kconfig                |    7 +++
 lib/percpu_ida.c           |  130 +++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 159 insertions(+), 2 deletions(-)
include/linux/percpu_ida.h +24 -0
index 463e3b3..be1036d 100644
@@ -12,6 +12,27 @@
 
 struct percpu_ida_cpu;
 
+#ifdef CONFIG_PERCPU_IDA_STATS
+struct percpu_ida_stats {
+	u64 alloc_tags;
+	u64 alloc_in_fastpath;
+	u64 alloc_from_global_pool;
+	u64 alloc_by_stealing;
+	u64 alloc_after_sched;
+
+	u64 freed_tags;
+	u64 freed_empty;
+	u64 freed_full;
+};
+
+#define percpu_ida_inc(pool, ptr)		\
+do {						\
+	__this_cpu_inc(pool->stats->ptr);	\
+} while (0)
+#else
+#define percpu_ida_inc(pool, ptr)	do {} while (0)
+#endif
+
 struct percpu_ida {
 	/*
 	 * number of tags available to be allocated, as passed to
@@ -55,6 +76,9 @@ struct percpu_ida {
 	} ____cacheline_aligned_in_smp;
 
 	struct kobject kobj;
+#ifdef CONFIG_PERCPU_IDA_STATS
+	struct percpu_ida_stats __percpu *stats;
+#endif
 };
 
 /*
lib/Kconfig +7 -0
index 325a8d4..d47a1cf 100644
@@ -476,6 +476,13 @@ config OID_REGISTRY
 	help
 	  Enable fast lookup object identifier registry.
 
+config PERCPU_IDA_STATS
+	bool "Export percpu_ida status by sysfs"
+	default n
+	help
+	  Export percpu_ida allocation/free information so
+	  the performance can be monitored.
+
 config UCS2_STRING
         tristate
 
lib/percpu_ida.c +128 -2

196 lines not on this page · raw message

Signature · 1 line
1.7.9.5
author
#3 lore raw

PATCH 3/3 blk-mq: add percpu_ida kobjects

In reply to Ming Lei

So that the percpu_ida performance can be monitored.

---
 block/blk-mq-sysfs.c |    7 +++++++
 1 file changed, 7 insertions(+)
block/blk-mq-sysfs.c +7 -0
index 8145b5b..4171ae2 100644
@@ -329,6 +329,8 @@ void blk_mq_unregister_disk(struct gendisk *disk)
 			kobject_del(&ctx->kobj);
 			kobject_put(&ctx->kobj);
 		}
+		percpu_ida_kobject_del(&hctx->tags->free_tags);
+		percpu_ida_kobject_del(&hctx->tags->reserved_tags);
 		kobject_del(&hctx->kobj);
 		kobject_put(&hctx->kobj);
 	}
@@ -362,6 +364,11 @@ int blk_mq_register_disk(struct gendisk *disk)
 		if (ret)
 			break;
 
+		percpu_ida_kobject_add(&hctx->tags->free_tags,
+				&hctx->kobj, "free_tags");
+		percpu_ida_kobject_add(&hctx->tags->reserved_tags,
+				&hctx->kobj, "reserved_tags");
+
 		if (!hctx->nr_ctx)
 			continue;
 
Signature · 1 line
1.7.9.5
author
#4 lore raw
In reply to Ming Lei

Hi,

Quoted 11 lines · Ming Lei

Hi,

These patches support to export percpu_ida allocation/free information via sysfs, so that percpu_ida performance can be monitored, and at least two use cases:

- some parameters(such as percpu_max_size) from its users are very sensitive to performance

- the data is helpful for verifying patches which try to improve percpu_ida

Gentle ping, :-)

Thanks,

Signature · 1 line
Ming Lei