From patchwork Wed Jan 23 20:46:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Francoise X-Patchwork-Id: 215037 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 22DFA2C0079 for ; Thu, 24 Jan 2013 07:47:10 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751885Ab3AWUqv (ORCPT ); Wed, 23 Jan 2013 15:46:51 -0500 Received: from stringer.orebokech.com ([88.190.240.207]:43321 "EHLO stringer.orebokech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750813Ab3AWUqt (ORCPT ); Wed, 23 Jan 2013 15:46:49 -0500 Received: from silenus.orebokech.com (silenus [192.168.1.4]) by stringer.orebokech.com (Postfix) with ESMTP id 3A279188002A; Wed, 23 Jan 2013 21:46:48 +0100 (CET) Received: by silenus.orebokech.com (Postfix, from userid 1000) id C21DCA0418; Wed, 23 Jan 2013 21:46:47 +0100 (CET) From: Romain Francoise To: "Michael S. Tsirkin" Cc: kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] vhost-net: fall back to vmalloc if high-order allocation fails Organization: orebokech dot com Date: Wed, 23 Jan 2013 21:46:47 +0100 Message-ID: <87k3r31vbc.fsf@silenus.orebokech.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Creating a vhost-net device allocates an object large enough (34320 bytes on x86-64) to trigger an order-4 allocation, which may fail if memory if fragmented: libvirtd: page allocation failure: order:4, mode:0x2000d0 ... SLAB: Unable to allocate memory on node 0 (gfp=0xd0) cache: size-65536, object size: 65536, order: 4 node 0: slabs: 8/8, objs: 8/8, free: 0 In that situation, rather than forcing the caller to use regular virtio-net, try to allocate the descriptor with vmalloc(). Signed-off-by: Romain Francoise --- drivers/vhost/net.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index ebd08b2..1ded79b 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -603,12 +604,23 @@ static void handle_rx_net(struct vhost_work *work) handle_rx(net); } +static void vhost_net_kvfree(void *addr) +{ + if (is_vmalloc_addr(addr)) + vfree(addr); + else + kfree(addr); +} + static int vhost_net_open(struct inode *inode, struct file *f) { - struct vhost_net *n = kmalloc(sizeof *n, GFP_KERNEL); + struct vhost_net *n; struct vhost_dev *dev; int r; + n = kmalloc(sizeof *n, GFP_KERNEL | __GFP_NOWARN); + if (!n) + n = vmalloc(sizeof *n); if (!n) return -ENOMEM; @@ -617,7 +629,7 @@ static int vhost_net_open(struct inode *inode, struct file *f) n->vqs[VHOST_NET_VQ_RX].handle_kick = handle_rx_kick; r = vhost_dev_init(dev, n->vqs, VHOST_NET_VQ_MAX); if (r < 0) { - kfree(n); + vhost_net_kvfree(n); return r; } @@ -719,7 +731,7 @@ static int vhost_net_release(struct inode *inode, struct file *f) /* We do an extra flush before freeing memory, * since jobs can re-queue themselves. */ vhost_net_flush(n); - kfree(n); + vhost_net_kvfree(n); return 0; }