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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 86BC2C33CAA for ; Thu, 23 Jan 2020 22:05:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2F5C921569 for ; Thu, 23 Jan 2020 22:05:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F5C921569 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C70546B0285; Thu, 23 Jan 2020 17:05:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C20286B0286; Thu, 23 Jan 2020 17:05:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B109B6B0287; Thu, 23 Jan 2020 17:05:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id 99C4F6B0285 for ; Thu, 23 Jan 2020 17:05:43 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 5831C440E for ; Thu, 23 Jan 2020 22:05:43 +0000 (UTC) X-FDA: 76410281766.21.mouth61_14bc3074e5341 X-HE-Tag: mouth61_14bc3074e5341 X-Filterd-Recvd-Size: 10299 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Jan 2020 22:05:42 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Jan 2020 14:05:27 -0800 X-IronPort-AV: E=Sophos;i="5.70,355,1574150400"; d="scan'208";a="400485240" Received: from ahduyck-desk1.jf.intel.com ([10.7.198.76]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Jan 2020 14:05:26 -0800 Message-ID: Subject: Re: [PATCH v16.1 0/9] mm / virtio: Provide support for free page reporting From: Alexander Duyck To: "Graf (AWS), Alexander" Cc: Alexander Duyck , "kvm@vger.kernel.org" , "mst@redhat.com" , "linux-kernel@vger.kernel.org" , "willy@infradead.org" , "mhocko@kernel.org" , "linux-mm@kvack.org" , "akpm@linux-foundation.org" , "mgorman@techsingularity.net" , "vbabka@suse.cz" , "yang.zhang.wz@gmail.com" , "nitesh@redhat.com" , "konrad.wilk@oracle.com" , "david@redhat.com" , "pagupta@redhat.com" , "riel@surriel.com" , "lcapitulino@redhat.com" , "dave.hansen@intel.com" , "wei.w.wang@intel.com" , "aarcange@redhat.com" , "pbonzini@redhat.com" , "dan.j.williams@intel.com" , "osalvador@suse.de" , "Paterson-Jones, Roland" , "hannes@cmpxchg.org" , "hare@suse.com" , Christian Borntraeger , "Singh, Balbir" Date: Thu, 23 Jan 2020 14:05:26 -0800 In-Reply-To: References: <20200122173040.6142.39116.stgit@localhost.localdomain> <914aa4c3-c814-45e0-830b-02796b00b762@amazon.com> ,<3e24a8ad7afe7c2f6ec8ffe7260a3e31bbe41651.camel@linux.intel.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, 2020-01-23 at 18:47 +0000, Graf (AWS), Alexander wrote: > > > Am 23.01.2020 um 19:34 schrieb Alexander Duyck : > > >=20 > > > =EF=BB=BFOn Thu, 2020-01-23 at 17:54 +0100, Alexander Graf wrote: > > > > On 23.01.20 17:26, Alexander Duyck wrote: > > > > On Thu, 2020-01-23 at 11:20 +0100, Alexander Graf wrote: > > > > > Hi Alex, > > > > > > On 22.01.20 18:43, Alexander Duyck wrote: > > > [...] > > > > > > The overall guest size is kept fairly small to only a few GB = while the test > > > > > > is running. If the host memory were oversubscribed this patch= set should > > > > > > result in a performance improvement as swapping memory in the= host can be > > > > > > avoided. > > > > > I really like the approach overall. Voluntarily propagating fre= e memory > > > > > from a guest to the host has been a sore point ever since KVM w= as > > > > > around. This solution looks like a very elegant way to do so. > > > > > The big piece I'm missing is the page cache. Linux will by defa= ult try > > > > > to keep the free list as small as it can in favor of page cache= , so most > > > > > of the benefit of this patch set will be void in real world sce= narios. > > > > Agreed. This is a the next piece of this I plan to work on once t= his is > > > > accepted. For now the quick and dirty approach is to essentially = make use > > > > of the /proc/sys/vm/drop_caches interface in the guest by either = putting > > > > it in a cronjob somewhere or to have it after memory intensive wo= rkloads. > > > > > Traditionally, this was solved by creating pressure from the ho= st > > > > > through virtio-balloon: Exactly the piece that this patch set g= ets away > > > > > with. I never liked "ballooning", because the host has very lim= ited > > > > > visibility into the actual memory utility of its guests. So lea= ving the > > > > > decision on how much memory is actually needed at a given point= in time > > > > > should ideally stay with the guest. > > > > > What would keep us from applying the page hinting approach to i= nactive, > > > > > clean page cache pages? With writeback in place as well, we wou= ld slowly > > > > > propagate pages from > > > > > dirty -> clean -> clean, inactive -> free -> host owned > > > > > which gives a guest a natural path to give up "not important" m= emory. > > > > I considered something similar. Basically one thought I had was t= o > > > > essentially look at putting together some sort of epoch. When the= host is > > > > under memory pressure it would need to somehow notify the guest a= nd then > > > > the guest would start moving the epoch forward so that we start e= victing > > > > pages out of the page cache when the host is under memory pressur= e. > > > I think we want to consider an interface in which the host actively= asks > > > guests to purge pages to be on the same line as swapping: The last = line > > > of defense. > >=20 > > I suppose. The only reason I was thinking that we may want to look at > > doing something like that was to avoid putting pressure on the guest = when > > the host doesn't need us to. > >=20 > > > In the normal mode of operation, you still want to shrink down > > > voluntarily, so that everyone cooperatively tries to make free for = new > > > guests you could potentially run on the same host. > > > If you start to apply pressure to guests to find out of they might = have > > > some pages to spare, we're almost back to the old style ballooning = approach. > >=20 > > Thats true. In addition we avoid possible issues with us trying to fl= ush > > out a bunch of memory from multiple guests as once since they would b= e > > proactively freeing the memory. > >=20 > > I'm thinking the inactive state could be something similar to MADV_FR= EE in > > terms of behavior. If it sits in the queue for long enough we decide > > nobody is using it anymore so it is freed, but if it is accessed it i= s > > cheap for us to just put it back without much in the way of overhead. >=20 > I think the main difference between the MADV_FREE and what we want is > that we also want to pull the page into active state on read. >=20 > But sure, that's a possible interface. What I'd like to make sure of is > that we can have different host policies: discard the page straight > away, keep it for a fixed amount of time or discard it lazily on > pressure. As long as the guest gives the host its clean pages > voluntarily, I'm happy. Well the current model I am working with has us using MAD_DONTNEED from the hypervisor if the unsued page is reported. So it will still have to b= e pulled back in, but it will start out as a zeroed page. > Btw, have you already given thought to the faulting interface when a > page was evicted? That's where it gets especially tricky. With a simple > "discard the page straight away" style interface, we would not have to > fault. So the fault I was referring to would be inside the guest only. Basically we would keep the page for a little while longer while it is inactive and just let the mapping go. Then if something accesses it before we finally release it we don't pay the heavy cost of having to get it back from the host and then copying the memory back in from swap or the file. I'm just loosely basing that on the "proactive reclaim" idea that was proposed back at the last lsf/mm summit (https://lwn.net/Articles/787611/= ) . I still haven't even started work on any of those pieces yet nor looked at it too closely. I'm still in the information gathering phase. > > > Btw, have you ever looked at CMM2 [1]? With that, the host can > > > essentially just "steal" pages from the guest when it needs any, wi= thout > > > the need to execute the guest meanwhile. That means inside the host > > > swapping path, CMM2 can just evict guest page cache pages as easily= as > > > we evict host page cache pages. To me, that's even more attractive = in > > > the swap / emergency case than an interface which requires the gues= t to > > > proactively execute while we are in a low mem situation. > >=20 > > > >=20 > > > [1] https://www.kernel.org/doc/ols/2006/ols2006v2-pages-321-336.pdf > >=20 > > I hadn't read through this before. If nothing else the verbiage is us= eful > > since what we are discussing is essentially how to deal with the > > "volatile" pages within the system, the "unused" pages are the ones w= e > > have reported to the host with the page reporting, and the "stable" p= ages > > are those pages that have been faulted back into the guest when it > > accessed them. > >=20 > > I can see there would be some advantages to CMM2, however it seems li= ke it > > is adding a significant amount of state to pages since it has to supp= ort a > > fairly significant number of states and then there is the added compl= exity > > for all the transitions in and out of stable from the various states > > depending on how things are being changed. > >=20 > > Do you happen to know if anyone has done any research into how much > > overhead is added with CMM2 enabled? I'd be curious since it seems li= ke > > the paper mentions having to track a signficant number of state > > transitions for the memory throughout the kernel. >=20 > Let me add Christian Borntraeger to the thread. He can definitely help > on that side. I asked him earlier today and he confirmed that cmm2 is i= n > active use on s390. >=20 > Alex Okay, sounds good. - Alex