Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 11 Jul 2013 10:23:12 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-hackers@freebsd.org, mangesh chitnis <mngesh1@yahoo.com>
Subject:   Re: memmap in FreeBSD
Message-ID:  <201307111023.12908.jhb@freebsd.org>
In-Reply-To: <1373197303.40304.YahooMailNeo@web160703.mail.bf1.yahoo.com>
References:  <1373197303.40304.YahooMailNeo@web160703.mail.bf1.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307111023.12908.jhb>