From nobody Sun Nov 24 05:26:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1726591187; cv=none; d=zohomail.com; s=zohoarc; b=IWAhgv+j9l/Oc1awsI16INHRvllFyG8lWAs1rwxTiHw43KHNic3FZs0njdFqB4FDUOQPjqdNBj+9WcS/OZ73C0dVBUj6JlhaT4r5OgPBurxnWptNIj7ReAlbw0TvccqRHJAw3g7CMpV0m8OTxNDt3hUMZ0jne1XvpRq3zVnHNzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726591187; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=84wnjWXrrC4dLoX00Djx1SeDqK9rvS4gkrQ6KA874uc=; b=jRH7Vyahb7pkFXx+zbz2z6/+yeQGj3EffS2MmXHCoW4FmdB1VN7+PTZBQeVPfuLJuPlM0hcyN8ptEYz2fbGqr00jZW1idsPyUKK99COEQdSm6m7OFGSwzvfKWabLNg4grreK35B6s197cCB6x0MxVFSLSZkzTEwIRVSCxg9Lz8k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726591187058230.10941780817507; Tue, 17 Sep 2024 09:39:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqbE3-0003no-DA; Tue, 17 Sep 2024 12:38:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqbDy-0003fs-92 for qemu-devel@nongnu.org; Tue, 17 Sep 2024 12:38:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqbDv-0008T2-Lq for qemu-devel@nongnu.org; Tue, 17 Sep 2024 12:38:46 -0400 Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-561-5uiXmEYROW-3mksrf6DkJA-1; Tue, 17 Sep 2024 12:38:41 -0400 Received: by mail-yb1-f197.google.com with SMTP id 3f1490d57ef6-e1dab3a941fso8488735276.3 for ; Tue, 17 Sep 2024 09:38:41 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-459aad2497asm39942911cf.95.2024.09.17.09.38.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2024 09:38:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726591122; 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=84wnjWXrrC4dLoX00Djx1SeDqK9rvS4gkrQ6KA874uc=; b=Ynn/YztC0PJPkfHwne8eQzw74Aonx6Ts+eM2bsYbKJhftRVylwXzZbQNjcGWX6jcDocwfo mYHUWD1jmq8DcIOMGQWcd5g2VonGwsCoppKhStQE0voCyS1U78HhHAlH0otD8tfUssEhjj bDNpGx8xB0s05oUnd1eKUZI1QxqHIC8= X-MC-Unique: 5uiXmEYROW-3mksrf6DkJA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726591120; x=1727195920; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=84wnjWXrrC4dLoX00Djx1SeDqK9rvS4gkrQ6KA874uc=; b=wWLubJZwRl/UxAagnsMyAYwt9gCvC+C1FQGDyt24eXqAcJ/tpkjLtqGw0Xcqckp2Yj hXsMc6JWSeovN+yxCAENngzEUdkIPNGpQHQpAM7/C7FWuMP20ibkAScD3G4iH5FwUB/z okwAet0xIvFnGPxuSt1tZNYkxMgD6/L62D0ARfXj49qOrp41fmonWadzwEnC0hEymIf/ 86UzC/ODOj6Ccvn/xXrznVxFDgCU0DqSoLyDQysMKDKEezbiXN9aOn1dXGJ7SgOz/CyL o6EYhm2XVEYec7ATQWQ4QiD+Ub1FXCGCt1sKtwPZ85L2SmBQO9flztoh4KtUFehN+8NP o6FQ== X-Gm-Message-State: AOJu0YxrBj/PVshV1MwTtFR+tNRDs5kioRZogNEaKdn4nWHzkive3OXQ H/0EWYb2xxd7C6OWVuOzGu3Exjb7kj4AA6YLfsPXWHjqDFKdagEdgzkaq4sOSLy5bRHWPGn1ure pdFMapQlkTHQ0MuDy/sR4J3EuZZkq3mUU334UaknLsy3TOg8AZvVaOxAKhy/TEBwa0ZW7WkqXrZ W01d2rj2Mt0JXuyRRRp2OsWMD+hk6Fl2EXWY7J X-Received: by 2002:a05:6902:1893:b0:e1b:dc38:1a8c with SMTP id 3f1490d57ef6-e1db00e4773mr13815152276.43.1726591119904; Tue, 17 Sep 2024 09:38:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElzacNy7x6dkzOnJFT0n9RqIS5nEMZPSy2z2kYH85YCnu73mrEu/uqmYb+UuCPLlp8IDcALA== X-Received: by 2002:a05:6902:1893:b0:e1b:dc38:1a8c with SMTP id 3f1490d57ef6-e1db00e4773mr13815099276.43.1726591119276; Tue, 17 Sep 2024 09:38:39 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Vitaly Kuznetsov , Fabiano Rosas , peterx@redhat.com, Prasad Pandit , Julia Suvorova , Juraj Marcin , Paolo Bonzini , David Hildenbrand , qemu-stable , Zhiyi Guo Subject: [PATCH v4 1/4] KVM: Dynamic sized kvm memslots array Date: Tue, 17 Sep 2024 12:38:32 -0400 Message-ID: <20240917163835.194664-2-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240917163835.194664-1-peterx@redhat.com> References: <20240917163835.194664-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1726591188231116600 Content-Type: text/plain; charset="utf-8" Zhiyi reported an infinite loop issue in VFIO use case. The cause of that was a separate discussion, however during that I found a regression of dirty sync slowness when profiling. Each KVMMemoryListerner maintains an array of kvm memslots. Currently it's statically allocated to be the max supported by the kernel. However after Linux commit 4fc096a99e ("KVM: Raise the maximum number of user memslots"), the max supported memslots reported now grows to some number large enough so that it may not be wise to always statically allocate with the max reported. What's worse, QEMU kvm code still walks all the allocated memslots entries to do any form of lookups. It can drastically slow down all memslot operations because each of such loop can run over 32K times on the new kernels. Fix this issue by making the memslots to be allocated dynamically. Here the initial size was set to 16 because it should cover the basic VM usages, so that the hope is the majority VM use case may not even need to grow at all (e.g. if one starts a VM with ./qemu-system-x86_64 by default it'll consume 9 memslots), however not too large to waste memory. There can also be even better way to address this, but so far this is the simplest and should be already better even than before we grow the max supported memslots. For example, in the case of above issue when VFIO was attached on a 32GB system, there are only ~10 memslots used. So it could be good enough as of now. In the above VFIO context, measurement shows that the precopy dirty sync shrinked from ~86ms to ~3ms after this patch applied. It should also apply to any KVM enabled VM even without VFIO. NOTE: we don't have a FIXES tag for this patch because there's no real commit that regressed this in QEMU. Such behavior existed for a long time, but only start to be a problem when the kernel reports very large nr_slots_max value. However that's pretty common now (the kernel change was merged in 2021) so we attached cc:stable because we'll want this change to be backported to stable branches. Cc: qemu-stable Reported-by: Zhiyi Guo Tested-by: Zhiyi Guo Signed-off-by: Peter Xu Acked-by: David Hildenbrand Reviewed-by: Fabiano Rosas --- include/sysemu/kvm_int.h | 1 + accel/kvm/kvm-all.c | 87 +++++++++++++++++++++++++++++++++------- accel/kvm/trace-events | 1 + 3 files changed, 74 insertions(+), 15 deletions(-) diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 17483ff53b..2304537b93 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -46,6 +46,7 @@ typedef struct KVMMemoryListener { MemoryListener listener; KVMSlot *slots; unsigned int nr_used_slots; + unsigned int nr_slots_allocated; int as_id; QSIMPLEQ_HEAD(, KVMMemoryUpdate) transaction_add; QSIMPLEQ_HEAD(, KVMMemoryUpdate) transaction_del; diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index beb1988d12..e0430f08ea 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -69,6 +69,9 @@ #define KVM_GUESTDBG_BLOCKIRQ 0 #endif =20 +/* Default num of memslots to be allocated when VM starts */ +#define KVM_MEMSLOTS_NR_ALLOC_DEFAULT 16 + struct KVMParkedVcpu { unsigned long vcpu_id; int kvm_fd; @@ -165,6 +168,57 @@ void kvm_resample_fd_notify(int gsi) } } =20 +/** + * kvm_slots_grow(): Grow the slots[] array in the KVMMemoryListener + * + * @kml: The KVMMemoryListener* to grow the slots[] array + * @nr_slots_new: The new size of slots[] array + * + * Returns: True if the array grows larger, false otherwise. + */ +static bool kvm_slots_grow(KVMMemoryListener *kml, unsigned int nr_slots_n= ew) +{ + unsigned int i, cur =3D kml->nr_slots_allocated; + KVMSlot *slots; + + if (nr_slots_new > kvm_state->nr_slots) { + nr_slots_new =3D kvm_state->nr_slots; + } + + if (cur >=3D nr_slots_new) { + /* Big enough, no need to grow, or we reached max */ + return false; + } + + if (cur =3D=3D 0) { + slots =3D g_new0(KVMSlot, nr_slots_new); + } else { + assert(kml->slots); + slots =3D g_renew(KVMSlot, kml->slots, nr_slots_new); + /* + * g_renew() doesn't initialize extended buffers, however kvm + * memslots require fields to be zero-initialized. E.g. pointers, + * memory_size field, etc. + */ + memset(&slots[cur], 0x0, sizeof(slots[0]) * (nr_slots_new - cur)); + } + + for (i =3D cur; i < nr_slots_new; i++) { + slots[i].slot =3D i; + } + + kml->slots =3D slots; + kml->nr_slots_allocated =3D nr_slots_new; + trace_kvm_slots_grow(cur, nr_slots_new); + + return true; +} + +static bool kvm_slots_double(KVMMemoryListener *kml) +{ + return kvm_slots_grow(kml, kml->nr_slots_allocated * 2); +} + unsigned int kvm_get_max_memslots(void) { KVMState *s =3D KVM_STATE(current_accel()); @@ -193,15 +247,26 @@ unsigned int kvm_get_free_memslots(void) /* Called with KVMMemoryListener.slots_lock held */ static KVMSlot *kvm_get_free_slot(KVMMemoryListener *kml) { - KVMState *s =3D kvm_state; + unsigned int n; int i; =20 - for (i =3D 0; i < s->nr_slots; i++) { + for (i =3D 0; i < kml->nr_slots_allocated; i++) { if (kml->slots[i].memory_size =3D=3D 0) { return &kml->slots[i]; } } =20 + /* + * If no free slots, try to grow first by doubling. Cache the old size + * here to avoid another round of search: if the grow succeeded, it + * means slots[] now must have the existing "n" slots occupied, + * followed by one or more free slots starting from slots[n]. + */ + n =3D kml->nr_slots_allocated; + if (kvm_slots_double(kml)) { + return &kml->slots[n]; + } + return NULL; } =20 @@ -222,10 +287,9 @@ static KVMSlot *kvm_lookup_matching_slot(KVMMemoryList= ener *kml, hwaddr start_addr, hwaddr size) { - KVMState *s =3D kvm_state; int i; =20 - for (i =3D 0; i < s->nr_slots; i++) { + for (i =3D 0; i < kml->nr_slots_allocated; i++) { KVMSlot *mem =3D &kml->slots[i]; =20 if (start_addr =3D=3D mem->start_addr && size =3D=3D mem->memory_s= ize) { @@ -267,7 +331,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, voi= d *ram, int i, ret =3D 0; =20 kvm_slots_lock(); - for (i =3D 0; i < s->nr_slots; i++) { + for (i =3D 0; i < kml->nr_slots_allocated; i++) { KVMSlot *mem =3D &kml->slots[i]; =20 if (ram >=3D mem->ram && ram < mem->ram + mem->memory_size) { @@ -1071,7 +1135,7 @@ static int kvm_physical_log_clear(KVMMemoryListener *= kml, =20 kvm_slots_lock(); =20 - for (i =3D 0; i < s->nr_slots; i++) { + for (i =3D 0; i < kml->nr_slots_allocated; i++) { mem =3D &kml->slots[i]; /* Discard slots that are empty or do not overlap the section */ if (!mem->memory_size || @@ -1719,12 +1783,8 @@ static void kvm_log_sync_global(MemoryListener *l, b= ool last_stage) /* Flush all kernel dirty addresses into KVMSlot dirty bitmap */ kvm_dirty_ring_flush(); =20 - /* - * TODO: make this faster when nr_slots is big while there are - * only a few used slots (small VMs). - */ kvm_slots_lock(); - for (i =3D 0; i < s->nr_slots; i++) { + for (i =3D 0; i < kml->nr_slots_allocated; i++) { mem =3D &kml->slots[i]; if (mem->memory_size && mem->flags & KVM_MEM_LOG_DIRTY_PAGES) { kvm_slot_sync_dirty_pages(mem); @@ -1839,12 +1899,9 @@ void kvm_memory_listener_register(KVMState *s, KVMMe= moryListener *kml, { int i; =20 - kml->slots =3D g_new0(KVMSlot, s->nr_slots); kml->as_id =3D as_id; =20 - for (i =3D 0; i < s->nr_slots; i++) { - kml->slots[i].slot =3D i; - } + kvm_slots_grow(kml, KVM_MEMSLOTS_NR_ALLOC_DEFAULT); =20 QSIMPLEQ_INIT(&kml->transaction_add); QSIMPLEQ_INIT(&kml->transaction_del); diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events index 82c65fd2ab..e43d18a869 100644 --- a/accel/kvm/trace-events +++ b/accel/kvm/trace-events @@ -36,3 +36,4 @@ kvm_io_window_exit(void) "" kvm_run_exit_system_event(int cpu_index, uint32_t event_type) "cpu_index %= d, system_even_type %"PRIu32 kvm_convert_memory(uint64_t start, uint64_t size, const char *msg) "start = 0x%" PRIx64 " size 0x%" PRIx64 " %s" kvm_memory_fault(uint64_t start, uint64_t size, uint64_t flags) "start 0x%= " PRIx64 " size 0x%" PRIx64 " flags 0x%" PRIx64 +kvm_slots_grow(unsigned int old, unsigned int new) "%u -> %u" --=20 2.45.0 From nobody Sun Nov 24 05:26:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1726591185; cv=none; d=zohomail.com; s=zohoarc; b=Jj40pYxpeijgAYuaMHxtPPweJHPW/GrbCxG46EKiwp/hjQudi2l5fjaAhm6cntd1sAzxMf3tHFocAPQMhMMC2tMap0Arc3kFbZLUqakxitAarGDAGd8+yJlQKADtuDmQQgOuNAS6WUz9EKfz1XHxXc0VTubO3o3updnRxMNYug0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726591185; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eenrsbEr6uJN92Yt183uHoXgP8OKY4iqp8mQemFQxtU=; b=U/FDIsj9tBg6M1TfgpJsSnOxdOXe5th/uT0RizspxuZ2ysYBN9Hm+OOmWVAsmyAnSfMo8hFR8WuoEyn/2n5uZ5Lb+qmSsWPEH57c9ik//AimSIxApSSF2jkk/qh+SsGS0mjfuKiYN0xPbbkt/lLo2MCTBoQ9n1CB9kKcYhIoNCI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726591185527332.62772426341564; Tue, 17 Sep 2024 09:39:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqbE4-0003ui-M9; Tue, 17 Sep 2024 12:38:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqbE0-0003ic-3b for qemu-devel@nongnu.org; Tue, 17 Sep 2024 12:38:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqbDy-0008TW-1F for qemu-devel@nongnu.org; Tue, 17 Sep 2024 12:38:47 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-nw-bClk3N_-6tYLN9g9WrA-1; Tue, 17 Sep 2024 12:38:42 -0400 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-45834f5927aso94088751cf.2 for ; Tue, 17 Sep 2024 09:38:42 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-459aad2497asm39942911cf.95.2024.09.17.09.38.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2024 09:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726591124; 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=eenrsbEr6uJN92Yt183uHoXgP8OKY4iqp8mQemFQxtU=; b=UXuNTBrSkgzeNlijWjsv22RgBeTKusJf303lZl+g+Y6goLYA4SYQ5svv3kk1XUBeccBYqA T3YaP8JzA9ddBE0IxMwIF259mz/V6yceJfkb+uhgyXJi+1cGv3/TGTSYQBHKArdRWI3uDV ltcou52dy+V31U+NHqC4qbCfxs2NiDo= X-MC-Unique: nw-bClk3N_-6tYLN9g9WrA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726591122; x=1727195922; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eenrsbEr6uJN92Yt183uHoXgP8OKY4iqp8mQemFQxtU=; b=IUSPvGTprfyVCozmDVhZ6LMUsDbJOqrpjtimj4W8hZ0Am6swJtJoZ39NztA/cHq+uX 8zhcvqZOsjEr3ULxV6N6O2l45e29kKlzuuOeqz5tiVQRUzWMEZDEElwa7eK3YMACIdc+ ruSx0k5KcooePFZa9lF2gW0nUWqSqIJsVjxTKNNNPtks6pev6e6zu/4No5Jn+SLqEoo4 XQQ/Zf3uJ1CNKOilLQyVqMz+ut9DYrLe0Ms/QdRPOcG+eVN+AL5vuCoHLW2ojSss9A3y di2giLjHP3NARBe8AJPJDV+ZuVcz5GLpFckr/SScba4leO/DxLwXDK/Iutdalj+1CeLT Kn1w== X-Gm-Message-State: AOJu0YwjZXU7Jmp5AKx9oCu8HMOPmlgI8k3kxhS5o6eYs3K1hzPDlAV2 kc35deMzb0MnP4YDQm8Ef6at2YYAkjESAn9ZeAqgD3EoKyM0bYmbDTTW5OReSYV+p4933iOdp12 Lx27MEZoHJWd2E/85lQwimffgq96ZZuRTS1nVtpZ/XoQ/nUNhfv98WRpVd4hhYCTIHnAi93Yhmg ilcExMXahZqlDOlJ/tzsIghk7FeUxkpL8lNZu1 X-Received: by 2002:a05:622a:2985:b0:458:2945:c4a3 with SMTP id d75a77b69052e-4586044df56mr272042091cf.56.1726591121797; Tue, 17 Sep 2024 09:38:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH9ypQjNrqRXuZW+HM0HoKKw84fnSrIcDR1EUfnrD80q0bpkvuTSxriC4/mzvhxeSF2pdhVFg== X-Received: by 2002:a05:622a:2985:b0:458:2945:c4a3 with SMTP id d75a77b69052e-4586044df56mr272041781cf.56.1726591121365; Tue, 17 Sep 2024 09:38:41 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Vitaly Kuznetsov , Fabiano Rosas , peterx@redhat.com, Prasad Pandit , Julia Suvorova , Juraj Marcin , Paolo Bonzini , David Hildenbrand Subject: [PATCH v4 2/4] KVM: Define KVM_MEMSLOTS_NUM_MAX_DEFAULT Date: Tue, 17 Sep 2024 12:38:33 -0400 Message-ID: <20240917163835.194664-3-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240917163835.194664-1-peterx@redhat.com> References: <20240917163835.194664-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1726591186077116600 Content-Type: text/plain; charset="utf-8" Make the default max nr_slots a macro, it's only used when KVM reports nothing. Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index e0430f08ea..0b66c8b27f 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -71,6 +71,8 @@ =20 /* Default num of memslots to be allocated when VM starts */ #define KVM_MEMSLOTS_NR_ALLOC_DEFAULT 16 +/* Default max allowed memslots if kernel reported nothing */ +#define KVM_MEMSLOTS_NR_MAX_DEFAULT 32 =20 struct KVMParkedVcpu { unsigned long vcpu_id; @@ -2515,7 +2517,7 @@ static int kvm_init(MachineState *ms) =20 /* If unspecified, use the default value */ if (!s->nr_slots) { - s->nr_slots =3D 32; + s->nr_slots_max =3D KVM_MEMSLOTS_NR_MAX_DEFAULT; } =20 s->nr_as =3D kvm_check_extension(s, KVM_CAP_MULTI_ADDRESS_SPACE); --=20 2.45.0 From nobody Sun Nov 24 05:26:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1726591198; cv=none; d=zohomail.com; s=zohoarc; b=WNH9oeZY9rqCEacnqgGwmNn/GGcEjOsX5RkBozpkWpaCrk3Pa5es2Ca8yM6x3yaSBxFT9yiflrFNIfx6MgYgg80p+tiwOCNJRIN6M39u0sUM+zE+yoT8ObmUdBqwTzZYpO5FzLcnipyZ2YS9/x/PkWUsrgnHXT+hIrhbsktVDt8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726591198; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZyaI/UCHK61GYnEHGZaEepibYRivTV0MRwcjjCl1LVM=; b=TGy+ipgrL8jU3Tg1/fy0HEJ6+P75zPUUG53sVHxFvgn0ktRt9gXVwH+mOv/RMh5GjfT+jw6vnnSfagDNv6cMtmHQv/WD7LB8cs1/hxW0obH1nXQOzRqk7ghAjrfHPFYzz77AkXfmzQwFG0hDaYrVBnUgUI8eo87TDHct8lb+nE8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726591198604437.2372366028561; Tue, 17 Sep 2024 09:39:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqbE6-0003zI-LP; Tue, 17 Sep 2024 12:38:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqbE0-0003id-Fg for qemu-devel@nongnu.org; Tue, 17 Sep 2024 12:38:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqbDy-0008To-Nx for qemu-devel@nongnu.org; Tue, 17 Sep 2024 12:38:48 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-31jIsb4VPWWYpH2s2EKYgA-1; Tue, 17 Sep 2024 12:38:45 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-4586e0c6597so90115181cf.2 for ; Tue, 17 Sep 2024 09:38:43 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-459aad2497asm39942911cf.95.2024.09.17.09.38.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2024 09:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726591126; 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=ZyaI/UCHK61GYnEHGZaEepibYRivTV0MRwcjjCl1LVM=; b=P1n1HzBGK1Hx8ALV/XJIFuwKlc5FYJ/FnqWbT3osyv2JuTNl485ixwjjH7hmlM687q6yve dqWFrMNVzg7xYFYq3eB5S8pQDAhzP/3rCNevm3vO/SFFTw8J/Y/AIL7oKAVUcj1dx2jtun sQoFP4u14sHBQe68PFmNrTZzh2XQyqU= X-MC-Unique: 31jIsb4VPWWYpH2s2EKYgA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726591123; x=1727195923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZyaI/UCHK61GYnEHGZaEepibYRivTV0MRwcjjCl1LVM=; b=oQdS4ine8zhUFK5gGyV/WY687AXAfCiv3lEUw2ALBVEzwXkptR7laaCdVM1VykAfIx Bz4JJhhwpnJLZsEugr9L+6PKBkJ1HhKxMoyWUlon+vUf9U4ipN1icrSBGT56qEKAtgMA HjsCdPWQAiqB5bT1dXSpX5wGr1SmMP9soWwSKZ8xG3V5Hpg+KrRYWSIAq9giNOLvarKU o6Uus8amdCRd1SnWFoZ+6pbm6hk7UUIdP/lEr0WXqjs5ojTGqev7z+hLWiP/x1kPqMfA xDHxmincYVMXegcqT8+y44cr1v2gKIBQ/W4L14PAtQc8HcRIrmyigKHSis2Lad+PU0gH KGug== X-Gm-Message-State: AOJu0YyDQKueepjJhsgjXuWM6yq0fP8kKm7CWgHxtRH2cNuDcToNK8FK LZq7PKQXgNtdp3dmCFDVfTHydwIQ6cINb1ufzej9lUJoegtq2VV2d81nZ+L9vpIo/N3wWsFOMxH fojfwLbr8j9RXt8xF/LPA+gkBdMXgYSYu7nvDIij65BsVggRxEN4x7iQHxDQOP8yM0hU8b2nSTX OuK2RzOu+qvkEfbhbOe2+a0XiJhddr5SgW6fKi X-Received: by 2002:a05:622a:5d3:b0:451:a12d:b9d1 with SMTP id d75a77b69052e-458602a7663mr333879171cf.10.1726591123218; Tue, 17 Sep 2024 09:38:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEOLri8g3HajwEL1z5d5V9xdqzSxTVr2uPDNOLqez36tIKXmhMQudxcO4H7ZM5SJg7TBopG/g== X-Received: by 2002:a05:622a:5d3:b0:451:a12d:b9d1 with SMTP id d75a77b69052e-458602a7663mr333878701cf.10.1726591122732; Tue, 17 Sep 2024 09:38:42 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Vitaly Kuznetsov , Fabiano Rosas , peterx@redhat.com, Prasad Pandit , Julia Suvorova , Juraj Marcin , Paolo Bonzini , David Hildenbrand Subject: [PATCH v4 3/4] KVM: Rename KVMMemoryListener.nr_used_slots to nr_slots_used Date: Tue, 17 Sep 2024 12:38:34 -0400 Message-ID: <20240917163835.194664-4-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240917163835.194664-1-peterx@redhat.com> References: <20240917163835.194664-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1726591200118116600 Content-Type: text/plain; charset="utf-8" This will make all nr_slots counters to be named in the same manner. Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- include/sysemu/kvm_int.h | 2 +- accel/kvm/kvm-all.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 2304537b93..914c5c9ec5 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -45,7 +45,7 @@ typedef struct KVMMemoryUpdate { typedef struct KVMMemoryListener { MemoryListener listener; KVMSlot *slots; - unsigned int nr_used_slots; + unsigned int nr_slots_used; unsigned int nr_slots_allocated; int as_id; QSIMPLEQ_HEAD(, KVMMemoryUpdate) transaction_add; diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 0b66c8b27f..bceb154943 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -239,7 +239,7 @@ unsigned int kvm_get_free_memslots(void) if (!s->as[i].ml) { continue; } - used_slots =3D MAX(used_slots, s->as[i].ml->nr_used_slots); + used_slots =3D MAX(used_slots, s->as[i].ml->nr_slots_used); } kvm_slots_unlock(); =20 @@ -1516,7 +1516,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, } start_addr +=3D slot_size; size -=3D slot_size; - kml->nr_used_slots--; + kml->nr_slots_used--; } while (size); return; } @@ -1555,7 +1555,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, ram_start_offset +=3D slot_size; ram +=3D slot_size; size -=3D slot_size; - kml->nr_used_slots++; + kml->nr_slots_used++; } while (size); } =20 --=20 2.45.0 From nobody Sun Nov 24 05:26:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1726591217; cv=none; d=zohomail.com; s=zohoarc; b=Qx2E1z89UpnWUFRWI2zcFB4bG8vwknaQepCgDByhXAr8lKxjBBscWbXBINI03olUe0PrWRq+hlWOlHXAoPO37ftOynMmpPO9krvjVjLV0b6x9PFZSnc4Q0Y6kYObEGGC+RvEdxAvi7x6M5+zdkK+INOC76rvEtrh2C/LZq6zekM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726591217; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SxzMnh3LR9kbrVwkJ0PAxEWUkiep6PxwmVi9MFzuWOA=; b=IHrz0eFY+on7sGqxBcCUE1P30ak5pGC9YEVi0I3QaQgoKLQ+RUkTBA/hYlbgtxklIKXNbLURITt1NcILcNbe++h0imnneRpfYemy0Vuc88NWd9yM0+14kpUJbbE5dcE3n9hNV8Llrjy8wDhq6uwQcb11FrPYDGSO20IzwFdACbY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726591217215807.6612089586356; Tue, 17 Sep 2024 09:40:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqbE7-00047C-Hg; Tue, 17 Sep 2024 12:38:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqbE1-0003lV-OZ for qemu-devel@nongnu.org; Tue, 17 Sep 2024 12:38:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqbE0-0008UB-45 for qemu-devel@nongnu.org; Tue, 17 Sep 2024 12:38:49 -0400 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-671-DTBg2HQHO2WmhZ25XzctQg-1; Tue, 17 Sep 2024 12:38:46 -0400 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-45828d941f1so94162121cf.3 for ; Tue, 17 Sep 2024 09:38:46 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-459aad2497asm39942911cf.95.2024.09.17.09.38.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2024 09:38:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726591127; 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=SxzMnh3LR9kbrVwkJ0PAxEWUkiep6PxwmVi9MFzuWOA=; b=XLekxeaGoeXNnb1Bb7+w3EVlgdkqbylCzYbpe3K4gYtqUDK8Eo+IhI3LU+p1dd4zQvDSgx f12bpMM+Cc6kt5Gyrhfs6N2X795xf9JncRq/tDiIcZSHPwdjniedR7+PYR7uramaDDqiJ+ pQjoQFr6js4KkFolLV87g7YWhu69b1k= X-MC-Unique: DTBg2HQHO2WmhZ25XzctQg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726591125; x=1727195925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SxzMnh3LR9kbrVwkJ0PAxEWUkiep6PxwmVi9MFzuWOA=; b=S4aSQOJ03VAUDEOPYMJ+4cXWyfzklLu9mtbDVdiiNc3/TMWrN287KdwPNRLUPsCJoz hohMbyWFo77HRfhyQ4KrzBbUt8QMgkRM+kh1eRqZ3j7zgDomRjuaAxMZOCSdORE4wC/b H28qAmHu1RbmdLgej8giW+2GQ1IghrrS4uYFfUa6ZpeBdV3/aQqe8UjsZH59LMZPec8n /oWsZ6X64Qg8jC4MKmuR6oxzombxBgq7JR8Jgk/f1gjU4wUYpKnPvyZ1kwCop//DrIIO NgMWxtOr1SuPvd2mpfxsrduiqX+YUFlerRH9dn0mJBZlxMsFv1/ThcVNXFwcP6I+cfTe Yo2g== X-Gm-Message-State: AOJu0Yxdvi5jEqTFfzW7+NJNUbh9YwHrbfVl+RDIBHYRCdkD9HpN/BZ2 hn5oR+djdkqvc64IOhqCtIpnOvCjVWAeOum7ccJgUOM8IbAe1elmjJnPLtqCsoJBOaemM7LFkim ZOOKE1UTjRMmNvhij76wSDRhT/1+y/NbnxuwbeAfprwReCqU2JBtwd8de7XWEXCy2zdDUuaaYGY x4UXcJPqnfASJEcM7ptk87n6/0qxVnbigJhqlP X-Received: by 2002:ac8:7e92:0:b0:458:53da:a4e9 with SMTP id d75a77b69052e-45b081eee24mr9435571cf.4.1726591125180; Tue, 17 Sep 2024 09:38:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDjAhygfHh81isAqOnGCSAncBV8wM9/StrqPBLPnSzDPMKQ8lr8HcuiEJLSJBzcyegFYrs6Q== X-Received: by 2002:ac8:7e92:0:b0:458:53da:a4e9 with SMTP id d75a77b69052e-45b081eee24mr9435191cf.4.1726591124707; Tue, 17 Sep 2024 09:38:44 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Vitaly Kuznetsov , Fabiano Rosas , peterx@redhat.com, Prasad Pandit , Julia Suvorova , Juraj Marcin , Paolo Bonzini , David Hildenbrand Subject: [PATCH v4 4/4] KVM: Rename KVMState->nr_slots to nr_slots_max Date: Tue, 17 Sep 2024 12:38:35 -0400 Message-ID: <20240917163835.194664-5-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240917163835.194664-1-peterx@redhat.com> References: <20240917163835.194664-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1726591218218116600 Content-Type: text/plain; charset="utf-8" This value used to reflect the maximum supported memslots from KVM kernel. Rename it to be clearer. Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- include/sysemu/kvm_int.h | 4 ++-- accel/kvm/kvm-all.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 914c5c9ec5..a1e72763da 100644 --- a/include/sysemu/kvm_int.h +++ b/include/sysemu/kvm_int.h @@ -103,8 +103,8 @@ struct KVMDirtyRingReaper { struct KVMState { AccelState parent_obj; - - int nr_slots; + /* Max number of KVM slots supported */ + int nr_slots_max; int fd; int vmfd; int coalesced_mmio; diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index bceb154943..7fa4019544 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -183,8 +183,8 @@ static bool kvm_slots_grow(KVMMemoryListener *kml, unsi= gned int nr_slots_new) unsigned int i, cur =3D kml->nr_slots_allocated; KVMSlot *slots; =20 - if (nr_slots_new > kvm_state->nr_slots) { - nr_slots_new =3D kvm_state->nr_slots; + if (nr_slots_new > kvm_state->nr_slots_max) { + nr_slots_new =3D kvm_state->nr_slots_max; } =20 if (cur >=3D nr_slots_new) { @@ -225,7 +225,7 @@ unsigned int kvm_get_max_memslots(void) { KVMState *s =3D KVM_STATE(current_accel()); =20 - return s->nr_slots; + return s->nr_slots_max; } =20 unsigned int kvm_get_free_memslots(void) @@ -243,7 +243,7 @@ unsigned int kvm_get_free_memslots(void) } kvm_slots_unlock(); =20 - return s->nr_slots - used_slots; + return s->nr_slots_max - used_slots; } =20 /* Called with KVMMemoryListener.slots_lock held */ @@ -2513,10 +2513,10 @@ static int kvm_init(MachineState *ms) (kvm_supported_memory_attributes & KVM_MEMORY_ATTRIBUTE_PRIVATE); =20 kvm_immediate_exit =3D kvm_check_extension(s, KVM_CAP_IMMEDIATE_EXIT); - s->nr_slots =3D kvm_check_extension(s, KVM_CAP_NR_MEMSLOTS); + s->nr_slots_max =3D kvm_check_extension(s, KVM_CAP_NR_MEMSLOTS); =20 /* If unspecified, use the default value */ - if (!s->nr_slots) { + if (!s->nr_slots_max) { s->nr_slots_max =3D KVM_MEMSLOTS_NR_MAX_DEFAULT; } =20 --=20 2.45.0