diff mbox series

[5/6] block: shrink plug->{nr_ios, rq_count} to unsigned char

Message ID 20240123173310.1966157-6-axboe@kernel.dk (mailing list archive)
State New, archived
Headers show
Series Cache issue side time querying | expand

Commit Message

Jens Axboe Jan. 23, 2024, 5:30 p.m. UTC
We never use more than 64 max in here, we can change them from unsigned
short to just a byte. Add a BUILD_BUG_ON() check, in case the max plug
count changes in the future.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
 block/blk-core.c       | 4 ++--
 block/blk-mq.c         | 2 ++
 include/linux/blkdev.h | 8 ++++----
 3 files changed, 8 insertions(+), 6 deletions(-)

Comments

Christoph Hellwig Jan. 24, 2024, 9:29 a.m. UTC | #1
On Tue, Jan 23, 2024 at 10:30:37AM -0700, Jens Axboe wrote:
> We never use more than 64 max in here, we can change them from unsigned
> short to just a byte. Add a BUILD_BUG_ON() check, in case the max plug
> count changes in the future.

Do we care about the size of this once per task structure?  byte-level
access tends to be quite a bit more expensive on various architectures.
Jens Axboe Jan. 24, 2024, 3:04 p.m. UTC | #2
On 1/24/24 2:29 AM, Christoph Hellwig wrote:
> On Tue, Jan 23, 2024 at 10:30:37AM -0700, Jens Axboe wrote:
>> We never use more than 64 max in here, we can change them from unsigned
>> short to just a byte. Add a BUILD_BUG_ON() check, in case the max plug
>> count changes in the future.
> 
> Do we care about the size of this once per task structure?  byte-level
> access tends to be quite a bit more expensive on various architectures.

I don't think we care that much, and honestly I'm fine dropping the last
two patches. They don't matter that much to me, and we can always
revisit if we do care more about shrinking the blk_plug later on.
diff mbox series

Patch

diff --git a/block/blk-core.c b/block/blk-core.c
index 71c6614a97fe..dd593008511c 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1063,7 +1063,7 @@  int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork,
 }
 EXPORT_SYMBOL(kblockd_mod_delayed_work_on);
 
-void blk_start_plug_nr_ios(struct blk_plug *plug, unsigned short nr_ios)
+void blk_start_plug_nr_ios(struct blk_plug *plug, unsigned char nr_ios)
 {
 	struct task_struct *tsk = current;
 
@@ -1076,7 +1076,7 @@  void blk_start_plug_nr_ios(struct blk_plug *plug, unsigned short nr_ios)
 	plug->cur_ktime = 0;
 	plug->mq_list = NULL;
 	plug->cached_rq = NULL;
-	plug->nr_ios = min_t(unsigned short, nr_ios, BLK_MAX_REQUEST_COUNT);
+	plug->nr_ios = min_t(unsigned char, nr_ios, BLK_MAX_REQUEST_COUNT);
 	plug->rq_count = 0;
 	plug->multiple_queues = false;
 	plug->has_elevator = false;
diff --git a/block/blk-mq.c b/block/blk-mq.c
index aff9e9492f59..a9b4a66e1e13 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1283,6 +1283,8 @@  EXPORT_SYMBOL(blk_mq_start_request);
  */
 static inline unsigned short blk_plug_max_rq_count(struct blk_plug *plug)
 {
+	BUILD_BUG_ON(2 * BLK_MAX_REQUEST_COUNT > U8_MAX);
+
 	if (plug->multiple_queues)
 		return BLK_MAX_REQUEST_COUNT * 2;
 	return BLK_MAX_REQUEST_COUNT;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 9660a65bb927..ce6d057de2f0 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -944,9 +944,9 @@  struct blk_plug {
 	/* if ios_left is > 1, we can batch tag/rq allocations */
 	struct request *cached_rq;
 	u64 cur_ktime;
-	unsigned short nr_ios;
+	unsigned char nr_ios;
 
-	unsigned short rq_count;
+	unsigned char rq_count;
 
 	bool multiple_queues;
 	bool has_elevator;
@@ -964,7 +964,7 @@  struct blk_plug_cb {
 extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug,
 					     void *data, int size);
 extern void blk_start_plug(struct blk_plug *);
-extern void blk_start_plug_nr_ios(struct blk_plug *, unsigned short);
+extern void blk_start_plug_nr_ios(struct blk_plug *, unsigned char);
 extern void blk_finish_plug(struct blk_plug *);
 
 void __blk_flush_plug(struct blk_plug *plug, bool from_schedule);
@@ -1060,7 +1060,7 @@  struct blk_plug {
 };
 
 static inline void blk_start_plug_nr_ios(struct blk_plug *plug,
-					 unsigned short nr_ios)
+					 unsigned char nr_ios)
 {
 }