Skip to contentSkip to conversation

PATCH: Further aacraid work

DISCUSSION Andi Kleen 5 participants 8 messages Jun 17, 2004 – Jun 18, 2004 2 messages not in the archive SCSI

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

Andi Kleen

author
#2 lore raw
Quoted 10 lines · Anton Blanchard

Please divert some of your anger towards your manufacturer of dodgy hardware. Any sane hardware with an IOMMU handles this just fine. eg on ppc64 running a disk test:

sg size in out

1           3      47569
2           0       2591
3           0       1123
4           0        447
5           0        429
Quoted 5 lines

...
62 5095 0
64 47061 0

The IOMMU is taking 62-64 entry SG lists and producing 1-5 entry lists.

The AMD64 IOMMU could do it too (and the code to do it exists in 2.6). But the problem is that the current IO layer doesn't provide a sufficient fallback path when this fails. You have to promise in advance that you can merge and then later it's too late to change your mind without signalling an IO error.

This is a real problem on AMD64, because IOMMU aperture is relatively small and can fragment.

I had a chat with James about this at last year's OLS. The Consensus was iirc that it needs driver interface changes at least.

If there was a sane fallback path for this I would enable merging always (and add some fragmentation avoidance algorithms to the bitmap allocator to make failure less likely)

It's also a balancing act in terms of performance. The IOMMU setup is relatively slow (it has to do an PCI config space write and an uncached memory access), and it depends on the device if it's actually faster to go through the IOMMU. I did some benchmarks and it seems to help on MPT Fusion controllers, but slows down ethernet. Most probably we need an driver function call where the driver can tell the IOMMU layer "I am slow at merging; give me merged sg lists and i can handle errors by falling back"

Also of course when the merging is used you will always get addresses <32bit and can potentially use smaller descriptors. But again you need fallback, because on AMD64 the IOMMus can be quite small and it's possible to overflow them in extreme traffic situations.

-Andi

#3 lore raw
Quoted 5 lines · Andi Kleen

The AMD64 IOMMU could do it too (and the code to do it exists in 2.6). But the problem is that the current IO layer doesn't provide a sufficient fallback path when this fails. You have to promise in advance that you can merge and then later it's too late to change your mind without signalling an IO error.

I would rather see it below the I/O layer for things like AMD64. The reason I say this is that many drivers would suffer from iommu merging not gain, and others may have limits.

Something like

new_sglist = sg_squash(old_sglist, [target max segments], [max per seg])

could be used by drivers when appropriate to hand back a better sg list (or if not possible the existing one). That would put control rather closer to the driver.

Alan

#4 lore raw
Quoted 11 lines · Alan Cox

I would rather see it below the I/O layer for things like AMD64. The reason I say this is that many drivers would suffer from iommu merging not gain, and others may have limits.

Something like

new_sglist = sg_squash(old_sglist, [target max segments], [max per seg])

could be used by drivers when appropriate to hand back a better sg list (or if not possible the existing one). That would put control rather closer to the driver.

You can't quite do it like this. The problem is that IOMMU merging is an input to the bio routines. If you tell it you can merge, it will spit out a nice list which will merge down to your card segment limit.

If you don't merge though, the list will be way over the number of SG segments you are allowed.

There was an infrastructure proposed a year ago to allow a "bypass mode" per device which would do something like you want.

This is also a separate problem from the IOMMU running out of resources...

James

author
#5 lore raw
In reply to Alan Cox
Quoted 11 lines · Alan Cox

I would rather see it below the I/O layer for things like AMD64. The reason I say this is that many drivers would suffer from iommu merging not gain, and others may have limits.

Something like

new_sglist = sg_squash(old_sglist, [target max segments], [max per seg])

could be used by drivers when appropriate to hand back a better sg list (or if not possible the existing one). That would put control rather closer to the driver.

My understanding was that it was too late in the driver because the SG lists are already sized, because higher layer manage this. That is why the BIO_VMERGE_BOUNDARY define is checked by BIO, not the driver.

The input of sg_squash should not be an already mapped list (that would be too costly) better would be probably a pci_map_sg_merge() with hints that tries to merge and other than that works like normal pci_map_sg()

-Andi

#6 lore raw
Quoted 13 lines · Andi Kleen
Quoted 11 lines · Alan Cox

I would rather see it below the I/O layer for things like AMD64. The reason I say this is that many drivers would suffer from iommu merging not gain, and others may have limits.

Something like

new_sglist = sg_squash(old_sglist, [target max segments], [max per seg])

could be used by drivers when appropriate to hand back a better sg list (or if not possible the existing one). That would put control rather closer to the driver.

Quoted 8 lines

My understanding was that it was too late in the driver because the SG lists are already sized, because higher layer manage this. That is why the BIO_VMERGE_BOUNDARY define is checked by BIO, not the driver.

The input of sg_squash should not be an already mapped list (that would be too costly) better would be probably a pci_map_sg_merge() with hints that tries to merge and other than that works like normal pci_map_sg()

Well, that's why we don't enable BIO_VMERGE_BOUNDARY nor any of the merging at the BIO level, at least we didn't on ppc64 when I last worked on the code.

We let the BIO generate things that will always fit. We just have pci_map_* do merging on a "best it can" basis. Most of the time, it does end up merging a lot.

I don't think any driver control would help much here ...

Ben.

#7 lore raw
In reply to Alan Cox
Quoted 9 lines · Alan Cox
Quoted 5 lines · Andi Kleen

The AMD64 IOMMU could do it too (and the code to do it exists in 2.6). But the problem is that the current IO layer doesn't provide a sufficient fallback path when this fails. You have to promise in advance that you can merge and then later it's too late to change your mind without signalling an IO error.

Quoted 3 lines

I would rather see it below the I/O layer for things like AMD64. The reason I say this is that many drivers would suffer from iommu merging not gain, and others may have limits.

This reminds me of good ole IDE: the first-generation SATA controllers carry forward the limits of the older PCI IDE controllers: neither the S/G table nor any single S/G entry may span a 64K boundary.

In theory the block layer / SCSI layer DMA boundary stuff takes care of this -- but iommu merging _undoes_ the segment splitting that the hardware _requires_. Thus, in ata_fill_sg in libata-core.c, I re-split the S/G list after DMA-mapping it. A bit lame.

James and BenH discussed a solution at the DMA level, but I don't think anything ever happened.

Jeff

#8 lore raw
Quoted 2 lines · Jeff Garzik

James and BenH discussed a solution at the DMA level, but I don't think anything ever happened.

Actually, yes it did. I have the patches but they depend on another bio change which is still making its way through the process.

James

#9 lore raw
In reply to Andi Kleen
Quoted 6 lines

The AMD64 IOMMU could do it too (and the code to do it exists in 2.6). But the problem is that the current IO layer doesn't provide a sufficient fallback path when this fails. You have to promise in advance that you can merge and then later it's too late to change your mind without signalling an IO error.

Well, the way I do it on ppc64 works with failure cases too. The IO layer is given my phusical limitations, that is it provides me with an SG list that will always fit. If I can do merging, great, that will improve, but I don't enforce merging.

You could do exactly the same.

The problem I agree is that this forces the IO layer to give you small enough requests, it would be nice to have a "try big and retry smaller" path but that require invasive changes.

Quoted 2 lines

I had a chat with James about this at last year's OLS. The Consensus was iirc that it needs driver interface changes at least.

Ben.