From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1F529A00C3; Thu, 3 Feb 2022 19:14:23 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B820D426D6; Thu, 3 Feb 2022 19:13:56 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2065.outbound.protection.outlook.com [40.107.93.65]) by mails.dpdk.org (Postfix) with ESMTP id 33E1E41233 for ; Thu, 3 Feb 2022 19:13:55 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e92Ooc+F0jxaUGbtMpd5qYJ6iJQg25GIESmLk1hnDbtt/YSVMGwqKEavDDBlQjZ61JYxOtQGekrIZb5bl4FO9JttbJo86BJ5fMmTdY15OJwLcOaxhV14yTxoQxNITPphkHugeQNekI6R1Kn5eVt08GL373lzRgzSbtomXi0dJLKVieo445pmN5Z4NxSR3abHIxr62HVBFkl4D8X1qHMKw1K5XCW51bvc+tHm7lUliFzoWFGGOpmlY6iYmqmki8l7WUc/570NcKYHngQC8K08xuxAakHhdmJf6tF1lFGW+QvNt1jFEeoG/AqpiBQDTVPIEtBYI9aCP/syBsEqDTQ8Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BU8DJ6ByBA+0aIen7ZO6BZpnSBHf1hnzVDJM0WCZ7nk=; b=E0ZyYngrN0gkbR6eqlyTc4vi/VLX/YNprP4naZMjreEwzvMI1V4mxZ80VTotCk6+BJ26QylceRFJHm8nGbKgiGNYrUGW3eOd+A9PZqJtw7fBM99o2dr9dl3mWfs2RnfpxOMvJkpxm0bfDeZotSdkYpg72ExNjzPNgObbRSXxN93guCfq+CCal99LrPGEGyWzT66AYzg0Z7jLAw4I9Qu1BpcTpx+sFgytiexzdEdedTWssWxZgG2N+QTJ5iflgfr4Rr5dL9lfHnBjaABFEO4v1nkG+T07siwCgbEfoXmzFu7VEi66QnZx0BSkv9Rk5peMo9zE6HogMliNhEIN/LXTYA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BU8DJ6ByBA+0aIen7ZO6BZpnSBHf1hnzVDJM0WCZ7nk=; b=rFeEeqxVxw3ZQkyc+XVyk0DTzBjNxfpMSE1YlCV3CQQoyb8IrxZ0uiXaN1C9Aa7tlhejcAM4Ce1FoH/Mt+g2Sw9k5O0fweMsQ85tsw1bd4s2A6cwCFPWqOXIuSlnjeZxYRBG2WqqIm6c8owWbLnYAVOtjVvN+BaxFhFWjLbi1+WSFW4PPE8E+7O4xp6CzAdCJFFFtRMf/bL3NxpTXFbjSTgpydwMu/U1bzZgDKDXvbsee664i5ede+jzFWVVers03CPKB09eL+PxB4fncO8I9G+Fj5cceEEQlISRAjJncEKQ4d9gPDEHTlXrjzO0iPhUn2LnnE6bxEqJ7/zBbh4aRQ== Received: from DM6PR21CA0018.namprd21.prod.outlook.com (2603:10b6:5:174::28) by MWHPR12MB1952.namprd12.prod.outlook.com (2603:10b6:300:114::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Thu, 3 Feb 2022 18:13:53 +0000 Received: from DM6NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:5:174:cafe::e8) by DM6PR21CA0018.outlook.office365.com (2603:10b6:5:174::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.6 via Frontend Transport; Thu, 3 Feb 2022 18:13:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.234) by DM6NAM11FT035.mail.protection.outlook.com (10.13.172.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4951.12 via Frontend Transport; Thu, 3 Feb 2022 18:13:52 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 3 Feb 2022 18:13:52 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.9; Thu, 3 Feb 2022 10:13:51 -0800 Received: from nvidia.com (10.127.8.11) by mail.nvidia.com (10.129.68.9) with Microsoft SMTP Server id 15.2.986.9 via Frontend Transport; Thu, 3 Feb 2022 10:13:50 -0800 From: Dmitry Kozlyuk To: CC: Thomas Monjalon , Anatoly Burakov Subject: [PATCH v3 6/6] eal: extend --huge-unlink for hugepage file reuse Date: Thu, 3 Feb 2022 20:13:36 +0200 Message-ID: <20220203181337.759161-7-dkozlyuk@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220203181337.759161-1-dkozlyuk@nvidia.com> References: <20220119210917.765505-1-dkozlyuk@nvidia.com> <20220203181337.759161-1-dkozlyuk@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 278b5d0e-c678-4cb0-df0f-08d9e740ef58 X-MS-TrafficTypeDiagnostic: MWHPR12MB1952:EE_ X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zb3Frx3hsXEETyGafndC37DU86/63SeE5pb4SdY3jt3rrLQrJ5xdmDdefHsUg2GegpOjjhF1Z42BdBfkDToD6J9cGp8ScymptNEVYcnyWJ3hA0fxJYN+jSrTcHrAAU/sHyLMBvY3I4b9HnkpCTeKRDo56rmrvwglSyCQt/n4ify1Zu4IX5AgOvjmTHvXc+NVh8CjXvS8ggnldz6CLQmSu1U1GKdfwvazRBCODiKemoYLea2AKRwlivdaEdhTaVzap+fZrWyX94BpFkGzj3uxs8dWFSiZlxSW8JeJBVDyv1jYJdzZCrPIcnAs5CCTm4ZilG9Nq2EsQxtk44/AtsfnWYhkmVOhlsqdkJZL0wSDExwZzDZA+vladLeFdCY1lrX36B3mj8PNFuAwxYuNkLqoooN6Te7YY9KREwAEWbkObcxp2bHNwwAYbAAPTFor6zDxuJVLmrLMafnvlyTDsfy6egtTXbKl/kg5wPJ0E1IKpFL5EFFyJKpsTVnfnNo3+owygLbMWEdVpeWARuxv8NgglInnr5PHoRxiFuk6wZCAIBcgjQ0sel7bdZbPqUr6GdxBhCqOaQzxvFMyfGESJY15Ch2t7RrCyxIqaZjvrAGWjcRJo2Xj9Pm3rK0NgOELTAvCIH5I+6Ffq4BEytn+sMlNw4m/jRHI72rcltCjr38W5sfkzHbphGlOxvl82lSp7ZyIjDFdnO9UBG65Ixk6+7bal/i157Maoekd2sp9nDRhp44= X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(40470700004)(46966006)(36840700001)(2906002)(83380400001)(70206006)(70586007)(8936002)(47076005)(6666004)(36860700001)(7696005)(82310400004)(86362001)(8676002)(4326008)(40460700003)(2616005)(6286002)(426003)(336012)(508600001)(55016003)(186003)(26005)(1076003)(5660300002)(81166007)(356005)(36756003)(54906003)(6916009)(316002)(14583001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2022 18:13:52.7263 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 278b5d0e-c678-4cb0-df0f-08d9e740ef58 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1952 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Expose Linux EAL ability to reuse existing hugepage files via --huge-unlink=never switch. Default behavior is unchanged, it can also be specified using --huge-unlink=existing for consistency. Old --huge-unlink switch is kept, it is an alias for --huge-unlink=always. Add a test case for the --huge-unlink=never mode. Signed-off-by: Dmitry Kozlyuk Acked-by: Thomas Monjalon --- app/test/test_eal_flags.c | 25 ++++++++++++ doc/guides/linux_gsg/linux_eal_parameters.rst | 24 ++++++++++-- .../prog_guide/env_abstraction_layer.rst | 13 +++++++ doc/guides/rel_notes/release_22_03.rst | 7 ++++ lib/eal/common/eal_common_options.c | 39 +++++++++++++++++-- 5 files changed, 101 insertions(+), 7 deletions(-) diff --git a/app/test/test_eal_flags.c b/app/test/test_eal_flags.c index d7f4c2cd47..e2696cda63 100644 --- a/app/test/test_eal_flags.c +++ b/app/test/test_eal_flags.c @@ -1122,6 +1122,11 @@ test_file_prefix(void) DEFAULT_MEM_SIZE, "--single-file-segments", "--file-prefix=" memtest1 }; + /* primary process with memtest1 and --huge-unlink=never mode */ + const char * const argv9[] = {prgname, "-m", + DEFAULT_MEM_SIZE, "--huge-unlink=never", + "--file-prefix=" memtest1 }; + /* check if files for current prefix are present */ if (process_hugefiles(prefix, HUGEPAGE_CHECK_EXISTS) != 1) { printf("Error - hugepage files for %s were not created!\n", prefix); @@ -1290,6 +1295,26 @@ test_file_prefix(void) return -1; } + /* this process will run with --huge-unlink, + * so it should not remove hugepage files when it exits + */ + if (launch_proc(argv9) != 0) { + printf("Error - failed to run with --huge-unlink=never\n"); + return -1; + } + + /* check if hugefiles for memtest1 are present */ + if (process_hugefiles(memtest1, HUGEPAGE_CHECK_EXISTS) == 0) { + printf("Error - hugepage files for %s were deleted!\n", + memtest1); + return -1; + } else { + if (process_hugefiles(memtest1, HUGEPAGE_DELETE) != 1) { + printf("Error - deleting hugepages failed!\n"); + return -1; + } + } + return 0; } diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index 74df2611b5..ea8f381391 100644 --- a/doc/guides/linux_gsg/linux_eal_parameters.rst +++ b/doc/guides/linux_gsg/linux_eal_parameters.rst @@ -84,10 +84,26 @@ Memory-related options Use specified hugetlbfs directory instead of autodetected ones. This can be a sub-directory within a hugetlbfs mountpoint. -* ``--huge-unlink`` - - Unlink hugepage files after creating them (implies no secondary process - support). +* ``--huge-unlink[=existing|always|never]`` + + No ``--huge-unlink`` option or ``--huge-unlink=existing`` is the default: + existing hugepage files are removed and re-created + to ensure the kernel clears the memory and prevents any data leaks. + + With ``--huge-unlink`` (no value) or ``--huge-unlink=always``, + hugepage files are also removed before mapping them, + so that the application leaves no files in hugetlbfs. + This mode implies no multi-process support. + + When ``--huge-unlink=never`` is specified, existing hugepage files + are never removed, but are remapped instead, allowing hugepage reuse. + This makes restart faster by saving time to clear memory at initialization, + but it may slow down zeroed allocations later. + Reused hugepages can contain data from previous processes that used them, + which may be a security concern. + Hugepage files created in this mode are also not removed + when all the hugepages mapped from them are freed, + which allows to reuse these files after a restart. * ``--match-allocations`` diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst index b467bdf004..8f06c34c22 100644 --- a/doc/guides/prog_guide/env_abstraction_layer.rst +++ b/doc/guides/prog_guide/env_abstraction_layer.rst @@ -283,6 +283,18 @@ to prevent data leaks from previous users of the same hugepage. EAL ensures this behavior by removing existing backing files at startup and by recreating them before opening for mapping (as a precaution). +One exception is ``--huge-unlink=never`` mode. +It is used to speed up EAL initialization, usually on application restart. +Clearing memory constitutes more than 95% of hugepage mapping time. +EAL can save it by remapping existing backing files +with all the data left in the mapped hugepages ("dirty" memory). +Such segments are marked with ``RTE_MEMSEG_FLAG_DIRTY``. +Memory allocator detects dirty segments and handles them accordingly, +in particular, it clears memory requested with ``rte_zmalloc*()``. +In this mode EAL also does not remove a backing file +when all pages mapped from it are freed, +because they are intended to be reusable at restart. + Anonymous mapping does not allow multi-process architecture. This mode does not use hugetlbfs and thus does not require root permissions for memory management @@ -959,6 +971,7 @@ to be virtually contiguous. * dirty - this flag is only meaningful when ``state`` is ``FREE``. It indicates that the content of the element is not fully zero-filled. Memory from such blocks must be cleared when requested via ``rte_zmalloc*()``. + Dirty elements only appear with ``--huge-unlink=never``. * pad - this holds the length of the padding present at the start of the block. In the case of a normal block header, it is added to the address of the end diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst index 746f50e84f..58361db687 100644 --- a/doc/guides/rel_notes/release_22_03.rst +++ b/doc/guides/rel_notes/release_22_03.rst @@ -73,6 +73,13 @@ New Features The new API ``rte_event_eth_rx_adapter_event_port_get()`` was added. +* **Added ability to reuse hugepages in Linux.** + + It is possible to reuse files in hugetlbfs to speed up hugepage mapping, + which may be useful for fast restart and large allocations. + The new mode is activated with ``--huge-unlink=never`` + and has security implications, refer to the user and programmer guides. + Removed Items ------------- diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index cdd2284b0c..45d393b393 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -74,7 +74,7 @@ eal_long_options[] = { {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM }, {OPT_HELP, 0, NULL, OPT_HELP_NUM }, {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM }, - {OPT_HUGE_UNLINK, 0, NULL, OPT_HUGE_UNLINK_NUM }, + {OPT_HUGE_UNLINK, 2, NULL, OPT_HUGE_UNLINK_NUM }, {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, @@ -1598,6 +1598,28 @@ available_cores(void) return str; } +#define HUGE_UNLINK_NEVER "never" + +static int +eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out) +{ + if (arg == NULL || strcmp(arg, "always") == 0) { + out->unlink_before_mapping = true; + return 0; + } + if (strcmp(arg, "existing") == 0) { + /* same as not specifying the option */ + return 0; + } + if (strcmp(arg, HUGE_UNLINK_NEVER) == 0) { + RTE_LOG(WARNING, EAL, "Using --"OPT_HUGE_UNLINK"=" + HUGE_UNLINK_NEVER" may create data leaks.\n"); + out->unlink_existing = false; + return 0; + } + return -1; +} + int eal_parse_common_option(int opt, const char *optarg, struct internal_config *conf) @@ -1739,7 +1761,10 @@ eal_parse_common_option(int opt, const char *optarg, /* long options */ case OPT_HUGE_UNLINK_NUM: - conf->hugepage_file.unlink_before_mapping = true; + if (eal_parse_huge_unlink(optarg, &conf->hugepage_file) < 0) { + RTE_LOG(ERR, EAL, "invalid --"OPT_HUGE_UNLINK" option\n"); + return -1; + } break; case OPT_NO_HUGE_NUM: @@ -2070,6 +2095,12 @@ eal_check_common_options(struct internal_config *internal_cfg) "not compatible with --"OPT_HUGE_UNLINK"\n"); return -1; } + if (!internal_cfg->hugepage_file.unlink_existing && + internal_cfg->in_memory) { + RTE_LOG(ERR, EAL, "Option --"OPT_IN_MEMORY" is not compatible " + "with --"OPT_HUGE_UNLINK"="HUGE_UNLINK_NEVER"\n"); + return -1; + } if (internal_cfg->legacy_mem && internal_cfg->in_memory) { RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible " @@ -2202,7 +2233,9 @@ eal_common_usage(void) " --"OPT_NO_TELEMETRY" Disable telemetry support\n" " --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n" "\nEAL options for DEBUG use only:\n" - " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n" + " --"OPT_HUGE_UNLINK"[=existing|always|never]\n" + " When to unlink files in hugetlbfs\n" + " ('existing' by default, no value means 'always')\n" " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n" " --"OPT_NO_PCI" Disable PCI\n" " --"OPT_NO_HPET" Disable HPET\n" -- 2.25.1