Re: [PATCH v3 33/51] resources: Make allocate_resource return just fit resource

From: Yinghai Lu
Date: Wed Aug 19 2015 - 03:22:18 EST


On Mon, Aug 17, 2015 at 9:21 PM, Bjorn Helgaas <bhelgaas@xxxxxxxxxx> wrote:
> On Mon, Jul 27, 2015 at 04:29:51PM -0700, Yinghai Lu wrote:
>> Find all suitable empty slots and pick one just fit, so we could save
>> the big slot for needed ones later when we have several pcie switches
>> and some bridges get assigned bios and we need to assign others in kernel.
>
> By "just fit," do you mean "best fit"? "Best fit" is a well-known term, so
> if that's what you mean, let's use it.

Sure. Thanks for dig that URL out.

>
> I couldn't quite parse the PCIe switch stuff here. How is that relevant to
> this change?

That is most use cases. One parent have several child bridges, and BIOS does
poor jobs and only resources to some child bridges. Kernel need to assign
for others. so before kernel start, parent resource window already have
several blank slots instead of one big chunk. then we need to make sure
first come only take best fit and leave big one for possible late comer.

>
> Allocating memory and building a list in a function that allocates space
> seems like a little bit of a hack. I think we're holding resource_lock
> anyway; can't we just find a candidate, reserve it, look for another one,
> reserve it, release the larger one, and repeat?

We need to reserve the all avail windows before pick up one window.

for examples: we have window
[0xc0000000, 0xd0000000), and [0xe0000000,0xe1000000)

and we try allocate 0x200000 size resources.

in this patch will reserve [0xc0000000, 0xd0000000) and
[0xe0000000,0xe1000000) at first, then pick [0xe0000000,0xe1000000)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/