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 3ABDDA00C3; Mon, 17 Jan 2022 17:40:54 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8FFC341C28; Mon, 17 Jan 2022 17:40:53 +0100 (CET) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mails.dpdk.org (Postfix) with ESMTP id 2722F4122E for ; Mon, 17 Jan 2022 17:40:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1642437652; x=1673973652; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=epuXYuPOROqgClhz70mf7khAiuIJr+JiRoiZ7UKmoeY=; b=NlL9vjhp0H6drU+qow2AfHpFcknWfODtd7koqr2HLGcO77zcSXeeyY8q GmxydKT5/I7sSU7XnlQbiugHn62OPU3YDGlyfYfI04HTvsaHZkP8Mev9t pRxNlzm54BR0zXdgyp65Ar8YinCjjVfJKYrFvoY4sT6xm8piuG/P2wb+Y mWW751+aI/WA+5j3QqrFc2JIlnwDSg7b2NTtDZoLM6jy0utIqpQrDlBl6 +twtE7IlQBerKBamul8QrQhXPtfHxkr33tCbBJxZ8Rn4hV8FXaWJEtdQt qK8fh9IXLQzX27cOv4c0vlbfE0xuDyZ9JDLVI0yrRZj0/QFWrrhm6Ojlq Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10229"; a="244456871" X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="244456871" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2022 08:40:51 -0800 X-IronPort-AV: E=Sophos;i="5.88,296,1635231600"; d="scan'208";a="531406482" Received: from bricha3-mobl.ger.corp.intel.com ([10.252.26.87]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 17 Jan 2022 08:40:49 -0800 Date: Mon, 17 Jan 2022 16:40:45 +0000 From: Bruce Richardson To: Dmitry Kozlyuk Cc: dev@dpdk.org, Anatoly Burakov , Viacheslav Ovsiienko , David Marchand , Thomas Monjalon , Lior Margalit Subject: Re: [PATCH v1 0/6] Fast restart with many hugepages Message-ID: References: <20211230143744.3550098-1-dkozlyuk@nvidia.com> <20220117080801.481568-1-dkozlyuk@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220117080801.481568-1-dkozlyuk@nvidia.com> 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 On Mon, Jan 17, 2022 at 10:07:55AM +0200, Dmitry Kozlyuk wrote: > This patchset is a new design and implementation of [1]. > Changes since RFC: > * Fix bugs with -m and --single-file-segments. > * Reject optimization of mmap() call number (see below). > > # Problem Statement > > Large allocations that involve mapping new hugepages are slow. > This is problematic, for example, in the following use case. > A single-process application allocates ~1TB of mempools at startup. > Sometimes the app needs to restart as quick as possible. > Allocating the hugepages anew takes as long as 15 seconds, > while the new process could just pick up all the memory > left by the old one (reinitializing the contents as needed). > > Almost all of mmap(2) time spent in the kernel > is clearing the memory, i.e. filling it with zeros. > This is done if a file in hugetlbfs is mapped > for the first time system-wide, i.e. a hugepage is committed > to prevent data leaks from the previous users of the same hugepage. > For example, mapping 32 GB from a new file may take 2.16 seconds, > while mapping the same pages again takes only 0.3 ms. > Security put aside, e.g. when the environment is controlled, > this effort is wasted for the memory intended for DMA, > because its content will be overwritten anyway. > > Linux EAL explicitly removes hugetlbfs files at initialization > and before mapping to force the kernel clear the memory. > This allows the memory allocator to clean memory on only on freeing. > > # Solution > > Add a new mode allowing EAL to remap existing hugepage files. > While it is intended to make restarts faster in the first place, > it makes any startup faster except the cold one > (with no existing files). > > It is the administrator who accepts security risks > implied by reusing hugepages. > The new mode is an opt-in and a warning is logged. > > The feature is Linux-only as it is related > to mapping hugepages from files which only Linux does. > It is inherently incompatible with --in-memory, > for --huge-unlink see below. > > There is formally no breakage of API contract, > but there is a behavior change in the new mode: > rte_malloc*() and rte_memzone_reserve*() may return dirty memory > (previously they were returning clean memory from free heap elements). > Their contract has always explicitly allowed this, > but still there may be users relying on the traditional behavior. > Such users will need to fix their code to use the new mode. > > # Implementation > > ## User Interface > > There is --huge-unlink switch in the same area to remove hugepage files > before mapping them. It is infeasible to use with the new mode, > because the point is to keep hugepage files for fast future restarts. > Extend --huge-unlink option to represent only valid combinations: > > * --huge-unlink=existing OR no option (for compatibility): > unlink files at initialization > and before opening them as a precaution. > > * --huge-unlink=always OR just --huge-unlink (for compatibility): > same as above + unlink created files before mapping. > > * --huge-unlink=never: > the new mode, do not unlink hugepages files, reuse them. > > This option was always Linux-only, but it is kept as common > in case there are users who expect it to be a no-op on other systems. > (Adding a separate --huge-reuse option was also considered, > but there is no obvious benefit and more combinations to test.) > > ## EAL > > If a memseg is mapped dirty, it is marked with RTE_MEMSEG_FLAG_DIRTY > so that the memory allocator may clear the memory if need be. > See patch 5/6 description for details how this is done > in different memory mapping modes. > > The memory manager tracks whether an element is clean or dirty. > If rte_zmalloc*() allocates from a dirty element, > the memory is cleared before handling it to the user. > On freeing, the allocator joins adjacent free elements, > but in the new mode it may not be feasible to clear the free memory > if the joint element is dirty (contains dirty parts). > In any case, memory will be cleared only once, > either on freeing or on allocation. > See patch 3/6 for details. > Patch 2/6 adds a benchmark to see how time is distributed > between allocation and freeing in different modes. > > Besides clearing memory, each mmap() call takes some time. > For example, 1024 calls for 1 TB may take ~300 ms. > The time of one call mapping N hugepages is O(N), > because inside the kernel hugepages are allocated ony by one. > Syscall overhead is negligeable even for one page. > Hence, it does not make sense to reduce the number of mmap() calls, > which would essentially move the loop over pages into the kernel. > > [1]: http://inbox.dpdk.org/dev/20211011085644.2716490-3-dkozlyuk@nvidia.com/ > Hi, this seems really interesting, but in the absense of TB of memory being used, is it easily possible to see the benefits of this work? I've been playing with adding large memory allocations to helloworld example and checking the runtime. Allocating 1GB using malloc per thread seems to show a small (<0.5 second at most) benefit, and using a fixed 10GB allocation using memzone_reserve at startup shows runtimes within the margin of error when run with --huge-unlink=existing vs huge-unlink=never. At what size of memory footprint is it expected to make a clear improvement? Thanks, /Bruce