Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp763674ybj; Thu, 7 May 2020 07:09:16 -0700 (PDT) X-Google-Smtp-Source: APiQypLbYfvW8ApFBYWXEhEe4dbJMwbWoezsu+df6UFgur//J7nW6jYdld1j56N538TAZOzY2AnH X-Received: by 2002:a17:906:2296:: with SMTP id p22mr12133711eja.269.1588860556556; Thu, 07 May 2020 07:09:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588860556; cv=none; d=google.com; s=arc-20160816; b=ehxsEEDmBquLZ7NEAkH15hz+RNQuH52GOp4JNHsbpUFBGbk+uQ00Ihn2EGUWHLPZx7 TJd6MvgWmxgEaQskiBHG1XXQpt1q7KUrDjwsQNlN7NQF88082ZnddymPtyDJQajdSQhH FQCJNk/Oo6LpY7uWA+B8UDAxNsNf0tbkcs/aIGloYlkPQYV0ejH3SEGoC1c1B0MzR86s BfnBIYvyP+K1p99KmXrpXEkhDxFF/uWVzg2a9R7yxb4mlN78WVNtNyGRs2NH/EXOf5NT frqvFraGxDNSfAJSzjiDDugpSnhaNJFSIL9VoJBNXAFKo+3hrXulg9Rt5UsRHIYgzzbQ eTaw== 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=mneKSrcFh5+MZzllxZ6nUp+i4lcHd2Bq+t93L/e/DVA=; b=ESYwhQk4WlCMhUY0BU9vSWHomr304JwrQrlAiUl/gZ6s/Z9wqHsh+o0juGy8njblfC /SyTN5j9XHhadeHDGSN4yjDZ3q248W5NUoMUHRehn8vZHiF0nFxeIj/t3yE7nQj/m23E DsMqs6h0HKgMXwq7TQNudsTN1vEYigiHZm0mDaIQO0soeQNM8ULWLNq4194yflLQWbe5 u9HU8HzYduM7vGytP2QXOrWSW0ISKPdoduTq8/rSuPJAUqdXE+CAzcwSJf24usOYKAE3 VL0FHyQ9vrS4Gg+2/Lg/7z6Zh4Tu4y+Tv6/GG4J+tyyScbmuSrlVP/raU5k0c2cubX5m KdSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DnDifyvM; 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 n1si2861807ejr.104.2020.05.07.07.08.52; Thu, 07 May 2020 07:09:16 -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=DnDifyvM; 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 S1727954AbgEGODw (ORCPT + 99 others); Thu, 7 May 2020 10:03:52 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:31916 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727904AbgEGODp (ORCPT ); Thu, 7 May 2020 10:03:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588860223; 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=mneKSrcFh5+MZzllxZ6nUp+i4lcHd2Bq+t93L/e/DVA=; b=DnDifyvM1riFCNssGNw4eH/5A8stCR99xS9AskCqT/i0ZJ2Hs93+HkNoQbQiW89WYG8Q09 akWOWZW5Mn/AxZy5KAprhWf1Rp3Co6e3ACOmNymf9dtmIkFWLVeU2AEYwQf95S6cVJDisP g7F+M1JniBmOmjHVQ+Q7iT6tnnRzpAg= 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-339-jkKsHUXTMYKhCTvguYHs1w-1; Thu, 07 May 2020 10:03:40 -0400 X-MC-Unique: jkKsHUXTMYKhCTvguYHs1w-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 D3E141895950; Thu, 7 May 2020 14:03:38 +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 CCE136109E; Thu, 7 May 2020 14:03:36 +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 v4 13/15] virtio-mem: Unplug subblocks right-to-left Date: Thu, 7 May 2020 16:01:37 +0200 Message-Id: <20200507140139.17083-14-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 We unplug blocks right-to-left, let's also unplug subblocks within a block 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 virtio_mem *vm, return find_next_bit(vm->sb_bitmap, bit + count, bit) >= bit + count; } -/* - * Find the first plugged subblock. Returns vm->nb_sb_per_mb in case there is - * none. - */ -static int virtio_mem_mb_first_plugged_sb(struct virtio_mem *vm, - unsigned long mb_id) -{ - const int bit = (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 there is * none. @@ -1016,21 +1004,27 @@ static int virtio_mem_mb_unplug_any_sb(struct virtio_mem *vm, int sb_id, count; int rc; + sb_id = vm->nb_sb_per_mb - 1; while (*nb_sb) { - sb_id = virtio_mem_mb_first_plugged_sb(vm, mb_id); - if (sb_id >= vm->nb_sb_per_mb) + /* Find the next candidate subblock */ + while (sb_id >= 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 = 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--; + } rc = virtio_mem_mb_unplug_sb(vm, mb_id, sb_id, count); if (rc) return rc; *nb_sb -= count; + sb_id--; } return 0; @@ -1337,12 +1331,12 @@ static int virtio_mem_mb_unplug_any_sb_online(struct 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 = 0; sb_id < vm->nb_sb_per_mb && *nb_sb; sb_id++) { + for (sb_id = vm->nb_sb_per_mb - 1; sb_id >= 0 && *nb_sb; sb_id--) { /* Find the next candidate subblock */ - while (sb_id < vm->nb_sb_per_mb && + while (sb_id >= 0 && !virtio_mem_mb_test_sb_plugged(vm, mb_id, sb_id, 1)) - sb_id++; - if (sb_id >= vm->nb_sb_per_mb) + sb_id--; + if (sb_id < 0) break; start_pfn = PFN_DOWN(virtio_mem_mb_id_to_phys(mb_id) + -- 2.25.3