From nobody Sun Nov 24 06:54:11 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=1725893714; cv=none; d=zohomail.com; s=zohoarc; b=HASx694YqikrC0fCNpg3epLq9FDfYVn/7dJ/wgBEpL/9TSUemcaOp5Jkpsm7jT07EndeXeReWPusvUrhDQO7Q5+asxGFztB1lfxhEpabX/ad5aauwYQXXpbsYnRVnwNCcA2CDiSGKe72KJSLCUTqVHIOef8z1PikeL2DqhHpAfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725893714; 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=YgDOLpz/hDWrlMg9+HuMzTJmCwIP7Slj84XnuZkB3o0=; b=hiOhsyo/g0RvKtvIoo3gqibO7oJ0Bj3jJTw5Llpv+aQW74ZIz02lhw7dPBxmYFRPX/IU7FWXziA9Q0b9utplvS6OfXCsP6/S8h9D3I8Foy8IXCYSkOMSudDxs6mL2J9UTHsWN4Ge3E7PsDh1tgs+PAcFyp9gMeSkSbCqtJ0YT5k= 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 1725893714915873.0367920337503; Mon, 9 Sep 2024 07:55:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfmg-0005Vi-Sl; Mon, 09 Sep 2024 10:54:30 -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 1snfmZ-0005Px-Vs for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:54:24 -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 1snfmY-00071k-0h for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:54:23 -0400 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-447-aBQNOo7JPpSUnAO2QbURLw-1; Mon, 09 Sep 2024 10:54:19 -0400 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7a9a6634b08so339260585a.0 for ; Mon, 09 Sep 2024 07:54:19 -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 af79cd13be357-7a9a79455b1sm225387585a.19.2024.09.09.07.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 07:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725893660; 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=YgDOLpz/hDWrlMg9+HuMzTJmCwIP7Slj84XnuZkB3o0=; b=IrpSzmWcDgGshrgL2dDRNtC89D0iKENB7TsxG4g9t7fD/WRPiDPDYSPeGpFcmE3VfXuFfq ARUQ5CCPVU6ueO/xFD6tCQWyq75MiMYvwQPDH9yHI9JpxL3djQCd/05gMlG76rnjYvw7y/ OyBF9KMX5EweeE6yj8bJDEaAHPquGWk= X-MC-Unique: aBQNOo7JPpSUnAO2QbURLw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725893658; x=1726498458; 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=YgDOLpz/hDWrlMg9+HuMzTJmCwIP7Slj84XnuZkB3o0=; b=qd0m1kgNFKPLNkGH1YOFFoUZdsiXwbFnL8Ea0RYRPNQYHb3NucOVpli593ZoDCR8ly aXGlqtUtwl1akt8lQJE8YM9YUCXUYsr/qAa/yXVThhwEGZvDglMGZGzFAiA/Go3z95Uu DnoAtNdb/wdigH0eikuxy40dtd2oqV6buV4PsCX2tb4TOZRjiMW72cQuwj73uA4sLw4A oGjvIGtjnul4//zqgEC2Rng4dpPillOh7x+9IRb0c1x7CRXoHiCS0qWiMbDchfOU7d49 1W8IRlHPy5KuDofHbAcH0cXaqlpAZMqCQtFcd9A+NmGzrZSkhczxeIcTI1DiQAyk3y63 GiIA== X-Gm-Message-State: AOJu0YwB3rxyGXK8CELZ78/uoD0Xo8eva3AHGNUNcgaWDWmro7ehKWgh uX92+jkUgAXr8qTEiYHf3Lyz6VtGxSgVqdf5paQ2IlOIJ8gYST5AEbPvkgxLAr65AGJjgnAtLUv ve98/jdtKjFTD1rn8iVXC4Sgyhhhkf6ZOPxJmtOODjZWqprAYnY29bocaUKA8PGpG44pTZp0Hya /mpOLdbS8B+W/QXh0oOkYkTWyKoV3C8oWfMBWu X-Received: by 2002:a05:620a:1a2a:b0:7a9:bbb8:e8b4 with SMTP id af79cd13be357-7a9bbb8ebc8mr343493485a.30.1725893658087; Mon, 09 Sep 2024 07:54:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQsjs13SOl6hOMZk2/Y1Tj9Bj2/sCA+SL854/D0Yr5PAOivfbzWtgLYTCbpFz27CGD86Y/ng== X-Received: by 2002:a05:620a:1a2a:b0:7a9:bbb8:e8b4 with SMTP id af79cd13be357-7a9bbb8ebc8mr343486985a.30.1725893657585; Mon, 09 Sep 2024 07:54:17 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Vitaly Kuznetsov , David Hildenbrand , Paolo Bonzini , peterx@redhat.com, Prasad Pandit , Juraj Marcin , Julia Suvorova , Fabiano Rosas , qemu-stable , Zhiyi Guo Subject: [PATCH v3 1/4] KVM: Dynamic sized kvm memslots array Date: Mon, 9 Sep 2024 10:54:10 -0400 Message-ID: <20240909145413.3748429-2-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240909145413.3748429-1-peterx@redhat.com> References: <20240909145413.3748429-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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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: 1725893716844116600 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 --- include/sysemu/kvm_int.h | 1 + accel/kvm/kvm-all.c | 99 ++++++++++++++++++++++++++++++++++------ accel/kvm/trace-events | 1 + 3 files changed, 86 insertions(+), 15 deletions(-) diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index 1d8fb1473b..48e496b3d4 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 75d11a07b2..c51a3f18db 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); @@ -2461,6 +2518,18 @@ static int kvm_init(MachineState *ms) s->nr_slots =3D 32; } =20 + /* + * A VM will at least require a few memslots to work, or it can even + * fail to boot. Make sure the supported value is always at least + * larger than what we will initially allocate. + */ + if (s->nr_slots < KVM_MEMSLOTS_NR_ALLOC_DEFAULT) { + ret =3D -EINVAL; + fprintf(stderr, "KVM max supported number of slots (%d) too small\= n", + s->nr_slots); + goto err; + } + s->nr_as =3D kvm_check_extension(s, KVM_CAP_MULTI_ADDRESS_SPACE); if (s->nr_as <=3D 1) { s->nr_as =3D 1; diff --git a/accel/kvm/trace-events b/accel/kvm/trace-events index 37626c1ac5..ad2ae6fca5 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 06:54:11 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=1725893701; cv=none; d=zohomail.com; s=zohoarc; b=WPQiAPxrUZWsAclNhOodHTQZFl23GCOpEBjvmJ9K29VnP8uS54rVUrEhjG8rCtf8tBiPdz0GH67tYyMmViw4/Gvtl/Gelhx197p0xMX/xeuvimTO/jwTVUblO9kUNrmH6dolOgs/e6MvXBnK2Ird4jHYCo4cX3sd4q9921T3+Bk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725893701; 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=muYuhVo8+jXYQG+i6YJIJ3ax/FpbTBxwSGmzcCzGN5c=; b=WTBtxCVWQGs65bIOcwj22p5ygw7xUrAHmh94HdVxf8x3OLWl4jazKUiXwRXa1hYHdDq13QTI13TeQR5sYedGxYqzo6AKc/rvZIR7Vs2WoG/Xmpb7VR9zPGtH6M9g/YKKcrQAXhgJFydx8JrpP6+D5wuHeLnIRDQ9U+cVHMib9dw= 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 1725893701913858.9204896362697; Mon, 9 Sep 2024 07:55:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfmj-0005lX-WA; Mon, 09 Sep 2024 10:54:34 -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 1snfmd-0005R2-UO for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:54:28 -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 1snfmb-00072G-OY for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:54:26 -0400 Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-300-VYQGZvV4OzSgKlkDLSf7jw-1; Mon, 09 Sep 2024 10:54:20 -0400 Received: by mail-oo1-f70.google.com with SMTP id 006d021491bc7-5df9375c3b1so3551924eaf.0 for ; Mon, 09 Sep 2024 07:54:20 -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 af79cd13be357-7a9a79455b1sm225387585a.19.2024.09.09.07.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 07:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725893664; 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=muYuhVo8+jXYQG+i6YJIJ3ax/FpbTBxwSGmzcCzGN5c=; b=T0CVXYs9uORhZ8TcIrjEHZg6p8tBAYS0TEbiCDhAwQkADEMoI3220PiwrzFeilBeq+R5Ju V0lxc29j+Ohz6H+0bj/gybgFzSh4sotkz3oDj75SRQKp+ssSVSJ2jtbu36j9Tjofo0gXNs 7KdT4uG2aAobcQhL69xLMOY+yWzof2c= X-MC-Unique: VYQGZvV4OzSgKlkDLSf7jw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725893660; x=1726498460; 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=muYuhVo8+jXYQG+i6YJIJ3ax/FpbTBxwSGmzcCzGN5c=; b=nWrTQP4wKOYwbQveeSqfArOjhQoG1w5T65niM4IH1KGoJrmfl1FelX8Q8826GZJ/Wk EyBA3lEeLVkSXpLsINDNmKwzgvaKiNDmCH+Rx1mvwTxo1XasN+MxjsU5X1A9+YXHXZGc uG+US70M2NKWEqyIEaRWnaIYOuhRSwszDEDFMI1bjFMjZud9iCuyIdJ+4qg6YSMKbsI4 USWl/v4cA5TyjYJlMTgDvDOyPy06I3knJaTwh8J4KWS1x4MXNb/hAMYkKvR/2f/EEWOD GzOk+uL2huCqDzUsYdCTiEaPUfMgpBc/sE8DGsxl6OSIqgZt1p9hDmmoKMNPP5M0tMLe tJpQ== X-Gm-Message-State: AOJu0YxTqZocXC5gvLHLkMmUOHDyVFXjrKvOutW9wFAvRTVh/3f2lHym +NGbtzd/frEoduLDDa2G5H8CxrndrbWiyPHoDq56E6LkKeGtBvRTHsumMUW0N7gzMXVLeTQ3Evz qhMseGj0kXK49gRjXBpHhYCU1flBqbH5ilfmCV2yBnhEZNkc2HtbGGEzCdONmx6ARMbCsC3I4tu kzo8wCpFhrAgrIKf/D6e2tBMehWgQWwp6lXh1H X-Received: by 2002:a05:6358:5699:b0:1aa:c9ba:4330 with SMTP id e5c5f4694b2df-1b838594932mr900867755d.4.1725893659857; Mon, 09 Sep 2024 07:54:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IES5WhyBmF3sil484vp7OgwsJAW2XD+suHtu9rSq+4peKLE8F1Ftmss6TZ3kRCSJ07u5mIsBA== X-Received: by 2002:a05:6358:5699:b0:1aa:c9ba:4330 with SMTP id e5c5f4694b2df-1b838594932mr900863755d.4.1725893659338; Mon, 09 Sep 2024 07:54:19 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Vitaly Kuznetsov , David Hildenbrand , Paolo Bonzini , peterx@redhat.com, Prasad Pandit , Juraj Marcin , Julia Suvorova , Fabiano Rosas Subject: [PATCH v3 2/4] KVM: Define KVM_MEMSLOTS_NUM_MAX_DEFAULT Date: Mon, 9 Sep 2024 10:54:11 -0400 Message-ID: <20240909145413.3748429-3-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240909145413.3748429-1-peterx@redhat.com> References: <20240909145413.3748429-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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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_H4=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: 1725893702621116600 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 c51a3f18db..2a2ee4e7d7 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 /* --=20 2.45.0 From nobody Sun Nov 24 06:54:11 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=1725893729; cv=none; d=zohomail.com; s=zohoarc; b=bx2jYzQt75L8sVX6Q6PEODIUVclqY4ckeB3DAtac9Kha2JuJmQU2//psaHeLTnYAPOrRRwjAQ4uHXfifY/BCoteDigZguSwzKl4ke9cz1kN1ehIHxhGsxUxURA8XJ95Z6ahldYWKui7n+Oiu444YZjn3DZZUZdCTGsGsZ+l5YnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725893729; 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=CrZS8781pHGUPuwCPCQ1wvEpYbe8ELrbjJpLH7JCnvU=; b=cXmjvcqo19yohDiTvlnlIWGRFbvSponMGPnrNW9DDt+LUvhC0uMFbdbydgCsrSuydCo0gBKmxvoEofVYsyZulGd7ioztulVnc4Ispa+h2fxXGbZjkcfToW3RWtXtZkKSQG40qi1LcLBzdBeCEU/tvVWtjsRCN7cEpo4RUjlY7q4= 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 1725893729405816.9855820057695; Mon, 9 Sep 2024 07:55:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfmh-0005Zn-5h; Mon, 09 Sep 2024 10:54:31 -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 1snfmb-0005QH-WF for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:54:27 -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 1snfma-000723-4U for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:54:25 -0400 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-65-nXApTwkuPlOkKOdEm8Sxsg-1; Mon, 09 Sep 2024 10:54:22 -0400 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7a9aae6728aso392750885a.1 for ; Mon, 09 Sep 2024 07:54:22 -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 af79cd13be357-7a9a79455b1sm225387585a.19.2024.09.09.07.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 07:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725893663; 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=CrZS8781pHGUPuwCPCQ1wvEpYbe8ELrbjJpLH7JCnvU=; b=JYlcdSZR+boXJ8UObiUhwupEkWvx57lVkPn4+QLjCyWxtw22hfPJZw70Jb39c1hNpFoD21 hpdl9z+0sBQ7x0diJFGjGMZm5x7h0m8Fr+Ctv90oGOY36fNI+4t+Tgg8+do7OojzAfC7+M v/g7ExzZxOLAepZtWpol3xP/G/xFntY= X-MC-Unique: nXApTwkuPlOkKOdEm8Sxsg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725893661; x=1726498461; 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=CrZS8781pHGUPuwCPCQ1wvEpYbe8ELrbjJpLH7JCnvU=; b=KUFHYfv0cdebyEEoT3ScBtMeH+ORrlpSmFEFWiIGRbi0uILyjepryuNi9M3MYCcTld y8I1c6c1lQ76soFKE7h9+imS4pujC6Keu19rCDuqsl37F6/2t1LoJGoNKED1pLsoPXpg w1MpElUqLh5fZCYs+eZz4chWI8bDg7W93ych7wE71jWl5+O3XyxjKv5RE8xf3Gb3cg/o PmSV/s9DbTD31esXa4rFeostL/pWwOGSpflP5IefEWg0wihZtslcaGTJTjqFDo/VJ+Bt 5PFcjPuWasKF+40jDTw3nDpqHbjpOI0kkz1wzqEQR9uQzcmopu4quevl7TVoA/pTqbjl zrDw== X-Gm-Message-State: AOJu0YzP2DbY2z2m/xpeK/Vj0/Jt5LvtbVhpP7fXnE4LABFENz/gzyER 0WqSVlcEfQJP3hDar0FCpHt/PGohaXgSJSlGfJUhBy+AyNaqpkCMkp1OUee5ImdOho1eN5gLEnH NbiJjWTv41nkWdocCnUVqwxUq8OdW+9oW7LcpFGlvP4dBxYzxcHrhXGAKNNDoIiJ29dyvmoSvHO CF54Hahy7PlJzNnkALiSLqKeL+y38dw8lzGIH8 X-Received: by 2002:a05:620a:2685:b0:7a9:bdac:63fe with SMTP id af79cd13be357-7a9bdac6734mr166867085a.11.1725893661299; Mon, 09 Sep 2024 07:54:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEhUWO9wpYAAnIhrWrEGD6pkrTLIfWjX1eE5Sp1EgBf7OqBu6xU+luf+nixk7K+GkpfA2SahA== X-Received: by 2002:a05:620a:2685:b0:7a9:bdac:63fe with SMTP id af79cd13be357-7a9bdac6734mr166862685a.11.1725893660833; Mon, 09 Sep 2024 07:54:20 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Vitaly Kuznetsov , David Hildenbrand , Paolo Bonzini , peterx@redhat.com, Prasad Pandit , Juraj Marcin , Julia Suvorova , Fabiano Rosas Subject: [PATCH v3 3/4] KVM: Rename KVMMemoryListener.nr_used_slots to nr_slots_used Date: Mon, 9 Sep 2024 10:54:12 -0400 Message-ID: <20240909145413.3748429-4-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240909145413.3748429-1-peterx@redhat.com> References: <20240909145413.3748429-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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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: 1725893730750116600 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 48e496b3d4..b705dfc9b4 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 2a2ee4e7d7..ab0ab98a71 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 06:54:11 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=1725893734; cv=none; d=zohomail.com; s=zohoarc; b=EX93SeRj5TRMYsQnj7woKVBrCfdwPhHrR5xt2sRv4CUI8dyWnzBkh3PKl7PQmPud8mJxJnv2RtEe+DtjdbKXcGq2yccmorNmrORV4CMXpn4LdrgG4I/fWYZAyr8qxOe/YUFz0xn6lvGAEFr+nH3aEYp7cNCr2s4xDMVmG5L9zho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725893734; 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=aJxhZRez+hiilw4HFMtQuOQuennGpo9FEmpsBy+bM5w=; b=NNSIDwkxgON0RoZwRq4hw7VCqOUF1S2pSVe93T92N8OjKXBTfRAC6+M3zZBNfmqmyU2pWg0FDw+lHd++N8w/hdLXqtCwZfZRL6c2eWZAtVUsLf9+WE2txthc2u/fXPE2X1BZA1bg3HARts4qT9lxWxLZLOXhQIpog7P00KXt+3w= 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 1725893734606769.3628879901546; Mon, 9 Sep 2024 07:55:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snfmj-0005lN-VA; Mon, 09 Sep 2024 10:54:33 -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 1snfmf-0005Tk-PN for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:54:29 -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 1snfmc-00072R-NH for qemu-devel@nongnu.org; Mon, 09 Sep 2024 10:54:28 -0400 Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-DqVq-GqMNSGvVrO9NLdRNg-1; Mon, 09 Sep 2024 10:54:23 -0400 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7a9b1216a68so282398285a.2 for ; Mon, 09 Sep 2024 07:54:23 -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 af79cd13be357-7a9a79455b1sm225387585a.19.2024.09.09.07.54.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Sep 2024 07:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725893666; 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=aJxhZRez+hiilw4HFMtQuOQuennGpo9FEmpsBy+bM5w=; b=iGh/CExUqxfbvgeG4BXz3yvjz0h2JsI3wJxUwd6jCr6MggquWiXYC5zumKwDQyKchAHUY0 YIzKQyILfgHuHD76jfNZezY464wG6fqnHHJjDcAY8mp1AxPALhbI5J/30Ge3xnJLi0Y1iD V7yYkPAHbRtkGx4SDDIj29Fa0RDKeTc= X-MC-Unique: DqVq-GqMNSGvVrO9NLdRNg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725893663; x=1726498463; 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=aJxhZRez+hiilw4HFMtQuOQuennGpo9FEmpsBy+bM5w=; b=XD43+f89548lMigiMvhX7H3hrim9NQ53zqEfrZWI9324EFgVwszX3bLmAToUAmZXQc D4dv1IQ4ecja2PCR8uyVlQ1I/5N8Bo3wq3TsK9KAUsRe3JYBKgv+5dHtJU9Xphulivq9 4QxkxFet6gDERTMD2yC+ieiqwlmQ0qUE959oEPXRJPL/IIKnqA8DfN7qyK67E+h6+IVC tHiGsBHDKHKBHOpaaH7Q4NmxoxNsUP+dBj9Z1ouN9PDEjo0jM0INjzXjN0l72xB8lYQq 4DaFue75tNsYqTrrc8csBLsQBgmcNLgltSbp2dYorW6+j5eIQu5HSLdWXzRUuvQQxxtO t02w== X-Gm-Message-State: AOJu0YzFS6gvjit4KcmW6yDVEUg+hZNHM0gCee2w1ZLOh6hPKIVxUk3d lvnRrOFW+0rzxOJJUIk2xmyitFQXml1+1NnPDMlgMD2Nr+F9D84o1HbtpPIS9ts8w5oWigS2TSY GzCNzoHVp2EBb2QP0Ix/BPG10EEFiMkx6FvzPFzjkWul50Scggme9UHpM550UGg0GUaRXeJPGzK nTB/BylNKL03SO4sb5nrQwagS1+jhe99tFY8g+ X-Received: by 2002:a05:620a:459f:b0:7a9:a744:f989 with SMTP id af79cd13be357-7a9a7450021mr761639185a.46.1725893662775; Mon, 09 Sep 2024 07:54:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxyyDuRFutZ9SurivTZezl9sM7RaJ/Sy3n2utubAl5K9EQoOTV0wbZ/DrDyKBpyDrg07WlGA== X-Received: by 2002:a05:620a:459f:b0:7a9:a744:f989 with SMTP id af79cd13be357-7a9a7450021mr761634785a.46.1725893662302; Mon, 09 Sep 2024 07:54:22 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Vitaly Kuznetsov , David Hildenbrand , Paolo Bonzini , peterx@redhat.com, Prasad Pandit , Juraj Marcin , Julia Suvorova , Fabiano Rosas Subject: [PATCH v3 4/4] KVM: Rename KVMState->nr_slots to nr_slots_max Date: Mon, 9 Sep 2024 10:54:13 -0400 Message-ID: <20240909145413.3748429-5-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240909145413.3748429-1-peterx@redhat.com> References: <20240909145413.3748429-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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, 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: 1725893734965116600 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 | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h index b705dfc9b4..2c57194b6b 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 ab0ab98a71..bad2930827 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 @@ -2525,10 +2525,10 @@ static int kvm_init(MachineState *ms) * fail to boot. Make sure the supported value is always at least * larger than what we will initially allocate. */ - if (s->nr_slots < KVM_MEMSLOTS_NR_ALLOC_DEFAULT) { + if (s->nr_slots_max < KVM_MEMSLOTS_NR_ALLOC_DEFAULT) { ret =3D -EINVAL; fprintf(stderr, "KVM max supported number of slots (%d) too small\= n", - s->nr_slots); + s->nr_slots_max); goto err; } =20 --=20 2.45.0