From owner-freebsd-hackers@FreeBSD.ORG Mon Dec 6 07:42:38 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DDBF216A4CE for ; Mon, 6 Dec 2004 07:42:38 +0000 (GMT) Received: from mail6.speakeasy.net (mail6.speakeasy.net [216.254.0.206]) by mx1.FreeBSD.org (Postfix) with ESMTP id 95ABC43D5C for ; Mon, 6 Dec 2004 07:42:38 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: (qmail 19147 invoked from network); 6 Dec 2004 07:42:38 -0000 Received: from gate.funkthat.com (HELO hydrogen.funkthat.com) ([69.17.45.168]) (envelope-sender ) by mail6.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 6 Dec 2004 07:42:38 -0000 Received: from hydrogen.funkthat.com (rgripy@localhost.funkthat.com [127.0.0.1])iB67gbGH002098; Sun, 5 Dec 2004 23:42:37 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.12.10/8.12.10/Submit) id iB67gbjh002097; Sun, 5 Dec 2004 23:42:37 -0800 (PST) Date: Sun, 5 Dec 2004 23:42:37 -0800 From: John-Mark Gurney To: "Kamal R. Prasad" Message-ID: <20041206074237.GP19624@funkthat.com> Mail-Followup-To: "Kamal R. Prasad" , freebsd-hackers@freebsd.org References: <41B20B19.3090204@acm.org> <20041206025126.GO19624@funkthat.com> <41B3F24B.1000903@acm.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41B3F24B.1000903@acm.org> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.2-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html cc: freebsd-hackers@freebsd.org Subject: Re: mmap() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: John-Mark Gurney List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Dec 2004 07:42:39 -0000 Kamal R. Prasad wrote this message on Mon, Dec 06, 2004 at 11:16 +0530: > John-Mark Gurney wrote: > > >Kamal R. Prasad wrote this message on Sun, Dec 05, 2004 at 00:38 +0530: > > > > > >>I wrote an mmap() interface for a USB device. But when I made a call to > >>it using mmap(), I saw that mmap interface is called 3-4 times. The > >>calls are being made from within mmap() i.e. sys/vm/vm_mmap.c. Can > >>someone tell me if there is something like a re-try going on for some > >>reason? > >>From userspace, I called it as > >>addr = mmap(NULL, 1024, PROT_READ, MAP_SHARED, fd, 0); > >>The version of OS is Freebsd 5.3(stable). > >> > >> > > > >each mmap call will be called whenever the kernel needs to map that > >specific page.. say you map 16k of your device... it won't map any > >of the 16k until the first time it is accessed, then it will call the > >mmap routine for each page as it is accessed... it is also possible that > >memory for the mappings needs to be reclaimed, at which point those page > >mappings will be reaped, and your mmap function will be called again when > >they need to be accessed again.. > > > > > > > Thanks. But then, the mmap'ed() address was yet to be used by the user > space and I don't see the need for multiple calls to my interface almost > as if in a while loop. Is there any return value from the mmap() > interface that could trigger another call? I am returning 0 after > setting the param to vtophys(kernel virtual address). You are suppose to return 0 on success (that the permission are correct and doable i.e. that you can write when the write bit is set) and put the phys adder in paddr... If you look at sys/vm/device_pager.c, you'll see that on line 139, it makes sure that the permissions are correct for the entire mapping (that the user doesn't try to map for writing a read-only mapping)... Then later at line 222, is when the actual mapping gets done.. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."