Date: Thu, 4 Dec 2008 12:06:39 +0100 From: "Alexej Sokolov" <bsd.quest@googlemail.com> To: "Mark Tinguely" <tinguely@casselton.net>, freebsd-hackers@freebsd.org Subject: Re: vm_map_entry for kernel virtual addres Message-ID: <671bb5fc0812040306i67345928wf5124e224d46bd52@mail.gmail.com> In-Reply-To: <200812031859.mB3IxHCi046359@casselton.net> References: <671bb5fc0812031004j28e9bfc4j88df11ce18b436b6@mail.gmail.com> <200812031859.mB3IxHCi046359@casselton.net>
next in thread | previous in thread | raw e-mail | index | archive | help
2008/12/3 Mark Tinguely <tinguely@casselton.net>
> > 2008/12/3 Mark Tinguely <tinguely@casselton.net>
> >
> > > on 3 Dec 2008 15:35:27, Alexej Sokolov <bsd.quest@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!
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?671bb5fc0812040306i67345928wf5124e224d46bd52>
