Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1298548ybv; Thu, 6 Feb 2020 01:26:37 -0800 (PST) X-Google-Smtp-Source: APXvYqxYBPQFdsQ1SWbNxcIiVdn1LSroJdzBHmKZEOvNFs4I0EFRcQDBRNgaHiefxy8SSJUW8Vy8 X-Received: by 2002:aca:d610:: with SMTP id n16mr6329916oig.108.1580981197168; Thu, 06 Feb 2020 01:26:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580981197; cv=none; d=google.com; s=arc-20160816; b=rmnsgL1Wg8SugEs2f3MzJX5yClxqdN7uGUMB71MmHdqPQ32FGQBPvrvGU6UbkAxplZ 9r2480ZjEcV00+BMSQ0fu72UIAl22WeV8MuakmwvriRHJlh7mb2eobIKv/UMgMjOCsca gdAxXy+/e/DH/c+KoTv3MXj/zeAKrtUe9rfTpd8/kDLu/KrQDCf+W5qZg7uJwT0PootU qqjDDxX6g6IwJSjkiX5b5+YRphtY+S4jPmMHnQ+joQFdkwRwTyxbzX+fSh0WLZPhu8km O0OMpQzR8hfdDjmbAFc94GPyl0uYyKELPSI99Kb+z1Cu/g5IWL8fOuhfSd+dMNgTZOnf MMQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=qGR9BoJMqlYQkkgwL0KQqNkpB+nmaSbXryXZ/AIPY1U=; b=xUUeuQMl9smzhotg1vTKMe+/AKjwJTlYQY8IBAo6lw+CosEejLHpnY7Ef9GAucb9gm inzg0IW0YN2rF/V3iXIGC2/C5Tx+l8pe/SEXPKJBAsxW7BMJhKGzllW/7CoWr+c3buQW 6Ye/jj5EV3tUlv6TptoV7lZSr90feKcxmfB0/cNdan9zETL0aRiRPuk0myvZuF1PDNhi VE4/gxKjQEP9MLU9kcZ8yryn35gZWrbtSJSMRIL1Otcqp8D6N2NX1RJfGArQLSlPDRXh 5hT+o9sF77v3PFa1FMFLkaMRgWU8fdVxCWnqNG4VhF9BoZlusWq4Fs0HhbjDhnft+dlq ovbA== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t28si1610697otr.16.2020.02.06.01.26.24; Thu, 06 Feb 2020 01:26:37 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728115AbgBFIwN (ORCPT + 99 others); Thu, 6 Feb 2020 03:52:13 -0500 Received: from mga03.intel.com ([134.134.136.65]:9873 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727778AbgBFIwM (ORCPT ); Thu, 6 Feb 2020 03:52:12 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2020 00:52:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,409,1574150400"; d="scan'208";a="264531173" Received: from devel-ww.sh.intel.com ([10.239.48.128]) by fmsmga002.fm.intel.com with ESMTP; 06 Feb 2020 00:52:10 -0800 From: Wei Wang To: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: tysand@google.com, mst@redhat.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, wei.w.wang@intel.com Subject: [PATCH RFC] virtio_balloon: conservative balloon page shrinking Date: Thu, 6 Feb 2020 16:01:47 +0800 Message-Id: <1580976107-16013-1-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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)) + 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