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=-13.3 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL 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 29C88C35247 for ; Mon, 3 Feb 2020 20:32:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9D13920658 for ; Mon, 3 Feb 2020 20:32:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AsMYb7Nb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D13920658 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 13EA46B0005; Mon, 3 Feb 2020 15:32:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F0036B0006; Mon, 3 Feb 2020 15:32:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F20596B0007; Mon, 3 Feb 2020 15:32:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D1ED56B0005 for ; Mon, 3 Feb 2020 15:32:18 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 84C802DFA for ; Mon, 3 Feb 2020 20:32:18 +0000 (UTC) X-FDA: 76449963156.23.dolls41_887a8709ce249 X-HE-Tag: dolls41_887a8709ce249 X-Filterd-Recvd-Size: 18241 Received: from mail-vk1-f170.google.com (mail-vk1-f170.google.com [209.85.221.170]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Mon, 3 Feb 2020 20:32:17 +0000 (UTC) Received: by mail-vk1-f170.google.com with SMTP id b69so4247326vke.9 for ; Mon, 03 Feb 2020 12:32:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vKNtC8O5oWdev4z2OZqYfGRqu370JrtOcoEaQ3EinoA=; b=AsMYb7Nbdih11U2SnpwzLWyvAwlOqEaJscrSQYVxa8cQisQxQs45lNJBrGiB0u6C1a eNWd5/TYFD4XbWOgTWw1znOHMWDvMddJc5kXGtsZujdB/VqVXalXB+nbHAfmUBCHxNG9 V+vslxEltJgcGee+J8P3l/UWD8/pdQ7As1GjraL5c8/5AkE07QtYJ0Hn4gL1fa5N+IHW dh6N4dvtn7liNdaKrv8UG+9CO6Vfi4qdqs389X9YhmlDnehjZoaEVVHqxxYM+HuCIzHm ZHiKLgRNS4oiE5FJHEVoZlEjax03ZG7DPRGCGGTGGdaY0iDzAQk3HyzIwdls0nHJAaKl wTfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vKNtC8O5oWdev4z2OZqYfGRqu370JrtOcoEaQ3EinoA=; b=BknTSqcjir628NEORJC0RXNIQ2czXlrFIo+nYrnGbdeeDEjlBHw9UfMVoWxVyrmP/Z f6WmHHdWt7rugrJj9927dsiZi6KpvrmkJQ7AzZbvNznHjTVkazZ5kV+uXi0C1WqjgDVy 3p61h5umzOLgLbSJw8Kq7tlHzqsu7WJ4QxMJa+pdtOTkDL/8sjjkEX6cnGo6f0mCoSpi 0Dz4bysRs1Qd4QzGRbB8TpBWo6KQEs6tL8yBB/do8eCNyu7xeWo1k/7zT5Mjv7BLcXds eNq08cYFvgaDMdBERoqo0jO5EHTTNlBIEEF2Foy+2pzwcUlurayy1XYyBe3cQZw79axV GsIA== X-Gm-Message-State: APjAAAU8p1p6b4zmTaF5XI+bgZRjYZngHIF79Li5fNPoqW/7cbuI4qEA r32TzaZLcHr00k9Xa0+K+Y0IStMEv0uQSZ4izyBFnQ== X-Google-Smtp-Source: APXvYqyq6qZqQYbsi9Qolh9OJutRlVBaZWAAAVdQb1aFxsdrtp+O3JPhx/e52rJOCEjl7RfVzI5ToK76/ooJKzCbaCE= X-Received: by 2002:a1f:7c0c:: with SMTP id x12mr14924704vkc.41.1580761936950; Mon, 03 Feb 2020 12:32:16 -0800 (PST) MIME-Version: 1.0 References: <91270a68-ff48-88b0-219c-69801f0c252f@redhat.com> <75d4594f-0864-5172-a0f8-f97affedb366@redhat.com> <286AC319A985734F985F78AFA26841F73E3F8A02@shsmsx102.ccr.corp.intel.com> <20200203080520-mutt-send-email-mst@kernel.org> <5ac131de8e3b7fc1fafd05a61feb5f6889aeb917.camel@linux.intel.com> <20200203120225-mutt-send-email-mst@kernel.org> In-Reply-To: <20200203120225-mutt-send-email-mst@kernel.org> From: Tyler Sanderson Date: Mon, 3 Feb 2020 12:32:05 -0800 Message-ID: Subject: Re: Balloon pressuring page cache To: "Michael S. Tsirkin" Cc: David Hildenbrand , Alexander Duyck , "Wang, Wei W" , "virtualization@lists.linux-foundation.org" , David Rientjes , "linux-mm@kvack.org" , Michal Hocko Content-Type: multipart/alternative; boundary="000000000000ba8db1059db1d188" 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: --000000000000ba8db1059db1d188 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable There were apparently good reasons for moving away from OOM notifier callback: https://lkml.org/lkml/2018/7/12/314 https://lkml.org/lkml/2018/8/2/322 In particular the OOM notifier is worse than the shrinker because: 1. It is last-resort, which means the system has already gone through heroics to prevent OOM. Those heroic reclaim efforts are expensive and impact application performance. 2. It lacks understanding of NUMA or other OOM constraints. 3. It has a higher potential for bugs due to the subtlety of the callback context. Given the above, I think the shrinker API certainly makes the most sense _if_ the balloon size is static. In that case memory should be reclaimed from the balloon early and proportionally to balloon size, which the shrinker API achieves. However, if the balloon is inflating and intentionally causing memory pressure then this results in the inefficiency pointed out earlier. If the balloon is inflating but not causing memory pressure then there is no problem with either API. This suggests another route: rather than cause memory pressure to shrink the page cache, the balloon could issue the equivalent of "echo 3 > /proc/sys/vm/drop_caches". Of course ideally, we want to be more fine grained than "drop everything". We really want an API that says "drop everything that hasn't been accessed in the last 5 minutes". This would eliminate the need for the balloon to cause memory pressure at all which avoids the inefficiency in question. Furthermore, this pairs nicely with the FREE_PAGE_HINT feature. On Mon, Feb 3, 2020 at 9:04 AM Michael S. Tsirkin wrote: > On Mon, Feb 03, 2020 at 05:34:20PM +0100, David Hildenbrand wrote: > > On 03.02.20 17:18, Alexander Duyck wrote: > > > On Mon, 2020-02-03 at 08:11 -0500, Michael S. Tsirkin wrote: > > >> On Thu, Jan 30, 2020 at 11:59:46AM -0800, Tyler Sanderson wrote: > > >>> > > >>> On Thu, Jan 30, 2020 at 7:31 AM Wang, Wei W > wrote: > > >>> > > >>> On Thursday, January 30, 2020 11:03 PM, David Hildenbrand wrote= : > > >>> > On 29.01.20 20:11, Tyler Sanderson wrote: > > >>> > > > > >>> > > > > >>> > > On Wed, Jan 29, 2020 at 2:31 AM David Hildenbrand < > david@redhat.com > > >>> > > > wrote: > > >>> > > > > >>> > > On 29.01.20 01:22, Tyler Sanderson via Virtualization > wrote: > > >>> > > > A primary advantage of virtio balloon over other > memory reclaim > > >>> > > > mechanisms is that it can pressure the guest's page > cache into > > >>> > > shrinking. > > >>> > > > > > >>> > > > However, since the balloon driver changed to using th= e > shrinker > > >>> API > > >>> > > > > > >>> > > > > >>> > < > https://github.com/torvalds/linux/commit/71994620bb25a8b109388fefa9 > > >>> > e99a28e355255a#diff-fd202acf694d9eba19c8c64da3e480c9> this > > >>> > > > use case has become a bit more tricky. I'm wondering > what the > > >>> > intended > > >>> > > > device implementation is. > > >>> > > > > > >>> > > > When inflating the balloon against page cache (i.e. n= o > free > > >>> memory > > >>> > > > remains) vmscan.c will both shrink page cache, but > also invoke > > >>> the > > >>> > > > shrinkers -- including the balloon's shrinker. So the > balloon > > >>> driver > > >>> > > > allocates memory which requires reclaim, vmscan gets > this memory > > >>> > by > > >>> > > > shrinking the balloon, and then the driver adds the > memory back > > >>> to > > >>> > the > > >>> > > > balloon. Basically a busy no-op. > > >>> > > >>> Per my understanding, the balloon allocation won=E2=80=99t invo= ke > shrinker as > > >>> __GFP_DIRECT_RECLAIM isn't set, no? > > >>> > > >>> I could be wrong about the mechanism, but the device sees lots of > activity on > > >>> the deflate queue. The balloon is being shrunk. And this only start= s > once all > > >>> free memory is depleted and we're inflating into page cache. > > >> > > >> So given this looks like a regression, maybe we should revert the > > >> patch in question 71994620bb25 ("virtio_balloon: replace oom notifie= r > with shrinker") > > >> Besides, with VIRTIO_BALLOON_F_FREE_PAGE_HINT > > >> shrinker also ignores VIRTIO_BALLOON_F_MUST_TELL_HOST which isn't ni= ce > > >> at all. > > >> > > >> So it looks like all this rework introduced more issues than it > > >> addressed ... > > >> > > >> I also CC Alex Duyck for an opinion on this. > > >> Alex, what do you use to put pressure on page cache? > > > > > > I would say reverting probably makes sense. I'm not sure there is muc= h > > > value to having a shrinker running deflation when you are actively > trying > > > to increase the balloon. It would make more sense to wait until you a= re > > > actually about to start hitting oom. > > > > I think the shrinker makes sense for free page hinting feature > > (everything on free_page_list). > > > > So instead of only reverting, I think we should split it up and always > > register the shrinker for VIRTIO_BALLOON_F_FREE_PAGE_HINT and the OOM > > notifier (as before) for VIRTIO_BALLOON_F_MUST_TELL_HOST. > > OK ... I guess that means we need to fix shrinker to take > VIRTIO_BALLOON_F_MUST_TELL_HOST into account correctly. > Hosts ignore it at the moment but it's a fragile thing > to do what it does and ignore used buffers. > > > (Of course, adapting what is being done in the shrinker and in the OOM > > notifier) > > > > -- > > Thanks, > > > > David / dhildenb > > --000000000000ba8db1059db1d188 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
There were apparently good reasons for moving away from OO= M notifier callback:
In particular the OOM notifier is worse than the shrinker beca= use:
  1. It is last-resort, which means the system has alread= y gone through heroics to prevent OOM. Those heroic reclaim efforts are exp= ensive and impact application performance.
  2. It lacks understanding o= f NUMA or other OOM constraints.
  3. It has a higher potential for bugs= due to the subtlety=C2=A0of the callback context.
Give= n the above, I think the shrinker=C2=A0API certainly makes the most sense _= if_ the balloon size is static. In that case memory should be reclaimed fro= m the balloon early and proportionally to balloon size, which the shrinker = API achieves.

However, if the balloon is inflating= and intentionally causing memory pressure then this results in the ineffic= iency pointed out earlier.

If the balloon is infla= ting but not causing memory pressure then there is no problem with either A= PI.

This suggests another route: rather than cause= memory pressure to shrink the page cache, the balloon could issue the equi= valent=C2=A0of "echo 3 > /proc/sys/vm/drop_caches".
= Of course ideally, we want to be more fine grained than "drop everythi= ng". We really want an API that says "drop everything that hasn&#= 39;t been accessed in the last 5 minutes".

This would eliminate the need for the balloon to cause memory pressure a= t all which=C2=A0avoids the inefficiency in question. Furthermore, this pai= rs nicely with the FREE_PAGE_HINT feature.

=
On Mon= , Feb 3, 2020 at 9:04 AM Michael S. Tsirkin <mst@redhat.com> wrote:
On Mon, Feb 03, 2020 at 05:34:20PM +0100, David Hilden= brand wrote:
> On 03.02.20 17:18, Alexander Duyck wrote:
> > On Mon, 2020-02-03 at 08:11 -0500, Michael S. Tsirkin wrote:
> >> On Thu, Jan 30, 2020 at 11:59:46AM -0800, Tyler Sanderson wro= te:
> >>>
> >>> On Thu, Jan 30, 2020 at 7:31 AM Wang, Wei W <wei.w.wang@intel.com= > wrote:
> >>>
> >>>=C2=A0 =C2=A0 =C2=A0On Thursday, January 30, 2020 11:03 PM= , David Hildenbrand wrote:
> >>>=C2=A0 =C2=A0 =C2=A0> On 29.01.20 20:11, Tyler Sanderso= n wrote:
> >>>=C2=A0 =C2=A0 =C2=A0> >
> >>>=C2=A0 =C2=A0 =C2=A0> >
> >>>=C2=A0 =C2=A0 =C2=A0> > On Wed, Jan 29, 2020 at 2:31= AM David Hildenbrand <david@redhat.com
> >>>=C2=A0 =C2=A0 =C2=A0> > <mailto:david@redhat.com>> wrote: > >>>=C2=A0 =C2=A0 =C2=A0> >
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0On 29.01.= 20 01:22, Tyler Sanderson via Virtualization wrote:
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> A pr= imary advantage of virtio balloon over other memory reclaim
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> mech= anisms is that it can pressure the guest's page cache into
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0shrinking= .
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0>
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> Howe= ver, since the balloon driver changed to using the shrinker
> >>>=C2=A0 =C2=A0 =C2=A0API
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0>
> >>>=C2=A0 =C2=A0 =C2=A0> >
> >>>=C2=A0 =C2=A0 =C2=A0> <https://github.com/torvalds/linux/commit/71994620bb25a8b109388= fefa9
> >>>=C2=A0 =C2=A0 =C2=A0> e99a28e355255a#diff-fd202acf694d9= eba19c8c64da3e480c9> this
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> use = case has become a bit more tricky. I'm wondering what the
> >>>=C2=A0 =C2=A0 =C2=A0> intended
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> devi= ce implementation is.
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0>
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> When= inflating the balloon against page cache (i.e. no free
> >>>=C2=A0 =C2=A0 =C2=A0memory
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> rema= ins) vmscan.c will both shrink page cache, but also invoke
> >>>=C2=A0 =C2=A0 =C2=A0the
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> shri= nkers -- including the balloon's shrinker. So the balloon
> >>>=C2=A0 =C2=A0 =C2=A0driver
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> allo= cates memory which requires reclaim, vmscan gets this memory
> >>>=C2=A0 =C2=A0 =C2=A0> by
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> shri= nking the balloon, and then the driver adds the memory back
> >>>=C2=A0 =C2=A0 =C2=A0to
> >>>=C2=A0 =C2=A0 =C2=A0> the
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> ball= oon. Basically a busy no-op.
> >>>
> >>>=C2=A0 =C2=A0 =C2=A0Per my understanding, the balloon allo= cation won=E2=80=99t invoke shrinker as
> >>>=C2=A0 =C2=A0 =C2=A0__GFP_DIRECT_RECLAIM isn't set, no= ?
> >>>
> >>> I could be wrong about the mechanism, but the device sees= lots of activity on
> >>> the deflate queue. The balloon is being shrunk. And this = only starts once all
> >>> free memory is depleted and we're inflating into page= cache.
> >>
> >> So given this looks like a regression, maybe we should revert= the
> >> patch in question 71994620bb25 ("virtio_balloon: replace= oom notifier with shrinker")
> >> Besides, with VIRTIO_BALLOON_F_FREE_PAGE_HINT
> >> shrinker also ignores VIRTIO_BALLOON_F_MUST_TELL_HOST which i= sn't nice
> >> at all.
> >>
> >> So it looks like all this rework introduced more issues than = it
> >> addressed ...
> >>
> >> I also CC Alex Duyck for an opinion on this.
> >> Alex, what do you use to put pressure on page cache?
> >
> > I would say reverting probably makes sense. I'm not sure ther= e is much
> > value to having a shrinker running deflation when you are activel= y trying
> > to increase the balloon. It would make more sense to wait until y= ou are
> > actually about to start hitting oom.
>
> I think the shrinker makes sense for free page hinting feature
> (everything on free_page_list).
>
> So instead of only reverting, I think we should split it up and always=
> register the shrinker for VIRTIO_BALLOON_F_FREE_PAGE_HINT and the OOM<= br> > notifier (as before) for VIRTIO_BALLOON_F_MUST_TELL_HOST.

OK ... I guess that means we need to fix shrinker to take
VIRTIO_BALLOON_F_MUST_TELL_HOST into account correctly.
Hosts ignore it at the moment but it's a fragile thing
to do what it does and ignore used buffers.

> (Of course, adapting what is being done in the shrinker and in the OOM=
> notifier)
>
> --
> Thanks,
>
> David / dhildenb

--000000000000ba8db1059db1d188-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tyler Sanderson via Virtualization Subject: Re: Balloon pressuring page cache Date: Mon, 3 Feb 2020 12:32:05 -0800 Message-ID: References: <91270a68-ff48-88b0-219c-69801f0c252f@redhat.com> <75d4594f-0864-5172-a0f8-f97affedb366@redhat.com> <286AC319A985734F985F78AFA26841F73E3F8A02@shsmsx102.ccr.corp.intel.com> <20200203080520-mutt-send-email-mst@kernel.org> <5ac131de8e3b7fc1fafd05a61feb5f6889aeb917.camel@linux.intel.com> <20200203120225-mutt-send-email-mst@kernel.org> Reply-To: Tyler Sanderson Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3095139446014947072==" Return-path: In-Reply-To: <20200203120225-mutt-send-email-mst@kernel.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" To: "Michael S. Tsirkin" Cc: "virtualization@lists.linux-foundation.org" , "linux-mm@kvack.org" , David Rientjes , Alexander Duyck , Michal Hocko List-Id: virtualization@lists.linuxfoundation.org --===============3095139446014947072== Content-Type: multipart/alternative; boundary="000000000000ba8db1059db1d188" --000000000000ba8db1059db1d188 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable There were apparently good reasons for moving away from OOM notifier callback: https://lkml.org/lkml/2018/7/12/314 https://lkml.org/lkml/2018/8/2/322 In particular the OOM notifier is worse than the shrinker because: 1. It is last-resort, which means the system has already gone through heroics to prevent OOM. Those heroic reclaim efforts are expensive and impact application performance. 2. It lacks understanding of NUMA or other OOM constraints. 3. It has a higher potential for bugs due to the subtlety of the callback context. Given the above, I think the shrinker API certainly makes the most sense _if_ the balloon size is static. In that case memory should be reclaimed from the balloon early and proportionally to balloon size, which the shrinker API achieves. However, if the balloon is inflating and intentionally causing memory pressure then this results in the inefficiency pointed out earlier. If the balloon is inflating but not causing memory pressure then there is no problem with either API. This suggests another route: rather than cause memory pressure to shrink the page cache, the balloon could issue the equivalent of "echo 3 > /proc/sys/vm/drop_caches". Of course ideally, we want to be more fine grained than "drop everything". We really want an API that says "drop everything that hasn't been accessed in the last 5 minutes". This would eliminate the need for the balloon to cause memory pressure at all which avoids the inefficiency in question. Furthermore, this pairs nicely with the FREE_PAGE_HINT feature. On Mon, Feb 3, 2020 at 9:04 AM Michael S. Tsirkin wrote: > On Mon, Feb 03, 2020 at 05:34:20PM +0100, David Hildenbrand wrote: > > On 03.02.20 17:18, Alexander Duyck wrote: > > > On Mon, 2020-02-03 at 08:11 -0500, Michael S. Tsirkin wrote: > > >> On Thu, Jan 30, 2020 at 11:59:46AM -0800, Tyler Sanderson wrote: > > >>> > > >>> On Thu, Jan 30, 2020 at 7:31 AM Wang, Wei W > wrote: > > >>> > > >>> On Thursday, January 30, 2020 11:03 PM, David Hildenbrand wrote= : > > >>> > On 29.01.20 20:11, Tyler Sanderson wrote: > > >>> > > > > >>> > > > > >>> > > On Wed, Jan 29, 2020 at 2:31 AM David Hildenbrand < > david@redhat.com > > >>> > > > wrote: > > >>> > > > > >>> > > On 29.01.20 01:22, Tyler Sanderson via Virtualization > wrote: > > >>> > > > A primary advantage of virtio balloon over other > memory reclaim > > >>> > > > mechanisms is that it can pressure the guest's page > cache into > > >>> > > shrinking. > > >>> > > > > > >>> > > > However, since the balloon driver changed to using th= e > shrinker > > >>> API > > >>> > > > > > >>> > > > > >>> > < > https://github.com/torvalds/linux/commit/71994620bb25a8b109388fefa9 > > >>> > e99a28e355255a#diff-fd202acf694d9eba19c8c64da3e480c9> this > > >>> > > > use case has become a bit more tricky. I'm wondering > what the > > >>> > intended > > >>> > > > device implementation is. > > >>> > > > > > >>> > > > When inflating the balloon against page cache (i.e. n= o > free > > >>> memory > > >>> > > > remains) vmscan.c will both shrink page cache, but > also invoke > > >>> the > > >>> > > > shrinkers -- including the balloon's shrinker. So the > balloon > > >>> driver > > >>> > > > allocates memory which requires reclaim, vmscan gets > this memory > > >>> > by > > >>> > > > shrinking the balloon, and then the driver adds the > memory back > > >>> to > > >>> > the > > >>> > > > balloon. Basically a busy no-op. > > >>> > > >>> Per my understanding, the balloon allocation won=E2=80=99t invo= ke > shrinker as > > >>> __GFP_DIRECT_RECLAIM isn't set, no? > > >>> > > >>> I could be wrong about the mechanism, but the device sees lots of > activity on > > >>> the deflate queue. The balloon is being shrunk. And this only start= s > once all > > >>> free memory is depleted and we're inflating into page cache. > > >> > > >> So given this looks like a regression, maybe we should revert the > > >> patch in question 71994620bb25 ("virtio_balloon: replace oom notifie= r > with shrinker") > > >> Besides, with VIRTIO_BALLOON_F_FREE_PAGE_HINT > > >> shrinker also ignores VIRTIO_BALLOON_F_MUST_TELL_HOST which isn't ni= ce > > >> at all. > > >> > > >> So it looks like all this rework introduced more issues than it > > >> addressed ... > > >> > > >> I also CC Alex Duyck for an opinion on this. > > >> Alex, what do you use to put pressure on page cache? > > > > > > I would say reverting probably makes sense. I'm not sure there is muc= h > > > value to having a shrinker running deflation when you are actively > trying > > > to increase the balloon. It would make more sense to wait until you a= re > > > actually about to start hitting oom. > > > > I think the shrinker makes sense for free page hinting feature > > (everything on free_page_list). > > > > So instead of only reverting, I think we should split it up and always > > register the shrinker for VIRTIO_BALLOON_F_FREE_PAGE_HINT and the OOM > > notifier (as before) for VIRTIO_BALLOON_F_MUST_TELL_HOST. > > OK ... I guess that means we need to fix shrinker to take > VIRTIO_BALLOON_F_MUST_TELL_HOST into account correctly. > Hosts ignore it at the moment but it's a fragile thing > to do what it does and ignore used buffers. > > > (Of course, adapting what is being done in the shrinker and in the OOM > > notifier) > > > > -- > > Thanks, > > > > David / dhildenb > > --000000000000ba8db1059db1d188 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
There were apparently good reasons for moving away from OO= M notifier callback:
In particular the OOM notifier is worse than the shrinker beca= use:
  1. It is last-resort, which means the system has alread= y gone through heroics to prevent OOM. Those heroic reclaim efforts are exp= ensive and impact application performance.
  2. It lacks understanding o= f NUMA or other OOM constraints.
  3. It has a higher potential for bugs= due to the subtlety=C2=A0of the callback context.
Give= n the above, I think the shrinker=C2=A0API certainly makes the most sense _= if_ the balloon size is static. In that case memory should be reclaimed fro= m the balloon early and proportionally to balloon size, which the shrinker = API achieves.

However, if the balloon is inflating= and intentionally causing memory pressure then this results in the ineffic= iency pointed out earlier.

If the balloon is infla= ting but not causing memory pressure then there is no problem with either A= PI.

This suggests another route: rather than cause= memory pressure to shrink the page cache, the balloon could issue the equi= valent=C2=A0of "echo 3 > /proc/sys/vm/drop_caches".
= Of course ideally, we want to be more fine grained than "drop everythi= ng". We really want an API that says "drop everything that hasn&#= 39;t been accessed in the last 5 minutes".

This would eliminate the need for the balloon to cause memory pressure a= t all which=C2=A0avoids the inefficiency in question. Furthermore, this pai= rs nicely with the FREE_PAGE_HINT feature.

=
On Mon= , Feb 3, 2020 at 9:04 AM Michael S. Tsirkin <mst@redhat.com> wrote:
On Mon, Feb 03, 2020 at 05:34:20PM +0100, David Hilden= brand wrote:
> On 03.02.20 17:18, Alexander Duyck wrote:
> > On Mon, 2020-02-03 at 08:11 -0500, Michael S. Tsirkin wrote:
> >> On Thu, Jan 30, 2020 at 11:59:46AM -0800, Tyler Sanderson wro= te:
> >>>
> >>> On Thu, Jan 30, 2020 at 7:31 AM Wang, Wei W <wei.w.wang@intel.com= > wrote:
> >>>
> >>>=C2=A0 =C2=A0 =C2=A0On Thursday, January 30, 2020 11:03 PM= , David Hildenbrand wrote:
> >>>=C2=A0 =C2=A0 =C2=A0> On 29.01.20 20:11, Tyler Sanderso= n wrote:
> >>>=C2=A0 =C2=A0 =C2=A0> >
> >>>=C2=A0 =C2=A0 =C2=A0> >
> >>>=C2=A0 =C2=A0 =C2=A0> > On Wed, Jan 29, 2020 at 2:31= AM David Hildenbrand <david@redhat.com
> >>>=C2=A0 =C2=A0 =C2=A0> > <mailto:david@redhat.com>> wrote: > >>>=C2=A0 =C2=A0 =C2=A0> >
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0On 29.01.= 20 01:22, Tyler Sanderson via Virtualization wrote:
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> A pr= imary advantage of virtio balloon over other memory reclaim
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> mech= anisms is that it can pressure the guest's page cache into
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0shrinking= .
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0>
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> Howe= ver, since the balloon driver changed to using the shrinker
> >>>=C2=A0 =C2=A0 =C2=A0API
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0>
> >>>=C2=A0 =C2=A0 =C2=A0> >
> >>>=C2=A0 =C2=A0 =C2=A0> <https://github.com/torvalds/linux/commit/71994620bb25a8b109388= fefa9
> >>>=C2=A0 =C2=A0 =C2=A0> e99a28e355255a#diff-fd202acf694d9= eba19c8c64da3e480c9> this
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> use = case has become a bit more tricky. I'm wondering what the
> >>>=C2=A0 =C2=A0 =C2=A0> intended
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> devi= ce implementation is.
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0>
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> When= inflating the balloon against page cache (i.e. no free
> >>>=C2=A0 =C2=A0 =C2=A0memory
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> rema= ins) vmscan.c will both shrink page cache, but also invoke
> >>>=C2=A0 =C2=A0 =C2=A0the
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> shri= nkers -- including the balloon's shrinker. So the balloon
> >>>=C2=A0 =C2=A0 =C2=A0driver
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> allo= cates memory which requires reclaim, vmscan gets this memory
> >>>=C2=A0 =C2=A0 =C2=A0> by
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> shri= nking the balloon, and then the driver adds the memory back
> >>>=C2=A0 =C2=A0 =C2=A0to
> >>>=C2=A0 =C2=A0 =C2=A0> the
> >>>=C2=A0 =C2=A0 =C2=A0> >=C2=A0 =C2=A0 =C2=A0> ball= oon. Basically a busy no-op.
> >>>
> >>>=C2=A0 =C2=A0 =C2=A0Per my understanding, the balloon allo= cation won=E2=80=99t invoke shrinker as
> >>>=C2=A0 =C2=A0 =C2=A0__GFP_DIRECT_RECLAIM isn't set, no= ?
> >>>
> >>> I could be wrong about the mechanism, but the device sees= lots of activity on
> >>> the deflate queue. The balloon is being shrunk. And this = only starts once all
> >>> free memory is depleted and we're inflating into page= cache.
> >>
> >> So given this looks like a regression, maybe we should revert= the
> >> patch in question 71994620bb25 ("virtio_balloon: replace= oom notifier with shrinker")
> >> Besides, with VIRTIO_BALLOON_F_FREE_PAGE_HINT
> >> shrinker also ignores VIRTIO_BALLOON_F_MUST_TELL_HOST which i= sn't nice
> >> at all.
> >>
> >> So it looks like all this rework introduced more issues than = it
> >> addressed ...
> >>
> >> I also CC Alex Duyck for an opinion on this.
> >> Alex, what do you use to put pressure on page cache?
> >
> > I would say reverting probably makes sense. I'm not sure ther= e is much
> > value to having a shrinker running deflation when you are activel= y trying
> > to increase the balloon. It would make more sense to wait until y= ou are
> > actually about to start hitting oom.
>
> I think the shrinker makes sense for free page hinting feature
> (everything on free_page_list).
>
> So instead of only reverting, I think we should split it up and always=
> register the shrinker for VIRTIO_BALLOON_F_FREE_PAGE_HINT and the OOM<= br> > notifier (as before) for VIRTIO_BALLOON_F_MUST_TELL_HOST.

OK ... I guess that means we need to fix shrinker to take
VIRTIO_BALLOON_F_MUST_TELL_HOST into account correctly.
Hosts ignore it at the moment but it's a fragile thing
to do what it does and ignore used buffers.

> (Of course, adapting what is being done in the shrinker and in the OOM=
> notifier)
>
> --
> Thanks,
>
> David / dhildenb

--000000000000ba8db1059db1d188-- --===============3095139446014947072== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization --===============3095139446014947072==--