Skip to content

Commit 23e77b5

Browse files
davidhildenbrandmstsirkin
authored andcommitted
virtio-mem: Better retry handling
Let's start with a retry interval of 5 seconds and double the time until we reach 5 minutes, in case we keep getting errors. Reset the retry interval in case we succeeded. The two main reasons for having to retry are - The hypervisor is busy and cannot process our request - We cannot reach the desired requested_size (esp., not enough memory can get unplugged because we can't allocate any subblocks). Tested-by: Pankaj Gupta <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: Jason Wang <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Igor Mammedov <[email protected]> Cc: Dave Young <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Dan Williams <[email protected]> Cc: Pavel Tatashin <[email protected]> Cc: Stefan Hajnoczi <[email protected]> Cc: Vlastimil Babka <[email protected]> Signed-off-by: David Hildenbrand <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent a573238 commit 23e77b5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/virtio/virtio_mem.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ struct virtio_mem {
141141

142142
/* Timer for retrying to plug/unplug memory. */
143143
struct hrtimer retry_timer;
144-
#define VIRTIO_MEM_RETRY_TIMER_MS 30000
144+
unsigned int retry_timer_ms;
145+
#define VIRTIO_MEM_RETRY_TIMER_MIN_MS 50000
146+
#define VIRTIO_MEM_RETRY_TIMER_MAX_MS 300000
145147

146148
/* Memory notifier (online/offline events). */
147149
struct notifier_block memory_notifier;
@@ -1550,6 +1552,7 @@ static void virtio_mem_run_wq(struct work_struct *work)
15501552

15511553
switch (rc) {
15521554
case 0:
1555+
vm->retry_timer_ms = VIRTIO_MEM_RETRY_TIMER_MIN_MS;
15531556
break;
15541557
case -ENOSPC:
15551558
/*
@@ -1565,8 +1568,7 @@ static void virtio_mem_run_wq(struct work_struct *work)
15651568
*/
15661569
case -ENOMEM:
15671570
/* Out of memory, try again later. */
1568-
hrtimer_start(&vm->retry_timer,
1569-
ms_to_ktime(VIRTIO_MEM_RETRY_TIMER_MS),
1571+
hrtimer_start(&vm->retry_timer, ms_to_ktime(vm->retry_timer_ms),
15701572
HRTIMER_MODE_REL);
15711573
break;
15721574
case -EAGAIN:
@@ -1586,6 +1588,8 @@ static enum hrtimer_restart virtio_mem_timer_expired(struct hrtimer *timer)
15861588
retry_timer);
15871589

15881590
virtio_mem_retry(vm);
1591+
vm->retry_timer_ms = min_t(unsigned int, vm->retry_timer_ms * 2,
1592+
VIRTIO_MEM_RETRY_TIMER_MAX_MS);
15891593
return HRTIMER_NORESTART;
15901594
}
15911595

@@ -1754,6 +1758,7 @@ static int virtio_mem_probe(struct virtio_device *vdev)
17541758
spin_lock_init(&vm->removal_lock);
17551759
hrtimer_init(&vm->retry_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
17561760
vm->retry_timer.function = virtio_mem_timer_expired;
1761+
vm->retry_timer_ms = VIRTIO_MEM_RETRY_TIMER_MIN_MS;
17571762

17581763
/* register the virtqueue */
17591764
rc = virtio_mem_init_vq(vm);

0 commit comments

Comments
 (0)