Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp764635ybh; Wed, 11 Mar 2020 10:19:11 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs6FolvESSa/ZoH266Oyz1/aDGofdyUVEFJBTAZvurwAU+s7/ckqP8SXImOrDV1Riw6aa7X X-Received: by 2002:a9d:48d:: with SMTP id 13mr2937917otm.249.1583947151400; Wed, 11 Mar 2020 10:19:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583947151; cv=none; d=google.com; s=arc-20160816; b=WgM/UNFrCzMt4XicQ4V0+TVG6r8F4+IpLnIRKDkFSzL/LarNSYhPy9qaQJNklFUIcO 3potssy6SmIwrUXVunpJLvLBXQ6Df+Y5MugXLnVvVjHOcpERi16K9bpFrSC82H2PB1au 0TyQAEfEcSAOZzV8TXSKaVVzANzypwn7gJ3yabtmoa3zLWCXtdAnFh8zka0uQaQmMIoy GoVzS0vo8KWPK3OUgcWedzIln7g8s0qaOxQ1J1nf4G2UEYoz0HYDtfhjgRGxUM+Icz54 GzQmt0v/LEeB8wQ2Q6Jz443yLyLLz0DUgUwLNKhsxmxYF6IL8c5NWK0Kr0K86BZp04HU BzBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T8uHgWgRrKhjOS0/8z1+bbTJM5VUQNPPAg1DCmOx02I=; b=dzZ2UnuKkQv/3o7wlq+Lh+E3xm1SBEm8MQcMGpOg1ePg4fWpoLrCDFjGBjgQDFTd/Q P/KEhsF/tGtwW1H/d85MeN95h0k03Un/RSbgT3LWHOjzstmyMytHeHtUmeuHupNYQmct DvjdlZdjm3oHkCVqeX8f31EglhIKgr3cSu2znQyPdDlyOFUzXMWuQ7dGbGSBNtOMdTTY 9yEUApf8jg9NtNPpYZ5ERpg/DLm4vyMwDVfOj5aTa590eRoqRqtXA0V+wnlygaRljEsz RtFm7v8yzlKgaDGSb1BZc7OKCgQx2QBMqEQe1KeJNcpQeCYV0gErmJOZX5jL6udvYksS GtiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Cyjd/D0b"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si402749ood.43.2020.03.11.10.18.57; Wed, 11 Mar 2020 10:19:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Cyjd/D0b"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730545AbgCKRQp (ORCPT + 99 others); Wed, 11 Mar 2020 13:16:45 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53215 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730362AbgCKRQo (ORCPT ); Wed, 11 Mar 2020 13:16:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583947004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T8uHgWgRrKhjOS0/8z1+bbTJM5VUQNPPAg1DCmOx02I=; b=Cyjd/D0bXCZLp8TYtNSXBshwLqYXHbrtyWMC9BtyTBzITP0FQ0cXj012ngDtRgpVKee02i pxct2wRoJ4OrzrZmJf5kzFCWdOJBLu0QabIppWxmga+AwAKS1kenP00PR+ivOp6RU2/S2i htZE200AAg7S+82BmlKJ1dV0nIcsZbM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-288-0R_hVMT8Osu2Hnt2IwParA-1; Wed, 11 Mar 2020 13:16:40 -0400 X-MC-Unique: 0R_hVMT8Osu2Hnt2IwParA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 43FB4800D5E; Wed, 11 Mar 2020 17:16:38 +0000 (UTC) Received: from t480s.redhat.com (ovpn-116-132.ams2.redhat.com [10.36.116.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id C87DD60BEE; Wed, 11 Mar 2020 17:16:23 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, virtio-dev@lists.oasis-open.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Michal Hocko , Andrew Morton , "Michael S . Tsirkin" , David Hildenbrand , Jason Wang , Oscar Salvador , Igor Mammedov , Dave Young , Dan Williams , Pavel Tatashin , Stefan Hajnoczi , Vlastimil Babka Subject: [PATCH v2 09/10] virtio-mem: Better retry handling Date: Wed, 11 Mar 2020 18:14:21 +0100 Message-Id: <20200311171422.10484-10-david@redhat.com> In-Reply-To: <20200311171422.10484-1-david@redhat.com> References: <20200311171422.10484-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). Cc: "Michael S. Tsirkin" Cc: Jason Wang Cc: Oscar Salvador Cc: Michal Hocko Cc: Igor Mammedov Cc: Dave Young Cc: Andrew Morton Cc: Dan Williams Cc: Pavel Tatashin Cc: Stefan Hajnoczi Cc: Vlastimil Babka Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index aa322e7732a4..48e96702d4ce 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -138,7 +138,9 @@ struct virtio_mem { =20 /* Timer for retrying to plug/unplug memory. */ struct hrtimer retry_timer; -#define VIRTIO_MEM_RETRY_TIMER_MS 30000 + unsigned int retry_timer_ms; +#define VIRTIO_MEM_RETRY_TIMER_MIN_MS 50000 +#define VIRTIO_MEM_RETRY_TIMER_MAX_MS 300000 =20 /* Memory notifier (online/offline events). */ struct notifier_block memory_notifier; @@ -1548,6 +1550,7 @@ static void virtio_mem_run_wq(struct work_struct *w= ork) =20 switch (rc) { case 0: + vm->retry_timer_ms =3D VIRTIO_MEM_RETRY_TIMER_MIN_MS; break; case -ENOSPC: /* @@ -1563,8 +1566,7 @@ static void virtio_mem_run_wq(struct work_struct *w= ork) */ case -ENOMEM: /* Out of memory, try again later. */ - hrtimer_start(&vm->retry_timer, - ms_to_ktime(VIRTIO_MEM_RETRY_TIMER_MS), + hrtimer_start(&vm->retry_timer, ms_to_ktime(vm->retry_timer_ms), HRTIMER_MODE_REL); break; case -EAGAIN: @@ -1584,6 +1586,8 @@ static enum hrtimer_restart virtio_mem_timer_expire= d(struct hrtimer *timer) retry_timer); =20 virtio_mem_retry(vm); + vm->retry_timer_ms =3D min_t(unsigned int, vm->retry_timer_ms * 2, + VIRTIO_MEM_RETRY_TIMER_MAX_MS); return HRTIMER_NORESTART; } =20 @@ -1750,6 +1754,7 @@ static int virtio_mem_probe(struct virtio_device *v= dev) spin_lock_init(&vm->removal_lock); hrtimer_init(&vm->retry_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); vm->retry_timer.function =3D virtio_mem_timer_expired; + vm->retry_timer_ms =3D VIRTIO_MEM_RETRY_TIMER_MIN_MS; =20 /* register the virtqueue */ rc =3D virtio_mem_init_vq(vm); --=20 2.24.1