From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 8FAEA2A9 for ; Tue, 9 Dec 2014 19:29:57 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 09 Dec 2014 10:29:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,546,1413270000"; d="scan'208";a="644980781" Received: from pgsmsx105.gar.corp.intel.com ([10.221.44.96]) by fmsmga002.fm.intel.com with ESMTP; 09 Dec 2014 10:29:53 -0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by pgsmsx105.gar.corp.intel.com (10.221.44.96) with Microsoft SMTP Server (TLS) id 14.3.195.1; Wed, 10 Dec 2014 02:29:52 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.110]) by shsmsx102.ccr.corp.intel.com ([169.254.2.216]) with mapi id 14.03.0195.001; Wed, 10 Dec 2014 02:29:51 +0800 From: "Xie, Huawei" To: "Richardson, Bruce" , Karmarkar Suyash Thread-Topic: [dpdk-dev] DDPK use of MAP_FIXED in mmap Thread-Index: AQHQE5ZaVRZPgTu3aUK4D3h4ii9PHpyHk/aw Date: Tue, 9 Dec 2014 18:29:50 +0000 Message-ID: References: <20141209095506.GB9472@bricha3-MOBL3> In-Reply-To: <20141209095506.GB9472@bricha3-MOBL3> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] DDPK use of MAP_FIXED in mmap X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Dec 2014 18:29:58 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Bruce Richardson > Sent: Tuesday, December 09, 2014 2:55 AM > To: Karmarkar Suyash > Cc: dev@dpdk.org > Subject: Re: [dpdk-dev] DDPK use of MAP_FIXED in mmap >=20 > On Mon, Dec 08, 2014 at 07:02:38PM +0000, Karmarkar Suyash wrote: > > Hello, > > > > In DPDK when we use mmap why are we passing the MAP_FIXED flag when > Linux man page itself says that the option is discouraged? Any specific r= eason > for passing the MAP_FIXED flag? > > > > > > http://linux.die.net/man/2/mmap > > > > MAP_FIXED > > Don't interpret addr as a hint: place the mapping at exactly that addre= ss. addr > must be a multiple of the page size. If the memory region specified by ad= dr and > len overlaps pages of any existing mapping(s), then the overlapped part o= f the > existing mapping(s) will be discarded. If the specified address cannot be= used, > mmap() will fail. Because requiring a fixed address for a mapping is less= portable, > the use of this option is discouraged. > > > > > > Regards > > Suyash Karmarkar >=20 > I won't comment on every occurance of "MAP_FIXED" in DPDK, but it's main = use > is > when mapping the hugepages into memory inside EAL init. In this case, we = are > ok to > use it, as we take good care to ensure that our mapping space is free. Wh= at we > do > is, once we know how many contiguous hugepages we need to map, we request > a mapping > from /dev/zero for that particular size. We then record the address of th= e > mapping > we get, and then unmap /dev/zero again - thereby freeing up the entire ad= dress > range. At this point, we then use MAP_FIXED to explicitly mmap in the > hugepages > into this region that we have just freed up - thereby guaranteeing contig= uous > hugepage mappings in the correct order. [The reason for doing things this= way is > that we found on some systems - particularly with 32-bit code, the regula= r > mmaps > of pages we being done in reverse order, meaning each page became it's ow= n > segment]. >=20 > On the other hand, it's also good to note where we don't use MAP_FIXED. W= e > don't > use map fixed when initializing a secondary process and are mapping the > hugepage > memory into it. In this case, although we know where the memory has to be > placed, > we don't know if it is safe to use or not. Instead of using MAP_FIXED, we= instead > hint to the kernel our preferred address and check if the request was sat= isfied > at that address. >=20 > Hope this clarifies things a bit, Don't know if kernel always use the hinted address if the target region is = free for mmap. The safe way is if we are absolutely sure the region is free(like through c= hecking maps file), use MMAP_FIXED(in secondary process). > /Bruce