From patchwork Thu May 6 07:39:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Schmidt X-Patchwork-Id: 97283 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o467eLQ2031059 for ; Thu, 6 May 2010 07:40:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755887Ab0EFHj4 (ORCPT ); Thu, 6 May 2010 03:39:56 -0400 Received: from mtagate3.de.ibm.com ([195.212.17.163]:46591 "EHLO mtagate3.de.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755848Ab0EFHjz (ORCPT ); Thu, 6 May 2010 03:39:55 -0400 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate3.de.ibm.com (8.13.1/8.13.1) with ESMTP id o467dsoE022532 for ; Thu, 6 May 2010 07:39:54 GMT Received: from d12av01.megacenter.de.ibm.com (d12av01.megacenter.de.ibm.com [9.149.165.212]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o467drYM1437698 for ; Thu, 6 May 2010 09:39:53 +0200 Received: from d12av01.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av01.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id o467drKv007312 for ; Thu, 6 May 2010 09:39:53 +0200 Received: from alex-laptop (dyn-9-152-241-49.boeblingen.de.ibm.com [9.152.241.49]) by d12av01.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id o467drvm007308; Thu, 6 May 2010 09:39:53 +0200 Date: Thu, 6 May 2010 09:39:49 +0200 From: Alexander Schmidt To: Roland Dreier , of-ewg , Linux RDMA Cc: Hoang-Nam Nguyen , Stefan Roscher , Joachim Fenkes , Christoph Raisch Subject: [RFC] libibverbs: ibv_fork_init() and libhugetlbfs Message-ID: <20100506093949.55916ab0@alex-laptop> X-Mailer: Claws Mail 3.6.1 (GTK+ 2.16.1; i486-pc-linux-gnu) Mime-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 06 May 2010 07:40:41 +0000 (UTC) --- libibverbs-1.1.2.orig/src/memory.c +++ libibverbs-1.1.2/src/memory.c @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include "ibverbs.h" @@ -54,6 +56,8 @@ #define MADV_DOFORK 11 #endif +#define HUGE_PAGE_SIZE (16 * 1024 * 1024) + struct ibv_mem_node { enum { IBV_RED, @@ -446,6 +450,48 @@ static struct ibv_mem_node *__mm_find_st return node; } +static void get_range_address(uintptr_t *start, uintptr_t *end, void *base, size_t size) +{ + pid_t pid; + FILE *file; + char buf[1024], lib[128]; + int range_page_size = page_size; + + pid = getpid(); + snprintf(buf, sizeof(buf), "/proc/%d/maps", pid); + + file = fopen(buf, "r"); + if (!file) + goto out; + + while (fgets(buf, sizeof(buf), file) != NULL) { + int n; + char *substr; + uintptr_t range_start, range_end; + + n = sscanf(buf, "%lx-%lx %*s %*x %*s %*u %127s", + &range_start, &range_end, &lib); + + if (n < 3) + continue; + + substr = strstr(lib, "libhugetlbfs"); + if (substr) { + if ((uintptr_t) base >= range_start && + (uintptr_t) base < range_end) { + range_page_size = HUGE_PAGE_SIZE; + break; + } + } + } + fclose(file); + +out: + *start = (uintptr_t) base & ~(range_page_size - 1); + *end = ((uintptr_t) (base + size + range_page_size - 1) & + ~(range_page_size - 1)) - 1; +} + static int ibv_madvise_range(void *base, size_t size, int advice) { uintptr_t start, end; @@ -458,9 +504,7 @@ static int ibv_madvise_range(void *base, inc = advice == MADV_DONTFORK ? 1 : -1; - start = (uintptr_t) base & ~(page_size - 1); - end = ((uintptr_t) (base + size + page_size - 1) & - ~(page_size - 1)) - 1; + get_range_address(&start, &end, base, size); pthread_mutex_lock(&mm_mutex);