From patchwork Sat May 1 14:14:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oren Laadan X-Patchwork-Id: 51434 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 3C411B81CC for ; Sun, 2 May 2010 00:27:41 +1000 (EST) Received: by ozlabs.org (Postfix) id C88E4100D73; Sun, 2 May 2010 00:26:34 +1000 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: from tarap.cc.columbia.edu (tarap.cc.columbia.edu [128.59.29.7]) by ozlabs.org (Postfix) with ESMTP id 403E4100D5D for ; Sun, 2 May 2010 00:26:33 +1000 (EST) Received: from localhost.localdomain (cpe-66-108-42-212.nyc.res.rr.com [66.108.42.212]) (user=ol2104 mech=PLAIN bits=0) by tarap.cc.columbia.edu (8.14.3/8.14.3) with ESMTP id o41EGS8j028326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 1 May 2010 10:16:40 -0400 (EDT) From: Oren Laadan To: Andrew Morton Subject: [PATCH v21 001/100] eclone (1/11): Factor out code to allocate pidmap page Date: Sat, 1 May 2010 10:14:43 -0400 Message-Id: <1272723382-19470-2-git-send-email-orenl@cs.columbia.edu> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1272723382-19470-1-git-send-email-orenl@cs.columbia.edu> References: <1272723382-19470-1-git-send-email-orenl@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.68 on 128.59.29.7 Cc: linux-s390@vger.kernel.org, linux-api@vger.kernel.org, containers@lists.linux-foundation.org, x86@kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org, Matt Helsley , Serge Hallyn , Sukadev Bhattiprolu , Pavel Emelyanov X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org From: Sukadev Bhattiprolu To simplify alloc_pidmap(), move code to allocate a pid map page to a separate function. Changelog[v4]: - [Oren Laadan] Adapt to kernel 2.6.33-rc5 Changelog[v3]: - Earlier version of patchset called alloc_pidmap_page() from two places. But now its called from only one place. Even so, moving this code out into a separate function simplifies alloc_pidmap(). Changelog[v2]: - (Matt Helsley, Dave Hansen) Have alloc_pidmap_page() return -ENOMEM on error instead of -1. Cc: linux-api@vger.kernel.org Cc: x86@kernel.org Cc: linux-s390@vger.kernel.org Cc: linuxppc-dev@ozlabs.org Signed-off-by: Sukadev Bhattiprolu Acked-by: Serge E. Hallyn Tested-by: Serge E. Hallyn Reviewed-by: Oren Laadan --- kernel/pid.c | 41 ++++++++++++++++++++++++++--------------- 1 files changed, 26 insertions(+), 15 deletions(-) diff --git a/kernel/pid.c b/kernel/pid.c index aebb30d..52a371a 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -122,6 +122,30 @@ static void free_pidmap(struct upid *upid) atomic_inc(&map->nr_free); } +static int alloc_pidmap_page(struct pidmap *map) +{ + void *page; + + if (likely(map->page)) + return 0; + + page = kzalloc(PAGE_SIZE, GFP_KERNEL); + /* + * Free the page if someone raced with us installing it: + */ + spin_lock_irq(&pidmap_lock); + if (!map->page) { + map->page = page; + page = NULL; + } + spin_unlock_irq(&pidmap_lock); + kfree(page); + if (unlikely(!map->page)) + return -1; + + return 0; +} + static int alloc_pidmap(struct pid_namespace *pid_ns) { int i, offset, max_scan, pid, last = pid_ns->last_pid; @@ -134,22 +158,9 @@ static int alloc_pidmap(struct pid_namespace *pid_ns) map = &pid_ns->pidmap[pid/BITS_PER_PAGE]; max_scan = (pid_max + BITS_PER_PAGE - 1)/BITS_PER_PAGE - !offset; for (i = 0; i <= max_scan; ++i) { - if (unlikely(!map->page)) { - void *page = kzalloc(PAGE_SIZE, GFP_KERNEL); - /* - * Free the page if someone raced with us - * installing it: - */ - spin_lock_irq(&pidmap_lock); - if (!map->page) { - map->page = page; - page = NULL; - } - spin_unlock_irq(&pidmap_lock); - kfree(page); - if (unlikely(!map->page)) + if (unlikely(!map->page)) + if (alloc_pidmap_page(map) < 0) break; - } if (likely(atomic_read(&map->nr_free))) { do { if (!test_and_set_bit(offset, map->page)) {