vm_map_entry for kernel virtual addres

Alexej Sokolov bsd.quest at googlemail.com
Thu Dec 4 03:06:40 PST 2008


2008/12/3 Mark Tinguely <tinguely at casselton.net>

> >  2008/12/3 Mark Tinguely <tinguely at casselton.net>
> >
> >  > on 3 Dec 2008 15:35:27, Alexej Sokolov <bsd.quest at googlemail.com>
> asked:
> >  >
> >  > >  Hello,
> >  > >  If I allocate memory from a kernel module:
> >  > >  MALLOC(addr, vm_offset_t, PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);
> >  > >
> >  > >  how can I get a pointer to vm_map_entry structure which describes
> the
> >  > memory
> >  > >  region where "addr" is ?
> >  > >
> >  > >  Thanks,
> >  > >  Alexey
> >  >
> >  > MALLOC is a macro for malloc() which returns a kernel virtual address
> into
> >  > the variable addr in this case.
> >  >
> >  > You want to find the vm_map_entry, use something like:
> >  >
> >  >        vm_map_entry_t *result;
> >  >        if (vm_map_lookup_entry(kernel_map, addr, result)) {
> >  >                /* found */
> >  >        } else {
> >  >                /* not found */
> >  >        }
> >
> >
> >  1. Should i use any locks or mutex for doing it ?
>
>  Good question, it really should be:
>
>        vm_map_lock(map);
>
> >  2. What map is used by MALLOC? It can be a some submap. Should i use
> then a
> >  submap for searching entry?
>
> I thought originally that malloc() allocated memory from kernel map
> (kernel_map), but on closer inspection, malloc() seems to use the
> default UMA zone allocator [page_alloc()] which takes the memory from
> the kmem_map. Which I should have know, big mallocs fill the kmem space.
> sooo I guess the more correct code would be:
>
>        vm_map_entry_t result;
>        vm_map_lock(kmem_map);
>        if (vm_map_lookup_entry(kmem_map, addr, &result)) {
>                /* found */
>        } else {
>                /* not found */
>        }
>        vm_map_unlock(kmem_map);
>
> Ok, thanks a lot!


More information about the freebsd-hackers mailing list