Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1766418imj; Fri, 8 Feb 2019 07:03:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IbJYB/4UTPKaR+spzNBjFy+jTHTEhs9sOnhHcxVn5DlvoHQ9oCsA5E/kJUinkGJTaNi/OB7 X-Received: by 2002:a63:fd0a:: with SMTP id d10mr4849662pgh.164.1549638235821; Fri, 08 Feb 2019 07:03:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549638235; cv=none; d=google.com; s=arc-20160816; b=MTypU6X8PEwGOu9Rh2OyeTa3UcPywurqgDcsEd1/sw0X90GIUKUnsBjgyg+jkx1ehn l7cLZzAF5MHe4RvE9+ewuEhEDdlakXtLQgKYSLzFVSP0h/bGX4k/JGH6GtqCyA+Yxyke nE1Y7RkiK4rueHs+vAn9HAFI+BnMNbRiBJalfx34tYKt87qNDX+dNIoI9INj257WRzQC V3TeLOCcpokFveP72TFeKXow1IOFl9IrueK38RNa0/q2o/56187OCZBkkChrm/VtCUgA VmmMyUUI14blHeE90x0rwG60W0mx8VFr9VQcXzUsoDfcFPzGFnbe+g04VCybRF5Cp/Nq 4KvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:message-id :dkim-signature; bh=oNW1cjqNraLzYK6Kh8uFIYVP1M6z46QbE9hpGbjPuM4=; b=uKWEn3MIJwXkIakugIc1ZKzSIQw0ssk4nbbyeVFyI0z3Po6dxcplNgJ/liKtNheMtL +9mxHPlquxrUerk7fKjDbi6OX4MsaN9WvrFvTvizECNH/qyCnz+N1vC5oCe9a62d6X9y sq/kQLwow8s3RD/TPx9oL5KRZmFlmjk6Th+KG20zaCRKa0TvZejv8RC2YmwznGDtAvlz MQYL7He0HF/BMHegQb4pjjcihD4jJHmtBw1235KWGLpf/cySeiIzh9CkAEx3iw9QAihC naVjSiP/aW9V1uIkyzEo1oVUQQFv3w+rMSzBTxVYPxxHSCO2ApVH3YEF48BJC+AZlkLI bKrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=M61Sg1II; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n187si2683878pfn.83.2019.02.08.07.03.38; Fri, 08 Feb 2019 07:03:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=M61Sg1II; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727920AbfBHPC5 (ORCPT + 99 others); Fri, 8 Feb 2019 10:02:57 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:21083 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726813AbfBHPC4 (ORCPT ); Fri, 8 Feb 2019 10:02:56 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 43wz2619x9z9vBxV; Fri, 8 Feb 2019 16:02:54 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=M61Sg1II; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id zHG7QCYHBWWY; Fri, 8 Feb 2019 16:02:54 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 43wz2606Zjz9vBxT; Fri, 8 Feb 2019 16:02:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1549638174; bh=oNW1cjqNraLzYK6Kh8uFIYVP1M6z46QbE9hpGbjPuM4=; h=From:Subject:To:Cc:Date:From; b=M61Sg1IIWrtqlKJKrthI1aJM1BEbxYs7yYyato/T7F5JpWTmzQThz6qFv0gdEeqIg ZXfCt7K9bPUqH/tnq7AxWtgtNx8LkrFWweVMDRelTQoadpaApcSBZRhShZCqpEi3Wh cnJWzhxSRKVRIeza3cruB7+y5Kdwdcd/7E3Ibg4Q= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7E4948B8DF; Fri, 8 Feb 2019 16:02:55 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id snUdZqBBPijt; Fri, 8 Feb 2019 16:02:55 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4BE468B756; Fri, 8 Feb 2019 16:02:55 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 49CB4656D3; Fri, 8 Feb 2019 15:02:55 +0000 (UTC) Message-Id: <59dbb1bc305068dd0fe8e2d5a75c4213e0134549.1549638049.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH] tools/selftest/vm: allow choosing mem size and page size in map_hugetlb To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Shuah Khan Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kselftest@vger.kernel.org Date: Fri, 8 Feb 2019 15:02:55 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org map_hugetlb maps 256Mbytes of memory with default hugepage size. This patch allows the user to pass the size and page shift as an argument in order to use different size and page size. Signed-off-by: Christophe Leroy --- tools/testing/selftests/vm/map_hugetlb.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vm/map_hugetlb.c b/tools/testing/selftests/vm/map_hugetlb.c index 9b777fa95f09..5a2d7b8efc40 100644 --- a/tools/testing/selftests/vm/map_hugetlb.c +++ b/tools/testing/selftests/vm/map_hugetlb.c @@ -23,6 +23,14 @@ #define MAP_HUGETLB 0x40000 /* arch specific */ #endif +#ifndef MAP_HUGE_SHIFT +#define MAP_HUGE_SHIFT 26 +#endif + +#ifndef MAP_HUGE_MASK +#define MAP_HUGE_MASK 0x3f +#endif + /* Only ia64 requires this */ #ifdef __ia64__ #define ADDR (void *)(0x8000000000000000UL) @@ -58,12 +66,29 @@ static int read_bytes(char *addr) return 0; } -int main(void) +int main(int argc, char **argv) { void *addr; int ret; + size_t length = LENGTH; + int flags = FLAGS; + int shift = 0; + + if (argc > 1) + length = atol(argv[1]) << 20; + if (argc > 2) { + shift = atoi(argv[2]); + if (shift) + flags |= (shift & MAP_HUGE_MASK) << MAP_HUGE_SHIFT; + } + + if (shift) + printf("%u kB hugepages\n", 1 << shift); + else + printf("Default size hugepages\n"); + printf("Mapping %lu Mbytes\n", (unsigned long)length >> 20); - addr = mmap(ADDR, LENGTH, PROTECTION, FLAGS, -1, 0); + addr = mmap(ADDR, length, PROTECTION, flags, -1, 0); if (addr == MAP_FAILED) { perror("mmap"); exit(1); -- 2.13.3