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=-3.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 4AC42C10F27 for ; Wed, 11 Mar 2020 11:12:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DECA321D56 for ; Wed, 11 Mar 2020 11:12:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eqUavx3D" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DECA321D56 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6186C6B0003; Wed, 11 Mar 2020 07:12:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A1AB6B0008; Wed, 11 Mar 2020 07:12:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46A6A6B000A; Wed, 11 Mar 2020 07:12:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id 2B61A6B0003 for ; Wed, 11 Mar 2020 07:12:58 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id D841C5821 for ; Wed, 11 Mar 2020 11:12:57 +0000 (UTC) X-FDA: 76582819194.02.test55_19d3793b80751 X-HE-Tag: test55_19d3793b80751 X-Filterd-Recvd-Size: 9099 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Mar 2020 11:12:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583925176; 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=Elqo1PIfdnB6nWEqMDCrT0axVRMlDVlbvZXH0BJIDBc=; b=eqUavx3DdKBI1bDOi6OpnKXIgkaophj4U1ipnbv7OjdiHRrJ4EdboWCJfSolLozfzmREUj aj8nHdThVRQBcEjOaZKoDYwmFBdFAbNpMNHu4IdsVCFfZEGdCPqTf+jw+QCKcqETvI6CZj UU/yptZ4f7j/+AbDsNCl9z7flMQVwRg= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-352-v0jEc-m0OsifcXFAX9NIog-1; Wed, 11 Mar 2020 07:12:46 -0400 X-MC-Unique: v0jEc-m0OsifcXFAX9NIog-1 Received: by mail-qt1-f200.google.com with SMTP id e21so942596qts.14 for ; Wed, 11 Mar 2020 04:12:46 -0700 (PDT) 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=J27SQcQ8+CHD3vks6FCpV5FX2N8wFEgpobTli186cvI=; b=iogJFNXKVXuut1JWUJ1dT+4mnFm6W/9zy/VQhRAmAoGe0cfy8Zq7xESTr/CZtJbC0z PbUWpnlJvhcMOCSlCeempCt9TAf2swIZWlH5YOxPqwxvnR8COmkHDLusNJDPE8g7I85E x0Sq/ex51gGqlVCZzAQCIdXfV3EWCJaHYXO326SwXyrXGd67N2CSNGqXK5BKMwgGzqsC bQ0TsI2gtEyK3teWlh4wAjN/8+mQ/83xnd5KiZ++wvX7iRp0LFbf0ODkqE6NAlGG+DBJ lhwO25BtX6CD+0lhc1n/rTrO4Ngf1fzF0TRvElTYZN8rKjprmXPAb2VPUbFMGzYpYvhh vHHQ== X-Gm-Message-State: ANhLgQ3/acdHSXGC4chE/BUfZDwsUZiJm3erDh8+74iySfcszAVc9vtD sZm4lm6yAB9XtaP1/NcobawGqJmVlplMZ0OMKiaTh6y7Avm0vu4UOrl1+y9xAEXszoatbmoaEJ6 U8QMcMDlfKNk= X-Received: by 2002:a37:bc1:: with SMTP id 184mr2146575qkl.57.1583925165493; Wed, 11 Mar 2020 04:12:45 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuFYc5tFK7zblYvbrcTfg23/Z2VBpJF5tj1r6y1PoPqomX102twr6p25lkiLGbRFJbUQ7JMrQ== X-Received: by 2002:a37:bc1:: with SMTP id 184mr2146542qkl.57.1583925165130; Wed, 11 Mar 2020 04:12:45 -0700 (PDT) Received: from redhat.com (bzq-79-178-2-19.red.bezeqint.net. [79.178.2.19]) by smtp.gmail.com with ESMTPSA id o7sm7446399qtg.63.2020.03.11.04.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 04:12:43 -0700 (PDT) Date: Wed, 11 Mar 2020 07:12:36 -0400 From: "Michael S. Tsirkin" To: David Hildenbrand Cc: David Rientjes , linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux-foundation.org, Jason Wang , Stephen Rothwell , Tyler Sanderson , Wei Wang , Alexander Duyck , Nadav Amit , Michal Hocko , Andrew Morton Subject: Re: [PATCH v3] virtio-balloon: Switch back to OOM handler for VIRTIO_BALLOON_F_DEFLATE_ON_OOM Message-ID: <20200311070952-mutt-send-email-mst@kernel.org> References: <20200310113854.11515-1-david@redhat.com> <890da35b-1ac2-9c2e-b42d-96d24d3e0f4c@redhat.com> MIME-Version: 1.0 In-Reply-To: <890da35b-1ac2-9c2e-b42d-96d24d3e0f4c@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 Tue, Mar 10, 2020 at 08:13:19PM +0100, David Hildenbrand wrote: > On 10.03.20 20:05, David Rientjes wrote: > > On Tue, 10 Mar 2020, David Hildenbrand wrote: > >=20 > >> Commit 71994620bb25 ("virtio_balloon: replace oom notifier with shrink= er") > >> changed the behavior when deflation happens automatically. Instead of > >> deflating when called by the OOM handler, the shrinker is used. > >> > >> However, the balloon is not simply some other slab cache that should b= e > >> shrunk when under memory pressure. The shrinker does not have a concep= t of > >> priorities yet, so this behavior cannot be configured. Eventually once > >> that is in place, we might want to switch back after doing proper > >> testing. > >> > >> There was a report that this results in undesired side effects when > >> inflating the balloon to shrink the page cache. [1] > >> =09"When inflating the balloon against page cache (i.e. no free memory > >> =09 remains) vmscan.c will both shrink page cache, but also invoke the > >> =09 shrinkers -- including the balloon's shrinker. So the balloon > >> =09 driver allocates memory which requires reclaim, vmscan gets this > >> =09 memory by shrinking the balloon, and then the driver adds the > >> =09 memory back to the balloon. Basically a busy no-op." > >> > >> The name "deflate on OOM" makes it pretty clear when deflation should > >> happen - after other approaches to reclaim memory failed, not while > >> reclaiming. This allows to minimize the footprint of a guest - memory > >> will only be taken out of the balloon when really needed. > >> > >> Keep using the shrinker for VIRTIO_BALLOON_F_FREE_PAGE_HINT, because > >> this has no such side effects. Always register the shrinker with > >> VIRTIO_BALLOON_F_FREE_PAGE_HINT now. We are always allowed to reuse fr= ee > >> pages that are still to be processed by the guest. The hypervisor take= s > >> care of identifying and resolving possible races between processing a > >> hinting request and the guest reusing a page. > >> > >> In contrast to pre commit 71994620bb25 ("virtio_balloon: replace oom > >> notifier with shrinker"), don't add a moodule parameter to configure t= he > >> number of pages to deflate on OOM. Can be re-added if really needed. > >> Also, pay attention that leak_balloon() returns the number of 4k pages= - > >> convert it properly in virtio_balloon_oom_notify(). > >> > >> Testing done by Tyler for future reference: > >> Test setup: VM with 16 CPU, 64GB RAM. Running Debian 10. We have a 4= 2 > >> GB file full of random bytes that we continually cat to /dev/null. > >> This fills the page cache as the file is read. Meanwhile we trigger > >> the balloon to inflate, with a target size of 53 GB. This setup caus= es > >> the balloon inflation to pressure the page cache as the page cache i= s > >> also trying to grow. Afterwards we shrink the balloon back to zero (= so > >> total deflate =3D total inflate). > >> > >> Without patch (kernel 4.19.0-5): > >> Inflation never reaches the target until we stop the "cat file > > >> /dev/null" process. Total inflation time was 542 seconds. The longes= t > >> period that made no net forward progress was 315 seconds (see attach= ed > >> graph). > >> Result of "grep balloon /proc/vmstat" after the test: > >> balloon_inflate 154828377 > >> balloon_deflate 154828377 > >> > >> With patch (kernel 5.6.0-rc4+): > >> Total inflation duration was 63 seconds. No deflate-queue activity > >> occurs when pressuring the page-cache. > >> Result of "grep balloon /proc/vmstat" after the test: > >> balloon_inflate 12968539 > >> balloon_deflate 12968539 > >> > >> Conclusion: This patch fixes the issue. In the test it reduced > >> inflate/deflate activity by 12x, and reduced inflation time by 8.6x. > >> But more importantly, if we hadn't killed the "grep balloon > >> /proc/vmstat" process then, without the patch, the inflation process > >> would never reach the target. > >> > >> [1] https://www.spinics.net/lists/linux-virtualization/msg40863.html > >> > >> Reported-by: Tyler Sanderson > >> Tested-by: Tyler Sanderson > >> Fixes: 71994620bb25 ("virtio_balloon: replace oom notifier with shrink= er") > >> Cc: Michael S. Tsirkin > >> Cc: Wei Wang > >> Cc: Alexander Duyck > >> Cc: David Rientjes > >> Cc: Nadav Amit > >> Cc: Michal Hocko > >> Cc: Andrew Morton > >> Signed-off-by: David Hildenbrand > >=20 > > Acked-by: David Rientjes > >=20 >=20 > Thanks! David could you repost with corrected commit log so Andrew can merge? To make sure it's not missed, it's probably a good idea to have a cover letter mentioning mm in the subject. > > Should this have: > >=20 > > Cc: stable@vger.kernel.org # 4.19+ >=20 > I guess as nothing will actually "crash" it's not worth stable. >=20 > --=20 > Thanks, >=20 > David / dhildenb