Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp613051ybj; Thu, 7 May 2020 03:36:35 -0700 (PDT) X-Google-Smtp-Source: APiQypIaxnW8fXKiVyckkrO104VYF66y2CMOhg1OWhmnunGkR9WLLgu+7qi0GVKYftL+r1Cugt8O X-Received: by 2002:a05:6402:3046:: with SMTP id bu6mr11060746edb.106.1588847795077; Thu, 07 May 2020 03:36:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588847795; cv=none; d=google.com; s=arc-20160816; b=lIONV6DrT1iIy4oYsTwedVkzu1ov7D5d7aRuXAtu3Y7VZT5qGlOy5YRL5Lr/4Wq7DG GFrzD+48TtulLqvXYuD4EALsUOaJJJb7O0pTMi4mNVkHGz34LmnrPGxnodj4XwUaKSSF pFXF70Wic/e1adoyDB06LCQg/cVKEIvC1PqqWZtd/nQiX/OFPYUfqy6saVLAAom6EpIM V0/AbP7fX4Xr7YfYtvXMhnUCXytt+Tb+YfzElU1wf2oUlDxsRXMGkoKTGT4ebQ9DXf3a rTp61e82klj8JUIt2CniMdFMYrasOTfUMS93yBOKayQe/niN5CwCkqkjCXFy2xIiuhe9 8Mnw== 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=VV+XtjN/vOPWAyzHKaECo8g5UUJQog8PwMWqUHC0ZqQ=; b=HINIczc31YzdsG5HesW6uUrHGxgdrLUfZwaEvLl3asRb8YmaBUOXmEgZhE1ukzXaF+ 6iOI3/2M65hIFr9lRzieXUxh/8bPrxY6Tg/gg5PV0ynmlDMQOVpCnZD7Enp2O5Tzoy2A LAQZfYsovHM41LcJsWPigyrRJ4Rd7doNXZ9CGMbh3Uq5fHtDoaKbSQI4Awn7bWPxTu1b b71oqQZkzDTryXETlENiI9cNVkrfVkQcSolAIpuJqiNkkxCM8pvw196b/Vr2RfsHMCmc no08Ac8ubQ2zkpZdOn5mqTHJviEKOY3swDen9qAFciAFOzmtpkfgnciLb0U1N3qH+kOY qQug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VziDYe4z; 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 p25si2920105eji.408.2020.05.07.03.36.10; Thu, 07 May 2020 03:36:35 -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=VziDYe4z; 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 S1727925AbgEGKd5 (ORCPT + 99 others); Thu, 7 May 2020 06:33:57 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:43454 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727837AbgEGKde (ORCPT ); Thu, 7 May 2020 06:33:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588847613; 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=VV+XtjN/vOPWAyzHKaECo8g5UUJQog8PwMWqUHC0ZqQ=; b=VziDYe4zlVV7aWragQNspBUUt1IewYbRRu+h9n84Ds92rwLJl4OHopwPilANsZ49LYKzEH 74jQFVmxW2XS+h6Ij+BW1klYywy7MiObu4gTdQE1djyLbcy43vbmwABdmT4CNxyeAjSkCR EWkADWMsk+LhzwiJhXT1/n+lA54l+PU= 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-494-pwgm0o-_Ms-r2SPNS6lnKg-1; Thu, 07 May 2020 06:33:31 -0400 X-MC-Unique: pwgm0o-_Ms-r2SPNS6lnKg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D6E7980183C; Thu, 7 May 2020 10:33:29 +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 D761E5D9C5; Thu, 7 May 2020 10:33:27 +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 Subject: [PATCH v3 13/15] virtio-mem: Unplug subblocks right-to-left Date: Thu, 7 May 2020 12:31:17 +0200 Message-Id: <20200507103119.11219-14-david@redhat.com> In-Reply-To: <20200507103119.11219-1-david@redhat.com> References: <20200507103119.11219-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We unplug blocks right-to-left, let's also unplug subblocks within a bloc= k right-to-left. Cc: "Michael S. Tsirkin" Cc: Pankaj Gupta Signed-off-by: David Hildenbrand --- drivers/virtio/virtio_mem.c | 38 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 8dd57b61b09b..a719e1a04ac7 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -353,18 +353,6 @@ static bool virtio_mem_mb_test_sb_unplugged(struct v= irtio_mem *vm, return find_next_bit(vm->sb_bitmap, bit + count, bit) >=3D bit + count; } =20 -/* - * Find the first plugged subblock. Returns vm->nb_sb_per_mb in case the= re is - * none. - */ -static int virtio_mem_mb_first_plugged_sb(struct virtio_mem *vm, - unsigned long mb_id) -{ - const int bit =3D (mb_id - vm->first_mb_id) * vm->nb_sb_per_mb; - - return find_next_bit(vm->sb_bitmap, bit + vm->nb_sb_per_mb, bit) - bit; -} - /* * Find the first unplugged subblock. Returns vm->nb_sb_per_mb in case t= here is * none. @@ -1016,21 +1004,27 @@ static int virtio_mem_mb_unplug_any_sb(struct vir= tio_mem *vm, int sb_id, count; int rc; =20 + sb_id =3D vm->nb_sb_per_mb - 1; while (*nb_sb) { - sb_id =3D virtio_mem_mb_first_plugged_sb(vm, mb_id); - if (sb_id >=3D vm->nb_sb_per_mb) + /* Find the next candidate subblock */ + while (sb_id >=3D 0 && + virtio_mem_mb_test_sb_unplugged(vm, mb_id, sb_id, 1)) + sb_id--; + if (sb_id < 0) break; + /* Try to unplug multiple subblocks at a time */ count =3D 1; - while (count < *nb_sb && - sb_id + count < vm->nb_sb_per_mb && - virtio_mem_mb_test_sb_plugged(vm, mb_id, sb_id + count, - 1)) + while (count < *nb_sb && sb_id > 0 && + virtio_mem_mb_test_sb_plugged(vm, mb_id, sb_id - 1, 1)) { count++; + sb_id--; + } =20 rc =3D virtio_mem_mb_unplug_sb(vm, mb_id, sb_id, count); if (rc) return rc; *nb_sb -=3D count; + sb_id--; } =20 return 0; @@ -1337,12 +1331,12 @@ static int virtio_mem_mb_unplug_any_sb_online(str= uct virtio_mem *vm, * we should sense via something like is_mem_section_removable() * first if it makes sense to go ahead any try to allocate. */ - for (sb_id =3D 0; sb_id < vm->nb_sb_per_mb && *nb_sb; sb_id++) { + for (sb_id =3D vm->nb_sb_per_mb - 1; sb_id >=3D 0 && *nb_sb; sb_id--) { /* Find the next candidate subblock */ - while (sb_id < vm->nb_sb_per_mb && + while (sb_id >=3D 0 && !virtio_mem_mb_test_sb_plugged(vm, mb_id, sb_id, 1)) - sb_id++; - if (sb_id >=3D vm->nb_sb_per_mb) + sb_id--; + if (sb_id < 0) break; =20 start_pfn =3D PFN_DOWN(virtio_mem_mb_id_to_phys(mb_id) + --=20 2.25.3