From patchwork Thu Jan 22 16:38:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 43539 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C3E16240DB for ; Thu, 22 Jan 2015 16:39:30 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id c13sf2277189eek.1 for ; Thu, 22 Jan 2015 08:39:30 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=oeatW4DqY1BTDBM9M8Vw1tsdztVEjJYp8nlD6IJebKI=; b=HYxdpcuRgVKgbhByuk1JmFI12QVlLDfYrXMWKpWJu4ebgWpB04aXYUkEgufYWsAAY1 0CccFW89YYo4ICevIdG7zY2bQAO+AKi1V+wVkPyuY71nmZOT60dY8d/GQRuivCHS0dle 3ZmDOsbqIES5LtI6zeuYYxbNhSgVMg4s0v+rKqN9VNAydg7AmyAtYtTwb8FiC+QqGpuJ 00h1qz3FoaNE/6QDRAsWUhAp5zcvjXVcS++vILiMHErW6XFVqA8J02g1X4tMTeVzJ4cg 6HSRkCKLb+I+8aBr9ObvTVEh66cQft4g7+GdzjN+zUqDujZHquJLMrLxtXvfGqgr2CML XyNA== X-Gm-Message-State: ALoCoQkpTGcv1mUqID0bq+iYOz8S9fsG4MH7STNZHyvvo0CtpwHJ5dByGXnxlenU3xtQ+JZVowJ4 X-Received: by 10.152.182.204 with SMTP id eg12mr14057lac.10.1421944770010; Thu, 22 Jan 2015 08:39:30 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.228.135 with SMTP id si7ls186531lac.51.gmail; Thu, 22 Jan 2015 08:39:29 -0800 (PST) X-Received: by 10.112.181.106 with SMTP id dv10mr2762699lbc.88.1421944769598; Thu, 22 Jan 2015 08:39:29 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id y8si21109619lbw.107.2015.01.22.08.39.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Jan 2015 08:39:29 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id u10so2519993lbd.12 for ; Thu, 22 Jan 2015 08:39:29 -0800 (PST) X-Received: by 10.112.41.234 with SMTP id i10mr2764918lbl.25.1421944769471; Thu, 22 Jan 2015 08:39:29 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp321490lbb; Thu, 22 Jan 2015 08:39:28 -0800 (PST) X-Received: by 10.140.46.37 with SMTP id j34mr4081295qga.12.1421944767811; Thu, 22 Jan 2015 08:39:27 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id k17si5123852qgd.66.2015.01.22.08.39.26 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 22 Jan 2015 08:39:27 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YEKmz-0001eu-0V; Thu, 22 Jan 2015 16:39:25 +0000 Received: from mail-la0-f46.google.com ([209.85.215.46]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YEKmk-0001c9-Fs for lng-odp@lists.linaro.org; Thu, 22 Jan 2015 16:39:10 +0000 Received: by mail-la0-f46.google.com with SMTP id s18so2667281lam.5 for ; Thu, 22 Jan 2015 08:39:04 -0800 (PST) X-Received: by 10.152.19.7 with SMTP id a7mr2783817lae.16.1421944744865; Thu, 22 Jan 2015 08:39:04 -0800 (PST) Received: from localhost.localdomain (broadband-46-188-125-104.2com.net. [46.188.125.104]) by mx.google.com with ESMTPSA id f4sm1136853lam.30.2015.01.22.08.39.03 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Jan 2015 08:39:03 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 22 Jan 2015 19:38:49 +0300 Message-Id: <1421944729-28510-3-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1421944729-28510-1-git-send-email-maxim.uvarov@linaro.org> References: <1421944729-28510-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 3/3] hugepages: align mmap size for hugepages X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 In case of hugepages munmap requires size aligned to page. Signed-off-by: Maxim Uvarov --- platform/linux-generic/odp_shared_memory.c | 18 ++++++++++++++---- test/validation/odp_shm.c | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c index 23a9ceb..d2b28bc 100644 --- a/platform/linux-generic/odp_shared_memory.c +++ b/platform/linux-generic/odp_shared_memory.c @@ -179,11 +179,22 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, int map_flag = MAP_SHARED; /* If already exists: O_EXCL: error, O_TRUNC: truncate to zero */ int oflag = O_RDWR | O_CREAT | O_TRUNC; - uint64_t alloc_size = size + align; + uint64_t alloc_size; uint64_t page_sz, huge_sz; + int need_huge_page = 0; - huge_sz = odp_sys_huge_page_size(); page_sz = odp_sys_page_size(); + alloc_size = size + align; + +#ifdef MAP_HUGETLB + huge_sz = odp_sys_huge_page_size(); + need_huge_page = (huge_sz && alloc_size > page_sz); + if (need_huge_page) { + /* munmap for huge pages requires sizes round up by page */ + alloc_size = (size + align + (huge_sz - 1)) + & (-huge_sz); + } +#endif if (flags & ODP_SHM_PROC) { /* Creates a file to /dev/shm */ @@ -235,12 +246,11 @@ odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align, #ifdef MAP_HUGETLB /* Try first huge pages */ - if (huge_sz && alloc_size > page_sz) { + if (need_huge_page) { addr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE, map_flag | MAP_HUGETLB, fd, 0); } #endif - /* Use normal pages for small or failed huge page allocations */ if (addr == MAP_FAILED) { addr = mmap(NULL, alloc_size, PROT_READ | PROT_WRITE, diff --git a/test/validation/odp_shm.c b/test/validation/odp_shm.c index c26925b..4b1a38e 100644 --- a/test/validation/odp_shm.c +++ b/test/validation/odp_shm.c @@ -32,7 +32,11 @@ static void *run_shm_thread(void *arg) CU_ASSERT(0 == info.flags); CU_ASSERT(test_shared_data == info.addr); CU_ASSERT(sizeof(test_shared_data_t) <= info.size); +#ifdef MAP_HUGETLB + CU_ASSERT(odp_sys_huge_page_size() == info.page_size); +#else CU_ASSERT(odp_sys_page_size() == info.page_size); +#endif odp_shm_print_all(); fflush(stdout);