From owner-freebsd-hackers@FreeBSD.ORG Mon Feb 6 22:58:37 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org 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 CC6D016A420 for ; Mon, 6 Feb 2006 22:58:37 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (gate.funkthat.com [69.17.45.168]) by mx1.FreeBSD.org (Postfix) with ESMTP id ADFCE43D53 for ; Mon, 6 Feb 2006 22:58:36 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (ny870vo0ax7g4n56@localhost.funkthat.com [127.0.0.1]) by hydrogen.funkthat.com (8.13.3/8.13.3) with ESMTP id k16MunbK067011; Mon, 6 Feb 2006 14:56:49 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.13.3/8.13.3/Submit) id k16Mun4Y067010; Mon, 6 Feb 2006 14:56:49 -0800 (PST) (envelope-from jmg) Date: Mon, 6 Feb 2006 14:56:49 -0800 From: John-Mark Gurney To: Raaf Message-ID: <20060206225649.GJ69162@funkthat.com> Mail-Followup-To: Raaf , freebsd-hackers@freebsd.org References: <43E7C583.3040904@luna.afraid.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43E7C583.3040904@luna.afraid.org> User-Agent: Mutt/1.4.2.1i X-Operating-System: FreeBSD 5.4-RELEASE-p6 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: Freeing mmapped memory X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 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 Feb 2006 22:58:37 -0000 Raaf wrote this message on Mon, Feb 06, 2006 at 22:54 +0100: > Hi, i am working on a usb driver that allocates some memory when > the device is opened using malloc. > > Now i want user processes to be able to access this memory using > mmap and i want to free this memory when it is no longer needed. > > The problem is that there seems to be no way of knowing for my > driver at what time the memory is no longer mapped in a process > address space so that i can safely free this memory. why not at close time? I would imagine that the device won't be closed until all the mmap's that are backed by the device are unmapped.. it shouldn't be hard to test... the mapping should hold a reference to the device until it's munmapped.. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."