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 A3F04A04A5; Thu, 30 Dec 2021 15:38:16 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D9CC54114B; Thu, 30 Dec 2021 15:38:13 +0100 (CET) Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2051.outbound.protection.outlook.com [40.107.237.51]) by mails.dpdk.org (Postfix) with ESMTP id C8E0641148 for ; Thu, 30 Dec 2021 15:38:10 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OJILh5PhUci3xoHse3cjsLXw0W5g/oa1ncnM0mEdzUA/iAFuEEXRCTqlXvWOqetxQR8jESOfZZr0b1cXVJXyFrfQ6fYn4gE/fUiWLP4pSJ1WpmyC9sjJ+YV1MijNrl3+mx6FNrxXwan+iWJ7MBMwSEpgzCueLgqo+eXVf5YmeVfpL0Pq2a7TUHP2e7b/VyuIM7f609/srn/Q6z1OFZ9GjwR1ZUnrfaYtppMcoTTeVie2j61WEkgwjO8oz4XMRvrVlRQURSsR44xfeYVF/pHzc5LDBb72HvMBoGcSmtdZoWdkghAyNvMFbfGwSZQ4Hv55vwKZI8CFTZL7NOy/LNeC2A== 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=qlfQCgnXh7AmEdsWvM57eF3cRI6VRAE5nfICFWeemwQ=; b=jdLr8kK46t11WvnhFAf+kqTJedvNGJSTalE24s+b8viioY8Ry0cdyEGMQkdR1DvOnyCejN2UDDmgasa5UroOIVYeLFAoBjj09dz0lg8ltVWT00Vh5ZWZ6SEaBzbkDSBPSo+QM4RCHKvDvLpqGYI7X1W6J0yqBSXBQo9/LfK5RwErAcYuBKmX5Jljc3NNCxFTPWdP13Wgmf5WNDbAM78ZNCnrh0+mG+w0lauo6rYEVn/sTNGfmzgw0TK+wY5ZmxPrFLY7JGgjvBHjhDY7CFkd+hrBR76BErsVFwif0cfp3mcEMX2WJyv37XeBE50n34Xwnb0GveZ6CkAwjSLqjKIiEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=monjalon.net 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=qlfQCgnXh7AmEdsWvM57eF3cRI6VRAE5nfICFWeemwQ=; b=PyJDbamQPpBIPDNX5QzvrxVbmCz9EvEsS2cxXhdnUKAHZjtHjHCZRVuF/p7MQX78DDq41/A1HPFI9XCEwdr3qVIc1fOCmwiKFhWcNl5Y6CI+FiqSuRTkGnpzywHDeO9ssvLr4EO3TMdf2kHYFMPRAKIiLx5nTexNw2RGkRHvRWkiu2yXN35Z0yu+qVkZAh7bKQVnvvqCqAmfHnyW3ksl7AAxzATj6uQE2AQWsOegk1gTPEm3Q3Sq6lPkcm00Y7yU78WP7ErImrcMxRTKDVwb0eg3Y7Cyb/2fhGv6p4aB6MKscF4gDW52FHLGXexDsIRSAruiJp8NX58o0vtVdfEn/Q== Received: from CO2PR18CA0051.namprd18.prod.outlook.com (2603:10b6:104:2::19) by DM4PR12MB5342.namprd12.prod.outlook.com (2603:10b6:5:39f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.22; Thu, 30 Dec 2021 14:38:09 +0000 Received: from CO1NAM11FT053.eop-nam11.prod.protection.outlook.com (2603:10b6:104:2:cafe::31) by CO2PR18CA0051.outlook.office365.com (2603:10b6:104:2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.13 via Frontend Transport; Thu, 30 Dec 2021 14:38:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT053.mail.protection.outlook.com (10.13.175.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4844.14 via Frontend Transport; Thu, 30 Dec 2021 14:38:08 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 30 Dec 2021 14:38:07 +0000 Received: from nvidia.com (172.20.187.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.986.9; Thu, 30 Dec 2021 06:38:01 -0800 From: Dmitry Kozlyuk To: CC: Anatoly Burakov , Thomas Monjalon Subject: [RFC PATCH 1/6] doc: add hugepage mapping details Date: Thu, 30 Dec 2021 16:37:39 +0200 Message-ID: <20211230143744.3550098-2-dkozlyuk@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211230143744.3550098-1-dkozlyuk@nvidia.com> References: <20211230143744.3550098-1-dkozlyuk@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1b5d6a76-ecc8-4291-ed44-08d9cba1ff94 X-MS-TrafficTypeDiagnostic: DM4PR12MB5342:EE_ X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XSfLMdPvU8hsj0H+bRE10djZozRuuUn+Mn3OQ+yTvdl24zBy9Y/c95zTcM/FQeNCxzbbnHHBEpI/OfjmUdOUb5CysSoNjCqcSE7SOUxNeUlPQpmyszfO6EaA/pb7mbKk98GyfR1QZrOhSIwFYU5iAn+E6ihJ5F8Gby5Vbq51xdQp2qvMaIhV+VjDyvv+0Ss91W5vMhI76g/kH+U1bBJrfvlBbtdA5BF7nh8s0J3cxJKq/yrgM6gwEr0utaJrRtTcoWk322XXChi/GL5nVAPHYsY4L2BLXov/4DWH7r6n5386kpBOLXhUrLn38eJVTylYmRG1+fmXgqGFg6shnyD+A8PkcH01t290JrD3CVcYsWNw6KMbi0cEV+xh79yG1dCPV8Xq09228Che/F5GAQX9z1JrW5GTwXiPGl9hsxidX1fYY79wvRzW8j5RttqCFl06LuCQraIA5678JYWAFAtEOFQxhEOFU03fj8XOOnYmbEKOE+fPhEsjUKPO4vN0PP1v3l4NGHlqRHX9LLnZODfVWNNLP4eptwlyR8cZ29jQCaUvPaTj8Ibd+YvxQZsuciQxD7bIIYCNjd/vL/yIluA+U6806DqgrPd+fRW883ua25Rpfjn3zfq+rDbnPyxw1QStOoAGronIWVlV4y8jEThXqZl0bLDidiJmCqjZTSxe/bTy5DsWNc4jH3+HNmRv34zs9044eWNR4UUGyxDWavtB3EC7FSXN5BnMFTU3N2TY9+dByUhX8xY5kVFnU3s0cdm122GA2PBi5Om+LeZl3WmSMMT034HaMa8XxGDNLyGdJgA= X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(4636009)(40470700002)(46966006)(36840700001)(82310400004)(336012)(508600001)(83380400001)(7696005)(6916009)(6666004)(40460700001)(356005)(316002)(55016003)(70206006)(8936002)(26005)(2906002)(81166007)(16526019)(186003)(86362001)(54906003)(4326008)(36756003)(1076003)(8676002)(70586007)(47076005)(426003)(2616005)(6286002)(5660300002)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Dec 2021 14:38:08.6509 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1b5d6a76-ecc8-4291-ed44-08d9cba1ff94 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.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT053.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5342 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 Hugepage mapping is a layer of EAL malloc builds upon. There were implicit references to its details, like mentions of segment file descriptors, but no explicit description of its modes and operation. Add an overview of mechanics used on ech supported OS. Convert memory management subsections from list items to level 4 headers: they are big and important enough. Signed-off-by: Dmitry Kozlyuk --- .../prog_guide/env_abstraction_layer.rst | 85 +++++++++++++++++-- 1 file changed, 76 insertions(+), 9 deletions(-) diff --git a/doc/guides/prog_guide/env_abstraction_layer.rst b/doc/guides/prog_guide/env_abstraction_layer.rst index 29f6fefc48..6cddb86467 100644 --- a/doc/guides/prog_guide/env_abstraction_layer.rst +++ b/doc/guides/prog_guide/env_abstraction_layer.rst @@ -86,7 +86,7 @@ See chapter Memory Mapping Discovery and Memory Reservation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -The allocation of large contiguous physical memory is done using the hugetlbfs kernel filesystem. +The allocation of large contiguous physical memory is done using hugepages. The EAL provides an API to reserve named memory zones in this contiguous memory. The physical address of the reserved memory for that memory zone is also returned to the user by the memory zone reservation API. @@ -95,11 +95,12 @@ and legacy mode. Both modes are explained below. .. note:: - Memory reservations done using the APIs provided by rte_malloc are also backed by pages from the hugetlbfs filesystem. + Memory reservations done using the APIs provided by rte_malloc are also backed by hugepages. -+ Dynamic memory mode +Dynamic Memory Mode +^^^^^^^^^^^^^^^^^^^ -Currently, this mode is only supported on Linux. +Currently, this mode is only supported on Linux and Windows. In this mode, usage of hugepages by DPDK application will grow and shrink based on application's requests. Any memory allocation through ``rte_malloc()``, @@ -155,7 +156,8 @@ of memory that can be used by DPDK application. :ref:`Multi-process Support ` for more details about DPDK IPC. -+ Legacy memory mode +Legacy Memory Mode +^^^^^^^^^^^^^^^^^^ This mode is enabled by specifying ``--legacy-mem`` command-line switch to the EAL. This switch will have no effect on FreeBSD as FreeBSD only supports @@ -168,7 +170,8 @@ not allow acquiring or releasing hugepages from the system at runtime. If neither ``-m`` nor ``--socket-mem`` were specified, the entire available hugepage memory will be preallocated. -+ Hugepage allocation matching +Hugepage Allocation Matching +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This behavior is enabled by specifying the ``--match-allocations`` command-line switch to the EAL. This switch is Linux-only and not supported with @@ -182,7 +185,8 @@ matching can be used by these types of applications to satisfy both of these requirements. This can result in some increased memory usage which is very dependent on the memory allocation patterns of the application. -+ 32-bit support +32-bit Support +^^^^^^^^^^^^^^ Additional restrictions are present when running in 32-bit mode. In dynamic memory mode, by default maximum of 2 gigabytes of VA space will be preallocated, @@ -192,7 +196,8 @@ used. In legacy mode, VA space will only be preallocated for segments that were requested (plus padding, to keep IOVA-contiguousness). -+ Maximum amount of memory +Maximum Amount of Memory +^^^^^^^^^^^^^^^^^^^^^^^^ All possible virtual memory space that can ever be used for hugepage mapping in a DPDK process is preallocated at startup, thereby placing an upper limit on how @@ -222,7 +227,68 @@ Normally, these options do not need to be changed. can later be mapped into that preallocated VA space (if dynamic memory mode is enabled), and can optionally be mapped into it at startup. -+ Segment file descriptors +Hugepage Mapping +^^^^^^^^^^^^^^^^ + +Below is an overview of methods used for each OS to obtain hugepages, +explaining why certain limitations and options exist in EAL. +See the user guide for a specific OS for configuration details. + +FreeBSD uses ``contigmem`` kernel module +to reserve a fixed number of hugepages at system start, +which are mapped by EAL at initialization using a specific ``sysctl()``. + +Windows EAL allocates hugepages from the OS as needed using Win32 API, +so available amount depends on the system load. +It uses ``virt2phys`` kernel module to obtain physical addresses, +unless running in IOVA-as-VA mode (e.g. forced with ``--iova-mode=va``). + +Linux implements a variety of methods: + +* mapping each hugepage from its own file in hugetlbfs; +* mapping multiple hugepages from a shared file in hugetlbfs; +* anonymous mapping. + +Mapping hugepages from files in hugetlbfs is essential for multi-process, +because secondary processes need to map the same hugepages. +EAL creates files like ``rtemap_0`` +in directories specified with ``--huge-dir`` option +(or in the mount point for a specific hugepage size). +The ``rtemap_`` prefix can be changed using ``--file-prefix``. +This may be needed for running multiple primary processes +that share a hugetlbfs mount point. +Each backing file by default corresponds to one hugepage, +it is opened and locked for the entire time the hugepage is used. +See :ref:`segment-file-descriptors` section +on how the number of open backing file descriptors can be reduced. + +Backing files may persist after the corresponding hugepage is freed +and even after the application terminates, +reducing the number of hugepages available to other processes. +EAL removes existing files at startup +and can remove newly created files before mapping them with ``--huge-unlink``. +However, since it disables multi-process anyway, +using anonymous mapping (``--in-memory``) is recommended instead. + +:ref:`EAL memory allocator ` relies on hugepages being zero-filled. +Hugepages are cleared by the kernel when a file in hugetlbfs or its part +is mapped for the first time system-wide +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). + +Anonymous mapping does not allow multi-process architecture, +but it is free of filename conflicts and leftover files on hugetlbfs. +If memfd_create(2) is supported both at build and run time, +DPDK memory manager can provide file descriptors for memory segments, +which are required for VirtIO with vhost-user backend. +This means open file descriptor issues may also affect this mode, +with the same solution. + +.. _segment-file-descriptors: + +Segment File Descriptors +^^^^^^^^^^^^^^^^^^^^^^^^ On Linux, in most cases, EAL will store segment file descriptors in EAL. This can become a problem when using smaller page sizes due to underlying limitations @@ -731,6 +797,7 @@ We expect only 50% of CPU spend on packet IO. echo 100000 > pkt_io/cpu.cfs_period_us echo 50000 > pkt_io/cpu.cfs_quota_us +.. _malloc: Malloc ------ -- 2.25.1