From patchwork Fri Jan 21 06:06:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsutomu Itoh X-Patchwork-Id: 494081 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 p0L67DQQ003896 for ; Fri, 21 Jan 2011 06:07:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752042Ab1AUGHG (ORCPT ); Fri, 21 Jan 2011 01:07:06 -0500 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:33870 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750862Ab1AUGHF (ORCPT ); Fri, 21 Jan 2011 01:07:05 -0500 Received: from m3.gw.fujitsu.co.jp (unknown [10.0.50.73]) by fgwmail6.fujitsu.co.jp (Postfix) with ESMTP id B25043EE0B5 for ; Fri, 21 Jan 2011 15:07:04 +0900 (JST) Received: from smail (m3 [127.0.0.1]) by outgoing.m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 96FE545DE5B for ; Fri, 21 Jan 2011 15:07:04 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (s3.gw.fujitsu.co.jp [10.0.50.93]) by m3.gw.fujitsu.co.jp (Postfix) with ESMTP id 70B6245DE5A for ; Fri, 21 Jan 2011 15:07:04 +0900 (JST) Received: from s3.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 6386F1DB803C for ; Fri, 21 Jan 2011 15:07:04 +0900 (JST) Received: from ml13.s.css.fujitsu.com (ml13.s.css.fujitsu.com [10.249.87.103]) by s3.gw.fujitsu.co.jp (Postfix) with ESMTP id 2E5171DB8038 for ; Fri, 21 Jan 2011 15:07:04 +0900 (JST) Received: from ml13.css.fujitsu.com (ml13 [127.0.0.1]) by ml13.s.css.fujitsu.com (Postfix) with ESMTP id 02787FD0007; Fri, 21 Jan 2011 15:07:04 +0900 (JST) Received: from [127.0.0.1] (unknown [10.124.101.86]) by ml13.s.css.fujitsu.com (Postfix) with ESMTP id 9AB3EFD0002; Fri, 21 Jan 2011 15:07:03 +0900 (JST) X-SecurityPolicyCheck-FJ: OK by FujitsuOutboundMailChecker v1.4.0 Received: from T-ITOH1[10.124.101.86] by T-ITOH1 (FujitsuOutboundMailChecker v1.4.0/9992[10.124.101.86]); Fri, 21 Jan 2011 15:06:49 +0900 (JST) Message-ID: <4D392265.1020003@jp.fujitsu.com> Date: Fri, 21 Jan 2011 15:06:29 +0900 From: Tsutomu Itoh User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 MIME-Version: 1.0 To: Josef Bacik CC: linux-btrfs@vger.kernel.org, chris.mason@oracle.com Subject: Re: [PATCH] btrfs: fix return value check of btrfs_start_transaction() References: <201101200619.AA00004@T-ITOH1.jp.fujitsu.com> <20110120160959.GB6609@dhcp231-156.rdu.redhat.com> <4D38C980.3020001@jp.fujitsu.com> In-Reply-To: <4D38C980.3020001@jp.fujitsu.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 21 Jan 2011 06:07:14 +0000 (UTC) diff -urNp linux-2.6.38-rc1/fs/btrfs/transaction.c linux-2.6.38-rc1.new/fs/btrfs/transaction.c --- linux-2.6.38-rc1/fs/btrfs/transaction.c 2011-01-19 08:14:02.000000000 +0900 +++ linux-2.6.38-rc1.new/fs/btrfs/transaction.c 2011-01-21 14:08:02.000000000 +0900 @@ -22,6 +22,7 @@ #include #include #include +#include #include "ctree.h" #include "disk-io.h" #include "transaction.h" @@ -175,6 +176,25 @@ static int may_wait_transaction(struct b return 0; } +#define MAX_ITERATIONS 10 + +static struct btrfs_trans_handle *alloc_trans_handle(void) +{ + struct btrfs_trans_handle *ret; + int i = 0; + + ret = kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS); + if (!ret) { + pr_notice_ratelimited("ENOMEM in %s, retrying.\n", __func__); + do { + yield(); + ret = kmem_cache_alloc(btrfs_trans_handle_cachep, + GFP_NOFS); + } while (!ret && i++ < MAX_ITERATIONS); + } + return ret; +} + static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, u64 num_items, int type) { @@ -185,7 +205,7 @@ static struct btrfs_trans_handle *start_ if (root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) return ERR_PTR(-EROFS); again: - h = kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS); + h = alloc_trans_handle(); if (!h) return ERR_PTR(-ENOMEM);