From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 4 11:06:40 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9EBDE1065672 for ; Thu, 4 Dec 2008 11:06:40 +0000 (UTC) (envelope-from bsd.quest@googlemail.com) Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.183]) by mx1.freebsd.org (Postfix) with ESMTP id 6FCCA8FC36 for ; Thu, 4 Dec 2008 11:06:40 +0000 (UTC) (envelope-from bsd.quest@googlemail.com) Received: by wa-out-1112.google.com with SMTP id m34so1956553wag.27 for ; Thu, 04 Dec 2008 03:06:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type:references; bh=PmJnzX8eb/AOii+DUJMzEo9ib3FTGZxfC8yFGn/vQco=; b=ktJUI6hfccqCQrYpTNIwJaLKCWZB7QLms42sCMkgiWWU/LSvUDYg7cVtFqWXkwi0Vr t+tepzvH4MO6PEFxRAiH1Rg4kEWomdzqg9Jd0O8KlzU5K488+YJSNO0H81QSP96Hzl82 q8GOh2m8qmDjtXo9zfFw96tiHlwZM/xguWcxQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:references; b=plnWDYcj9RIcAjeEmMGWR04rydQ8UWwQEWQ49pIa4Pd47i4osrgK1VLT3tI2I/1Vi5 1cQEr+tVffZxlSgNe74sSGcorAiPk/8LeFDc7HFiLtlG3nOB5ZAFdw/zjhjVJg8B+HPr yuE1pwO1Lxbuu/yskpZSha2hKmtMj3z2YBbNo= Received: by 10.114.148.2 with SMTP id v2mr8901001wad.169.1228388799995; Thu, 04 Dec 2008 03:06:39 -0800 (PST) Received: by 10.114.76.4 with HTTP; Thu, 4 Dec 2008 03:06:39 -0800 (PST) Message-ID: <671bb5fc0812040306i67345928wf5124e224d46bd52@mail.gmail.com> Date: Thu, 4 Dec 2008 12:06:39 +0100 From: "Alexej Sokolov" To: "Mark Tinguely" , freebsd-hackers@freebsd.org In-Reply-To: <200812031859.mB3IxHCi046359@casselton.net> MIME-Version: 1.0 References: <671bb5fc0812031004j28e9bfc4j88df11ce18b436b6@mail.gmail.com> <200812031859.mB3IxHCi046359@casselton.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: Subject: Re: vm_map_entry for kernel virtual addres X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Dec 2008 11:06:40 -0000 2008/12/3 Mark Tinguely > > 2008/12/3 Mark Tinguely > > > > > on 3 Dec 2008 15:35:27, Alexej Sokolov > 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!