Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp168774pxb; Wed, 27 Oct 2021 00:17:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzUPOEaTdY9H5kAnjW1JXZIRR0epurMfIlZHFvFv0uYKucTD2Ag09NXso2FJx703QBuXel X-Received: by 2002:a17:90b:4c4f:: with SMTP id np15mr2466655pjb.48.1635319023996; Wed, 27 Oct 2021 00:17:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635319023; cv=none; d=google.com; s=arc-20160816; b=nROHuL4EI22FuMtFuVxQwgcXGto14P2kK9TcNZ2muTr6Dw8pTBkRlS8M8svvZg9DpS UWD7h/szcbTXFh2izQCBUdARaBThZE1OZlyhJE9h8wKAfJKd2e459Lv2yAlIIyD3UJvv dDFh90KhTYThgVskqemj4CoWeoclHKaAgQxslkYWfkyAa4W0f1AAxZXa23a9mxCO5ai7 KXLDawSLwwDkR/eD4Nf76qcr06lZRGAoyaYvxmdpozPzdWe/B/uVnbNtcfJwYXoyWRIh Y0Ji99ukW08VHnpqLX118nVXNjJrNoV6Q/ZOS7oJO2eoeVb6iJo3SUgiKldjPMM2/1/m m24A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=8o2OX0MoA2BHPQbDzrPvGQhav9Hnok7epmkumfkbe9I=; b=VdPJMUFVljUx0NIFGPj1Bn1u9vh6IPWRPGTpV1hQR6D67vCKCqWQTlxGzsnZZPha7T HveT08zCr2d+3fWSK2jthktnAEN5iRzHnesQqe+xHX419I5l7vKFXdjK0+k4tBtL0RBH VnBJrtAoSbHkyY3/Yh5Ipa4KX7KVTMXQbFOMMWslZx+RjJER9yaVY7i87FjMTUFwM7oN 5f3CzVJ9H4I2xAtb5CLZVVrNKdqYJ0UgGBVCMMG29zV0JFzZGLd0gcQ1ISJMRvB/g/cI k0EpF8RB/pcCEs5lg599letmKITxSHZPiaxfO/DO4EArhS8W61edJ3jKSbge7ZJOl3+2 K42g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v23si8684775ple.9.2021.10.27.00.16.51; Wed, 27 Oct 2021 00:17:03 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236409AbhJZSs6 (ORCPT + 99 others); Tue, 26 Oct 2021 14:48:58 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:49342 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238414AbhJZSsz (ORCPT ); Tue, 26 Oct 2021 14:48:55 -0400 Received: from MUA by vps-vb.mhejs.net with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mfRSn-0007Fb-4t; Tue, 26 Oct 2021 20:46:21 +0200 Subject: Re: [PATCH v5 09/13] KVM: Use interval tree to do fast hva lookup in memslots To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Igor Mammedov , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <89deea791ff7a5f4faa535edb9956e9863a564b8.1632171479.git.maciej.szmigiero@oracle.com> From: "Maciej S. Szmigiero" Message-ID: Date: Tue, 26 Oct 2021 20:46:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 26.10.2021 20:19, Sean Christopherson wrote: > On Mon, Sep 20, 2021, Maciej S. Szmigiero wrote: >> From: "Maciej S. Szmigiero" >> >> The current memslots implementation only allows quick binary search by gfn, >> quick lookup by hva is not possible - the implementation has to do a linear >> scan of the whole memslots array, even though the operation being performed >> might apply just to a single memslot. >> >> This significantly hurts performance of per-hva operations with higher >> memslot counts. >> >> Since hva ranges can overlap between memslots an interval tree is needed >> for tracking them. >> >> Signed-off-by: Maciej S. Szmigiero >> --- >> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c >> index 50597608d085..7ed780996910 100644 >> --- a/virt/kvm/kvm_main.c >> +++ b/virt/kvm/kvm_main.c >> @@ -472,6 +472,12 @@ static void kvm_null_fn(void) >> } >> #define IS_KVM_NULL_FN(fn) ((fn) == (void *)kvm_null_fn) >> >> +/* Iterate over each memslot intersecting [start, last] (inclusive) range */ >> +#define kvm_for_each_memslot_in_hva_range(node, slots, start, last) \ >> + for (node = interval_tree_iter_first(&slots->hva_tree, start, last); \ >> + node; \ >> + node = interval_tree_iter_next(node, start, last)) \ > > Similar to kvm_for_each_memslot_in_gfn_range(), this should use an opaque iterator > to hide the implementation details from the caller, e.g. to avoid having to define > a "struct interval_tree_node" and do container_of. > Will convert to an iterator-based for_each implementation in the next version of this patchset. Thanks, Maciej