From patchwork Sun Aug 19 00:17:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 10569657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79BD6109C for ; Sun, 19 Aug 2018 00:18:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E5B629A9E for ; Sun, 19 Aug 2018 00:18:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 604E929AA8; Sun, 19 Aug 2018 00:18:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0698A29A9E for ; Sun, 19 Aug 2018 00:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726399AbeHSD1k (ORCPT ); Sat, 18 Aug 2018 23:27:40 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:42786 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726389AbeHSD1j (ORCPT ); Sat, 18 Aug 2018 23:27:39 -0400 Received: by mail-pl0-f67.google.com with SMTP id g23-v6so2390622plq.9 for ; Sat, 18 Aug 2018 17:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Jw9lcVcMFiXqKfL3ZFLCfx7YeDqCWjdTkiN6sZ/7x48=; b=aIruetxFTlLWJGmHX2atzh3WEqN0A67sB6yjdp2ilWH1RQhLulT8uqw7m3hScOZJit O3uS328TCjPF/9FhuH4tWJH9yErzbz8xp8u5MIuZ9bq+0MmmsPglxaJ1AsWqLTyRhKmg 4CbykScgaDlFp1dy+TxgdfKR6PylUjCbpFl7xuYnkLMfYBcEuLri9Kdu35LP3300zhA9 IjQoWLYmAJ/WDiupORlldbXdGAbNujwN5lyb4j+UDRPV1z96yXVRf2RASCSgPnkNmwby tDw+tR5ysK3iiXdxiLPexVmNLimLe3HTMscDj7EtkYZbTqcXXgcm0l+hvq78tRfMcnkQ reAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Jw9lcVcMFiXqKfL3ZFLCfx7YeDqCWjdTkiN6sZ/7x48=; b=MGRprPlSEdxdXOJKWCfXMBHdgVxNnRzfzAgOmreIu3aRnZkmNwI6/J/nI9GfMWBjSG +ttMzTrnaKU1RfMsV2MY08tq/tOVstC90YgfUVsrH/Uw59rtW+acb3T8K8XGOgdycXNK VI06TZp9ETgHabF47+jz2tJd2yDFoYlmrv4UnnPTYdwDhA6Nq6bDQYVfsh6hNjlkC8QP jG/D8M7dSNZOIFcX2vHL3JSOZFgmME76W4I0h39352wsI/97X4JaIAQZ/9MIRUH3SK1a mbY6A/Xq8Qbc1UQCSyIKlkG0dTl5WqQb/TJfpojz/zukWqtTOX1Vfeq17n+QmfjgFjjl nQNQ== X-Gm-Message-State: AOUpUlGA5SB476FUJOx53GvrcygMafP93El+KytdoJ6Gqm/eZEGTjDaU XKtgp3SmK8FoAXotD+uhOcC+GGHA6ik= X-Google-Smtp-Source: AA+uWPzfZdhVgpU3EkohW2a3/ulfxvF9xGG2UR7IdgfhbA5F8mWWCe8XRAGVkQhIfJKDNDhn2DSG0g== X-Received: by 2002:a17:902:d706:: with SMTP id w6-v6mr39426762ply.158.1534637890213; Sat, 18 Aug 2018 17:18:10 -0700 (PDT) Received: from localhost (65.49.233.5.16clouds.com. [65.49.233.5]) by smtp.gmail.com with ESMTPSA id m7-v6sm4098439pgr.62.2018.08.18.17.18.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Aug 2018 17:18:09 -0700 (PDT) From: Wei Yang To: pbonzini@redhat.com, rkrcmar@redhat.com Cc: kvm@vger.kernel.org, Wei Yang Subject: [PATCH 2/2] KVM: set the boundary of the loop in update_memslots() with used_slots Date: Sun, 19 Aug 2018 08:17:46 +0800 Message-Id: <20180819001746.21586-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180819001746.21586-1-richard.weiyang@gmail.com> References: <20180819001746.21586-1-richard.weiyang@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a trivial optimization of the first loop in update_memslots(). Since used_slots records the number of valid slots, it could be used as the boundary of the loop instead of looping the whole array and check npages. Signed-off-by: Wei Yang --- virt/kvm/kvm_main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 5c1911790f25..fac3225eff35 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -806,15 +806,13 @@ static void update_memslots(struct kvm_memslots *slots, { int id = new->id; int i = slots->id_to_index[id]; + int used_slots = slots->used_slots; struct kvm_memory_slot *mslots = slots->memslots; WARN_ON(mslots[i].id != id); slots->used_slots += (char)change; - while (i < KVM_MEM_SLOTS_NUM - 1 && - new->base_gfn <= mslots[i + 1].base_gfn) { - if (!mslots[i + 1].npages) - break; + while (i < used_slots - 1 && new->base_gfn <= mslots[i + 1].base_gfn) { mslots[i] = mslots[i + 1]; slots->id_to_index[mslots[i].id] = i; i++;