Subject: Re: uvm_km_free() does not unloan implicitly?
To: Jaromr Dolecek <>
From: Chuck Cranor <>
List: tech-kern
Date: 10/10/2001 21:06:46
On Tue, Sep 18, 2001 at 11:36:04PM +0200, Jaromr Dolecek wrote:
> and ^C it, kernel with NEW_PIPE leaks the amount of memory used
> for memory loan for the write(2) call to pipe (this is 1MB, or
> PIPE_DIRECT_CHUNK of memory). The 1MB of memory also stays wired
> (the wiring is done implicitly for LOAN_TOPAGE in uvm_loan()). I've
> tested this with both TOPAGE and TOANON loans, and it happens for
> both, though no wiring happens for TOANON case, of course.
> If I add appropriate uvm_unloanFOO() call before uvm_km_free() of
> the kva used for loaned memory in pipe_loan_free(), no memory leak
> occurs.
> Up to now, I though that uvm_km_free() of kva using the loaned
> memory pages would implicitly 'unloan' up the loaned pages. Either this
> is not done, or I still miss something.
> Is this supposed to work this way, or is this a bug?

hmmm, i dug through my notes and memory and what i recall is:

  to page: the idea is that you are gaining a loan reference here
	   for some special kernel use of the memory and thus you 
	   should unloan it to get rid of the pages.

	   it does currently wire the pages (following the logic
	   that all kernel allocated memory is wired), but in an
	   email from chuck silvers (which you have been cc'd on)
	   we believe that this may not be necessary given the 
	   protection already in place.    chuck proposed an 
	   optimization where we bypass the wire on the pages (assuming
	   the non-zero loan count on the page is good enough).

  to anon: the idea is that you are encapsulating some memory pages
	   in an anon for insertion into an amap in a process.  the 
	   pages can either come from other anons or can be pages from
	   a uvm_object.

	   in this case the control of the memory is turned over to
	   the anon/amap subsystem and you shouldn't need to unloan
	   it (_provided_ you insert it in a map somewhere so that it
	   can be unmapped later).    if you loan it to an anon and 
	   then decide you don't want it, then the idea was that you'd
	   unloan it to get rid of it.

does this match the behavior you are seeing now?   [i realize your
msg is somewhat old now so things may have changed ... i have been 
off-line from all mailing lists since the attack on WTC took out the 
network connection for   thanks to kimmo suominen, 
et al.  for getting back on the air...]