Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp761837ybj; Thu, 7 May 2020 07:07:01 -0700 (PDT) X-Google-Smtp-Source: APiQypKXCLUcXT9/IVxu1gefV4Q1VY4A+kApOlb85RGUMAzBe7EK7boBiM2VVn2PZtCS7NmhTOu8 X-Received: by 2002:a17:907:4304:: with SMTP id nh4mr7525481ejb.193.1588860421165; Thu, 07 May 2020 07:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588860421; cv=none; d=google.com; s=arc-20160816; b=B4mvDsDv3fVW3t0UY1fl5EGxFGRCXYTdhyCDnhd9lTLN67hvn/+Mx/gkdNva7TKwi5 wrCPZwB4NYjtDI1eMnD3p9HrtW11q/ke4aNte0YLVNKJp4j1liNxwk0T9gca0by9Jegi oVcrfHOJHj6pZKFC9hUK5ODYyCcXkYH3LDpYNOtTt0angU2nbkq1Ks4P6F8T2BxUw71N 4iJbru02mLX0KfNS3i3LrzPEoqh7vEEom9TMjWQ+f5qINd+4YIwDszJiUi/WWNvT7NGn etEyL/n5eC6rSFxftH4ifTaPgAcqRwB6sWTtw+1OW1f8tVs8sJDKYjh7IfrPUrU4b+FY akrA== 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=13CBXUgFaROppSBpwCabjmSoPoTrMXx78+A8AjTRtPc=; b=vuK2zgmZ9E6lIvk/MHXiVgTr2suKUKQXxkRxppXTjoiHEf1T28IquxHCv+Rkj1s4Lr 9ZDsqB2OYGrL8L/+25DlEkvyC9rPnRp+WkkTE0006r462e4DbBy7Mr8Dl/FdXMzrJb7f 8AlWo8Bcc5IGcWT8W2MOgsjvMBe84pda0i8+/ZvON09CeE/zR7gqQxoI8R1CQrU1Dzrl CYSXoixbLOreFW84xRMVlqvyRBWfXB4/3w9ew2UDKzY9m9b6IMogyAlz/7Io0YG1qTqK VgLoYqXDuj5tAEPjVewVgrnNo0TV5GxrdERADReC3EHYMSrOliqJc7Azsq6vV35oo05h ciSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hIw+3k9U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id z18si3209203ejf.186.2020.05.07.07.06.34; Thu, 07 May 2020 07:07:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hIw+3k9U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727871AbgEGODi (ORCPT + 99 others); Thu, 7 May 2020 10:03:38 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:26179 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727853AbgEGODg (ORCPT ); Thu, 7 May 2020 10:03:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588860213; 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=13CBXUgFaROppSBpwCabjmSoPoTrMXx78+A8AjTRtPc=; b=hIw+3k9UO45A2TyeNMdWjLBmMHcD2AlotIuSfqbzg9ineo0jhGShfqXTa2eiwNN8rNU5yH t3anOxV13hXQwtYicsJObfKboNsuZuXAAz6VosEj29ZLkqFZoMGeHpIBzth6D1U2R2D0CQ avhhAeuuzbS/i7gnZwdAG2Zo+Dp28fs= 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-257-aATx9xwONgiOsdZL0sO6iA-1; Thu, 07 May 2020 10:03:28 -0400 X-MC-Unique: aATx9xwONgiOsdZL0sO6iA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F3858BF624; Thu, 7 May 2020 14:03:26 +0000 (UTC) Received: from t480s.redhat.com (ovpn-113-245.ams2.redhat.com [10.36.113.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77E936109E; Thu, 7 May 2020 14:03:20 +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 , Pankaj Gupta , Jason Wang , Oscar Salvador , Igor Mammedov , Dave Young , Dan Williams , Pavel Tatashin , Stefan Hajnoczi , Vlastimil Babka Subject: [PATCH v4 10/15] virtio-mem: Better retry handling Date: Thu, 7 May 2020 16:01:34 +0200 Message-Id: <20200507140139.17083-11-david@redhat.com> In-Reply-To: <20200507140139.17083-1-david@redhat.com> References: <20200507140139.17083-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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). Tested-by: Pankaj Gupta 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 a2edb87e5ed8..eb4c16d634e0 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -141,7 +141,9 @@ struct virtio_mem { /* 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 /* Memory notifier (online/offline events). */ struct notifier_block memory_notifier; @@ -1550,6 +1552,7 @@ static void virtio_mem_run_wq(struct work_struct *work) switch (rc) { case 0: + vm->retry_timer_ms = VIRTIO_MEM_RETRY_TIMER_MIN_MS; break; case -ENOSPC: /* @@ -1565,8 +1568,7 @@ static void virtio_mem_run_wq(struct work_struct *work) */ 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: @@ -1586,6 +1588,8 @@ static enum hrtimer_restart virtio_mem_timer_expired(struct hrtimer *timer) retry_timer); virtio_mem_retry(vm); + vm->retry_timer_ms = min_t(unsigned int, vm->retry_timer_ms * 2, + VIRTIO_MEM_RETRY_TIMER_MAX_MS); return HRTIMER_NORESTART; } @@ -1754,6 +1758,7 @@ static int virtio_mem_probe(struct virtio_device *vdev) spin_lock_init(&vm->removal_lock); hrtimer_init(&vm->retry_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); vm->retry_timer.function = virtio_mem_timer_expired; + vm->retry_timer_ms = VIRTIO_MEM_RETRY_TIMER_MIN_MS; /* register the virtqueue */ rc = virtio_mem_init_vq(vm); -- 2.25.3