[PATCH] random: give up adding randomness to the entropy pool when block devices are busy
From: Kazuya Hisaki
Date: Thu Mar 27 2014 - 07:44:08 EST
Hi,
This gives up adding randomness to the entropy pool when block devices
are busy, to avoid lock contention in I/O intensive situation.
Currently randomness is added to the entropy pool for each 4096 I/O
completion, and holds a global spinlock during its process.
Contention for the spinlock occurs In I/O intensive situation that
many cores process I/O completions, even each core processes
completion for different block device.
This just replaces spin_lock_irqsave() in mix_pool_bytes()
with spin_trylock_irqsave(), and gives up adding randomness
when trylock is failed.
And, it moves trace_mix_pool_bytes() after lock, to trace
events only where addition of randomness is executed.
Thank you,
Signed-off-by: Kazuya Hisaki <kazuya.hisaki.bx@xxxxxxxxxxx>
Cc: "Theodore Ts'o" <tytso@xxxxxxx>
Cc: Arnd Bergmann <arnd@xxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Cc: linux-kernel@xxxxxxxxxxxxxxx
---
drivers/char/random.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 429b75b..d2603f8 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -545,8 +545,9 @@ static void mix_pool_bytes(struct entropy_store *r, const void *in,
{
unsigned long flags;
+ if (!spin_trylock_irqsave(&r->lock, flags))
+ return;
trace_mix_pool_bytes(r->name, nbytes, _RET_IP_);
- spin_lock_irqsave(&r->lock, flags);
_mix_pool_bytes(r, in, nbytes, out);
spin_unlock_irqrestore(&r->lock, flags);
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/