From patchwork Mon Aug 29 16:56:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671537 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YJKVzIPb; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGc8d3k7Dz1yhC for ; Tue, 30 Aug 2022 02:58:41 +1000 (AEST) Received: from localhost ([::1]:55630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSi5u-0002gE-BN for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 12:58:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4X-0002ci-Hr for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24934) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4U-0008FW-62 for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792227; 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=iQ5Ra+ruvStjfFrbVSdey9x+7/jgCpP+KsGMmIk95tM=; b=YJKVzIPb/DmfjSXPq4W820nSi1iG9L0xi8ctB6NUW1+4HkbGgtHq/NA2G4WWHpk7h35obR r8g+g5EAgPxVgw6xEhLgcIqW3tlpQfnx+5RCk2xqeVN5eztj3hTP9VAmDSFk4t8N7fZMcZ fWKjq/k8M4ViO2AyQlVznmArwvu4HaM= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-418-IDmkA_NUOx-SXvcYUtVBbg-1; Mon, 29 Aug 2022 12:57:06 -0400 X-MC-Unique: IDmkA_NUOx-SXvcYUtVBbg-1 Received: by mail-io1-f72.google.com with SMTP id o10-20020a6b5a0a000000b0068aba769d73so5057234iob.4 for ; Mon, 29 Aug 2022 09:57:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=iQ5Ra+ruvStjfFrbVSdey9x+7/jgCpP+KsGMmIk95tM=; b=z1W+jAhEdvuo7+qPCS2vwO/TJMZphG1LFoc6i9eCVReYmflp+eZ68Qf0TEaV1Cw+iY DmdT+69djnYq+/H//yVOOfieFt8OCyzzerteLmxHcvKu9vePfyWY71NEfEllyhFG1fJI 9oT6REz5k9cug5pL9ub73rdcy1BJTaI1/5d3C5YaCdXynHYsBdcuAH1CvvNNWl770OKT tpx+R0YKbciqOzPX0pXzhga2ITE+mQ20UJ70W9mpHmO16vGtg+869gVR0z2QzwpVcB5/ z8ZQlUojmAnnd7iPTSjgYC7sCV29Z35DVMOmj51kUXgUw6rJHg72FsMxeq7vA93E+3Wk LnMQ== X-Gm-Message-State: ACgBeo0VnjMTJchPKfDgYP98ATwkeajen544qcXQtrMyPXHitF6j7euI IZekQUqFdKVRPHKGo/mUyTf0fKazEzVUQrfFNJ7B2Jjcf+p0TVx7PoziB2jKNhG/Rfz5ii+BEdM rXXCpdd1Pf0HGwda70RMv5mTBfyjckfG+/KE2Q6Qp350KM0loMeEMC7HhceBdRhxT X-Received: by 2002:a02:29c2:0:b0:34a:195e:9574 with SMTP id p185-20020a0229c2000000b0034a195e9574mr10302904jap.79.1661792224972; Mon, 29 Aug 2022 09:57:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR7DENDl2POjwg2ICP6sziCNGLmMtWInpPiZoHQUi+oV14X9MJZ1gsgTrMJ85Lcn16BmMzDkLQ== X-Received: by 2002:a02:29c2:0:b0:34a:195e:9574 with SMTP id p185-20020a0229c2000000b0034a195e9574mr10302887jap.79.1661792224701; Mon, 29 Aug 2022 09:57:04 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 01/13] migration: Use non-atomic ops for clear log bitmap Date: Mon, 29 Aug 2022 12:56:47 -0400 Message-Id: <20220829165659.96046-2-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Since we already have bitmap_mutex to protect either the dirty bitmap or the clear log bitmap, we don't need atomic operations to set/clear/test on the clear log bitmap. Switching all ops from atomic to non-atomic versions, meanwhile touch up the comments to show which lock is in charge. Introduced non-atomic version of bitmap_test_and_clear_atomic(), mostly the same as the atomic version but simplified a few places, e.g. dropped the "old_bits" variable, and also the explicit memory barriers. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- include/exec/ram_addr.h | 11 +++++----- include/qemu/bitmap.h | 1 + util/bitmap.c | 45 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index f3e0c78161..5092a2e0ff 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -42,7 +42,8 @@ static inline long clear_bmap_size(uint64_t pages, uint8_t shift) } /** - * clear_bmap_set: set clear bitmap for the page range + * clear_bmap_set: set clear bitmap for the page range. Must be with + * bitmap_mutex held. * * @rb: the ramblock to operate on * @start: the start page number @@ -55,12 +56,12 @@ static inline void clear_bmap_set(RAMBlock *rb, uint64_t start, { uint8_t shift = rb->clear_bmap_shift; - bitmap_set_atomic(rb->clear_bmap, start >> shift, - clear_bmap_size(npages, shift)); + bitmap_set(rb->clear_bmap, start >> shift, clear_bmap_size(npages, shift)); } /** - * clear_bmap_test_and_clear: test clear bitmap for the page, clear if set + * clear_bmap_test_and_clear: test clear bitmap for the page, clear if set. + * Must be with bitmap_mutex held. * * @rb: the ramblock to operate on * @page: the page number to check @@ -71,7 +72,7 @@ static inline bool clear_bmap_test_and_clear(RAMBlock *rb, uint64_t page) { uint8_t shift = rb->clear_bmap_shift; - return bitmap_test_and_clear_atomic(rb->clear_bmap, page >> shift, 1); + return bitmap_test_and_clear(rb->clear_bmap, page >> shift, 1); } static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 82a1d2f41f..3ccb00865f 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -253,6 +253,7 @@ void bitmap_set(unsigned long *map, long i, long len); void bitmap_set_atomic(unsigned long *map, long i, long len); void bitmap_clear(unsigned long *map, long start, long nr); bool bitmap_test_and_clear_atomic(unsigned long *map, long start, long nr); +bool bitmap_test_and_clear(unsigned long *map, long start, long nr); void bitmap_copy_and_clear_atomic(unsigned long *dst, unsigned long *src, long nr); unsigned long bitmap_find_next_zero_area(unsigned long *map, diff --git a/util/bitmap.c b/util/bitmap.c index f81d8057a7..8d12e90a5a 100644 --- a/util/bitmap.c +++ b/util/bitmap.c @@ -240,6 +240,51 @@ void bitmap_clear(unsigned long *map, long start, long nr) } } +bool bitmap_test_and_clear(unsigned long *map, long start, long nr) +{ + unsigned long *p = map + BIT_WORD(start); + const long size = start + nr; + int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG); + unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start); + bool dirty = false; + + assert(start >= 0 && nr >= 0); + + /* First word */ + if (nr - bits_to_clear > 0) { + if ((*p) & mask_to_clear) { + dirty = true; + } + *p &= ~mask_to_clear; + nr -= bits_to_clear; + bits_to_clear = BITS_PER_LONG; + p++; + } + + /* Full words */ + if (bits_to_clear == BITS_PER_LONG) { + while (nr >= BITS_PER_LONG) { + if (*p) { + dirty = true; + *p = 0; + } + nr -= BITS_PER_LONG; + p++; + } + } + + /* Last word */ + if (nr) { + mask_to_clear &= BITMAP_LAST_WORD_MASK(size); + if ((*p) & mask_to_clear) { + dirty = true; + } + *p &= ~mask_to_clear; + } + + return dirty; +} + bool bitmap_test_and_clear_atomic(unsigned long *map, long start, long nr) { unsigned long *p = map + BIT_WORD(start); From patchwork Mon Aug 29 16:56:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671535 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N2ylz5kx; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGc8c1G10z1yhC for ; Tue, 30 Aug 2022 02:58:40 +1000 (AEST) Received: from localhost ([::1]:45200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSi5u-0002el-1B for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 12:58:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4X-0002d7-II for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40114) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4V-0008Fg-HB for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792228; 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=rgr99bIWyM5L4P9pc8hfhC39aU33CUh7xyLzYjt26gI=; b=N2ylz5kxbfKJOpDOKF+dluTfqTyMg3BU5Blbqvw8/57vb+daiWP3gWlKkpbpXu2/waAOQK oxihFl6MmmvdLZPY8h+hYR42PtNOsyBee0nQYXukKGoENmv/6RCT7kzv6zZ6tJ6eMib4SE Zl/Oqfwllw3MlWdnk3ss9QaGLj0AQXQ= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-542-h9Ay70-BOZm47rYEAzDrWA-1; Mon, 29 Aug 2022 12:57:07 -0400 X-MC-Unique: h9Ay70-BOZm47rYEAzDrWA-1 Received: by mail-il1-f198.google.com with SMTP id k9-20020a056e021a8900b002e5bd940e96so6334815ilv.13 for ; Mon, 29 Aug 2022 09:57:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=rgr99bIWyM5L4P9pc8hfhC39aU33CUh7xyLzYjt26gI=; b=fQ9NpN9fyRCyx/TbViHp5IGmJYoWj5Ea/WaqsgJEuHkZyEVxAk+6vw8yhuY6+GnOQL AyuDYW+xiD2NRT/F9P2oA3toquxALJTtHe2ETRLvUKERQmwBz48ATTSTVbifagmuSwWf u6QVG62geOVvqisDVpVPFXL+aeRiTTBi8ClfRngohxPjR+/wQfWOIS5HY0jjm+SoiE5L nq0qBNkinK9NhVMsuIodL2kWNtw5mPK8vBsm1qE9kInnOOkIWuShBw4HUIJJHPSc6Jjg HypBI1CsCb766G+hQkSXNxTECFZTvF/tpE9LfG3wkjVf3OdjPhjbT2Fo1c7Cbx679gjZ 0yag== X-Gm-Message-State: ACgBeo286ubD4bD7ukg5TVyWTntlJ9PYLaSEA/QEJTIn/Tbeub7A9KS+ 8lLvb0q2TPDDm/k5j9Fj94qU3It8GXaXdsGfn9yn6BSD+ha3/LxdqL7kw+Zd5AY+J76fmfZhnTX 7i9+Bc868i1fvAAKJ9SiJsyvocFTTdku6QdBvv5Yjpgke6Pf3jbgDtDVcBmZkF9zq X-Received: by 2002:a05:6e02:923:b0:2eb:2f46:c97 with SMTP id o3-20020a056e02092300b002eb2f460c97mr1781854ilt.116.1661792226233; Mon, 29 Aug 2022 09:57:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR4YO8x2Mhi4UUg5anPTnYKI/M25Hhf/KcwIhMUouNhOfnK3HQItrU8NZO5cakBCFTtPoI2V/A== X-Received: by 2002:a05:6e02:923:b0:2eb:2f46:c97 with SMTP id o3-20020a056e02092300b002eb2f460c97mr1781841ilt.116.1661792226041; Mon, 29 Aug 2022 09:57:06 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:05 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 02/13] migration: Add postcopy_preempt_active() Date: Mon, 29 Aug 2022 12:56:48 -0400 Message-Id: <20220829165659.96046-3-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add the helper to show that postcopy preempt enabled, meanwhile active. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index dc1de9ddbc..8c5d5332e8 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -162,6 +162,11 @@ out: return ret; } +static bool postcopy_preempt_active(void) +{ + return migrate_postcopy_preempt() && migration_in_postcopy(); +} + bool ramblock_is_ignored(RAMBlock *block) { return !qemu_ram_is_migratable(block) || @@ -2434,7 +2439,7 @@ static void postcopy_preempt_choose_channel(RAMState *rs, PageSearchStatus *pss) /* We need to make sure rs->f always points to the default channel elsewhere */ static void postcopy_preempt_reset_channel(RAMState *rs) { - if (migrate_postcopy_preempt() && migration_in_postcopy()) { + if (postcopy_preempt_active()) { rs->postcopy_channel = RAM_CHANNEL_PRECOPY; rs->f = migrate_get_current()->to_dst_file; trace_postcopy_preempt_reset_channel(); @@ -2472,7 +2477,7 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) return 0; } - if (migrate_postcopy_preempt() && migration_in_postcopy()) { + if (postcopy_preempt_active()) { postcopy_preempt_choose_channel(rs, pss); } From patchwork Mon Aug 29 16:56:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671538 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=O2hKxpsT; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGc8g4fbBz1yhC for ; Tue, 30 Aug 2022 02:58:43 +1000 (AEST) Received: from localhost ([::1]:55634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSi5x-0002n0-Gv for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 12:58:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4X-0002d6-It for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52177) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4U-0008Fl-Kt for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792229; 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=2a+RxJMAC8kQq3wYpNHzFC5aT7sCj9AyeAPBtAZ223E=; b=O2hKxpsTf2bWzsk8v6qVgacut8QMzc99IgD8G2I4ZdxkMLepf2/MkrCMTlyTqswR1Z9yYw 8h/j/fLX4G9DNIsCnyLWPXESAp3IGiBok0zYgK7x7XReT/Nge/Lsad1XF1TeVanAJXKkaJ zXxGBQk31bLN+CGZcu0zRQEeJwyilZw= Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-77-on3qCicGOTuUHnUru_LxJA-1; Mon, 29 Aug 2022 12:57:08 -0400 X-MC-Unique: on3qCicGOTuUHnUru_LxJA-1 Received: by mail-il1-f197.google.com with SMTP id i13-20020a056e02152d00b002e97839ff00so6346998ilu.15 for ; Mon, 29 Aug 2022 09:57:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=2a+RxJMAC8kQq3wYpNHzFC5aT7sCj9AyeAPBtAZ223E=; b=me3t/McXEv1cPxTvk4nOl3i8U028e+ZH7OZlV3CY+PY3vmM/JHjvbY8yQtkrhXBGBN IRAKgpahXBsGn9K9JucIEHlaTjyolRLV8qFpdV9TBtIHK5pITzFsPiZBSjBPbeRhUcEI 4najqcsipU2YNxUg/iPUmDZopOXVE2k+dpdlYz86kV0s4gjwNEHIlM4i8EHzjnP5C9/G tW1CsEMs7N2FrKVamlfAdnJ1VCjst7mThf52d1hL0IyFF2Nk0OWG3K/kfO0+Is8wnOxa IDTRpZEpQTt5tPauY/Dx1KGTfez04X68rBNW+mzxye8mkaFPkW9GBZQ7gTCb14t+5N7V 3L7g== X-Gm-Message-State: ACgBeo2Vl8wxafbR0MBGhrgAP0zsyWmML/zDapG0l+v9H/iRDIFXK7g5 JY21D9MT6S+zvaLvVtjZ5Io1qRjeP2sNJ8iYEDhlX2t4S/Cabm1hbAH1OzE3F+h5cO6hhYkEEgS QwLwXQ5RkjmDn93zsWyAjeaJcAEa339t/UuohV+YX3cAUcI41QzxOmHgT1WGuSw57 X-Received: by 2002:a05:6602:1681:b0:678:9e4e:cd76 with SMTP id s1-20020a056602168100b006789e4ecd76mr8940604iow.80.1661792227722; Mon, 29 Aug 2022 09:57:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR40d95gvGIKlXJ2Zc5qiJqspihaPdTCeEtF5kerzlYI48vv8iYv4EOyn89lFTFsKM8tx6z/FA== X-Received: by 2002:a05:6602:1681:b0:678:9e4e:cd76 with SMTP id s1-20020a056602168100b006789e4ecd76mr8940590iow.80.1661792227437; Mon, 29 Aug 2022 09:57:07 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:07 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 03/13] migration: Yield bitmap_mutex properly when sending/sleeping Date: Mon, 29 Aug 2022 12:56:49 -0400 Message-Id: <20220829165659.96046-4-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Don't take the bitmap mutex when sending pages, or when being throttled by migration_rate_limit() (which is a bit tricky to call it here in ram code, but seems still helpful). It prepares for the possibility of concurrently sending pages in >1 threads using the function ram_save_host_page() because all threads may need the bitmap_mutex to operate on bitmaps, so that either sendmsg() or any kind of qemu_sem_wait() blocking for one thread will not block the other from progressing. Signed-off-by: Peter Xu --- migration/ram.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 8c5d5332e8..9e96a46323 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2470,6 +2470,7 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) unsigned long hostpage_boundary = QEMU_ALIGN_UP(pss->page + 1, pagesize_bits); unsigned long start_page = pss->page; + bool page_dirty; int res; if (ramblock_is_ignored(pss->block)) { @@ -2487,22 +2488,41 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) break; } + page_dirty = migration_bitmap_clear_dirty(rs, pss->block, pss->page); + /* + * Properly yield the lock only in postcopy preempt mode because + * both migration thread and rp-return thread can operate on the + * bitmaps. + */ + if (postcopy_preempt_active()) { + qemu_mutex_unlock(&rs->bitmap_mutex); + } + /* Check the pages is dirty and if it is send it */ - if (migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { + if (page_dirty) { tmppages = ram_save_target_page(rs, pss); - if (tmppages < 0) { - return tmppages; + if (tmppages >= 0) { + pages += tmppages; + /* + * Allow rate limiting to happen in the middle of huge pages if + * something is sent in the current iteration. + */ + if (pagesize_bits > 1 && tmppages > 0) { + migration_rate_limit(); + } } + } else { + tmppages = 0; + } - pages += tmppages; - /* - * Allow rate limiting to happen in the middle of huge pages if - * something is sent in the current iteration. - */ - if (pagesize_bits > 1 && tmppages > 0) { - migration_rate_limit(); - } + if (postcopy_preempt_active()) { + qemu_mutex_lock(&rs->bitmap_mutex); } + + if (tmppages < 0) { + return tmppages; + } + pss->page = migration_bitmap_find_dirty(rs, pss->block, pss->page); } while ((pss->page < hostpage_boundary) && offset_in_ramblock(pss->block, From patchwork Mon Aug 29 16:56:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZBCi9hSk; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGcKH4vVFz1yhy for ; Tue, 30 Aug 2022 03:06:10 +1000 (AEST) Received: from localhost ([::1]:59572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSiD8-0000AV-OQ for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 13:06:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4X-0002d8-JP for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35480) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4W-0008Fq-1i for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792231; 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=RnBByk/sg3d5WrRRuIt463rDLN2iKCyHCcDizi40DdU=; b=ZBCi9hSkXUvkYxI1KbseyN+A1kd5qy7ROintCCkLPQt5PSA7YD17Wjxaj/mM/1sJ3+xWBa V21Qh/K1E3eLVh+SFv/UHJe/uBrblRdyeQjZt9nLuSd/tFNjoNrODJe2ce9xj+zY1zQfD5 0EGPL1209a1uULqj7XE/vU7T/aBfTsc= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-53-eNzzH4u8PeS1ZAlImPvLrg-1; Mon, 29 Aug 2022 12:57:10 -0400 X-MC-Unique: eNzzH4u8PeS1ZAlImPvLrg-1 Received: by mail-il1-f198.google.com with SMTP id l20-20020a056e02067400b002dfa7256498so6364573ilt.4 for ; Mon, 29 Aug 2022 09:57:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=RnBByk/sg3d5WrRRuIt463rDLN2iKCyHCcDizi40DdU=; b=jbVKinA1hpOa6ayIcow3EFoSiWaMSnTOxp6rSDwTAthrqDX54MzOo6H0tMKWhe4Hht xmupb4tBOhLApoO3W+LXmeBC3EtmQjFZMayS2LNS9BsaOSA0r6Kpr/jH0VoDTE1gWxnS gqKjw76Z0EDgWIJinbR4xXzbKGfNEaNabQGvM/7AaB7ULYUhWmfmu5NzRIEiUwQBHit/ 9Z8PUpIH6+QwEzrnAmZ9USMJpDmrv+QXiEV7myBWqdgsy1GJppA5ggCdV5jXSf54sWXU 8JBaST/6vZeTpRjYMlQxNftajZHHCSv5UnxWWHrQkPTl2cBtYfS6PIuwmlHw12NSiEAl /5fw== X-Gm-Message-State: ACgBeo38Dt0XGPYK9Kn5AiQjO1cayhwon7R4pdG2APIgnwfOO+FSnYWb KW7sUW3irNza1h4xRw9mSmywLCWEdvKfvB2sdwHx09Pzrnfv/Sg6oWyEujb2mY1R0sJJiROBu+P czeuMzcFPDEm9nQlm7ELFa6lfLpreA5kZR+dSYFwwd8FawDVOrEt9jYKFrd83xlZ2 X-Received: by 2002:a05:6638:3e17:b0:34a:49dc:48c3 with SMTP id co23-20020a0566383e1700b0034a49dc48c3mr2399988jab.158.1661792229508; Mon, 29 Aug 2022 09:57:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Qk21U1y9qvjOiBy2eAeX9NJJ4MbXjk6MlS69URDLn0/r5/kM6T9Aqe3TWs25AeAOBVtpGbA== X-Received: by 2002:a05:6638:3e17:b0:34a:49dc:48c3 with SMTP id co23-20020a0566383e1700b0034a49dc48c3mr2399970jab.158.1661792229125; Mon, 29 Aug 2022 09:57:09 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:08 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 04/13] migration: Cleanup xbzrle zero page cache update logic Date: Mon, 29 Aug 2022 12:56:50 -0400 Message-Id: <20220829165659.96046-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The major change is to replace "!save_page_use_compression()" with "xbzrle_enabled" to make it clear. Reasonings: (1) When compression enabled, "!save_page_use_compression()" is exactly the same as checking "xbzrle_enabled". (2) When compression disabled, "!save_page_use_compression()" always return true. We used to try calling the xbzrle code, but after this change we won't, and we shouldn't need to. Since at it, drop the xbzrle_enabled check in xbzrle_cache_zero_page() because with this change it's not needed anymore. Signed-off-by: Peter Xu --- migration/ram.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 9e96a46323..612c7dd708 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -741,10 +741,6 @@ void mig_throttle_counter_reset(void) */ static void xbzrle_cache_zero_page(RAMState *rs, ram_addr_t current_addr) { - if (!rs->xbzrle_enabled) { - return; - } - /* We don't care if this fails to allocate a new cache page * as long as it updated an old one */ cache_insert(XBZRLE.cache, current_addr, XBZRLE.zero_target_page, @@ -2301,7 +2297,7 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss) /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale */ - if (!save_page_use_compression(rs)) { + if (rs->xbzrle_enabled) { XBZRLE_cache_lock(); xbzrle_cache_zero_page(rs, block->offset + offset); XBZRLE_cache_unlock(); From patchwork Mon Aug 29 16:56:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671563 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=R+vbtWr7; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGcKK6t4mz1yhw for ; Tue, 30 Aug 2022 03:06:13 +1000 (AEST) Received: from localhost ([::1]:41204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSiDD-0000Fe-Gp for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 13:06:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4Z-0002d9-CE for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:58151) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4X-0008G8-V6 for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792232; 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=cC3mgjSqsxkLeKj7H0avzhkHAl95oTqWqQAf5MqmKUk=; b=R+vbtWr7BpbC0Z2D9rFzBheGusxCb717WrrrpntnjjHUa33mVxaCXeBAcArqjrJRFiw4IY /h23OxsrZ9spXMwZ5+dmoE5qaUOrYJXLoYPLMWXsYBEXxFuGWUiHDqqTd7IWgEaZGCc0pD xx897V5ljhbatsmPkAOSeLuZCxn2G2U= Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-487-0w4yNk2BM369AmLjINyEYg-1; Mon, 29 Aug 2022 12:57:11 -0400 X-MC-Unique: 0w4yNk2BM369AmLjINyEYg-1 Received: by mail-io1-f72.google.com with SMTP id x9-20020a056602210900b006897b3869e4so5051027iox.16 for ; Mon, 29 Aug 2022 09:57:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=cC3mgjSqsxkLeKj7H0avzhkHAl95oTqWqQAf5MqmKUk=; b=JXhkqqX6DW9KhQFb5goKXpep9RTV/a81plVO70D2w5wRh+aTBHDA6k20APYyraqJe8 vav9gExmkJbj2/kErO6IWNLdgZ2hm3riosd8WccPzbQ+cyFzvlIsvt81iHGoezA3bXur qXKelSWTSEhbFlwhyoG/grBcaD+WdycTcCAS3/Oon9DcHwB9CHokyEJ32JViP5G8tb73 gDlZ98qUWgTEErUKnn/g80+N0psHJDhWiXTB/NrYPnF5JzvTbryC45YbA9oiVXqiYM1v 5beBqgnSW2AUbe8eQR/N6AgvaO0DDaPu+AHO8ATbEcvbFEe7lj99k9Ye5OY2bbBnChSX rM5g== X-Gm-Message-State: ACgBeo14Oqoe06grXg4W1ytkF0sPs6FUAAycDms6BKNsveeQWkjTWoS4 ekkINMm86ZOYbzkdkk2Sj/bvAMPlY8y6JiILPRcH47qfdb3mC3t9pALCUkRKvGSdKkWxvNiNQrx lukZPb08kFAKsenNdiwhld9NaOykw0zE7ZSxBtq8giUqie0eh4aobwejKzfc7f8Fh X-Received: by 2002:a6b:5d0f:0:b0:688:6559:7a00 with SMTP id r15-20020a6b5d0f000000b0068865597a00mr9005444iob.42.1661792230803; Mon, 29 Aug 2022 09:57:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR5kqEtgNIcXipnoc3ypE8mxcYkk9943WRYI/A++IoF5+jN2Rr8Fk9QU69MwkIOxjD6Z0t/AHg== X-Received: by 2002:a6b:5d0f:0:b0:688:6559:7a00 with SMTP id r15-20020a6b5d0f000000b0068865597a00mr9005432iob.42.1661792230561; Mon, 29 Aug 2022 09:57:10 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:10 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 05/13] migration: Disallow postcopy preempt to be used with compress Date: Mon, 29 Aug 2022 12:56:51 -0400 Message-Id: <20220829165659.96046-6-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The preempt mode requires the capability to assign channel for each of the page, while the compression logic will currently assign pages to different compress thread/local-channel so potentially they're incompatible. Signed-off-by: Peter Xu --- migration/migration.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index bb8bbddfe4..844bca1ff6 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1336,6 +1336,17 @@ static bool migrate_caps_check(bool *cap_list, error_setg(errp, "Postcopy preempt requires postcopy-ram"); return false; } + + /* + * Preempt mode requires urgent pages to be sent in separate + * channel, OTOH compression logic will disorder all pages into + * different compression channels, which is not compatible with the + * preempt assumptions on channel assignments. + */ + if (cap_list[MIGRATION_CAPABILITY_COMPRESS]) { + error_setg(errp, "Postcopy preempt not compatible with compress"); + return false; + } } return true; From patchwork Mon Aug 29 16:56:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671562 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=H+zsg3S0; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGcKH4bYCz1yhw for ; Tue, 30 Aug 2022 03:06:09 +1000 (AEST) Received: from localhost ([::1]:59570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSiD8-000086-EC for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 13:06:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4a-0002dp-Jn for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:49211) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4Z-0008GQ-6f for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792234; 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=YSVZP7q1cz5AOinl1NXbXvPRjmI+K/D6yOV6R5m+7mg=; b=H+zsg3S0gbRqOuYuTC98zEC4TeUn65QEwCdorC6SYtm86kTvQ1xMJnbTcaYbSL8oJ05VA2 b8t3+I+c2AdjiYv0dTb87D1QyOL0/hp1eHojg4Ku6cSeu2gPwaFaKRcRZThKxETdCqGEuu OAvchiFiGoNziYOm7RBG/YUfasRutaM= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-547-TOfdNtq1NmC0jvHiIG6kvw-1; Mon, 29 Aug 2022 12:57:13 -0400 X-MC-Unique: TOfdNtq1NmC0jvHiIG6kvw-1 Received: by mail-io1-f71.google.com with SMTP id g13-20020a056602072d00b0068825561753so4968782iox.7 for ; Mon, 29 Aug 2022 09:57:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=YSVZP7q1cz5AOinl1NXbXvPRjmI+K/D6yOV6R5m+7mg=; b=DJFHNG8oqmCMTopksmSu1fhj1sMaVWE79QCe/QH33nviFpXSLd1n188N8odMiYE3VD pENDIWQT7NNVrMcIVZKl+MjO1XVl5rRXPFMz6iX6uqbjsk9RFaBCRr4DU6wZ35BlhAql 7VkfL8KHePU8o6KSeBtlup2BzuG/Fqf5bRYPaG5cV9QbzVQXJ9ryMLKUkqb0tInuF3eE vj/CQF8OigBTyEkjRMQ3sgHfJ/U9+SdZAZ1Yd6JTv66xHmD++AOYrgrK0TN1xfBUFz9w wP7Udbla5c8jibKd/FfUL9EFv7ZYD9pVsETknyGiX/tuYaoQDvWNOLYk699/2TKD/6+b YbDA== X-Gm-Message-State: ACgBeo3vMjfJ2cDuT5FFscpTmg65DLyaLKBIKZvM7kKfMC3sWBztRUPH 5iu8GMP4qj5G7WwjtPvnJCldVt1RK7M1VUHhJlgOXRzafzCiUYJa8MBs5SyeZuRcHmKQDSyjHa6 KZ6tspP/IMuCiOpYSdUp+6C1eZhJXHQ1hM2Sj89vqyLIkcEUC0RXgXQthcose6Kzz X-Received: by 2002:a05:6e02:2181:b0:2eb:3770:e3f8 with SMTP id j1-20020a056e02218100b002eb3770e3f8mr1487391ila.79.1661792232201; Mon, 29 Aug 2022 09:57:12 -0700 (PDT) X-Google-Smtp-Source: AA6agR5GMA4LXuBUaEb5E56tNKOzyWeU9DedNMvOwPHbcUsdDIRIKPNLzLjdQvC73YuLB3TnbV2JUw== X-Received: by 2002:a05:6e02:2181:b0:2eb:3770:e3f8 with SMTP id j1-20020a056e02218100b002eb3770e3f8mr1487382ila.79.1661792231999; Mon, 29 Aug 2022 09:57:11 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.10 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:11 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 06/13] migration: Trivial cleanup save_page_header() on same block check Date: Mon, 29 Aug 2022 12:56:52 -0400 Message-Id: <20220829165659.96046-7-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The 2nd check on RAM_SAVE_FLAG_CONTINUE is a bit redundant. Use a boolean to be clearer. Signed-off-by: Peter Xu --- migration/ram.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 612c7dd708..43893d0a40 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -661,14 +661,15 @@ static size_t save_page_header(RAMState *rs, QEMUFile *f, RAMBlock *block, ram_addr_t offset) { size_t size, len; + bool same_block = (block == rs->last_sent_block); - if (block == rs->last_sent_block) { + if (same_block) { offset |= RAM_SAVE_FLAG_CONTINUE; } qemu_put_be64(f, offset); size = 8; - if (!(offset & RAM_SAVE_FLAG_CONTINUE)) { + if (!same_block) { len = strlen(block->idstr); qemu_put_byte(f, len); qemu_put_buffer(f, (uint8_t *)block->idstr, len); From patchwork Mon Aug 29 16:56:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=XbBvJowB; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGcRc2GZkz1yhC for ; Tue, 30 Aug 2022 03:11:38 +1000 (AEST) Received: from localhost ([::1]:39822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSiIR-0006aL-J8 for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 13:11:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4d-0002eh-9J for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:56560) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4a-0008Ge-Gq for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792236; 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=5MPDuDAfLazs+SShwtUZHPzu/djfRVD6rIJwUkAwzK0=; b=XbBvJowBs2hBN/nAjjQXmsz11yRc7f3jgtLf/qO+Ds4ePVGUqy4+0PRKGNkN6hpuOti0L9 arLiYu1frjPE2aYRhGvRDfx2i8JR0UChmF9H8+3sc5PPFfnksX4/oHfGFs8vMI64M8ZyLO aEbYI/WkqrkoG1kts7BajSxG3OYklSU= Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-593-10nPmsApNhm3h4PfYLuQZg-1; Mon, 29 Aug 2022 12:57:14 -0400 X-MC-Unique: 10nPmsApNhm3h4PfYLuQZg-1 Received: by mail-io1-f70.google.com with SMTP id z4-20020a6b0a04000000b006887f66dcf3so5038026ioi.18 for ; Mon, 29 Aug 2022 09:57:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=5MPDuDAfLazs+SShwtUZHPzu/djfRVD6rIJwUkAwzK0=; b=J9SeqH0Rd7dDbSdTXrwysECAFsOqDP0nccUs9xE4vElqC8RX+eWgUhTnW8EtUO3EeC CloddIDfnY3z+5pAslQqN72mzibfSDyX0QfB5kcpVz/5Ekag+OWVCCZk01v6UWh0xtDj 2JQ6Kzv8xe1116IewRagSd3Vwb5mo7PmEj7LFq8gVbhq2tHdNpiSjcoIv0JjVKn3Rv9X Unt1irMR5IdJ2O+nzJzrECqe3hzYIL79c0oDMLwLNMkQ4HTXV4ogD19AZpBlN8TCTbeX nv90ENVnbim73/tgkBunRLkwN39HVunGOXr8UgVtlfSD3xIG9DfPLcenn6EyOjWAcaFf gP7g== X-Gm-Message-State: ACgBeo1qLjk6eJCfDTGvJ6EttBFCgCNWJ4x/zcM/l3kulkAWsUDRZIsZ KfKWAW/Z+eUnUbcZadPgwOaiPAQ2X5/jgTVOhyhdd1NdUAo9oiXlMrpvhFhx5VAPS7E6RholrdQ 6DbtO1FG8Gq6UkJu2o6EU2jxUZ57fZ+VNxYciyN4DPQcvQLoQeEuYjZVZPrmXyWgF X-Received: by 2002:a05:6e02:1b0e:b0:2df:67ee:beaf with SMTP id i14-20020a056e021b0e00b002df67eebeafmr10322925ilv.239.1661792233641; Mon, 29 Aug 2022 09:57:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR77DiEzvs7+Op41R/uOxfDpXjipVh/6DiDFTk+c16TsZi4HAJzJjoMVG/qPhvClsr0QuWxTMQ== X-Received: by 2002:a05:6e02:1b0e:b0:2df:67ee:beaf with SMTP id i14-20020a056e021b0e00b002df67eebeafmr10322910ilv.239.1661792233370; Mon, 29 Aug 2022 09:57:13 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:12 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 07/13] migration: Remove RAMState.f references in compression code Date: Mon, 29 Aug 2022 12:56:53 -0400 Message-Id: <20220829165659.96046-8-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Removing referencing to RAMState.f in compress_page_with_multi_thread() and flush_compressed_data(). Compression code by default isn't compatible with having >1 channels (or it won't currently know which channel to flush the compressed data), so to make it simple we always flush on the default to_dst_file port until someone wants to add >1 ports support, as rs->f right now can really change (after postcopy preempt is introduced). There should be no functional change at all after patch applied, since as long as rs->f referenced in compression code, it must be to_dst_file. Signed-off-by: Peter Xu --- migration/ram.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 43893d0a40..2f37520be4 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1461,6 +1461,7 @@ static bool save_page_use_compression(RAMState *rs); static void flush_compressed_data(RAMState *rs) { + MigrationState *ms = migrate_get_current(); int idx, len, thread_count; if (!save_page_use_compression(rs)) { @@ -1479,7 +1480,7 @@ static void flush_compressed_data(RAMState *rs) for (idx = 0; idx < thread_count; idx++) { qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { - len = qemu_put_qemu_file(rs->f, comp_param[idx].file); + len = qemu_put_qemu_file(ms->to_dst_file, comp_param[idx].file); /* * it's safe to fetch zero_page without holding comp_done_lock * as there is no further request submitted to the thread, @@ -1498,11 +1499,11 @@ static inline void set_compress_params(CompressParam *param, RAMBlock *block, param->offset = offset; } -static int compress_page_with_multi_thread(RAMState *rs, RAMBlock *block, - ram_addr_t offset) +static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t offset) { int idx, thread_count, bytes_xmit = -1, pages = -1; bool wait = migrate_compress_wait_thread(); + MigrationState *ms = migrate_get_current(); thread_count = migrate_compress_threads(); qemu_mutex_lock(&comp_done_lock); @@ -1510,7 +1511,8 @@ retry: for (idx = 0; idx < thread_count; idx++) { if (comp_param[idx].done) { comp_param[idx].done = false; - bytes_xmit = qemu_put_qemu_file(rs->f, comp_param[idx].file); + bytes_xmit = qemu_put_qemu_file(ms->to_dst_file, + comp_param[idx].file); qemu_mutex_lock(&comp_param[idx].mutex); set_compress_params(&comp_param[idx], block, offset); qemu_cond_signal(&comp_param[idx].cond); @@ -2263,7 +2265,7 @@ static bool save_compress_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) return false; } - if (compress_page_with_multi_thread(rs, block, offset) > 0) { + if (compress_page_with_multi_thread(block, offset) > 0) { return true; } From patchwork Mon Aug 29 16:56:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671576 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ha7hz5ur; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGcYV22K9z1yh5 for ; Tue, 30 Aug 2022 03:16:44 +1000 (AEST) Received: from localhost ([::1]:43128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSiNM-0003zW-UZ for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 13:16:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4f-0002eu-1n for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24331) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4d-0008Gp-9V for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792238; 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=/Bs72gDpZQsQ5D8YLbgg7KPsy2uWBo73grO+mJOIV5o=; b=ha7hz5urDeSlKCZTMoIu7Ir23JLf/UAnAps4HdEBzpz2xUT28rSVpB7AjzEYHcea258mmz 34ahNaQdb5FqzBV1Se1Zs4c/eUsvO+7/XBnKUMPFSdmJ9bvdrFAsCJST4tTb4PjcWjXLd0 VyGLfLgHriGWI4TpHS8USLc33tBotyU= Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-588-5i_4Oph0NQaGMiLbEYiGlg-1; Mon, 29 Aug 2022 12:57:17 -0400 X-MC-Unique: 5i_4Oph0NQaGMiLbEYiGlg-1 Received: by mail-il1-f200.google.com with SMTP id x7-20020a056e021ca700b002ea01be6018so6337470ill.18 for ; Mon, 29 Aug 2022 09:57:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=/Bs72gDpZQsQ5D8YLbgg7KPsy2uWBo73grO+mJOIV5o=; b=DUgrfFiFlEYMCmQaGwwlIkmysVVSImQkuMqq88jfgJZJ1ZxYqXpyqVtbMSuxWvqXoL d3oBWgcz4jd6nu8gwo6Sty3X9n32eQdRVFfFRWKSehN1EbO08UeXe8P246kloxz8vi0F JgcGxpRiO9vFptlGcpUgMt9WklYZk/SrDcUZGkL8r/jAqZft0RSjeu4veYcg9uTHWoXO +QUEIMPP6+EuPDrxG/aOaIdUU3m+HA9gMTSctXmhSfHAQSQYZPstGvxa5yBIx4MxMZ0w OkndeAAhVKk+0EdlQqN8/WN+ilhrI6UVrR3JzpDWUU6dUF3bkjshRiIcp0otbw+Joeug EYzQ== X-Gm-Message-State: ACgBeo2mROXg96vedOXJiCbX+6pboV1scXM39TOuK8vMeCfPMj/Qszxm S0Y9coz8Yh/p7fBFi9L6/uLf1pgP6wufaDsmI/jPqrkrHuH5IYLogfBPc7elqKz+ag5qaDNPdgj Sha0UGSye4qxoQkCox+BeoZZwt0J4X+PrOPr6dX7o47B69MDfo3CWXHEjfxWwvpfl X-Received: by 2002:a05:6602:3cc:b0:678:eb57:5eb with SMTP id g12-20020a05660203cc00b00678eb5705ebmr8765829iov.125.1661792235239; Mon, 29 Aug 2022 09:57:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR4uqVkBZMYVaOFNPuul+BSN6lFO6VNnljefQhoTSCblj4Uv7yVfgHvtWwoIluLq/lC5VRdhNA== X-Received: by 2002:a05:6602:3cc:b0:678:eb57:5eb with SMTP id g12-20020a05660203cc00b00678eb5705ebmr8765806iov.125.1661792234815; Mon, 29 Aug 2022 09:57:14 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:14 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 08/13] migration: Teach PSS about host page Date: Mon, 29 Aug 2022 12:56:54 -0400 Message-Id: <20220829165659.96046-9-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Migration code has a lot to do with host pages. Teaching PSS core about the idea of host page helps a lot and makes the code clean. Meanwhile, this prepares for the future changes that can leverage the new PSS helpers that this patch introduces to send host page in another thread. Three more fields are introduced for this: (1) host_page_sending: this is set to true when QEMU is sending a host page, false otherwise. (2) host_page_{start|end}: this points to the end of host page, and it's only valid when host_page_sending==true. For example, when we look up the next dirty page on the ramblock, with host_page_sending==true, we'll not even try to look for anything beyond the current host page. This can be efficient than current code because currently we'll set pss->page to next dirty bit (which can be over current host page) and reset it to host page boundary if we found overflow. The latter is not efficient as we don't need to scan over host page boundary. Meanwhile with above, we can easily make migration_bitmap_find_dirty() self contained by updating pss->page properly. rs* parameter is removed because it's not even used in old code. When sending a host page, we should use the pss helpers like this: - pss_host_page_prepare(pss): called before sending host page - pss_within_range(pss): whether we're still working on the cur host page? - pss_host_page_finish(pss): called after sending a host page If there'll be another function to send host page (e.g. in return path thread) in the future, it should follow the same style. Signed-off-by: Peter Xu --- migration/ram.c | 91 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 73 insertions(+), 18 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 2f37520be4..e2b922ad59 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -474,6 +474,11 @@ struct PageSearchStatus { * postcopy pages via postcopy preempt channel. */ bool postcopy_target_channel; + /* Whether we're sending a host page */ + bool host_page_sending; + /* The start/end of current host page. Invalid if host_page_sending==false */ + unsigned long host_page_start; + unsigned long host_page_end; }; typedef struct PageSearchStatus PageSearchStatus; @@ -851,26 +856,36 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **current_data, } /** - * migration_bitmap_find_dirty: find the next dirty page from start + * pss_find_next_dirty: find the next dirty page of current ramblock * - * Returns the page offset within memory region of the start of a dirty page + * This function updates pss->page to point to the next dirty page index + * within the ramblock, or the end of ramblock when nothing found. * * @rs: current RAM state - * @rb: RAMBlock where to search for dirty pages - * @start: page where we start the search + * @pss: the current page search status */ -static inline -unsigned long migration_bitmap_find_dirty(RAMState *rs, RAMBlock *rb, - unsigned long start) +static void pss_find_next_dirty(PageSearchStatus *pss) { + RAMBlock *rb = pss->block; unsigned long size = rb->used_length >> TARGET_PAGE_BITS; unsigned long *bitmap = rb->bmap; if (ramblock_is_ignored(rb)) { - return size; + /* Points directly to the end, so we know no dirty page */ + pss->page = size; + return; } - return find_next_bit(bitmap, size, start); + /* + * If during sending a host page, only look for dirty pages within the + * current host page being send. + */ + if (pss->host_page_sending) { + assert(pss->host_page_end); + size = MIN(size, pss->host_page_end); + } + + pss->page = find_next_bit(bitmap, size, pss->page); } static void migration_clear_memory_region_dirty_bitmap(RAMBlock *rb, @@ -1555,7 +1570,9 @@ static bool find_dirty_block(RAMState *rs, PageSearchStatus *pss, bool *again) pss->postcopy_requested = false; pss->postcopy_target_channel = RAM_CHANNEL_PRECOPY; - pss->page = migration_bitmap_find_dirty(rs, pss->block, pss->page); + /* Update pss->page for the next dirty bit in ramblock */ + pss_find_next_dirty(pss); + if (pss->complete_round && pss->block == rs->last_seen_block && pss->page >= rs->last_page) { /* @@ -2445,6 +2462,44 @@ static void postcopy_preempt_reset_channel(RAMState *rs) } } +/* Should be called before sending a host page */ +static void pss_host_page_prepare(PageSearchStatus *pss) +{ + /* How many guest pages are there in one host page? */ + size_t guest_pfns = qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS; + + pss->host_page_sending = true; + pss->host_page_start = ROUND_DOWN(pss->page, guest_pfns); + pss->host_page_end = ROUND_UP(pss->page + 1, guest_pfns); +} + +/* + * Whether the page pointed by PSS is within the host page being sent. + * Must be called after a previous pss_host_page_prepare(). + */ +static bool pss_within_range(PageSearchStatus *pss) +{ + ram_addr_t ram_addr; + + assert(pss->host_page_sending); + + /* Over host-page boundary? */ + if (pss->page >= pss->host_page_end) { + return false; + } + + ram_addr = ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; + + return offset_in_ramblock(pss->block, ram_addr); +} + +static void pss_host_page_finish(PageSearchStatus *pss) +{ + pss->host_page_sending = false; + /* This is not needed, but just to reset it */ + pss->host_page_end = 0; +} + /** * ram_save_host_page: save a whole host page * @@ -2466,8 +2521,6 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) int tmppages, pages = 0; size_t pagesize_bits = qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS; - unsigned long hostpage_boundary = - QEMU_ALIGN_UP(pss->page + 1, pagesize_bits); unsigned long start_page = pss->page; bool page_dirty; int res; @@ -2481,6 +2534,9 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) postcopy_preempt_choose_channel(rs, pss); } + /* Update host page boundary information */ + pss_host_page_prepare(pss); + do { if (postcopy_needs_preempt(rs, pss)) { postcopy_do_preempt(rs, pss); @@ -2519,15 +2575,14 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) } if (tmppages < 0) { + pss_host_page_finish(pss); return tmppages; } - pss->page = migration_bitmap_find_dirty(rs, pss->block, pss->page); - } while ((pss->page < hostpage_boundary) && - offset_in_ramblock(pss->block, - ((ram_addr_t)pss->page) << TARGET_PAGE_BITS)); - /* The offset we leave with is the min boundary of host page and block */ - pss->page = MIN(pss->page, hostpage_boundary); + pss_find_next_dirty(pss); + } while (pss_within_range(pss)); + + pss_host_page_finish(pss); /* * When with postcopy preempt mode, flush the data as soon as possible for From patchwork Mon Aug 29 16:56:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671572 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QqueRyX/; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGcSN1XWYz1yhC for ; Tue, 30 Aug 2022 03:12:20 +1000 (AEST) Received: from localhost ([::1]:50148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSiJ7-0007Bz-1D for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 13:12:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4h-0002fb-6v for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28122) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4f-0008H7-4j for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792240; 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=emeNw4WxvScLdHxLIDiyYXPsKXE7awd6bMCY3tJ81XM=; b=QqueRyX/IbNgt+0xsONyvbcfyw8IjWiQIb1xJ3+qhZMW95RvDYB91ZrQ+pnG9oZyYNxa3o 6tBed9W5UFSS+pcxda6h8jRbJqTFdIYGSK93nd+JpCMmhYIuDs1VH29DqIflrsPww5tiH/ g+Z/WeYQV7dRvR7BoGZSCHMizwdUf1s= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-540-rvCRjm3GNs25TgLwYWUGag-1; Mon, 29 Aug 2022 12:57:18 -0400 X-MC-Unique: rvCRjm3GNs25TgLwYWUGag-1 Received: by mail-io1-f71.google.com with SMTP id x9-20020a056602210900b006897b3869e4so5051217iox.16 for ; Mon, 29 Aug 2022 09:57:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=emeNw4WxvScLdHxLIDiyYXPsKXE7awd6bMCY3tJ81XM=; b=L3IivVWeUvnq//6fvg44SPF67cKOuRYmllQ+0xLO4LdJMwQRy+yR7nVrgoUHW/4dtO n9iGgM695Cf91vvEoNoH6QvOcUvmWfThMUwlFdogAHtS9uK0rOqa1PUQrabgdqYw2ytr HXcHShCkvw3Qydc0Ey+ONjkcyqE1wTXqwUHsSfdc9bRv2VmuIMieLsmuNEg6ENlt/skg RtAm91fWd8zWxi0hkhUadLTxMIVeHj54gNUIIuKGAC5mARy1KSxt3yBNu7qS0qlKj050 QcufIa26EIKU+fOLeGWqkmfLxGcmS4TcouAjlBopxAelEExtkcMJqqRzI29kYBDIA7F3 lvGQ== X-Gm-Message-State: ACgBeo1V3+R0fkyomVH9TPckDExQdwAfOk9GWVBgQaP6R+MPHaLhnrjy 3OBanclWUK3JL7uIWd5HV7li9zqOEizRNYRY9OptvVOIBv1gRM8oDWPY0IcWBaZVNKXgd/AH1Wb nIwSVN0PFcmtFtNY8C0UCggihEZZANcFziJmvm2nb/NWXbJRF4NY5DVeAiG+3SqFk X-Received: by 2002:a05:6602:2e0e:b0:689:4f74:926a with SMTP id o14-20020a0566022e0e00b006894f74926amr9303322iow.27.1661792236916; Mon, 29 Aug 2022 09:57:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR5PsCRtltSskC2/cqkXDRXVEvLnEWp3nB6Antrblt3sOZoWjt0vqwM17gevmqiTiD52mO+Usw== X-Received: by 2002:a05:6602:2e0e:b0:689:4f74:926a with SMTP id o14-20020a0566022e0e00b006894f74926amr9303302iow.27.1661792236560; Mon, 29 Aug 2022 09:57:16 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:16 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 09/13] migration: Introduce pss_channel Date: Mon, 29 Aug 2022 12:56:55 -0400 Message-Id: <20220829165659.96046-10-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Introduce pss_channel for PageSearchStatus, define it as "the migration channel to be used to transfer this host page". We used to have rs->f, which is a mirror to MigrationState.to_dst_file. After postcopy preempt initial version, rs->f can be dynamically changed depending on which channel we want to use. But that later work still doesn't grant full concurrency of sending pages in e.g. different threads, because rs->f can either be the PRECOPY channel or POSTCOPY channel. This needs to be per-thread too. PageSearchStatus is actually a good piece of struct which we can leverage if we want to have multiple threads sending pages. Sending a single guest page may not make sense, so we make the granule to be "host page", and in the PSS structure we allow specify a QEMUFile* to migrate a specific host page. Then we open the possibility to specify different channels in different threads with different PSS structures. The PSS prefix can be slightly misleading here because e.g. for the upcoming usage of postcopy channel/thread it's not "searching" (or, scanning) at all but sending the explicit page that was requested. However since PSS existed for some years keep it as-is until someone complains. This patch mostly (simply) replace rs->f with pss->pss_channel only. No functional change intended for this patch yet. But it does prepare to finally drop rs->f, and make ram_save_guest_page() thread safe. Signed-off-by: Peter Xu --- migration/ram.c | 70 +++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index e2b922ad59..adcc57c584 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -446,6 +446,8 @@ void dirty_sync_missed_zero_copy(void) /* used by the search for pages to send */ struct PageSearchStatus { + /* The migration channel used for a specific host page */ + QEMUFile *pss_channel; /* Current block being searched */ RAMBlock *block; /* Current page to search from */ @@ -768,9 +770,9 @@ static void xbzrle_cache_zero_page(RAMState *rs, ram_addr_t current_addr) * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_xbzrle_page(RAMState *rs, uint8_t **current_data, - ram_addr_t current_addr, RAMBlock *block, - ram_addr_t offset) +static int save_xbzrle_page(RAMState *rs, QEMUFile *file, + uint8_t **current_data, ram_addr_t current_addr, + RAMBlock *block, ram_addr_t offset) { int encoded_len = 0, bytes_xbzrle; uint8_t *prev_cached_page; @@ -838,11 +840,11 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **current_data, } /* Send XBZRLE based compressed page */ - bytes_xbzrle = save_page_header(rs, rs->f, block, + bytes_xbzrle = save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_XBZRLE); - qemu_put_byte(rs->f, ENCODING_FLAG_XBZRLE); - qemu_put_be16(rs->f, encoded_len); - qemu_put_buffer(rs->f, XBZRLE.encoded_buf, encoded_len); + qemu_put_byte(file, ENCODING_FLAG_XBZRLE); + qemu_put_be16(file, encoded_len); + qemu_put_buffer(file, XBZRLE.encoded_buf, encoded_len); bytes_xbzrle += encoded_len + 1 + 2; /* * Like compressed_size (please see update_compress_thread_counts), @@ -1295,9 +1297,10 @@ static int save_zero_page_to_file(RAMState *rs, QEMUFile *file, * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) +static int save_zero_page(RAMState *rs, QEMUFile *file, RAMBlock *block, + ram_addr_t offset) { - int len = save_zero_page_to_file(rs, rs->f, block, offset); + int len = save_zero_page_to_file(rs, file, block, offset); if (len) { ram_counters.duplicate++; @@ -1314,15 +1317,15 @@ static int save_zero_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) * * Return true if the pages has been saved, otherwise false is returned. */ -static bool control_save_page(RAMState *rs, RAMBlock *block, ram_addr_t offset, - int *pages) +static bool control_save_page(PageSearchStatus *pss, RAMBlock *block, + ram_addr_t offset, int *pages) { uint64_t bytes_xmit = 0; int ret; *pages = -1; - ret = ram_control_save_page(rs->f, block->offset, offset, TARGET_PAGE_SIZE, - &bytes_xmit); + ret = ram_control_save_page(pss->pss_channel, block->offset, offset, + TARGET_PAGE_SIZE, &bytes_xmit); if (ret == RAM_SAVE_CONTROL_NOT_SUPP) { return false; } @@ -1356,17 +1359,17 @@ static bool control_save_page(RAMState *rs, RAMBlock *block, ram_addr_t offset, * @buf: the page to be sent * @async: send to page asyncly */ -static int save_normal_page(RAMState *rs, RAMBlock *block, ram_addr_t offset, - uint8_t *buf, bool async) +static int save_normal_page(RAMState *rs, QEMUFile *file, RAMBlock *block, + ram_addr_t offset, uint8_t *buf, bool async) { - ram_transferred_add(save_page_header(rs, rs->f, block, + ram_transferred_add(save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_PAGE)); if (async) { - qemu_put_buffer_async(rs->f, buf, TARGET_PAGE_SIZE, + qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, migrate_release_ram() && migration_in_postcopy()); } else { - qemu_put_buffer(rs->f, buf, TARGET_PAGE_SIZE); + qemu_put_buffer(file, buf, TARGET_PAGE_SIZE); } ram_transferred_add(TARGET_PAGE_SIZE); ram_counters.normal++; @@ -1399,8 +1402,8 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss) XBZRLE_cache_lock(); if (rs->xbzrle_enabled && !migration_in_postcopy()) { - pages = save_xbzrle_page(rs, &p, current_addr, block, - offset); + pages = save_xbzrle_page(rs, pss->pss_channel, &p, current_addr, + block, offset); if (!rs->last_stage) { /* Can't send this cached data async, since the cache page * might get updated before it gets to the wire @@ -1411,7 +1414,8 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss) /* XBZRLE overflow or normal page */ if (pages == -1) { - pages = save_normal_page(rs, block, offset, p, send_async); + pages = save_normal_page(rs, pss->pss_channel, block, offset, + p, send_async); } XBZRLE_cache_unlock(); @@ -1419,10 +1423,10 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss) return pages; } -static int ram_save_multifd_page(RAMState *rs, RAMBlock *block, +static int ram_save_multifd_page(QEMUFile *file, RAMBlock *block, ram_addr_t offset) { - if (multifd_queue_page(rs->f, block, offset) < 0) { + if (multifd_queue_page(file, block, offset) < 0) { return -1; } ram_counters.normal++; @@ -1717,7 +1721,7 @@ static int ram_save_release_protection(RAMState *rs, PageSearchStatus *pss, uint64_t run_length = (pss->page - start_page) << TARGET_PAGE_BITS; /* Flush async buffers before un-protect. */ - qemu_fflush(rs->f); + qemu_fflush(pss->pss_channel); /* Un-protect memory range. */ res = uffd_change_protection(rs->uffdio_fd, page_address, run_length, false, false); @@ -2304,7 +2308,7 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss) ram_addr_t offset = ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; int res; - if (control_save_page(rs, block, offset, &res)) { + if (control_save_page(pss, block, offset, &res)) { return res; } @@ -2312,7 +2316,7 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss) return 1; } - res = save_zero_page(rs, block, offset); + res = save_zero_page(rs, pss->pss_channel, block, offset); if (res > 0) { /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale @@ -2333,7 +2337,7 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss) */ if (!save_page_use_compression(rs) && migrate_use_multifd() && !migration_in_postcopy()) { - return ram_save_multifd_page(rs, block, offset); + return ram_save_multifd_page(pss->pss_channel, block, offset); } return ram_save_page(rs, pss); @@ -2530,10 +2534,6 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) return 0; } - if (postcopy_preempt_active()) { - postcopy_preempt_choose_channel(rs, pss); - } - /* Update host page boundary information */ pss_host_page_prepare(pss); @@ -2594,7 +2594,7 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) * explicit flush or it won't flush until the buffer is full. */ if (migrate_postcopy_preempt() && pss->postcopy_requested) { - qemu_fflush(rs->f); + qemu_fflush(pss->pss_channel); } res = ram_save_release_protection(rs, pss, start_page); @@ -2652,6 +2652,12 @@ static int ram_find_and_save_block(RAMState *rs) } if (found) { + /* Update rs->f with correct channel */ + if (postcopy_preempt_active()) { + postcopy_preempt_choose_channel(rs, &pss); + } + /* Cache rs->f in pss_channel (TODO: remove rs->f) */ + pss.pss_channel = rs->f; pages = ram_save_host_page(rs, &pss); } } while (!pages && again); From patchwork Mon Aug 29 16:56:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671567 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HuOYDZ5r; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGcKr0xSxz1yg7 for ; Tue, 30 Aug 2022 03:06:40 +1000 (AEST) Received: from localhost ([::1]:53806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSiDd-0000fZ-VU for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 13:06:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4g-0002fB-8g for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:48242) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4e-0008H2-Mr for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792240; 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=SAw+KBxODpeo0q8eAHUrT+axCF1AXEnatmPu6o5lxes=; b=HuOYDZ5rLJJILqhyrITBEzqdNtltzor8yPyUor2Mvy6SCEIWO+RXMvskU7JUZzghGoS9La VjCKRDT8iCh7ADRM0V7eH33IIfMKORXP0abDpxqXbxHCCx+aihF6JpTJzMMFljkANFWy3d 49VTwzzj6T0AERaK4dwg/PF//wjFDDA= Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-319-XbBOyv8HOhKbzQaM9w22wg-1; Mon, 29 Aug 2022 12:57:19 -0400 X-MC-Unique: XbBOyv8HOhKbzQaM9w22wg-1 Received: by mail-io1-f69.google.com with SMTP id q10-20020a0566022f0a00b00688d703717bso5017311iow.9 for ; Mon, 29 Aug 2022 09:57:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=SAw+KBxODpeo0q8eAHUrT+axCF1AXEnatmPu6o5lxes=; b=CgoqRQqwIBjWmE9eIsBeLrLfaHHw7+tkl0V9B0ZFo4/R9O+pIGTCOlFoaIknwEOL5m rBsmMX50YXKT/eoNYbugJ32IVEjxCTnYLOhwRyJ5EkzJUvweTZ6H9b7V40pWDzrAwE/x 9hy4fVXUEjmT1qr63HGD9YZby1bWKp93DrmhhX2klozJJNINNhkPdxK73fq5zdXihvBS mRhf9JqrNYnYYs8GKGJBOoHugGEZESvC+9ufPUmmlRi/QBIPRJMuJLEUMvbwKxe/UUpO kBgQOTYf+8IvZrlwVTf4rqHvgKLN+gODsoTNaupivbdQKwRTXxXsw8kNtAOokYlPDp99 Al1g== X-Gm-Message-State: ACgBeo2l0NdSxpYsD3f8gHkN0MNJ0hjbrFFBz6vBrlsvqxHbph2vxAMQ dXdzTadDgBrABFRbj3swmMucMRpIdZOqmCKAnMEOsxEN3D7nfewjEvH4L0fGApsDQ9dSsWbeKe0 do77NqwF8M4RrmZ3X3n7hfzhFwMqJgZMJzY9LpauhnQN6x81rAaGwxvAiPfWcBUlv X-Received: by 2002:a05:6638:2042:b0:346:e51a:da4e with SMTP id t2-20020a056638204200b00346e51ada4emr10597295jaj.164.1661792238318; Mon, 29 Aug 2022 09:57:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR5OX92x8c39bNwXM1FVSOZdVmdjabkOAwdZS7svCZnLlcv300dtEiao9uPOvz85DYD7gSx1/A== X-Received: by 2002:a05:6638:2042:b0:346:e51a:da4e with SMTP id t2-20020a056638204200b00346e51ada4emr10597272jaj.164.1661792238049; Mon, 29 Aug 2022 09:57:18 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:17 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 10/13] migration: Add pss_init() Date: Mon, 29 Aug 2022 12:56:56 -0400 Message-Id: <20220829165659.96046-11-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Helper to init PSS structures. Signed-off-by: Peter Xu --- migration/ram.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index adcc57c584..bdfcc6171a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -535,6 +535,14 @@ static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block, static void postcopy_preempt_restore(RAMState *rs, PageSearchStatus *pss, bool postcopy_requested); +/* NOTE: page is the PFN not real ram_addr_t. */ +static void pss_init(PageSearchStatus *pss, RAMBlock *rb, ram_addr_t page) +{ + pss->block = rb; + pss->page = page; + pss->complete_round = false; +} + static void *do_data_compress(void *opaque) { CompressParam *param = opaque; @@ -2625,9 +2633,7 @@ static int ram_find_and_save_block(RAMState *rs) return pages; } - pss.block = rs->last_seen_block; - pss.page = rs->last_page; - pss.complete_round = false; + pss_init(&pss, rs->last_seen_block, rs->last_page); if (!pss.block) { pss.block = QLIST_FIRST_RCU(&ram_list.blocks); From patchwork Mon Aug 29 16:56:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671571 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=g/r5aEfY; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGcRc5jqcz1yhy for ; Tue, 30 Aug 2022 03:11:40 +1000 (AEST) Received: from localhost ([::1]:38478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSiIU-0006iK-CU for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 13:11:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4i-0002gJ-Si for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32726) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4g-0008HO-Oi for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792242; 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=oYFTO/SnDxhA57XvApXDNNpD3BIWLiN5Mc5ccfYx5AI=; b=g/r5aEfYxm/G/iIdHqLD+BXnxzaCAja7trhuVqbdY/lfwjsL8rxel2rpIvowDyOVOk6sae +B8vbzVUI+EW6d+1ik+qsXzJrrP6bdSzwQ/fowuh3+pcZegN+qwy2v42s4diZv+Noao8GG kLBJWdgMQjoqVz2xPm7KdSlYCZMp84s= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-664-IqV1hz5aPt60exmUZAT-eA-1; Mon, 29 Aug 2022 12:57:21 -0400 X-MC-Unique: IqV1hz5aPt60exmUZAT-eA-1 Received: by mail-io1-f71.google.com with SMTP id y10-20020a5d914a000000b00688fa7b2252so5033348ioq.0 for ; Mon, 29 Aug 2022 09:57:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=oYFTO/SnDxhA57XvApXDNNpD3BIWLiN5Mc5ccfYx5AI=; b=sfUE0EwnQpOu9XktqJ3d2ySxWTAppqhjDOQ3JStl1fV6znreWj0QzXiuj+Z1q4I04g Dv023aqn5Aub9Rzk1axjXRf9bx5E/5O/Bm+XJKoc7QXb0CXZkcaUNs9JhcbFxlc3vBYb nsov965vDjmiiDyOYqbOOm0B5kh74Uvgxipuhu2hkKc3IfuuDq7FdBlaLLMcchNnRwv3 k0EGRnEtX+1QwRDKy91QCLaloe2AX15Nv8dxC/v2IxtkTN/mz/ipO6JWxi0HD3IiIJHq T+sb7FkFgYDRu43a2im6K0yWQ0Qx9ls48ubxEHX+7iR7dJxlEppnvCPy6RgqYR1/klhS WUew== X-Gm-Message-State: ACgBeo2hgHXHmIcPH7rsH9rwq6IPlRqWx4RTdxYFbf2ZHfjk+V8/mgSJ 0FjF15uatg1I+V1xNarAW7MYQr5p07oNyDfzY2kujFcLbR1E2S9tgROdZepayU9ytHET+AZ/EhK Hv2fa0yi/d9GMjY/e8nlN36WkJDrFIdWaj908W2UdW3ddd/HoX6SfB+Br2pInBy8f X-Received: by 2002:a05:6e02:198f:b0:2de:91f6:f70e with SMTP id g15-20020a056e02198f00b002de91f6f70emr10096187ilf.80.1661792239754; Mon, 29 Aug 2022 09:57:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR7XUxA2xRhxQnQhEJHf2ujx50seekDgQrt1Gk2jIKvrc9XWhk3rT7h3qWgmk5DWofuzmiqLSw== X-Received: by 2002:a05:6e02:198f:b0:2de:91f6:f70e with SMTP id g15-20020a056e02198f00b002de91f6f70emr10096172ilf.80.1661792239443; Mon, 29 Aug 2022 09:57:19 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.18 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:19 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 11/13] migration: Make PageSearchStatus part of RAMState Date: Mon, 29 Aug 2022 12:56:57 -0400 Message-Id: <20220829165659.96046-12-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We used to allocate PSS structure on the stack for precopy when sending pages. Make it static, so as to describe per-channel ram migration status. Here we declared RAM_CHANNEL_MAX instances, preparing for postcopy to use it, even though this patch has not yet to start using the 2nd instance. This should not have any functional change per se, but it already starts to export PSS information via the RAMState, so that e.g. one PSS channel can start to reference the other PSS channel. Always protect PSS access using the same RAMState.bitmap_mutex. We already do so, so no code change needed, just some comment update. Maybe we should consider renaming bitmap_mutex some day as it's going to be a more commonly and big mutex we use for ram states, but just leave it for later. Signed-off-by: Peter Xu --- migration/ram.c | 116 ++++++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 53 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index bdfcc6171a..2be9b91ffc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -85,6 +85,46 @@ XBZRLECacheStats xbzrle_counters; +/* used by the search for pages to send */ +struct PageSearchStatus { + /* The migration channel used for a specific host page */ + QEMUFile *pss_channel; + /* Current block being searched */ + RAMBlock *block; + /* Current page to search from */ + unsigned long page; + /* Set once we wrap around */ + bool complete_round; + /* + * [POSTCOPY-ONLY] Whether current page is explicitly requested by + * postcopy. When set, the request is "urgent" because the dest QEMU + * threads are waiting for us. + */ + bool postcopy_requested; + /* + * [POSTCOPY-ONLY] The target channel to use to send current page. + * + * Note: This may _not_ match with the value in postcopy_requested + * above. Let's imagine the case where the postcopy request is exactly + * the page that we're sending in progress during precopy. In this case + * we'll have postcopy_requested set to true but the target channel + * will be the precopy channel (so that we don't split brain on that + * specific page since the precopy channel already contains partial of + * that page data). + * + * Besides that specific use case, postcopy_target_channel should + * always be equal to postcopy_requested, because by default we send + * postcopy pages via postcopy preempt channel. + */ + bool postcopy_target_channel; + /* Whether we're sending a host page */ + bool host_page_sending; + /* The start/end of current host page. Invalid if host_page_sending==false */ + unsigned long host_page_start; + unsigned long host_page_end; +}; +typedef struct PageSearchStatus PageSearchStatus; + /* struct contains XBZRLE cache and a static page used by the compression */ static struct { @@ -319,6 +359,11 @@ typedef struct { struct RAMState { /* QEMUFile used for this migration */ QEMUFile *f; + /* + * PageSearchStatus structures for the channels when send pages. + * Protected by the bitmap_mutex. + */ + PageSearchStatus pss[RAM_CHANNEL_MAX]; /* UFFD file descriptor, used in 'write-tracking' migration */ int uffdio_fd; /* Last block that we have visited searching for dirty pages */ @@ -362,7 +407,12 @@ struct RAMState { uint64_t target_page_count; /* number of dirty bits in the bitmap */ uint64_t migration_dirty_pages; - /* Protects modification of the bitmap and migration dirty pages */ + /* + * Protects: + * - dirty/clear bitmap + * - migration_dirty_pages + * - pss structures + */ QemuMutex bitmap_mutex; /* The RAMBlock used in the last src_page_requests */ RAMBlock *last_req_rb; @@ -444,46 +494,6 @@ void dirty_sync_missed_zero_copy(void) ram_counters.dirty_sync_missed_zero_copy++; } -/* used by the search for pages to send */ -struct PageSearchStatus { - /* The migration channel used for a specific host page */ - QEMUFile *pss_channel; - /* Current block being searched */ - RAMBlock *block; - /* Current page to search from */ - unsigned long page; - /* Set once we wrap around */ - bool complete_round; - /* - * [POSTCOPY-ONLY] Whether current page is explicitly requested by - * postcopy. When set, the request is "urgent" because the dest QEMU - * threads are waiting for us. - */ - bool postcopy_requested; - /* - * [POSTCOPY-ONLY] The target channel to use to send current page. - * - * Note: This may _not_ match with the value in postcopy_requested - * above. Let's imagine the case where the postcopy request is exactly - * the page that we're sending in progress during precopy. In this case - * we'll have postcopy_requested set to true but the target channel - * will be the precopy channel (so that we don't split brain on that - * specific page since the precopy channel already contains partial of - * that page data). - * - * Besides that specific use case, postcopy_target_channel should - * always be equal to postcopy_requested, because by default we send - * postcopy pages via postcopy preempt channel. - */ - bool postcopy_target_channel; - /* Whether we're sending a host page */ - bool host_page_sending; - /* The start/end of current host page. Invalid if host_page_sending==false */ - unsigned long host_page_start; - unsigned long host_page_end; -}; -typedef struct PageSearchStatus PageSearchStatus; - CompressionStats compression_counters; struct CompressParam { @@ -2624,7 +2634,7 @@ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) */ static int ram_find_and_save_block(RAMState *rs) { - PageSearchStatus pss; + PageSearchStatus *pss = &rs->pss[RAM_CHANNEL_PRECOPY]; int pages = 0; bool again, found; @@ -2633,15 +2643,15 @@ static int ram_find_and_save_block(RAMState *rs) return pages; } - pss_init(&pss, rs->last_seen_block, rs->last_page); + pss_init(pss, rs->last_seen_block, rs->last_page); - if (!pss.block) { - pss.block = QLIST_FIRST_RCU(&ram_list.blocks); + if (!pss->block) { + pss->block = QLIST_FIRST_RCU(&ram_list.blocks); } do { again = true; - found = get_queued_page(rs, &pss); + found = get_queued_page(rs, pss); if (!found) { /* @@ -2649,27 +2659,27 @@ static int ram_find_and_save_block(RAMState *rs) * preempted precopy. Otherwise find the next dirty bit. */ if (postcopy_preempt_triggered(rs)) { - postcopy_preempt_restore(rs, &pss, false); + postcopy_preempt_restore(rs, pss, false); found = true; } else { /* priority queue empty, so just search for something dirty */ - found = find_dirty_block(rs, &pss, &again); + found = find_dirty_block(rs, pss, &again); } } if (found) { /* Update rs->f with correct channel */ if (postcopy_preempt_active()) { - postcopy_preempt_choose_channel(rs, &pss); + postcopy_preempt_choose_channel(rs, pss); } /* Cache rs->f in pss_channel (TODO: remove rs->f) */ - pss.pss_channel = rs->f; - pages = ram_save_host_page(rs, &pss); + pss->pss_channel = rs->f; + pages = ram_save_host_page(rs, pss); } } while (!pages && again); - rs->last_seen_block = pss.block; - rs->last_page = pss.page; + rs->last_seen_block = pss->block; + rs->last_page = pss->page; return pages; } From patchwork Mon Aug 29 16:56:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671570 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MOvV1vQd; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGcRc2KFMz1yhw for ; Tue, 30 Aug 2022 03:11:38 +1000 (AEST) Received: from localhost ([::1]:39826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSiIS-0006bw-4z for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 13:11:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4j-0002j7-PD for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24665) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4h-0008Hc-Pk for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792243; 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=35BvSFsp8gMyTF7mi9IgY+2x7vc1egd5S+Y/5jbj7nI=; b=MOvV1vQdCYGWfqLQfGohXc2AKyTrygsn27ResQvFPemcLyOrsSVpiMnHf+F10G6126iSXf zc4kUSiaQ7rDwmsDzyq9PDmHVbglQDWnDhmbaIP+qbWTuZrO37QuMzQSwIhwFo0GKPlnuc wTL3xhYgH0VKYPKHdnaIpLPATzE7GFc= Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-16-erXW5B3-PnqeJFVev_1zJA-1; Mon, 29 Aug 2022 12:57:22 -0400 X-MC-Unique: erXW5B3-PnqeJFVev_1zJA-1 Received: by mail-io1-f69.google.com with SMTP id y1-20020a056602200100b006893cd97da9so5015789iod.1 for ; Mon, 29 Aug 2022 09:57:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=35BvSFsp8gMyTF7mi9IgY+2x7vc1egd5S+Y/5jbj7nI=; b=zkz49r7YaWNF44xqoQDnrtfLcBcjJi5T9HEqaC81lybJg+uuXqfXXpaetqvK5M0YDA K1kxEhVf+NbPSVWdh9LmnuEJnzBIy+0WqRpmKtHD66RfBhtXCPbJDqks9fH0sQIJYw51 VgFJCmRvPg+hXDJJ+K4aFkCSvM1xJXg9ywzLdVhXznoQYGrcffSWOE4Xx/114d3WpB9X BNVIu4HaNT9YWvbLwsle/zUs2OZ1u0nFE4EUmyRlEPpljN3XPdPl5Jf5BqpCm0OKtwnN W0Uil8TxdN7mGgaWf5Da3uIOEk/je936V18qGJ4j6m57faiMMWqToE0SODy6XI8zp/x9 1y9g== X-Gm-Message-State: ACgBeo2TdfxMptyga0X1nT1qZmmwckLCx/qrYUQBqZQWZ7wecrhXwyUd vpeAcUPpZGomrVIo0S5/rEPubpOGsj2cac6Vjpbn8mLLJjzwhZZuv+dUZ2o8Z3pcOzSdnrsR2H7 XAuRuCZySQrJciY/+cCw0yTlp9VnhvpDqeCnFdfKSci8jrq88igtwUIr+KgvknMJh X-Received: by 2002:a92:d0ca:0:b0:2eb:33e4:7734 with SMTP id y10-20020a92d0ca000000b002eb33e47734mr1454000ila.42.1661792241173; Mon, 29 Aug 2022 09:57:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR4XIt/dIcJhe8Hl6DueYRyaRiIxBEqguxmi9QqpkRn0+gpteWoyo+qJerruP9txKHt8dEnrSQ== X-Received: by 2002:a92:d0ca:0:b0:2eb:33e4:7734 with SMTP id y10-20020a92d0ca000000b002eb33e47734mr1453977ila.42.1661792240726; Mon, 29 Aug 2022 09:57:20 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:20 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 12/13] migration: Move last_sent_block into PageSearchStatus Date: Mon, 29 Aug 2022 12:56:58 -0400 Message-Id: <20220829165659.96046-13-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Since we use PageSearchStatus to represent a channel, it makes perfect sense to keep last_sent_block (aka, leverage RAM_SAVE_FLAG_CONTINUE) to be per-channel rather than global because each channel can be sending different pages on ramblocks. Hence move it from RAMState into PageSearchStatus. Signed-off-by: Peter Xu --- migration/ram.c | 71 ++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 2be9b91ffc..ef89812c69 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -89,6 +89,8 @@ XBZRLECacheStats xbzrle_counters; struct PageSearchStatus { /* The migration channel used for a specific host page */ QEMUFile *pss_channel; + /* Last block from where we have sent data */ + RAMBlock *last_sent_block; /* Current block being searched */ RAMBlock *block; /* Current page to search from */ @@ -368,8 +370,6 @@ struct RAMState { int uffdio_fd; /* Last block that we have visited searching for dirty pages */ RAMBlock *last_seen_block; - /* Last block from where we have sent data */ - RAMBlock *last_sent_block; /* Last dirty target page we have sent */ ram_addr_t last_page; /* last ram version we have seen */ @@ -677,16 +677,17 @@ exit: * * Returns the number of bytes written * - * @f: QEMUFile where to send the data + * @pss: current PSS channel status * @block: block that contains the page we want to send * @offset: offset inside the block for the page * in the lower bits, it contains flags */ -static size_t save_page_header(RAMState *rs, QEMUFile *f, RAMBlock *block, +static size_t save_page_header(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset) { size_t size, len; - bool same_block = (block == rs->last_sent_block); + bool same_block = (block == pss->last_sent_block); + QEMUFile *f = pss->pss_channel; if (same_block) { offset |= RAM_SAVE_FLAG_CONTINUE; @@ -699,7 +700,7 @@ static size_t save_page_header(RAMState *rs, QEMUFile *f, RAMBlock *block, qemu_put_byte(f, len); qemu_put_buffer(f, (uint8_t *)block->idstr, len); size += 1 + len; - rs->last_sent_block = block; + pss->last_sent_block = block; } return size; } @@ -783,17 +784,19 @@ static void xbzrle_cache_zero_page(RAMState *rs, ram_addr_t current_addr) * -1 means that xbzrle would be longer than normal * * @rs: current RAM state + * @pss: current PSS channel * @current_data: pointer to the address of the page contents * @current_addr: addr of the page * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_xbzrle_page(RAMState *rs, QEMUFile *file, +static int save_xbzrle_page(RAMState *rs, PageSearchStatus *pss, uint8_t **current_data, ram_addr_t current_addr, RAMBlock *block, ram_addr_t offset) { int encoded_len = 0, bytes_xbzrle; uint8_t *prev_cached_page; + QEMUFile *file = pss->pss_channel; if (!cache_is_cached(XBZRLE.cache, current_addr, ram_counters.dirty_sync_count)) { @@ -858,7 +861,7 @@ static int save_xbzrle_page(RAMState *rs, QEMUFile *file, } /* Send XBZRLE based compressed page */ - bytes_xbzrle = save_page_header(rs, file, block, + bytes_xbzrle = save_page_header(pss, block, offset | RAM_SAVE_FLAG_XBZRLE); qemu_put_byte(file, ENCODING_FLAG_XBZRLE); qemu_put_be16(file, encoded_len); @@ -1286,19 +1289,19 @@ static void ram_release_page(const char *rbname, uint64_t offset) * Returns the size of data written to the file, 0 means the page is not * a zero page * - * @rs: current RAM state - * @file: the file where the data is saved + * @pss: current PSS channel * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page_to_file(RAMState *rs, QEMUFile *file, +static int save_zero_page_to_file(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset) { uint8_t *p = block->host + offset; + QEMUFile *file = pss->pss_channel; int len = 0; if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { - len += save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_ZERO); + len += save_page_header(pss, block, offset | RAM_SAVE_FLAG_ZERO); qemu_put_byte(file, 0); len += 1; ram_release_page(block->idstr, offset); @@ -1311,14 +1314,14 @@ static int save_zero_page_to_file(RAMState *rs, QEMUFile *file, * * Returns the number of pages written. * - * @rs: current RAM state + * @pss: current PSS channel * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page(RAMState *rs, QEMUFile *file, RAMBlock *block, +static int save_zero_page(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset) { - int len = save_zero_page_to_file(rs, file, block, offset); + int len = save_zero_page_to_file(pss, block, offset); if (len) { ram_counters.duplicate++; @@ -1371,16 +1374,18 @@ static bool control_save_page(PageSearchStatus *pss, RAMBlock *block, * * Returns the number of pages written. * - * @rs: current RAM state + * @pss: current PSS channel * @block: block that contains the page we want to send * @offset: offset inside the block for the page * @buf: the page to be sent * @async: send to page asyncly */ -static int save_normal_page(RAMState *rs, QEMUFile *file, RAMBlock *block, +static int save_normal_page(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset, uint8_t *buf, bool async) { - ram_transferred_add(save_page_header(rs, file, block, + QEMUFile *file = pss->pss_channel; + + ram_transferred_add(save_page_header(pss, block, offset | RAM_SAVE_FLAG_PAGE)); if (async) { qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, @@ -1420,7 +1425,7 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss) XBZRLE_cache_lock(); if (rs->xbzrle_enabled && !migration_in_postcopy()) { - pages = save_xbzrle_page(rs, pss->pss_channel, &p, current_addr, + pages = save_xbzrle_page(rs, pss, &p, current_addr, block, offset); if (!rs->last_stage) { /* Can't send this cached data async, since the cache page @@ -1432,8 +1437,7 @@ static int ram_save_page(RAMState *rs, PageSearchStatus *pss) /* XBZRLE overflow or normal page */ if (pages == -1) { - pages = save_normal_page(rs, pss->pss_channel, block, offset, - p, send_async); + pages = save_normal_page(pss, block, offset, p, send_async); } XBZRLE_cache_unlock(); @@ -1456,14 +1460,15 @@ static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block, ram_addr_t offset, uint8_t *source_buf) { RAMState *rs = ram_state; + PageSearchStatus *pss = &rs->pss[RAM_CHANNEL_PRECOPY]; uint8_t *p = block->host + offset; int ret; - if (save_zero_page_to_file(rs, f, block, offset)) { + if (save_zero_page_to_file(pss, block, offset)) { return true; } - save_page_header(rs, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); + save_page_header(pss, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); /* * copy it to a internal buffer to avoid it being modified by VM @@ -2283,7 +2288,8 @@ static bool save_page_use_compression(RAMState *rs) * has been properly handled by compression, otherwise needs other * paths to handle it */ -static bool save_compress_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) +static bool save_compress_page(RAMState *rs, PageSearchStatus *pss, + RAMBlock *block, ram_addr_t offset) { if (!save_page_use_compression(rs)) { return false; @@ -2299,7 +2305,7 @@ static bool save_compress_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) * We post the fist page as normal page as compression will take * much CPU resource. */ - if (block != rs->last_sent_block) { + if (block != pss->last_sent_block) { flush_compressed_data(rs); return false; } @@ -2330,11 +2336,11 @@ static int ram_save_target_page(RAMState *rs, PageSearchStatus *pss) return res; } - if (save_compress_page(rs, block, offset)) { + if (save_compress_page(rs, pss, block, offset)) { return 1; } - res = save_zero_page(rs, pss->pss_channel, block, offset); + res = save_zero_page(pss, block, offset); if (res > 0) { /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale @@ -2466,7 +2472,7 @@ static void postcopy_preempt_choose_channel(RAMState *rs, PageSearchStatus *pss) * If channel switched, reset last_sent_block since the old sent block * may not be on the same channel. */ - rs->last_sent_block = NULL; + pss->last_sent_block = NULL; trace_postcopy_preempt_switch_channel(channel); } @@ -2793,8 +2799,13 @@ static void ram_save_cleanup(void *opaque) static void ram_state_reset(RAMState *rs) { + int i; + + for (i = 0; i < RAM_CHANNEL_MAX; i++) { + rs->pss[i].last_sent_block = NULL; + } + rs->last_seen_block = NULL; - rs->last_sent_block = NULL; rs->last_page = 0; rs->last_version = ram_list.version; rs->xbzrle_enabled = false; @@ -2988,8 +2999,8 @@ void ram_postcopy_send_discard_bitmap(MigrationState *ms) migration_bitmap_sync(rs); /* Easiest way to make sure we don't resume in the middle of a host-page */ + rs->pss[RAM_CHANNEL_PRECOPY].last_sent_block = NULL; rs->last_seen_block = NULL; - rs->last_sent_block = NULL; rs->last_page = 0; postcopy_each_ram_send_discard(ms); From patchwork Mon Aug 29 16:56:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1671577 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=P8hVXd+n; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MGcYV24Cqz1yhw for ; Tue, 30 Aug 2022 03:16:45 +1000 (AEST) Received: from localhost ([::1]:43132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oSiNP-00045D-7l for incoming@patchwork.ozlabs.org; Mon, 29 Aug 2022 13:16:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4k-0002ms-Ty for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:41606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oSi4j-0008Hj-58 for qemu-devel@nongnu.org; Mon, 29 Aug 2022 12:57:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661792244; 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=q9PZpoWjSYmjZlpIGj1RNi7dEGqI8ybiJeAb4fl779M=; b=P8hVXd+n6nrYYbA1aIh1Cg8+HmmKIVI3bAeRZgWfvf6z6bs42+e7yh+rUelxDUz6mp/yvM E5bKNKV0rALzZOnwRAyB5ZGEkbw560oYjYAp2CaWLj+dx4a9kmaGryNxBztA1S4wvhD0yg 714UdNXmcoPVH2p2TVrLmfXD7yKbMcs= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-177-GfX_TjFUMNOIyglj3adIRg-1; Mon, 29 Aug 2022 12:57:23 -0400 X-MC-Unique: GfX_TjFUMNOIyglj3adIRg-1 Received: by mail-io1-f71.google.com with SMTP id q10-20020a0566022f0a00b00688d703717bso5017407iow.9 for ; Mon, 29 Aug 2022 09:57:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=q9PZpoWjSYmjZlpIGj1RNi7dEGqI8ybiJeAb4fl779M=; b=DlcN7P35Hwvw7IxuP2JsksGyDCu87CphQfPB8F8cKGbpCDbawN0Ih08g+81UfKVOnF h3daqhvjYKbAEOsgU6rLSQketdXYe2GQZBIkTe47xprb3WS1rtn1Y71YPHq7tDxrcH03 jJ5OKK78e5sC9uW/B1GjVMNbt/71ZXhAum5v44dXAS/68poXunjnEuMM2VtJ9H95RiYp PAervHj2vT6okelLQNFANowcAA+zU0P9mpmqlBiSgBHoAoXrKnpKKqZvr7GZ+fltBdvf ZBTV1ndUNZB7z/H728Ps1Nlj/6J53Nre51iVOyCLHnNKNMgEZDr21Lz6iDzTrHeEtZQl jMkA== X-Gm-Message-State: ACgBeo1t5Hgutg2kay9Sjsei6amdUk7Wa0vPct+7ePO6cmiyCSz8PuCb GEGiOBhn6/vlrPHKTTM/T0Hw+JmYvRNnuIm5itk4wN6x5NKfaUHzarNbnPebMKd9sPZp+5N8JWk lYuwbCIET3T15KeOT2p9qgOCYpN5avziIB+w9pBz3pYgxJHB+RMhlM6zBboAVsHoT X-Received: by 2002:a05:6638:160b:b0:346:ab00:9c7c with SMTP id x11-20020a056638160b00b00346ab009c7cmr10273050jas.241.1661792242575; Mon, 29 Aug 2022 09:57:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR7LXTMEZbQKBsGRxf5U15xCJH9zAWN2Ne1b08UiB7Y2RtP0U7tSyYtIk7Pc1faNuzukpMmV6Q== X-Received: by 2002:a05:6638:160b:b0:346:ab00:9c7c with SMTP id x11-20020a056638160b00b00346ab009c7cmr10273037jas.241.1661792242268; Mon, 29 Aug 2022 09:57:22 -0700 (PDT) Received: from localhost.localdomain (bras-base-aurron9127w-grc-35-70-27-3-10.dsl.bell.ca. [70.27.3.10]) by smtp.gmail.com with ESMTPSA id y9-20020a056638228900b00344c3de5ec7sm4404709jas.150.2022.08.29.09.57.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Aug 2022 09:57:21 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: "Daniel P . Berrange" , Leonardo Bras Soares Passos , Manish Mishra , Juan Quintela , "Dr . David Alan Gilbert" , peterx@redhat.com Subject: [PATCH RFC 13/13] migration: Send requested page directly in rp-return thread Date: Mon, 29 Aug 2022 12:56:59 -0400 Message-Id: <20220829165659.96046-14-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220829165659.96046-1-peterx@redhat.com> References: <20220829165659.96046-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" With all the facilities ready, send the requested page directly in the rp-return thread rather than queuing it in the request queue, if and only if postcopy preempt is enabled. It can achieve so because it uses separate channel for sending urgent pages. The only shared data is bitmap and it's protected by the bitmap_mutex. Signed-off-by: Peter Xu --- migration/ram.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index ef89812c69..e731a70255 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -539,6 +539,8 @@ static QemuThread *decompress_threads; static QemuMutex decomp_done_lock; static QemuCond decomp_done_cond; +static int ram_save_host_page_urgent(PageSearchStatus *pss); + static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *block, ram_addr_t offset, uint8_t *source_buf); @@ -553,6 +555,16 @@ static void pss_init(PageSearchStatus *pss, RAMBlock *rb, ram_addr_t page) pss->complete_round = false; } +/* + * Check whether two PSSs are actively sending the same page. Return true + * if it is, false otherwise. + */ +static bool pss_overlap(PageSearchStatus *pss1, PageSearchStatus *pss2) +{ + return pss1->host_page_sending && pss2->host_page_sending && + (pss1->host_page_start == pss2->host_page_start); +} + static void *do_data_compress(void *opaque) { CompressParam *param = opaque; @@ -2250,6 +2262,53 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len) return -1; } + /* + * When with postcopy preempt, we send back the page directly in the + * rp-return thread. + */ + if (postcopy_preempt_active()) { + ram_addr_t page_start = start >> TARGET_PAGE_BITS; + size_t page_size = qemu_ram_pagesize(ramblock); + PageSearchStatus *pss = &ram_state->pss[RAM_CHANNEL_POSTCOPY]; + int ret = 0; + + qemu_mutex_lock(&rs->bitmap_mutex); + + pss_init(pss, ramblock, page_start); + /* Always use the preempt channel, and make sure it's there */ + pss->pss_channel = migrate_get_current()->postcopy_qemufile_src; + pss->postcopy_requested = true; + assert(pss->pss_channel); + + /* + * It must be either one or multiple of host page size. Just + * assert; if something wrong we're mostly split brain anyway. + */ + assert(len % page_size == 0); + while (len) { + if (ram_save_host_page_urgent(pss)) { + error_report("%s: ram_save_host_page_urgent() failed: " + "ramblock=%s, start_addr=0x"RAM_ADDR_FMT, + __func__, ramblock->idstr, start); + ret = -1; + break; + } + /* + * NOTE: after ram_save_host_page_urgent() succeeded, pss->page + * will automatically be moved and point to the next host page + * we're going to send, so no need to update here. + * + * Normally QEMU never sends >1 host page in requests, so + * logically we don't even need that as the loop should only + * run once, but just to be consistent. + */ + len -= page_size; + }; + qemu_mutex_unlock(&rs->bitmap_mutex); + + return ret; + } + struct RAMSrcPageRequest *new_entry = g_new0(struct RAMSrcPageRequest, 1); new_entry->rb = ramblock; @@ -2528,6 +2587,55 @@ static void pss_host_page_finish(PageSearchStatus *pss) pss->host_page_end = 0; } +/* + * Send an urgent host page specified by `pss'. Need to be called with + * bitmap_mutex held. + * + * Returns 0 if save host page succeeded, false otherwise. + */ +static int ram_save_host_page_urgent(PageSearchStatus *pss) +{ + bool page_dirty, sent = false; + RAMState *rs = ram_state; + int ret = 0; + + trace_postcopy_preempt_send_host_page(pss->block->idstr, pss->page); + pss_host_page_prepare(pss); + + /* + * If precopy is sending the same page, let it be done in precopy, or + * we could send the same page in two channels and none of them will + * receive the whole page. + */ + if (pss_overlap(pss, &ram_state->pss[RAM_CHANNEL_PRECOPY])) { + trace_postcopy_preempt_hit(pss->block->idstr, + pss->page << TARGET_PAGE_BITS); + return 0; + } + + do { + page_dirty = migration_bitmap_clear_dirty(rs, pss->block, pss->page); + + if (page_dirty) { + /* Be strict to return code; it must be 1, or what else? */ + if (ram_save_target_page(rs, pss) != 1) { + error_report_once("%s: ram_save_target_page failed", __func__); + ret = -1; + goto out; + } + sent = true; + } + pss_find_next_dirty(pss); + } while (pss_within_range(pss)); +out: + pss_host_page_finish(pss); + /* For urgent requests, flush immediately if sent */ + if (sent) { + qemu_fflush(pss->pss_channel); + } + return ret; +} + /** * ram_save_host_page: save a whole host page *