From owner-freebsd-hackers@FreeBSD.ORG Thu Jul 11 17:41:29 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 0693C873 for ; Thu, 11 Jul 2013 17:41:29 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) by mx1.freebsd.org (Postfix) with ESMTP id D6F081C2E for ; Thu, 11 Jul 2013 17:41:28 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id E99EFB953; Thu, 11 Jul 2013 13:41:27 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org, mangesh chitnis Subject: Re: memmap in FreeBSD Date: Thu, 11 Jul 2013 10:23:12 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p25; KDE/4.5.5; amd64; ; ) References: <1373197303.40304.YahooMailNeo@web160703.mail.bf1.yahoo.com> In-Reply-To: <1373197303.40304.YahooMailNeo@web160703.mail.bf1.yahoo.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201307111023.12908.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Thu, 11 Jul 2013 13:41:28 -0400 (EDT) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Jul 2013 17:41:29 -0000 On Sunday, July 07, 2013 7:41:43 am mangesh chitnis wrote: > Hi, > > What is the memmap equivalent of Linux in FreeBSD? > > In Linux memmap is used to reserve a portion of physical memory. This is used as a kernel boot argument. E.g.: memmap=2G$1G will reserve 1GB memory above 2GB, incase I have 3GB RAM. This 1GB reserved memory is not visible to the OS, however this 1GB can be used using ioremap. > How can I reserve memory in FreeBSD and later use it i.e memmap and ioremap equivalent? > > I have tried using hw.physmem loader parameter. > I have 3 GB system memory and I have set hw.physmem=2G. > > > sysctl -a shows: > hw.physmem: 2.12G Note that 'hw.physmem=2G' is using power of 2 units (so 2 * 2^30), not power of 10. > hw.usermem: 1.9G > hw.realmem: 2.15G > > devinfo -rv shows: > ram0: > > 0x00-0x9f3ff > 0x10000000-0xbfedffff > 0xbff00000-0xbfffffff > > Here, looks like it is showing the full 3 GB mapping. ram0 is reserving address space, so it always claims all of the memory installed. > Now, how do I know which is that 1 GB available memory (In Linux, this memory is shown as reserved in /proc/iomem under System RAM) ? Also, which function(similar to ioremap) should I call to map the physical address to virtual address? There is currently no way to see the memory above the cap you set. In the kernel you could perhaps fetch the SMAP metadata and walk the list to see if there is memory above Maxmem (and if so it is presumably available for use). However, to map it you would need to use pmap_*() routines directly. Alternatively, you could abuse OBJT_SG by creating an sglist that describes the unused memory range and then creating an OBJT_SG VM object backed by that sglist. You could then insert that VM object into the kernel's address space to map it into the kernel, or even make it available to userland via d_mmap_single(), or direct manipulation of a process' address space via an ioctl, etc. -- John Baldwin