Skip to content

Commit e2e1a14

Browse files
author
Jens Axboe
committed
block: add sysfs knob for turning off disk entropy contributions
There are two reasons for doing this: - On SSD disks, the completion times aren't as random as they are for rotational drives. So it's questionable whether they should contribute to the random pool in the first place. - Calling add_disk_randomness() has a lot of overhead. This adds /sys/block/<dev>/queue/add_random that will allow you to switch off on a per-device basis. The default setting is on, so there should be no functional changes from this patch. Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent 841fdff commit e2e1a14

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎block/blk-core.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2111,7 +2111,8 @@ static bool blk_update_bidi_request(struct request *rq, int error,
21112111
blk_update_request(rq->next_rq, error, bidi_bytes))
21122112
return true;
21132113

2114-
add_disk_randomness(rq->rq_disk);
2114+
if (blk_queue_add_random(rq->q))
2115+
add_disk_randomness(rq->rq_disk);
21152116

21162117
return false;
21172118
}

‎block/blk-sysfs.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,27 @@ queue_rq_affinity_store(struct request_queue *q, const char *page, size_t count)
250250
return ret;
251251
}
252252

253+
static ssize_t queue_random_show(struct request_queue *q, char *page)
254+
{
255+
return queue_var_show(blk_queue_add_random(q), page);
256+
}
257+
258+
static ssize_t queue_random_store(struct request_queue *q, const char *page,
259+
size_t count)
260+
{
261+
unsigned long val;
262+
ssize_t ret = queue_var_store(&val, page, count);
263+
264+
spin_lock_irq(q->queue_lock);
265+
if (val)
266+
queue_flag_set(QUEUE_FLAG_ADD_RANDOM, q);
267+
else
268+
queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, q);
269+
spin_unlock_irq(q->queue_lock);
270+
271+
return ret;
272+
}
273+
253274
static ssize_t queue_iostats_show(struct request_queue *q, char *page)
254275
{
255276
return queue_var_show(blk_queue_io_stat(q), page);
@@ -374,6 +395,12 @@ static struct queue_sysfs_entry queue_iostats_entry = {
374395
.store = queue_iostats_store,
375396
};
376397

398+
static struct queue_sysfs_entry queue_random_entry = {
399+
.attr = {.name = "add_random", .mode = S_IRUGO | S_IWUSR },
400+
.show = queue_random_show,
401+
.store = queue_random_store,
402+
};
403+
377404
static struct attribute *default_attrs[] = {
378405
&queue_requests_entry.attr,
379406
&queue_ra_entry.attr,
@@ -394,6 +421,7 @@ static struct attribute *default_attrs[] = {
394421
&queue_nomerges_entry.attr,
395422
&queue_rq_affinity_entry.attr,
396423
&queue_iostats_entry.attr,
424+
&queue_random_entry.attr,
397425
NULL,
398426
};
399427

‎include/linux/blkdev.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,13 @@ struct request_queue
467467
#define QUEUE_FLAG_IO_STAT 15 /* do IO stats */
468468
#define QUEUE_FLAG_DISCARD 16 /* supports DISCARD */
469469
#define QUEUE_FLAG_NOXMERGES 17 /* No extended merges */
470+
#define QUEUE_FLAG_ADD_RANDOM 18 /* Contributes to random pool */
470471

471472
#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
472473
(1 << QUEUE_FLAG_CLUSTER) | \
473474
(1 << QUEUE_FLAG_STACKABLE) | \
474-
(1 << QUEUE_FLAG_SAME_COMP))
475+
(1 << QUEUE_FLAG_SAME_COMP) | \
476+
(1 << QUEUE_FLAG_ADD_RANDOM))
475477

476478
static inline int queue_is_locked(struct request_queue *q)
477479
{
@@ -596,6 +598,7 @@ enum {
596598
test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
597599
#define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags)
598600
#define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
601+
#define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags)
599602
#define blk_queue_flushing(q) ((q)->ordseq)
600603
#define blk_queue_stackable(q) \
601604
test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)

0 commit comments

Comments
 (0)