From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D4FBC4338F for ; Thu, 5 Aug 2021 08:27:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B91B860EBC for ; Thu, 5 Aug 2021 08:27:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B91B860EBC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:51448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mBYjN-0003fI-MR for qemu-devel@archiver.kernel.org; Thu, 05 Aug 2021 04:27:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBYil-0002yU-U9 for qemu-devel@nongnu.org; Thu, 05 Aug 2021 04:27:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBYik-00020v-AY for qemu-devel@nongnu.org; Thu, 05 Aug 2021 04:27:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628152037; 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=QCR8wotBj6Y+gZ+KimM+pS/Dg2KJNkY0MqKaKKjb4qg=; b=Mh8hWbtFLsM92rNXIXl7UQx6M4nutdLjyDfdX2IP04MgZ05YZt/yqZs4+PoP4Tfb09uIb6 KZhlbfdskOQiONqDqJJSYi2dw1/xPrWboV8VW2rnSwO/4souFEgUqapPevWNh0MMWf4nYF xxiGoAMTGJBOH//a+N5XxdgrgU9FGXA= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-442-j8D8g-dROUipiXyh_9jfYQ-1; Thu, 05 Aug 2021 04:27:16 -0400 X-MC-Unique: j8D8g-dROUipiXyh_9jfYQ-1 Received: by mail-wr1-f69.google.com with SMTP id w1-20020adf8bc10000b0290154bed98988so367802wra.1 for ; Thu, 05 Aug 2021 01:27:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=QCR8wotBj6Y+gZ+KimM+pS/Dg2KJNkY0MqKaKKjb4qg=; b=Juk6mq+Cybm9U9GjLw9DQVJiZBhtBxmA1lIOGnnezLWb2p5uazAzwGPMMK9A5YF5Um EeVV4bnUBD9c3h8CKCdHx6XA9lAiu1ssey+oM4LVhcR3s9TxBnAYUrFYQvN/CmsmQagr qDyanEMRViTKGVBy9YRdk/egnUEUz2lKEw7uAbI4wQrGIGY98Z+nMZcd9KjuQ0dz/GXI EXplBJMqwkfogCfulqWbbx+wdBuFlEaH5/HT8UYmQd+1u4s3cxrvNzCeiZSu2YXL7q40 ldtBnihpa0krtqVdLDsGLEQVvdJ5i0ty75iQtogLPPBw6VSF2BXRHRiipoVsb4kxL9VX FjWQ== X-Gm-Message-State: AOAM5326vfTKqVRFJYL+Po9fkgMrpdVTzJhe08ipVS9x1gIYGLDS2Aa5 p8Dr78sFz1+VntEuEzkuXaNGvoXfzumvLm07YSqNkLX+nsINu//jhCn1W8+5UpRLd8Vs+tWZO+H lnSLR+PPljersgTE= X-Received: by 2002:adf:d20a:: with SMTP id j10mr3784037wrh.152.1628152035525; Thu, 05 Aug 2021 01:27:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwH5mUTXjQrEQlMal1g+6V/8QAP9FzzNkEa5KT9aCPLAm+JxwcAbup5K3XXzFarravnOgS5GQ== X-Received: by 2002:adf:d20a:: with SMTP id j10mr3784010wrh.152.1628152035331; Thu, 05 Aug 2021 01:27:15 -0700 (PDT) Received: from [192.168.3.132] (p5b0c630b.dip0.t-ipconnect.de. [91.12.99.11]) by smtp.gmail.com with ESMTPSA id f3sm5502250wro.30.2021.08.05.01.27.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Aug 2021 01:27:14 -0700 (PDT) Subject: Re: [PATCH v3 7/7] migration/ram: Handle RAMBlocks with a RamDiscardManager on background snapshots To: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= , qemu-devel@nongnu.org References: <20210730085249.8246-1-david@redhat.com> <20210730085249.8246-8-david@redhat.com> <265427ef-ea74-e352-8148-7e4353af6ceb@redhat.com> <025af202-759f-3d8b-b40a-dba346a36696@redhat.com> From: David Hildenbrand Organization: Red Hat Message-ID: <385f16de-106e-1d28-1678-56840f5f693d@redhat.com> Date: Thu, 5 Aug 2021 10:27:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <025af202-759f-3d8b-b40a-dba346a36696@redhat.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.699, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.132, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Williamson , Eduardo Habkost , Juan Quintela , "Michael S. Tsirkin" , "Dr. David Alan Gilbert" , Peter Xu , Andrey Gruzdev , Pankaj Gupta , teawater , Paolo Bonzini , Marek Kedzierski , Wei Yang Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 05.08.21 10:21, Philippe Mathieu-Daudé wrote: > On 8/5/21 10:11 AM, David Hildenbrand wrote: >> On 05.08.21 10:04, Philippe Mathieu-Daudé wrote: >>> On 7/30/21 10:52 AM, David Hildenbrand wrote: >>>> We already don't ever migrate memory that corresponds to discarded >>>> ranges >>>> as managed by a RamDiscardManager responsible for the mapped memory >>>> region >>>> of the RAMBlock. >>>> >>>> virtio-mem uses this mechanism to logically unplug parts of a RAMBlock. >>>> Right now, we still populate zeropages for the whole usable part of the >>>> RAMBlock, which is undesired because: >>>> >>>> 1. Even populating the shared zeropage will result in memory getting >>>>     consumed for page tables. >>>> 2. Memory backends without a shared zeropage (like hugetlbfs and shmem) >>>>     will populate an actual, fresh page, resulting in an unintended >>>>     memory consumption. >>>> >>>> Discarded ("logically unplugged") parts have to remain discarded. As >>>> these pages are never part of the migration stream, there is no need to >>>> track modifications via userfaultfd WP reliably for these parts. >>>> >>>> Further, any writes to these ranges by the VM are invalid and the >>>> behavior is undefined. >>>> >>>> Note that Linux only supports userfaultfd WP on private anonymous memory >>>> for now, which usually results in the shared zeropage getting populated. >>>> The issue will become more relevant once userfaultfd WP supports shmem >>>> and hugetlb. >>>> >>>> Acked-by: Peter Xu >>>> Signed-off-by: David Hildenbrand >>>> --- >>>>   migration/ram.c | 53 +++++++++++++++++++++++++++++++++++++++++-------- >>>>   1 file changed, 45 insertions(+), 8 deletions(-) >>>> >>>> diff --git a/migration/ram.c b/migration/ram.c >>>> index 01cea01774..fd5949734e 100644 >>>> --- a/migration/ram.c >>>> +++ b/migration/ram.c >>>> @@ -1639,6 +1639,28 @@ out: >>>>       return ret; >>>>   } >>>>   +static inline void populate_range(RAMBlock *block, hwaddr offset, >>>> hwaddr size) >>>> +{ >>>> +    char *ptr = (char *) block->host; >>>> + >>>> +    for (; offset < size; offset += ) { >>>> +        char tmp = *(ptr + offset); >>>> + >>>> +        /* Don't optimize the read out */ >>>> +        asm volatile("" : "+r" (tmp)); >>>> +    } >>> >>> This template is now used 3 times, a good opportunity to extract it as >>> an (inline?) helper. >>> >> >> Can you point me at the other users? > > Oops I got lost reviewing the series. > >> Isn't populate_range() the inline helper you are looking for? :) > > Indeed :) > > Being a bit picky, I'd appreciate if you split this patch in 2, > extracting populate_range() as a first trivial step. > Will do, and while at it again, will use ram_addr_t for the parameters and block->page_size instead of qemu_real_host_page_size. -- Thanks, David / dhildenb