Subject: Re: special treatment of "residual" buffers in machdep.c?
To: None <tls@rek.tjls.com>
From: Chris G Demetriou <Chris_G_Demetriou@auchentoshan.pdl.cs.cmu.edu>
List: tech-kern
Date: 12/08/1996 12:53:43
> > base = bufpages / nbuf;
> > residual = bufpages % nbuf;
> > for (i = 0; i < nbuf; i++) {
> > vm_size_t curbufsize;
> > vm_offset_t curbuf;
> >
> > /*
> > * First <residual> buffers get (base+1) physical pages
> > * allocated for them. The rest get (base) physical pages.
> > *
> > * The rest of each buffer occupies virtual space,
> > * but has no physical memory allocated for it.
> > */
> > curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
> > curbufsize = CLBYTES * (i < residual ? base+1 : base);
> > vm_map_pageable(buffer_map, curbuf, curbuf+curbufsize, FALSE);
> > vm_map_simplify(buffer_map, curbuf);
>
> A) Often (usually?) nbuf = bufpages. So this does nothing.
No, normally it allocates 'base' (== 1) pages for all buffers, since
nbuf == bufpages.
> B) Isn't it wrong, anyway? Let's say I've got nbuf = 512, and
> bufpages = 768. I'll allocate 512 pages to the "residual" buffers,
> and 512 pages to the rest of the buffers, for a total of 1024
> pages allocated.
In a word, No. (Or at least, at not time that i've looked at it have
i noticed a bug in the code, and as far as i can tell the calculation
is mathematically sound. 8-) walk through the code.
the algorithm boils down to:
for (each buffer) {
if (this buffer is a residual buffer)
allocate it (base + 1) pages
else
allocate is (base) pages
}
residual = bufpages % nbuf
and therefore "not_ residual" is "nbuf - (bufpages % nbuf)".
base is (bufpages / nbuf).
Therefore, your total allocation ends up being:
(residual) * (base + 1) + (not_residual) * (base)
also known as:
(residual + not_residual) * base + residual.
or:
(nbuf) * (bufpages / nbuf) + (bufpages % nbuf)
which is "bufpages." 8-)
chris