Received: by 2002:ac2:4c03:0:0:0:0:0 with SMTP id t3csp3743234lfq; Tue, 15 Dec 2020 10:28:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxqO4ijxptPFWoSIGTwi4Zx3tYpHwPBOfMn6ugZEeb7ZsU03vSBrtHRD7NI2nNQqjIbd+DL X-Received: by 2002:a25:8283:: with SMTP id r3mr44970512ybk.66.1608056903033; Tue, 15 Dec 2020 10:28:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608056903; cv=none; d=google.com; s=arc-20160816; b=jnCBRM6RCE/lB4qjRtxyaTZRQ7yIMB5mjlYXvdNn/wbWwfamyo2fP5C9f5X9uGHCJR 7WSUsNFyszNJGN3EM9uyFjEuyGuoK3h9v8R7cN05EwA2EOyZu56TQj/0WDfULc9OzoOj UfZFYb5F/yqk8olIRW0WR6F86L0GAiDdQSx2FFtxsClwZSL0RwGSh9urNefP81wpJo5U aNy5wYe41CDeOPd3iK1pWSFgPsho+/Cz1QqgM6qfFmmm+g/i9IWuttfVhWZmdfIT7ak0 2xkaQQyp0n+vhhWx5pb63WeYGDFqHapPk52cPAlaCgAjXFrDbjkPSH/UMiUYWYtLxFGt jbQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=NVHSw98Fk2e0k0Tks1NpbMkvfdMNBonhoxN6qjDhoUw=; b=fI75xVCRiJEU6oPOzerOXC0jI6KxedG3HGiQfH/TeTnesVVKqdj9dVB2zPoep5i4yl 8CFl/KMD5rXbHzhbU1aBOYlan9VYncMsL2Bgf1XwPzqRuycGX4hqMQD9Q0t0cjE8xNy6 btayRhDveF7ttYlhjv+VehzLnL26oZHgnnhoUoyr6JN+N+sQWZruSvCWjdComDRKduae qrlwN8iHwzLLJGk8QbRyd7XC3c1Lf1M4UcDG2AFspMsMKpIxGcXQoy+oMB/dtKx1si4y y5P+auMuDQ/OOIzOeitXYJs3cHG4hOTbdbM8WjoR+JZsrc5UZjDFrQhbmMVyOBR5Rb0q JC7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=B+pboVhN; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 7si15993774ybo.332.2020.12.15.10.28.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Dec 2020 10:28:23 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=B+pboVhN; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:37008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpF3e-0005vD-DV for alex.bennee@linaro.org; Tue, 15 Dec 2020 13:28:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35018) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpEZl-0006SB-Uv for qemu-arm@nongnu.org; Tue, 15 Dec 2020 12:57:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46688) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpEZh-00020R-K4 for qemu-arm@nongnu.org; Tue, 15 Dec 2020 12:57:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608055045; 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: in-reply-to:in-reply-to:references:references; bh=NVHSw98Fk2e0k0Tks1NpbMkvfdMNBonhoxN6qjDhoUw=; b=B+pboVhNymAotO189wMOXCQS/yq1F2T7blIxkLG+rqDaMj8ekMWc8s3xHw1gZ82rDUQi4J XV9Jz5TggXeREY+hBohDMlpl7kYQ/29G9RrVt7uuumpootNvma2OcSqwDz902kf6xBFqzc BlRmPhv53duGsyLDa3LtnaWs2XhMQ8k= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-540-pDp-LmV1MMqLb6qz7IjQyw-1; Tue, 15 Dec 2020 12:57:22 -0500 X-MC-Unique: pDp-LmV1MMqLb6qz7IjQyw-1 Received: by mail-qk1-f197.google.com with SMTP id u67so15782972qkd.6 for ; Tue, 15 Dec 2020 09:57:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NVHSw98Fk2e0k0Tks1NpbMkvfdMNBonhoxN6qjDhoUw=; b=rGEBOxiIwO5lKXood/almjBncbK0RsxLmWT0Pw7PJEac5chX+CLTv8sJw6oGpKOmFN NbgBjgSiJc4G83N+0RMZYMnD9ZdVgP/EeItOrymuegLr5rkCNXUbv+u+6DQ6Q7jeKda6 kQ0JvoTwVDqdHKiBEikoJK4GbbkKMQepTPhI1cRQKOuh9wIHY/VuNZ68eedMYMU9vHAg Im9sLSAL11dWlhgbclkbOuZRLv6ble+OCF9PPy6hKH7SalRL0rdWgJD2MJCWZ7z2Ln6p XEIsjY/nXgtzMXFJ17QzLwFZ8iE76d/HtfV2HXW6sm+TDvMkj2tsVeNcycohW0a+ttAd JHzA== X-Gm-Message-State: AOAM531uM3MO38MAmiIj1pNY36Z4panaL6flZ+1Yi58bWyxCw81jX9JM C5BRoAl66oaiVwJvnc4AI0a/Pkc89xglEfxXXlZr99MPuva4PL1NTN6kpXbtjW12fTny4ks6UQI 68D86/Q4Girkj X-Received: by 2002:a37:9b8d:: with SMTP id d135mr37695648qke.338.1608055041937; Tue, 15 Dec 2020 09:57:21 -0800 (PST) X-Received: by 2002:a37:9b8d:: with SMTP id d135mr37695633qke.338.1608055041698; Tue, 15 Dec 2020 09:57:21 -0800 (PST) Received: from xz-x1 ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id c28sm9952166qtv.2.2020.12.15.09.57.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 09:57:21 -0800 (PST) Date: Tue, 15 Dec 2020 12:57:19 -0500 From: Peter Xu To: Keqian Zhu Subject: Re: [PATCH 1/2] accel: kvm: Fix memory waste under mismatch page size Message-ID: <20201215175719.GA112585@xz-x1> References: <20201215071948.23940-1-zhukeqian1@huawei.com> <20201215071948.23940-2-zhukeqian1@huawei.com> MIME-Version: 1.0 In-Reply-To: <20201215071948.23940-2-zhukeqian1@huawei.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , jiangkunkun@huawei.com, qemu-devel@nongnu.org, "Dr . David Alan Gilbert" , qemu-arm@nongnu.org, Paolo Bonzini , Zenghui Yu , wanghaibin.wang@huawei.com Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: cbwNymOQXwZN On Tue, Dec 15, 2020 at 03:19:47PM +0800, Keqian Zhu wrote: > When handle dirty log, we face qemu_real_host_page_size and > TARGET_PAGE_SIZE. The first one is the granule of KVM dirty > bitmap, and the second one is the granule of QEMU dirty bitmap. > > Generally speaking, qemu_real_host_page_size >= TARGET_PAGE_SIZE, > so misuse TARGET_PAGE_SIZE to init kvmslot dirty_bmap may waste > memory. For example, when qemu_real_host_page_size is 64K and > TARGET_PAGE_SIZE is 4K, this bugfix can save 93.75% memory. > > Signed-off-by: Keqian Zhu > --- > accel/kvm/kvm-all.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c > index baaa54249d..c5e06288eb 100644 > --- a/accel/kvm/kvm-all.c > +++ b/accel/kvm/kvm-all.c > @@ -620,8 +620,12 @@ static void kvm_memslot_init_dirty_bitmap(KVMSlot *mem) > * too, in most cases). > * So for now, let's align to 64 instead of HOST_LONG_BITS here, in > * a hope that sizeof(long) won't become >8 any time soon. > + * > + * Note: the granule of kvm dirty log is qemu_real_host_page_size. > + * And mem->memory_size is aligned to it (otherwise this mem can't > + * be registered to KVM). > */ > - hwaddr bitmap_size = ALIGN(((mem->memory_size) >> TARGET_PAGE_BITS), > + hwaddr bitmap_size = ALIGN(mem->memory_size / qemu_real_host_page_size, > /*HOST_LONG_BITS*/ 64) / 8; Yes I think this is correct. Thanks. So one thing I failed to notice is cpu_physical_memory_set_dirty_lebitmap() will "amplify" the host dirty pages into guest ones; seems we're all good then. Reviewed-by: Peter Xu -- Peter Xu