Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1305916ybv; Thu, 6 Feb 2020 01:35:49 -0800 (PST) X-Google-Smtp-Source: APXvYqzCNj0JZecDuLvXwO8/BEKrPD7UuGTlcQGkypanJKgUksZ2+xlGC/tNZgRYZL0GtV4hJ84i X-Received: by 2002:a05:6830:1184:: with SMTP id u4mr28564368otq.221.1580981749383; Thu, 06 Feb 2020 01:35:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580981749; cv=none; d=google.com; s=arc-20160816; b=ghL36cWWJ5EPrCLZ6KZ5aOG+cJmOjUviovaJrD7psCBFMtRJEpMw+CaiPq3fv0vyKN IS2SxL9RR0YVEdJmnXgZM15r4aCczKhA1wD2iEweQw3ucvlnr1C/CpPJuS8t9QD/zMUP Mbv8MEuJRIUe96LmYNzBp+jNwQfFYJiM82beVBQlriawL2cnXvUCix590LDjNVXXu7hk 5ua0VsV57qWiwSf69AZnObCioXKwMyAIyUplA+Sj7LziO6nS89mn2TK0RGAMllChpVHj 0aWlxhsonQRo1xAuSJSSgWye4Xnv7j3gq2rHyY8bOU0jGLupm4Y8fv1+lLdXpXF3ajWf 6mQg== 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 :dkim-signature; bh=u+qkwfnp/KTTLaMdjyM+vV6SHYAbouc0gSH5Oc/Hljw=; b=t1i2SBL1V7SK0SIOsSoU8r3ML4aiLawB7h5QkFhdZDGNZPPtsSd5HP1PjBcxuaqcRY HOSCBHt8y7p9fEy7G8qpskNqgGVL7rSKENezzllaHztPR7e2+EB8hQREApGV1j+1zthc 0BxFHNl6TAHkExIb1DXsOxM10YRwHZ+cDsN5akwnY90X6CdMiYuKTTiS6vDIuQG7Ggpk BJAYuiKXVLIKUtqOd5YecLYiE7UDMDl18KOaKarHkhlKt71U/03/n4pE0mTbuLd0geRb JoKaXSwkLj6oJn1KhnvTuoSziRf8Nkk7n6Dvh7y4oi+efl9TG/N0p8zbZ4VfoRlrFJ42 s0GA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eNFIuJzL; 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=pass (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 i13si1522947oth.175.2020.02.06.01.35.36; Thu, 06 Feb 2020 01:35:49 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=eNFIuJzL; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbgBFJEf (ORCPT + 99 others); Thu, 6 Feb 2020 04:04:35 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53024 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726452AbgBFJEf (ORCPT ); Thu, 6 Feb 2020 04:04:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580979874; 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=u+qkwfnp/KTTLaMdjyM+vV6SHYAbouc0gSH5Oc/Hljw=; b=eNFIuJzLK3A/lIQzdVnuPeoFAEUZ00JXEJi6Ak08x0HqYjNm86fFLWJw+g4I3s+wK90B8u 9uCyRYmUDht4R75CclbdoTcjoeZ5lJNF0t0b5DG4n15zHpK0mcDfFy1aMkNA95ii75gHJs 1uIEkDN3hjtVId/Ae4d/uBqZwwabCBY= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-vYf2zWDRPGSea9LTtOnbiA-1; Thu, 06 Feb 2020 04:04:27 -0500 X-MC-Unique: vYf2zWDRPGSea9LTtOnbiA-1 Received: by mail-qv1-f69.google.com with SMTP id k2so3244738qvu.22 for ; Thu, 06 Feb 2020 01:04:27 -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=u+qkwfnp/KTTLaMdjyM+vV6SHYAbouc0gSH5Oc/Hljw=; b=eMFQF1wXD/+orKmB0tZX//vbhhPhxxac+6CXowIJ3xvMi+BVRBeP6tJ5AIbPYh5PxE /fjRA+tEIFJ/gTIMG4bOs6ZGzNvshozgjqMyqa+CAwuQhY9Ou08pO9gmge4DJ/+sEvXg 0mdmZ4fwQb0Ze1yqzuAVBTe0w/DORttD4942q1ISUKPgXd1bd1WW9kILM0CLBhfTHcdB x6rK8/i1kxxgbBdKkkCLYQU9rJTW5lcGj3kZf+p2D3LlKtQvOQiPJN/qsZn0dDeF0bNj dwZvdJVRA6CO8CMzZco789ckry2PV1MoHHg1uj5U8qGowj9guuKAw4s4OFMZTLdoRvzF fpmw== X-Gm-Message-State: APjAAAVDIuOxRGmjpoUWUA8DMsJWphOqGWXGCiARjBXpvYNYihjgbqC0 lOkewY0PVfkj1KaoK3nZMX2nYyww5htpDUO96uwzQSS+hFcLpQtnBn8jsB0YMd9/iOxqozYB8/7 o82fMnQfuQ9JQJ7kvRBpPBWfG X-Received: by 2002:a05:6214:1267:: with SMTP id r7mr1480791qvv.160.1580979867105; Thu, 06 Feb 2020 01:04:27 -0800 (PST) X-Received: by 2002:a05:6214:1267:: with SMTP id r7mr1480773qvv.160.1580979866830; Thu, 06 Feb 2020 01:04:26 -0800 (PST) Received: from redhat.com (bzq-79-176-41-183.red.bezeqint.net. [79.176.41.183]) by smtp.gmail.com with ESMTPSA id 205sm1121279qkd.61.2020.02.06.01.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Feb 2020 01:04:25 -0800 (PST) Date: Thu, 6 Feb 2020 04:04:21 -0500 From: "Michael S. Tsirkin" To: Wei Wang Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, tysand@google.com, david@redhat.com, alexander.h.duyck@linux.intel.com, rientjes@google.com, mhocko@kernel.org, namit@vmware.com, penguin-kernel@i-love.sakura.ne.jp Subject: Re: [PATCH RFC] virtio_balloon: conservative balloon page shrinking Message-ID: <20200206035749-mutt-send-email-mst@kernel.org> References: <1580976107-16013-1-git-send-email-wei.w.wang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1580976107-16013-1-git-send-email-wei.w.wang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 06, 2020 at 04:01:47PM +0800, Wei Wang wrote: > There are cases that users want to shrink balloon pages after the > pagecache depleted. The conservative_shrinker lets the shrinker > shrink balloon pages when all the pagecache has been reclaimed. > > Signed-off-by: Wei Wang I'd rather avoid module parameters, but otherwise looks like a reasonable idea. Tyler, what do you think? > --- > drivers/virtio/virtio_balloon.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c > index 93f995f6cf36..b4c5bb13a867 100644 > --- a/drivers/virtio/virtio_balloon.c > +++ b/drivers/virtio/virtio_balloon.c > @@ -42,6 +42,10 @@ > static struct vfsmount *balloon_mnt; > #endif > > +static bool conservative_shrinker = true; > +module_param(conservative_shrinker, bool, 0644); > +MODULE_PARM_DESC(conservative_shrinker, "conservatively shrink balloon pages"); > + > enum virtio_balloon_vq { > VIRTIO_BALLOON_VQ_INFLATE, > VIRTIO_BALLOON_VQ_DEFLATE, > @@ -796,6 +800,10 @@ static unsigned long shrink_balloon_pages(struct virtio_balloon *vb, > { > unsigned long pages_freed = 0; > > + /* Balloon pages only gets shrunk when the pagecache depleted */ > + if (conservative_shrinker && global_node_page_state(NR_FILE_PAGES)) > + return 0; > + > /* > * One invocation of leak_balloon can deflate at most > * VIRTIO_BALLOON_ARRAY_PFNS_MAX balloon pages, so we call it > @@ -837,7 +845,11 @@ static unsigned long virtio_balloon_shrinker_count(struct shrinker *shrinker, > struct virtio_balloon, shrinker); > unsigned long count; > > - count = vb->num_pages / VIRTIO_BALLOON_PAGES_PER_PAGE; > + if (conservative_shrinker && global_node_page_state(NR_FILE_PAGES)) I'd rather have an API for that in mm/. In particular, do we want other shrinkers to run, not just pagecache? To pick an example I'm familiar with, kvm mmu cache for nested virt? > + count = 0; > + else > + count = vb->num_pages / VIRTIO_BALLOON_PAGES_PER_PAGE; > + > count += vb->num_free_page_blocks * VIRTIO_BALLOON_HINT_BLOCK_PAGES; > > return count; > -- > 2.17.1