From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B32E7A00BE; Thu, 28 May 2020 13:26:43 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5CBB81DB80; Thu, 28 May 2020 13:26:42 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 637B91DB7E for ; Thu, 28 May 2020 13:26:40 +0200 (CEST) IronPort-SDR: 3xOqMtPHlUiUjyUMeg9qTYyxj7WD4ZMRzFpZivo/Fvw8gZSjss4Fiv4+EWBXGoFiAbmaK0iHYI 63gKVla1eCsA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 04:26:39 -0700 IronPort-SDR: ST6V3gGQFUMaA6tSY1rvttmLRuEBQnlo9Kj1/EteOAiEO4sOtlGHfa++3ZS3hq3vZGfA4XzTrq J82ny1uENl2A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,444,1583222400"; d="scan'208";a="376341813" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.252.45.206]) ([10.252.45.206]) by fmsmga001.fm.intel.com with ESMTP; 28 May 2020 04:26:36 -0700 To: Dmitry Kozlyuk , dev@dpdk.org Cc: Dmitry Malloy , Narcisa Ana Maria Vasile , Fady Bader , Tal Shnaiderman , Bruce Richardson , Ray Kinsella , Neil Horman References: <20200428235015.2820677-1-dmitry.kozliuk@gmail.com> <20200525003720.6410-1-dmitry.kozliuk@gmail.com> <20200525003720.6410-4-dmitry.kozliuk@gmail.com> From: "Burakov, Anatoly" Message-ID: Date: Thu, 28 May 2020 12:26:35 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: <20200525003720.6410-4-dmitry.kozliuk@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v5 03/11] eal: introduce memory management wrappers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 25-May-20 1:37 AM, Dmitry Kozlyuk wrote: > Introduce OS-independent wrappers for memory management operations used > across DPDK and specifically in common code of EAL: > > * rte_mem_map() > * rte_mem_unmap() > * rte_get_page_size() > * rte_mem_lock() > > Windows uses different APIs for memory mapping and reservation, while > Unices reserve memory by mapping it. Introduce EAL private functions to > support memory reservation in common code: > > * eal_mem_reserve() > * eal_mem_free() > * eal_mem_set_dump() > > Wrappers follow POSIX semantics limited to DPDK tasks, but their > signatures deliberately differ from POSIX ones to be more safe and > expressive. > > Signed-off-by: Dmitry Kozlyuk > --- > - page_sz = sysconf(_SC_PAGESIZE); > + page_sz = rte_get_page_size(); > if (page_sz == (size_t)-1) { > free(ma); > return -1; > @@ -754,9 +751,11 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len, > > if (internal_config.no_shconf) { > /* remap virtual area as writable */ > - void *new_data = mmap(data, mmap_len, PROT_READ | PROT_WRITE, > - MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, fd, 0); > - if (new_data == MAP_FAILED) { > + static const int flags = RTE_MAP_FORCE_ADDRESS | > + RTE_MAP_PRIVATE | RTE_MAP_ANONYMOUS; > + void *new_data = rte_mem_map(data, mmap_len, > + RTE_PROT_READ | RTE_PROT_WRITE, flags, fd, 0); > + if (new_data == NULL) { > RTE_LOG(DEBUG, EAL, "%s(): couldn't remap anonymous memory: %s\n", > __func__, strerror(errno)); I believe this should be rte_strerror(rte_errno) instead of strerror(errno). > goto fail; > @@ -821,7 +820,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len, > return 0; > fail: > if (data) > - munmap(data, mmap_len); > + rte_mem_unmap(data, mmap_len); > if (fd >= 0) > close(fd); > free(ma); > @@ -859,7 +858,7 @@ rte_fbarray_attach(struct rte_fbarray *arr) > return -1; > > +/** > + * Memory protection flags. > + */ > +enum rte_mem_prot { > + RTE_PROT_READ = 1 << 0, /**< Read access. */ > + RTE_PROT_WRITE = 1 << 1, /**< Write access. */ > + RTE_PROT_EXECUTE = 1 << 2 /**< Code execution. */ > +}; > + > +/** > + * Additional flags for memory mapping. > + */ > +enum rte_map_flags { > + /** Changes to the mapped memory are visible to other processes. */ > + RTE_MAP_SHARED = 1 << 0, > + /** Mapping is not backed by a regular file. */ > + RTE_MAP_ANONYMOUS = 1 << 1, > + /** Copy-on-write mapping, changes are invisible to other processes. */ > + RTE_MAP_PRIVATE = 1 << 2, > + /** > + * Force mapping to the requested address. This flag should be used > + * with caution, because to fulfill the request implementation > + * may remove all other mappings in the requested region. However, > + * it is not required to do so, thus mapping with this flag may fail. > + */ > + RTE_MAP_FORCE_ADDRESS = 1 << 3 > +}; I have no strong opinion on this, but it feels like the fact that these are enums is a relic from the times where you used enum everywhere :) i have a feeling that DPDK codebase prefers #define's for this usage, while what you have here is more of a C++ thing. -- Thanks, Anatoly