Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2802267imj; Mon, 18 Feb 2019 12:32:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IZaKM67vV1owRMYjt4Y5gLe4rXTdklrNypzIOOkBNA1eGzUFfFRXil72+tzWtdAYyZ3SPUX X-Received: by 2002:aa7:8101:: with SMTP id b1mr26510052pfi.148.1550521945707; Mon, 18 Feb 2019 12:32:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550521945; cv=none; d=google.com; s=arc-20160816; b=zbH1BXCmsKDbPYebL7/1lEKcAcEiMtyZkstl8rO1NeGBB0p+oeQz/ZBPdtNEa1AbbJ pj3SpEihOPXnBSEAjyJA48opkVNd7AvIjsuYtG2FNtD80ODPSbh+/fftdtFjGgA1rygh WOaldBNryixUsyeQh+hmlyiA14Bgxx3QrST9vEcfAV5j3OzSXwaq9gB6/n9TkxOTeHqs R1X9FxFnlhvybpuFlCC0cDbJy2+NBg+JhzopWsMRVDum0kwpgGji2r8Y1riy3vLizoD+ tmbW5BpL+RU4isjLXiqNLGyosJgmuz/XikWSPuOGQ6xZv8pzPFFl8tccMG8x4Jl+PrRl E4ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=fxOkcYT1hPxPrsd41FYLrGuBmt3Uo7mYHZUzA1PaaVw=; b=OAKuBhILNSHJTC/pe21rB0R3mmQiKmO3GCDT2QfNNrs9ZuZs3QmUyMmxa81k9wKehR xPkeZjtdmq/QSMXBtGfnxSBYNQhFJnfeCZ6/r9bV7tJTurxQd7Rjn5a1X3Mwb0baEfFm nhdJgaLaVl25PwoDJTMvlPexuFpvFdfN4xxoohKTNxBdf8O6+HzuOh5Y3wK9D2TLO6zm 8QmpmQMGAE7ftFWd82bYtsR/gOFiwBRQYzRZ2oCFGVYZ+YJ4sXfwwj9bDci9E5ZNZxgu /bfs04NvrDR+Ud/4vxEzMX024okd6d7uHwxLbHuYmWZJUyHMadurK7XFuIuiBwPfU5km DaSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i9si13337575pgs.156.2019.02.18.12.32.09; Mon, 18 Feb 2019 12:32:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728346AbfBRUcC (ORCPT + 99 others); Mon, 18 Feb 2019 15:32:02 -0500 Received: from mail-qt1-f174.google.com ([209.85.160.174]:46197 "EHLO mail-qt1-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726476AbfBRUcC (ORCPT ); Mon, 18 Feb 2019 15:32:02 -0500 Received: by mail-qt1-f174.google.com with SMTP id y20so20610973qtm.13 for ; Mon, 18 Feb 2019 12:32:01 -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=fxOkcYT1hPxPrsd41FYLrGuBmt3Uo7mYHZUzA1PaaVw=; b=EK1nbo1yRwqNOZu+B1G1UP8gBfpNEvUiFAOAni7aEZix18nossloYcT5ULG8rJ8UOm OFRT6MaeJ2xWz5hiXfuFDX1cH0zBWdZojL5JJal4WwNGrBJiaHXspmmO9S8lnUEeP1Gd QL14e2Ia2bE/Aup1AMQEKCd3CbK62zNNSMytFWQuXaFWavMVHWWkvRFny87w4CS/hk7M bBZB8chsfJgVKFq+OSdYFDPcDo32pfdWm/7WeB8r+C4oCSlRne6N5nJd73QMuupi7zLL SSzZF/I3UAAPmZoQWixxLD5kVphev/xH4iC9A/6K2TAUDERIRA2+zEKkQoPlKVJU3SgA h8yA== X-Gm-Message-State: AHQUAuZk8MIVHNC5oVyyPQRO9eTAx+A7R3HPesAXdxyAcBP2tOBFRLBm /Zwrg2xAt9rSrXM5vP72CbSZng== X-Received: by 2002:a0c:d968:: with SMTP id t37mr18788905qvj.195.1550521921182; Mon, 18 Feb 2019 12:32:01 -0800 (PST) Received: from redhat.com (pool-173-76-246-42.bstnma.fios.verizon.net. [173.76.246.42]) by smtp.gmail.com with ESMTPSA id m124sm7165747qkc.16.2019.02.18.12.31.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Feb 2019 12:32:00 -0800 (PST) Date: Mon, 18 Feb 2019 15:31:57 -0500 From: "Michael S. Tsirkin" To: David Hildenbrand Cc: Nitesh Narayan Lal , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, lcapitulino@redhat.com, pagupta@redhat.com, wei.w.wang@intel.com, yang.zhang.wz@gmail.com, riel@surriel.com, dodgen@google.com, konrad.wilk@oracle.com, dhildenb@redhat.com, aarcange@redhat.com, Alexander Duyck Subject: Re: [RFC][Patch v8 0/7] KVM: Guest Free Page Hinting Message-ID: <20190218152021-mutt-send-email-mst@kernel.org> References: <20190204201854.2328-1-nitesh@redhat.com> <20190218114601-mutt-send-email-mst@kernel.org> <44740a29-bb14-e6e6-2992-98d0ae58e994@redhat.com> <20190218122636-mutt-send-email-mst@kernel.org> <20190218140947-mutt-send-email-mst@kernel.org> <4039c2e8-5db4-cddd-b997-2fdbcc6f529f@redhat.com> <20190218143819-mutt-send-email-mst@kernel.org> <58714908-f203-0b64-845b-5818e52a62fa@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <58714908-f203-0b64-845b-5818e52a62fa@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 18, 2019 at 09:04:57PM +0100, David Hildenbrand wrote: > >>>>> So I'm fine with a simple implementation but the interface needs to > >>>>> allow the hypervisor to process hints in parallel while guest is > >>>>> running. We can then fix any issues on hypervisor without breaking > >>>>> guests. > >>>> > >>>> Yes, I am fine with defining an interface that theoretically let's us > >>>> change the implementation in the guest later. > >>>> I consider this even a > >>>> prerequisite. IMHO the interface shouldn't be different, it will be > >>>> exactly the same. > >>>> > >>>> It is just "who" calls the batch freeing and waits for it. And as I > >>>> outlined here, doing it without additional threads at least avoids us > >>>> for now having to think about dynamic data structures and that we can > >>>> sometimes not report "because the thread is still busy reporting or > >>>> wasn't scheduled yet". > >>> > >>> Sorry I wasn't clear. I think we need ability to change the > >>> implementation in the *host* later. IOW don't rely on > >>> host being synchronous. > >>> > >>> > >> I actually misread it :) . In any way, there has to be a mechanism to > >> synchronize. > >> > >> If we are going via a bare hypercall (like s390x, like what Alexander > >> proposes), it is going to be a synchronous interface either way. Just a > >> bare hypercall, there will not really be any blocking on the guest side. > > > > It bothers me that we are now tied to interface being synchronous. We > > won't be able to fix it if there's an issue as that would break guests. > > I assume with "fix it" you mean "fix kfree taking longer on every X call"? > > Yes, as I initially wrote, this mimics s390x. That might be good (we > know it has been working for years) and bad (we are inheriting the same > problem class, if it exists). And being synchronous is part of the > approach for now. BTW on s390 are these hypercalls handled by Linux? > I tend to focus on the first part (we don't know anything besides it is > working) while you focus on the second part (there could be a potential > problem). Having a real problem at hand would be great, then we would > know what exactly we actually have to fix. But read below. If we end up doing a hypercall per THP, maybe we could at least not block with interrupts disabled? Poll in guest until hypervisor reports its done? That would already be an improvement IMHO. E.g. perf within guest will point you in the right direction and towards disabling hinting. > > > >> Via virtio, I guess it is waiting for a response to a requests, right? > > > > For the buffer to be used, yes. And it could mean putting some pages > > aside until hypervisor is done with them. Then you don't need timers or > > tricks like this, you can get an interrupt and start using the memory. > > I am very open to such an approach as long as we can make it work and it > is not too complicated. (-> simple) > > This would mean for example > > 1. Collect entries to be reported per VCPU in a buffer. Say magic number > 256/512. > > 2. Once the buffer is full, do crazy "take pages out of the balloon > action" and report them to the hypervisor via virtio. Let the VCPU > continue. This will require some memory to store the request. Small > hickup for the VCPU to kick of the reporting to the hypervisor. > > 3. On interrupt/response, go over the response and put the pages back to > the buddy. > > (assuming that reporting a bulk of frees is better than reporting every > single free obviously) > > This could allow nice things like "when OOM gets trigger, see if pages > are currently being reported and wait until they have been put back to > the buddy, return "new pages available", so in a real "low on memory" > scenario, no OOM killer would get involved. This could address the issue > Wei had with reporting when low on memory. > > Is that something you have in mind? Yes that seems more future proof I think. > I assume we would have to allocate > memory when crafting the new requests. This is the only reason I tend to > prefer a synchronous interface for now. But if allocation is not a > problem, great. There are two main ways to avoid allocation: 1. do not add extra data on top of each chunk passed 2. add extra data but pre-allocate buffers for it > -- > > Thanks, > > David / dhildenb