From owner-freebsd-current@FreeBSD.ORG Wed Jun 1 17:00:58 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CDC0A1065674 for ; Wed, 1 Jun 2011 17:00:58 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id A63B88FC13 for ; Wed, 1 Jun 2011 17:00:58 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 4901946B0D; Wed, 1 Jun 2011 13:00:58 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id D08758A01F; Wed, 1 Jun 2011 13:00:57 -0400 (EDT) From: John Baldwin To: freebsd-current@freebsd.org Date: Wed, 1 Jun 2011 12:59:45 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110325; KDE/4.5.5; amd64; ; ) References: <20110531202142.GA7105@onelab2.iet.unipi.it> In-Reply-To: <20110531202142.GA7105@onelab2.iet.unipi.it> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201106011259.45652.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Wed, 01 Jun 2011 13:00:57 -0400 (EDT) Cc: Luigi Rizzo Subject: Re: "lazy" mmap for a device driver ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jun 2011 17:00:58 -0000 On Tuesday, May 31, 2011 4:21:42 pm Luigi Rizzo wrote: > hi, > i have a kernel module implementing a memory mapped special device > which exports a large block of memory to the process. > I see that when the process calls mmap(), my routine foo_mmap() > is called immediately once per page, even though the process is > not actually touching the pages. I believe this happens > through dev_pager_alloc(). Yes, this is to verify that all the pages in the mmap() request are permitted for access so that an error can be returned to userland if it maps an invalid region of the device's virtual address space. > Right now i can live with that because all the memory is allocated > at module load time, but i might want to have a sparse memory > region which is populated dynamically, so i was wondering if > there is a way to achieve this. I see there are two other > device routines, d_mmap2 and d_mmap_single, any pointer to > documentation or comments on how they differ ? d_mmap2 is an ABI hack in 7/8, it is identical to d_mmap in 9. d_mmap_single() allows a driver to "claim" an entire mmap() request and return an arbitrary VM object. If all you need is a random assortment of pages of a fixed size object that is shared between userland and the kernel, you can create an OBJT_DEFAULT VM object and let it fault in pages on demand perhaps. You would need to be careful to wire the pages if you are going to access them from the kernel. -- John Baldwin