Using mmap(2) with a hint address

Andriy Gapon avg at FreeBSD.org
Tue Dec 20 10:10:52 UTC 2011


on 20/12/2011 10:08 Ganael LAPLANCHE said the following:
> Hi folks,
> 
> I am trying to use mmap(2) with a hint address. Unfortunately, this address
> seems to be ignored and I never manage to get the desired one, while it
> seems to be free.
[snip]
> Using MAP_FIXED, I can get the desired address, but it is overkill (it
> replaces
> any previous mappings and its use is discouraged, see mmap(2)) and
> should not
> be needed here.
> 
> Am I doing something wrong here ?

Can the following code explain what you are seeing?

/*
 * XXX for non-fixed mappings where no hint is provided or
 * the hint would fall in the potential heap space,
 * place it after the end of the largest possible heap.
 *
 * There should really be a pmap call to determine a reasonable
 * location.
 */
PROC_LOCK(td->td_proc);
if (addr == 0 ||
    (addr >= round_page((vm_offset_t)vms->vm_taddr) &&
    addr < round_page((vm_offset_t)vms->vm_daddr +
    lim_max(td->td_proc, RLIMIT_DATA))))
        addr = round_page((vm_offset_t)vms->vm_daddr +
            lim_max(td->td_proc, RLIMIT_DATA));
PROC_UNLOCK(td->td_proc);

-- 
Andriy Gapon


More information about the freebsd-stable mailing list