Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: save user max_sectors limit

The user can set the max_sectors limit to any valid value via sysfs
/sys/block/<dev>/queue/max_sectors_kb attribute. If the device limits
are ever rescanned, though, the limit reverts back to the potentially
artificially low BLK_DEF_MAX_SECTORS value.

Preserve the user's setting as the max_sectors limit as long as it's
valid. The user can reset back to defaults by writing 0 to the sysfs
file.

Signed-off-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20230105205146.3610282-3-kbusch@meta.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Keith Busch and committed by
Jens Axboe
c9c77418 0a26f327

+25 -9
+2 -1
Documentation/ABI/stable/sysfs-block
··· 432 432 Description: 433 433 [RW] This is the maximum number of kilobytes that the block 434 434 layer will allow for a filesystem request. Must be smaller than 435 - or equal to the maximum size allowed by the hardware. 435 + or equal to the maximum size allowed by the hardware. Write 0 436 + to use default kernel settings. 436 437 437 438 438 439 What: /sys/block/<disk>/queue/max_segment_size
+7 -2
block/blk-settings.c
··· 40 40 lim->virt_boundary_mask = 0; 41 41 lim->max_segment_size = BLK_MAX_SEGMENT_SIZE; 42 42 lim->max_sectors = lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS; 43 - lim->max_dev_sectors = 0; 43 + lim->max_user_sectors = lim->max_dev_sectors = 0; 44 44 lim->chunk_sectors = 0; 45 45 lim->max_write_zeroes_sectors = 0; 46 46 lim->max_zone_append_sectors = 0; ··· 135 135 limits->max_hw_sectors = max_hw_sectors; 136 136 137 137 max_sectors = min_not_zero(max_hw_sectors, limits->max_dev_sectors); 138 - max_sectors = min(max_sectors, BLK_DEF_MAX_SECTORS); 138 + 139 + if (limits->max_user_sectors) 140 + max_sectors = min(max_sectors, limits->max_user_sectors); 141 + else 142 + max_sectors = min(max_sectors, BLK_DEF_MAX_SECTORS); 143 + 139 144 max_sectors = round_down(max_sectors, 140 145 limits->logical_block_size >> SECTOR_SHIFT); 141 146 limits->max_sectors = max_sectors;
+15 -6
block/blk-sysfs.c
··· 239 239 static ssize_t 240 240 queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) 241 241 { 242 - unsigned long max_sectors_kb, 242 + unsigned long var; 243 + unsigned int max_sectors_kb, 243 244 max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1, 244 245 page_kb = 1 << (PAGE_SHIFT - 10); 245 - ssize_t ret = queue_var_store(&max_sectors_kb, page, count); 246 + ssize_t ret = queue_var_store(&var, page, count); 246 247 247 248 if (ret < 0) 248 249 return ret; 249 250 250 - max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, (unsigned long) 251 + max_sectors_kb = (unsigned int)var; 252 + max_hw_sectors_kb = min_not_zero(max_hw_sectors_kb, 251 253 q->limits.max_dev_sectors >> 1); 252 - 253 - if (max_sectors_kb > max_hw_sectors_kb || max_sectors_kb < page_kb) 254 - return -EINVAL; 254 + if (max_sectors_kb == 0) { 255 + q->limits.max_user_sectors = 0; 256 + max_sectors_kb = min(max_hw_sectors_kb, 257 + BLK_DEF_MAX_SECTORS >> 1); 258 + } else { 259 + if (max_sectors_kb > max_hw_sectors_kb || 260 + max_sectors_kb < page_kb) 261 + return -EINVAL; 262 + q->limits.max_user_sectors = max_sectors_kb << 1; 263 + } 255 264 256 265 spin_lock_irq(&q->queue_lock); 257 266 q->limits.max_sectors = max_sectors_kb << 1;
+1
include/linux/blkdev.h
··· 288 288 unsigned int max_dev_sectors; 289 289 unsigned int chunk_sectors; 290 290 unsigned int max_sectors; 291 + unsigned int max_user_sectors; 291 292 unsigned int max_segment_size; 292 293 unsigned int physical_block_size; 293 294 unsigned int logical_block_size;