From nobody Sat Feb 7 13:45:29 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642581899814300.1390071461791; Wed, 19 Jan 2022 00:44:59 -0800 (PST) Received: from localhost ([::1]:59822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nA6aO-0003IF-Vv for importer@patchew.org; Wed, 19 Jan 2022 03:44:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58764) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nA62h-00071p-K8 for qemu-devel@nongnu.org; Wed, 19 Jan 2022 03:10:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60939) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nA62e-0000ve-RD for qemu-devel@nongnu.org; Wed, 19 Jan 2022 03:10:07 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-592-7o66h_i1NKyRGreovZcf_w-1; Wed, 19 Jan 2022 03:09:59 -0500 Received: by mail-wm1-f69.google.com with SMTP id f187-20020a1c38c4000000b0034d5c66d8f5so1424803wma.5 for ; Wed, 19 Jan 2022 00:09:58 -0800 (PST) Received: from localhost.localdomain ([85.203.46.175]) by smtp.gmail.com with ESMTPSA id a20sm4351606wmb.27.2022.01.19.00.09.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Jan 2022 00:09:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642579800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MjqZSUin4KGk042s0HnlvgC6wrmCkM8/MM5iweJa6Cc=; b=E7FqOMyD7EyZUfkYdKBEHhQlNAOMSnU+lMymnL+Do0T5asoCY8b3qraJfhMeQSXXSyI/V1 Xt4bGOPMTl1B7hy6+4clu2HE0pGO50bzc463tcjKAuKxDXYW51Tg/3sqeEBeGyAEQFPQDS W6/pt0ddCLTN88TlNKPV0MVodR2voMM= X-MC-Unique: 7o66h_i1NKyRGreovZcf_w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MjqZSUin4KGk042s0HnlvgC6wrmCkM8/MM5iweJa6Cc=; b=uVOxmkkCegoep/RGJfjajPU+S2YuyD7wIQ1I3kXIP2Jbnfa0g2kHMUAnqpzOqZeil0 jqG5vTogHEwUIbi/KueyO2Tl5CwrVmrNVwtFi1XH2c/ZR6NvZWdM2l8+Sy0tbcXREcpR PTsTWImkumfxd5vdEUVCRynem4awlck60d9FLYvOjSxUoSxObc1cGno37mcMEVUv9UAn EvgIvnPDQkWIIy7Q6pifkLWTx3BzK2tbJTxUv8YCzOeBa6A63v07zjUZkihqeeOnbqJo ZdR2ZsVj8WjdS09kz5p0ghK7mdFqcL1RicISRDz4VlPc8Mmq5zURVDja/6TEANon5Ke+ d0rg== X-Gm-Message-State: AOAM533Zxh1CEdjRyPwUPHAaJ9ZCHHokMsPt2A9CNA6PRFHeWJdRWEEs JrxLH/A4sMn7auZRr3Mv+sV1dPi27VytavSkhEacI918pQpWoq5SRloI3+FrGZgwky26XumcZqV KLrJ9zuf9MnYnRrofdEyYCpOETe/oSOw3PpMCMYaS5NFCoUwaupX6ZtG0kPLM5VE0 X-Received: by 2002:a5d:64c1:: with SMTP id f1mr15358217wri.633.1642579797489; Wed, 19 Jan 2022 00:09:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJz+aZ0BIt09rnM/y9DndauFJob9gDwVcWyarrfIAAc0ofP98joFoAWbZaYkHz1MtlwX635+ow== X-Received: by 2002:a5d:64c1:: with SMTP id f1mr15358195wri.633.1642579797214; Wed, 19 Jan 2022 00:09:57 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH RFC 04/15] migration: Add postcopy_has_request() Date: Wed, 19 Jan 2022 16:09:18 +0800 Message-Id: <20220119080929.39485-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220119080929.39485-1-peterx@redhat.com> References: <20220119080929.39485-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URG_BIZ=0.573 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: , Cc: Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com, Leonardo Bras Soares Passos Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642581902349100001 Content-Type: text/plain; charset="utf-8" Add a helper to detect whether postcopy has pending request. Since at it, cleanup the code a bit, e.g. in unqueue_page() we shouldn't ne= ed to check it again on queue empty because we're the only one (besides cleanup code, which should never run during this process) that will take a request = off the list, so the request list can only grow but not shrink under the hood. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela --- migration/ram.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 94b0ad4234..dc6ba041fa 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -354,6 +354,12 @@ static RAMState *ram_state; =20 static NotifierWithReturnList precopy_notifier_list; =20 +/* Whether postcopy has queued requests? */ +static bool postcopy_has_request(RAMState *rs) +{ + return !QSIMPLEQ_EMPTY_ATOMIC(&rs->src_page_requests); +} + void precopy_infrastructure_init(void) { notifier_with_return_list_init(&precopy_notifier_list); @@ -1533,28 +1539,33 @@ static bool find_dirty_block(RAMState *rs, PageSear= chStatus *pss, bool *again) */ static RAMBlock *unqueue_page(RAMState *rs, ram_addr_t *offset) { + struct RAMSrcPageRequest *entry; RAMBlock *block =3D NULL; =20 - if (QSIMPLEQ_EMPTY_ATOMIC(&rs->src_page_requests)) { + if (!postcopy_has_request(rs)) { return NULL; } =20 QEMU_LOCK_GUARD(&rs->src_page_req_mutex); - if (!QSIMPLEQ_EMPTY(&rs->src_page_requests)) { - struct RAMSrcPageRequest *entry =3D - QSIMPLEQ_FIRST(&rs->src_page_requests); - block =3D entry->rb; - *offset =3D entry->offset; - - if (entry->len > TARGET_PAGE_SIZE) { - entry->len -=3D TARGET_PAGE_SIZE; - entry->offset +=3D TARGET_PAGE_SIZE; - } else { - memory_region_unref(block->mr); - QSIMPLEQ_REMOVE_HEAD(&rs->src_page_requests, next_req); - g_free(entry); - migration_consume_urgent_request(); - } + + /* + * This should _never_ change even after we take the lock, because no = one + * should be taking anything off the request list other than us. + */ + assert(postcopy_has_request(rs)); + + entry =3D QSIMPLEQ_FIRST(&rs->src_page_requests); + block =3D entry->rb; + *offset =3D entry->offset; + + if (entry->len > TARGET_PAGE_SIZE) { + entry->len -=3D TARGET_PAGE_SIZE; + entry->offset +=3D TARGET_PAGE_SIZE; + } else { + memory_region_unref(block->mr); + QSIMPLEQ_REMOVE_HEAD(&rs->src_page_requests, next_req); + g_free(entry); + migration_consume_urgent_request(); } =20 return block; @@ -2996,7 +3007,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) t0 =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); i =3D 0; while ((ret =3D qemu_file_rate_limit(f)) =3D=3D 0 || - !QSIMPLEQ_EMPTY(&rs->src_page_requests)) { + postcopy_has_request(rs)) { int pages; =20 if (qemu_file_get_error(f)) { --=20 2.32.0