Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 Jul 2001 13:44:25 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Zhihui Zhang <zzhang@cs.binghamton.edu>
Cc:        Bosko Milekic <bmilekic@technokratis.com>, Alfred Perlstein <bright@mu.org>, vishwanath pargaonkar <vishubp@yahoo.com>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: cluster size
Message-ID:  <3B632429.D3FA2EB0@mindspring.com>
References:  <Pine.SOL.4.21.0107272018280.13783-100000@opal>

next in thread | previous in thread | raw e-mail | index | archive | help
Zhihui Zhang wrote:
> I thought doing a memory free is always safe in an interrupt context. Now
> it seems doing an allocation of memory is safe too.  Does MCLGET() call
> vm_page_alloc() or malloc() eventually?  If so, it might block.

The mbuf allocator uses the zone allocator.

The reason this works at interupt is that the page table
entries for the memory are already in place in the kernel,
but the actual allocations have not taken place.

When you are running with less than a full complement of
RAM (e.g. 4G on a 32 bit Intel machine), this will permit
you to do the allocations of physical RAM later, and have
a KVA (kernel virtual address) space that exceeds the amount
of physical memory.

In practice, this means that your system is not specifically
tuned for particular loading, until the memory is committed
(when that happens, say, by using all possible mbufs, then
you are unable to recover the memory to the system memory
pool: it has become type stable).  This lets you have a mostly
general system that then commits resources based on the
character of its load, yet which does not permit the character
of the load to change over time.

When you have all the memory you can address in physical
space, then the problem changes somewhat, and you basically do
not overcommit resources.

The upshot of having the page descriptors preallocated,
however, is that you can allocate in interrupt context, and
the zone headers are statically allocated at compile time,
instead of being malloc'ed later in the kernel boot cycle.

You should look at the "ziniti" and "zalloci" code: the zone
allocator code.  The mbuf issue has recently been a bit
obfuscated by the -current commit of a replacement allocator,
which is mbuf specific.  I think this new allocator has some
unforgivable drawbacks; you yould be better off looking at
the 4.3 kernel source code to get an idea of why interrupt
allocations work.

So, in general:

1)	Only some allocators can be used at interrupt time
2)	If they can, they must precommit kernel address space
	to the task
3)	Once memory is allocated from one of these pools, it
	is never returned to the system for reuse
4)	The general malloc() code _can not_ be used at interrupt
	time in FreeBSD (but SVR4's allocator can).

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




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