mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
block: make /sys/block/<dev>/queue/discard_max_bytes writeable
Lots of devices support huge discard sizes these days. Depending on how the device handles them internally, huge discards can introduce massive latencies (hundreds of msec) on the device side. We have a sysfs file, discard_max_bytes, that advertises the max hardware supported discard size. Make this writeable, and split the settings into a soft and hard limit. This can be set from 'discard_granularity' and up to the hardware limit. Add a new sysfs file, 'discard_max_hw_bytes', that shows the hw set limit. Reviewed-by: Jeff Moyer <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
This commit is contained in:
parent
2bb4cd5cc4
commit
0034af0365
4 changed files with 53 additions and 2 deletions
|
|
@ -145,12 +145,43 @@ static ssize_t queue_discard_granularity_show(struct request_queue *q, char *pag
|
|||
return queue_var_show(q->limits.discard_granularity, page);
|
||||
}
|
||||
|
||||
static ssize_t queue_discard_max_hw_show(struct request_queue *q, char *page)
|
||||
{
|
||||
unsigned long long val;
|
||||
|
||||
val = q->limits.max_hw_discard_sectors << 9;
|
||||
return sprintf(page, "%llu\n", val);
|
||||
}
|
||||
|
||||
static ssize_t queue_discard_max_show(struct request_queue *q, char *page)
|
||||
{
|
||||
return sprintf(page, "%llu\n",
|
||||
(unsigned long long)q->limits.max_discard_sectors << 9);
|
||||
}
|
||||
|
||||
static ssize_t queue_discard_max_store(struct request_queue *q,
|
||||
const char *page, size_t count)
|
||||
{
|
||||
unsigned long max_discard;
|
||||
ssize_t ret = queue_var_store(&max_discard, page, count);
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (max_discard & (q->limits.discard_granularity - 1))
|
||||
return -EINVAL;
|
||||
|
||||
max_discard >>= 9;
|
||||
if (max_discard > UINT_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
if (max_discard > q->limits.max_hw_discard_sectors)
|
||||
max_discard = q->limits.max_hw_discard_sectors;
|
||||
|
||||
q->limits.max_discard_sectors = max_discard;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *page)
|
||||
{
|
||||
return queue_var_show(queue_discard_zeroes_data(q), page);
|
||||
|
|
@ -360,9 +391,15 @@ static struct queue_sysfs_entry queue_discard_granularity_entry = {
|
|||
.show = queue_discard_granularity_show,
|
||||
};
|
||||
|
||||
static struct queue_sysfs_entry queue_discard_max_hw_entry = {
|
||||
.attr = {.name = "discard_max_hw_bytes", .mode = S_IRUGO },
|
||||
.show = queue_discard_max_hw_show,
|
||||
};
|
||||
|
||||
static struct queue_sysfs_entry queue_discard_max_entry = {
|
||||
.attr = {.name = "discard_max_bytes", .mode = S_IRUGO },
|
||||
.attr = {.name = "discard_max_bytes", .mode = S_IRUGO | S_IWUSR },
|
||||
.show = queue_discard_max_show,
|
||||
.store = queue_discard_max_store,
|
||||
};
|
||||
|
||||
static struct queue_sysfs_entry queue_discard_zeroes_data_entry = {
|
||||
|
|
@ -421,6 +458,7 @@ static struct attribute *default_attrs[] = {
|
|||
&queue_io_opt_entry.attr,
|
||||
&queue_discard_granularity_entry.attr,
|
||||
&queue_discard_max_entry.attr,
|
||||
&queue_discard_max_hw_entry.attr,
|
||||
&queue_discard_zeroes_data_entry.attr,
|
||||
&queue_write_same_max_entry.attr,
|
||||
&queue_nonrot_entry.attr,
|
||||
|
|
|
|||
Loading…
Reference in a new issue