Skip to contentSkip to conversation

add sysfs to dynamically control blk request tag maintenance

RFC In review Chen, Kenneth W 2 participants 2 messages Oct 7, 2005 Block layer

lore
Share & tools
lore
#0 lore raw

RFC 1/1 add sysfs to dynamically control blk request tag maintenance

blk_queue_start_tag and blk_queue_end_tag are called for tagging I/O to scsi device that is capable of tcq. blk_queue_find_tag is a function that utilizes the tag information built up on every I/O.

However, there aren't many consumers for blk_queue_find_tag, except NCR53c700 and tekram-dc390. Vast majority of scsi drivers don't use these tag currently. So why bother build them at the beginning of an I/O and then tear it all down at the end, all doing hard work but no other functions in the kernel appears to care.

Is there another big scheme in the works to use these tags? If not, I'd like to propose we add a sysfs attribute to dynamically control whether kernel maintains blk request tag or not. This has performance advantage that we don't needlessly waste CPU cycle on things we throw away without using them. Would the following patch be acceptable? Comments?

drivers/block/ll_rw_blk.c renamed from drivers/block/ll_rw_blk.c.orig +31 -2
@@ -757,7 +757,7 @@ static void __blk_queue_free_tags(reques
 	}
 
 	q->queue_tags = NULL;
-	q->queue_flags &= ~(1 << QUEUE_FLAG_QUEUED);
+	q->queue_flags &= ~(1 << QUEUE_FLAG_QUEUED | 1 << QUEUE_FLAG_TAGGED);
 }
 
 /**
@@ -771,6 +771,7 @@ static void __blk_queue_free_tags(reques
 void blk_queue_free_tags(request_queue_t *q)
 {
 	clear_bit(QUEUE_FLAG_QUEUED, &q->queue_flags);
+	clear_bit(QUEUE_FLAG_TAGGED, &q->queue_flags);
 }
 
 EXPORT_SYMBOL(blk_queue_free_tags);
@@ -838,6 +839,7 @@ int blk_queue_init_tags(request_queue_t 
 		if ((rc = blk_queue_resize_tags(q, depth)))
 			return rc;
 		set_bit(QUEUE_FLAG_QUEUED, &q->queue_flags);
+		set_bit(QUEUE_FLAG_TAGGED, &q->queue_flags);
 		return 0;
 	} else
 		atomic_inc(&tags->refcnt);
@@ -846,7 +848,7 @@ int blk_queue_init_tags(request_queue_t 
 	 * assign it, all done
 	 */
 	q->queue_tags = tags;
-	q->queue_flags |= (1 << QUEUE_FLAG_QUEUED);
+	q->queue_flags |= (1 << QUEUE_FLAG_QUEUED | 1 << QUEUE_FLAG_TAGGED);
 	return 0;
 fail:
 	kfree(tags);
@@ -3589,6 +3591,26 @@ static ssize_t queue_max_hw_sectors_show
 	return queue_var_show(max_hw_sectors_kb, (page));
 }
 
+static ssize_t
+queue_tag_maint_store(struct request_queue *q, const char *page, size_t count)
+{
+	unsigned long tag_maint;
+	ssize_t ret = queue_var_store(&tag_maint, page, count);
+
+	if (blk_queue_queued(q)) {
+		if (tag_maint)
+			set_bit(QUEUE_FLAG_TAGGED, &q->queue_flags);
+		else
+			clear_bit(QUEUE_FLAG_TAGGED, &q->queue_flags);
+	}
+
+	return ret;
+}
+
+static ssize_t queue_tag_maint_show(struct request_queue *q, char *page)
+{
+	return queue_var_show(blk_queue_tagged(q), (page));
+}
 
 static struct queue_sysfs_entry queue_requests_entry = {
 	.attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR },
@@ -3619,12 +3641,19 @@ static struct queue_sysfs_entry queue_io
 	.store = elv_iosched_store,
 };
 
+static struct queue_sysfs_entry queue_tag_maint_entry = {
+	.attr = {.name = "tag_maint", .mode = S_IRUGO | S_IWUSR },
+	.show = queue_tag_maint_show,
+	.store = queue_tag_maint_store,
+};
+
 static struct attribute *default_attrs[] = {
 	&queue_requests_entry.attr,
 	&queue_ra_entry.attr,
 	&queue_max_hw_sectors_entry.attr,
 	&queue_max_sectors_entry.attr,
 	&queue_iosched_entry.attr,
+	&queue_tag_maint_entry.attr,
 	NULL,
 };
 
include/linux/blkdev.h renamed from include/linux/blkdev.h.orig +3 -1
@@ -436,9 +436,11 @@ enum {
 #define QUEUE_FLAG_PLUGGED	7	/* queue is plugged */
 #define QUEUE_FLAG_DRAIN	8	/* draining queue for sched switch */
 #define QUEUE_FLAG_FLUSH	9	/* doing barrier flush sequence */
+#define QUEUE_FLAG_TAGGED	10	/* maintain per request tag */
 
 #define blk_queue_plugged(q)	test_bit(QUEUE_FLAG_PLUGGED, &(q)->queue_flags)
-#define blk_queue_tagged(q)	test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags)
+#define blk_queue_queued(q)	test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags)
+#define blk_queue_tagged(q)	test_bit(QUEUE_FLAG_TAGGED, &(q)->queue_flags)
 #define blk_queue_stopped(q)	test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)
 #define blk_queue_flushing(q)	test_bit(QUEUE_FLAG_FLUSH, &(q)->queue_flags)
 
#1 lore raw
Quoted 10 lines · Kenneth W

blk_queue_start_tag and blk_queue_end_tag are called for tagging I/O to scsi device that is capable of tcq. blk_queue_find_tag is a function that utilizes the tag information built up on every I/O.

However, there aren't many consumers for blk_queue_find_tag, except NCR53c700 and tekram-dc390. Vast majority of scsi drivers don't use these tag currently. So why bother build them at the beginning of an I/O and then tear it all down at the end, all doing hard work but no other functions in the kernel appears to care.

Quoted 6 lines

Is there another big scheme in the works to use these tags? If not, I'd like to propose we add a sysfs attribute to dynamically control whether kernel maintains blk request tag or not. This has performance advantage that we don't needlessly waste CPU cycle on things we throw away without using them. Would the following patch be acceptable? Comments?

I don't understand the need for this patch - the generic tagging is only used if the SCSI LLD indicated it wanted it by issuing a scsi_activate_tcq(). So blk_queue_start_tag() is only called if the LLD already did a scsi_activate_tcq(), and blk_queue_end_tag() is only called if the rq is block layer tagged. blk_queue_find_tag() is only used with direct use of scsi_find_tag(), a function that should (and is) only usable by users of the generic tagging already.

So please, a description of what problem you are trying to solve would be appreciated :-)

Signature · 1 line
Jens Axboe