[dpdk-dev] DDPK use of MAP_FIXED in mmap

Neil Horman nhorman at tuxdriver.com
Tue Dec 9 19:22:42 CET 2014


On Tue, Dec 09, 2014 at 04:04:11PM +0000, Bruce Richardson wrote:
> On Tue, Dec 09, 2014 at 10:26:34AM -0500, Neil Horman wrote:
> > 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 reason for passing the MAP_FIXED flag?
> > > 
> > Because theres nothing wrong with doing so.  The man page says its discouraged
> > because it creates less portable applications (due to the fact that not all
> > operating systems support MAP_FIXED).  Given that we currently only support BSD
> > and Linux however, and given that MAP_FIXED was added to POSIX for
> > XSI compliant systems, it seems like a reasonable thing to use, as we will most
> > likely never run into a system that won't support it
> > Neil
> > 
> 
> Whatever about portability, I thing the best reason to avoid it is given in the
> quote from the map page given below: "If the memory region specified by addr and
> len overlaps pages of any existing mapping(s), then the overlapped part of the
> existing mapping(s) will be discarded." i.e. an mmap with MAP_FIXED can silently
> discard an existing mapping. This can lead to some strange behaviour for the
> unwary.
> 
> /Bruce
> 
That can definately produce some odd behavior, but thats completely avoidable.
An application can introspect its own address mapping to avoid such overlaps.

Of course, if we can avoid using MAP_FIXED, it just makes things a bit easier :)
Neil

> > > 
> > > http://linux.die.net/man/2/mmap
> > > 
> > > MAP_FIXED
> > > Don't interpret addr as a hint: place the mapping at exactly that address. addr must be a multiple of the page size. If the memory region specified by addr and len overlaps pages of any existing mapping(s), then the overlapped part of 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
> > > 
> 


More information about the dev mailing list