From owner-freebsd-hackers@FreeBSD.ORG Wed Mar 21 23:28:29 2012 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 DBBF4106564A for ; Wed, 21 Mar 2012 23:28:29 +0000 (UTC) (envelope-from eric.saintetienne@gmail.com) Received: from mail-vb0-f54.google.com (mail-vb0-f54.google.com [209.85.212.54]) by mx1.freebsd.org (Postfix) with ESMTP id 9A05E8FC12 for ; Wed, 21 Mar 2012 23:28:29 +0000 (UTC) Received: by vbmv11 with SMTP id v11so1021310vbm.13 for ; Wed, 21 Mar 2012 16:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=W4jJ2X7w+dpSBojDkTRUYvaYAWk5CH8W93UWiYXZ+ic=; b=ND/0W84cPzUFZsZeVjSKDkdgCHs2Lc9MwzKiVgb9wosJmGpYzuOvPKY/a9CV38nrcO 27v6nDkpMQArceHMzm+PhygdnYOdwiji5ytuFS9Xi4HU/YmQ6P14HUYvJdOndh3b+VJf qzx1jo7dwr/TjixJZeT3xMqs49Le11Merw/i+aTIpaTF7Uw/eQvWCSOounFIWTmhCogK VtEeugH7853iP375pGKL8fnJ2m7Rrl3pq/Y22X4oe9lAa60gPwDMRj2t+ieJ51pDA6y5 1Mkr/1tMi1J17rh1EkVIO4dStKKrTt3okt2hOOcQVgCgBW5w/SfcZKecPuOUlChOy+ek AJJA== Received: by 10.52.29.244 with SMTP id n20mr2344381vdh.22.1332372508975; Wed, 21 Mar 2012 16:28:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.149.9 with HTTP; Wed, 21 Mar 2012 16:27:58 -0700 (PDT) From: Eric Saint-Etienne Date: Wed, 21 Mar 2012 23:27:58 +0000 Message-ID: To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: malloc pages map to user space 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: Wed, 21 Mar 2012 23:28:29 -0000 Hi, >From within the freeBSD kernel, not all malloc are made equal: * malloc() smaller than=C2=A0KMEM_ZMAX (set to=C2=A0one page size) end up = in UMA SLABs, themselves laid out in powers of 2 (from 16 bytes, 32... to 4096 bytes) * bigger malloc() are done through=C2=A0uma_large_malloc() which uses the kmem wired space In my driver, I need to map some malloc-ed memory, obtained from another module, into userspace. The problem: on the smaller mallocs, as well as on some bigeer ones (8k seems fine, 64k fails): vm_map_lookup() fails finding the underlying vm object. Do somebody know how (or better, have a piece of code!) to retrieve the vm_object associated with malloc-ed memory? (small and big ones) As far as I can see in the vm code, there isn't any object associated with the slabs (the smaller mallocs), it seems that a huge chunk of virtual space is used "as is", so I presume the virtual addresses where the SLABs are have some remarkable property, with respect to physical addresses, that could allow creating an object from scratch? The usual answer is: use mmap(). It seems mmap() is the solution to everything. But what I dislike with mmap() is the following cost *for each page*: 1/ a page fault 2/ a call to a pager function that will do the "on demand" mapping. Thank you. Eric