From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753299AbdJTMJF (ORCPT ); Fri, 20 Oct 2017 08:09:05 -0400 Received: from mga05.intel.com ([192.55.52.43]:59904 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753108AbdJTMIY (ORCPT ); Fri, 20 Oct 2017 08:08:24 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,405,1503385200"; d="scan'208";a="911896772" From: Wei Wang To: mst@redhat.com, penguin-kernel@I-love.SAKURA.ne.jp, mhocko@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, virtualization@lists.linux-foundation.org Cc: Wei Wang Subject: [PATCH v1 2/3] virtio-balloon: deflate up to oom_pages on OOM Date: Fri, 20 Oct 2017 19:54:25 +0800 Message-Id: <1508500466-21165-3-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508500466-21165-1-git-send-email-wei.w.wang@intel.com> References: <1508500466-21165-1-git-send-email-wei.w.wang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current implementation only deflates 256 pages even when a user specifies more than that via the oom_pages module param. This patch enables the deflating of up to oom_pages pages if there are enough inflated pages. Signed-off-by: Wei Wang Cc: Michael S. Tsirkin Cc: Michal Hocko Cc: Tetsuo Handa --- drivers/virtio/virtio_balloon.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 1ecd15a..ab55cf8 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -43,8 +43,8 @@ #define OOM_VBALLOON_DEFAULT_PAGES 256 #define VIRTBALLOON_OOM_NOTIFY_PRIORITY 80 -static int oom_pages = OOM_VBALLOON_DEFAULT_PAGES; -module_param(oom_pages, int, S_IRUSR | S_IWUSR); +static unsigned int oom_pages = OOM_VBALLOON_DEFAULT_PAGES; +module_param(oom_pages, uint, 0600); MODULE_PARM_DESC(oom_pages, "pages to free on OOM"); #ifdef CONFIG_BALLOON_COMPACTION @@ -359,16 +359,20 @@ static int virtballoon_oom_notify(struct notifier_block *self, { struct virtio_balloon *vb; unsigned long *freed; - unsigned num_freed_pages; + unsigned int npages = oom_pages; vb = container_of(self, struct virtio_balloon, nb); if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) return NOTIFY_OK; freed = parm; - num_freed_pages = leak_balloon(vb, oom_pages); + + /* Don't deflate more than the number of inflated pages */ + while (npages && atomic64_read(&vb->num_pages)) + npages -= leak_balloon(vb, npages); + update_balloon_size(vb); - *freed += num_freed_pages; + *freed += oom_pages - npages; return NOTIFY_OK; } -- 2.7.4