From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 9CACA1BEA4; Tue, 3 Jul 2018 14:37:28 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jul 2018 05:37:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,303,1526367600"; d="scan'208";a="69283586" Received: from aburakov-mobl.ger.corp.intel.com (HELO [10.237.220.109]) ([10.237.220.109]) by fmsmga001.fm.intel.com with ESMTP; 03 Jul 2018 05:37:09 -0700 To: Alejandro Lucero , dev@dpdk.org Cc: stable@dpdk.org, maxime.coquelin@redhat.com References: <1530619789-33337-1-git-send-email-alejandro.lucero@netronome.com> <1530619789-33337-5-git-send-email-alejandro.lucero@netronome.com> From: "Burakov, Anatoly" Message-ID: <7e2608f0-24e5-a356-bfe2-9d2980f0f736@intel.com> Date: Tue, 3 Jul 2018 13:37:08 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <1530619789-33337-5-git-send-email-alejandro.lucero@netronome.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v2 4/6] mem: use address hint for mapping hugepages 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: , X-List-Received-Date: Tue, 03 Jul 2018 12:37:29 -0000 On 03-Jul-18 1:09 PM, Alejandro Lucero wrote: > Linux kernel uses a really high address as starting address for > serving mmaps calls. If there exists addressing limitations and > IOVA mode is VA, this starting address is likely too high for > those devices. However, it is possible to use a lower address in > the process virtual address space as with 64 bits there is a lot > of available space. > > This patch adds an address hint as starting address for 64 bits > systems. > > Signed-off-by: Alejandro Lucero > --- > +static void * > +get_addr_hint(void) > +{ > + if (internal_config.base_virtaddr != 0) { > + return (void *) (uintptr_t) > + (internal_config.base_virtaddr + > + baseaddr_offset); > + } > +#ifdef RTE_ARCH_64 > + else { > + return (void *) (uintptr_t) (baseaddr + > + baseaddr_offset); > + } > +#else > + else { > + return NULL; > + } > +#endif Nitpicking, but probably ifdefs should be inside else clause? Two else's look weird. > +} > + > /* > * Try to mmap *size bytes in /dev/zero. If it is successful, return the > * pointer to the mmap'd area and keep *size unmodified. Else, retry > @@ -260,16 +297,10 @@ > static void * > get_virtual_area(size_t *size, size_t hugepage_sz) > { > - addr = mmap(addr, > + addr_hint = get_addr_hint(); > + > + addr = mmap(addr_hint, > (*size) + hugepage_sz, PROT_READ, > #ifdef RTE_ARCH_PPC_64 > MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, > @@ -286,8 +319,15 @@ > MAP_PRIVATE, > #endif > fd, 0); > - if (addr == MAP_FAILED) > + if (addr == MAP_FAILED) { > + /* map failed. Let's try with less memory */ > *size -= hugepage_sz; > + } else if (addr_hint && addr != addr_hint) { > + /* hint was not used. Try with another offset */ > + munmap(addr, (*size) + hugepage_sz); Maybe store mapping size in a variable. Otherwise, Acked-by: Anatoly Burakov -- Thanks, Anatoly