From patchwork Tue Sep 28 13:19:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Young X-Patchwork-Id: 214882 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8SDK23k008318 for ; Tue, 28 Sep 2010 13:20:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754117Ab0I1NUA (ORCPT ); Tue, 28 Sep 2010 09:20:00 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:51799 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753862Ab0I1NT7 (ORCPT ); Tue, 28 Sep 2010 09:19:59 -0400 Received: by pvg2 with SMTP id 2so1546074pvg.19 for ; Tue, 28 Sep 2010 06:19:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=Ki8IIbkQ6tIDWx2IDNZp3oRPHS96R+4IHtcMI42ujAg=; b=Ls6b/oMRmTewgvxYromT3DZYHuAXPnur22A3qpuvXuzcnB/ip6oGbqbYt1QwAIGY8G 5nO1LQ4aduP4PC6hNFWxM2MmSzMluTvRnehzn1u3l01M5sgQFpGWf83htEL+nY2CSXub Y3tMiL/eN5GGqnu7YfA7fksW4nn5uNVX0vE5M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=Hms3ea6zzMKxcGwzrM9NnnUDcKFHJdwgyqCQ/5VRWUbH2OoxsancAgd7gC3lTP2stO Tc9b0RJUCjGWVv24d8ZOCyhM7PeSZryG19MgeYj51RJ+TiF0z2WAgo/XjusztQfl+HmS QZzd9yJDOkURdTpmWTCHwWUHETHGjx8xKoZnc= Received: by 10.142.191.10 with SMTP id o10mr1374370wff.16.1285679998991; Tue, 28 Sep 2010 06:19:58 -0700 (PDT) Received: from darkstar ([221.220.54.54]) by mx.google.com with ESMTPS id c14sm8822889wfe.14.2010.09.28.06.19.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 28 Sep 2010 06:19:57 -0700 (PDT) Date: Tue, 28 Sep 2010 21:19:55 +0800 From: Dave Young To: kvm@vger.kernel.org, Avi Kivity , Rusty Russell Subject: [RFC] virtio_balloon: disable oom killer when fill balloon Message-ID: <20100928131954.GA2939@darkstar> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 28 Sep 2010 13:20:03 +0000 (UTC) --- linux-2.6.orig/drivers/virtio/virtio_balloon.c 2010-09-25 20:58:14.190000001 +0800 +++ linux-2.6/drivers/virtio/virtio_balloon.c 2010-09-28 21:05:42.203333675 +0800 @@ -25,6 +25,7 @@ #include #include #include +#include struct virtio_balloon { @@ -97,8 +98,22 @@ static void tell_host(struct virtio_ball wait_for_completion(&vb->acked); } -static void fill_balloon(struct virtio_balloon *vb, size_t num) +static int cblimit(int times) { + static int t; + + if (t < times) + t++; + else + t = 0; + + return !t; +} + +static int fill_balloon(struct virtio_balloon *vb, size_t num) +{ + int ret = 0; + /* We can only do one array worth at a time. */ num = min(num, ARRAY_SIZE(vb->pfns)); @@ -106,10 +121,13 @@ static void fill_balloon(struct virtio_b struct page *page = alloc_page(GFP_HIGHUSER | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN); if (!page) { - if (printk_ratelimit()) + if (cblimit(5)) { dev_printk(KERN_INFO, &vb->vdev->dev, "Out of puff! Can't get %zu pages\n", num); + ret = -ENOMEM; + goto out; + } /* Sleep for at least 1/5 of a second before retry. */ msleep(200); break; @@ -120,11 +138,11 @@ static void fill_balloon(struct virtio_b list_add(&page->lru, &vb->pages); } - /* Didn't get any? Oh well. */ - if (vb->num_pfns == 0) - return; +out: + if (vb->num_pfns) + tell_host(vb, vb->inflate_vq); - tell_host(vb, vb->inflate_vq); + return ret; } static void release_pages_by_pfn(const u32 pfns[], unsigned int num) @@ -251,6 +269,14 @@ static void update_balloon_size(struct v &actual, sizeof(actual)); } +static void update_balloon_target(struct virtio_balloon *vb) +{ + __le32 num_pages = cpu_to_le32(vb->num_pages); + vb->vdev->config->set(vb->vdev, + offsetof(struct virtio_balloon_config, num_pages), + &num_pages, sizeof(num_pages)); +} + static int balloon(void *_vballoon) { struct virtio_balloon *vb = _vballoon; @@ -267,9 +293,14 @@ static int balloon(void *_vballoon) || freezing(current)); if (vb->need_stats_update) stats_handle_request(vb); - if (diff > 0) - fill_balloon(vb, diff); - else if (diff < 0) + if (diff > 0) { + int oom; + oom_killer_disable(); + oom = fill_balloon(vb, diff); + oom_killer_enable(); + if (oom) + update_balloon_target(vb); + } else if (diff < 0) leak_balloon(vb, -diff); update_balloon_size(vb); }