Re: [PATCH 00/10] PCI: Improve head free space usage

From: Bjorn Helgaas

Date: Thu Mar 26 2026 - 15:25:35 EST


[+cc Xifer; thanks very much for reporting and testing!]

On Tue, Mar 24, 2026 at 06:56:23PM +0200, Ilpo Järvinen wrote:
> Hi all,
>
> This series attempts to take advantage of free head space (the free
> space before the aligned start address) in order to generally produce a
> tighter packing of the resources/bridge windows.
>
> The recent changes to the resource fitting algorithm caused resource
> allocation failures in some cases where a bridge window that is sized
> to be gapless could no longer be assigned. The previous algorithm left
> a huge gaps which allowed it to place the remainder (non-aligning part
> of the size) before the start address of used for the gapless fit,
> whereas the new gapless approach always had to place the remainder
> after the aligning part of the resources. There is not always space
> for the remainder triggering those failures (e.g., when the aligning
> part must be placed at the top of the window).
>
> This series attempts to allow placing the remainder once again before
> the aligning part, but now without leaving huge gaps to retain the
> benefits of the gapless bridge windows. The approach is somewhat hacky
> but should work thanks to PCI resources fundamentally consisting only
> power-of-two atoms.
>
> There maybe cases where architecture would not want to do such
> relocation. This series adds the relocation to arch
> pcibios_align_resource() functions to allow all of them taking
> advantage of the better resource packing but if somebody objects doing
> this relocation for a particular arch, I can remove it, please just let
> me know (this relocation doesn't seem critical unless there are
> regressions).
>
> Ilpo Järvinen (10):
> resource: Add __resource_contains_unbound() for internal contains
> checks
> resource: Pass full extent of empty space to resource_alignf CB
> resource: Rename 'tmp' variable to 'full_avail'
> ARM/PCI: Remove unnecessary second application of align
> am68k/PCI: Remove unnecessary second application of align
> MIPS: PCI: Remove unnecessary second application of align
> parisc/PCI: Cleanup align handling
> PCI: Rename window_alignment() to pci_min_window_alignment()
> PCI: Align head space better
> PCI: Fix alignment calculation for resource size larger than align
>
> arch/alpha/kernel/pci.c | 1 +
> arch/arm/kernel/bios32.c | 9 ++++---
> arch/m68k/kernel/pcibios.c | 8 +++++--
> arch/mips/pci/pci-generic.c | 8 ++++---
> arch/mips/pci/pci-legacy.c | 3 +++
> arch/parisc/kernel/pci.c | 17 ++++++++------
> arch/powerpc/kernel/pci-common.c | 6 ++++-
> arch/s390/pci/pci.c | 1 +
> arch/sh/drivers/pci/pci.c | 6 ++++-
> arch/x86/pci/i386.c | 5 +++-
> arch/xtensa/kernel/pci.c | 3 +++
> drivers/pci/pci.h | 3 +++
> drivers/pci/setup-bus.c | 15 ++++++++----
> drivers/pci/setup-res.c | 40 +++++++++++++++++++++++++++++++-
> drivers/pcmcia/rsrc_nonstatic.c | 3 ++-
> include/linux/ioport.h | 22 +++++++++++++++---
> include/linux/pci.h | 12 +++++++---
> kernel/resource.c | 33 +++++++++++++-------------
> 18 files changed, 149 insertions(+), 46 deletions(-)

I added Xifer's tested-by, fixed the "am68k" and missing "if"
typos, and applied these to pci/resource for v7.1.

Ilpo, if you post a v2 with more changes, I'll update to it. I
applied the series now to get a head start on 0-day building and into
next.