Skip to contentSkip to conversation

generic device DMA (dma_pool update)

PATCH Adam J. Richter 3 participants 3 messages Jan 2, 2003

lore
Share & tools
lore
#0 lore raw
Quoted 8 lines · David Brownell
Quoted 7 lines · James Bottomley
Quoted 3 lines · [email protected] said:

Can someone show me or invent an example of two different uses of
dma_alloc_coherent that really should use different policies on whether to block or not?

Quoted 8 lines
Quoted 4 lines

The obvious one is allocations from interrupt routines, which must be GFP_ATOMIC (ignoring the issue of whether a driver should be doing a memory allocation in an interrupt). Allocating large pools at driver initialisation should probably be GFP_KERNEL as you say.

More: not just "from interrupt routines", also "when a spinlock is held". Though one expects that if a dma_pool were in use, it'd probably have one of that kind of chunk already available (ideally, even initialized).

Let me clarify or revise my request. By "show me or invent an
example" I mean describe a case where this would be used, as in specific hardware devices that Linux has trouble supporting right now, or specific programs that can't be run efficiently under Linux, etc. What device would need to do this kind of allocation? Why haven't I seen requests for this from people working on real device drivers? Where is this going to make the kernel smaller, more reliable, faster, more maintainable, able to make a computer do something it could do before under Linux, etc.?

I have trouble understanding why, for example, a USB hard
disk driver would want anything more than a fixed size pool of transfer descriptors. At some point you know that you've queued enough IO so that the driver can be confident that it will be called again before that queue is completely emptied.

Quoted 2 lines

Many task-initiated allocations would use GFP_KERNEL; not just major driver activation points like open().

Here too, it would help me to understand if you would try
to construct an example.

Also, your use of the term GFP_KERNEL is potentially
ambiguous. In some cases GFP_KERNEL seems to mean "wait indifinitely until memory is available; never fail." In other cases it means "perhaps wait a second or two if memory is unavailable, but fail if memory is not available by then."

I don't dispute that adding a memory allocation class argument
to dma_alloc_consistent would make it capable of being used in more cases. I just don't know if any of those cases actually come up, in which case the Linux community is probably better off with the smaller kernel footprint.

Adam J. Richter     __     ______________   575 Oroville Road
[email protected]     \ /                  Milpitas, California 95035
+1 408 309-6081         | g g d r a s i l   United States of America

"Free Software For The Rest Of Us."

#1 lore raw
Quoted 9 lines · [email protected] said:

Let me clarify or revise my request. By "show me or invent an
example" I mean describe a case where this would be used, as in specific hardware devices that Linux has trouble supporting right now, or specific programs that can't be run efficiently under Linux, etc. What device would need to do this kind of allocation? Why haven't I seen requests for this from people working on real device drivers? Where is this going to make the kernel smaller, more reliable, faster, more maintainable, able to make a computer do something it could do before under Linux, etc.?

I'm not really the right person to be answering this. For any transfer you set up (which encompasses all of the SCSI stuff bar target mode and AENs) you should have all the resources ready and waiting in the interrupt, and so never require an in_interrupt allocation.

However, for unsolicited transfer requests---the best example I can think of would be incoming network packets---it does make sense: You allocate with GFP_ATOMIC, if the kernel can fulfil the request, fine; if not, you drop the packet on the floor. Now, whether there's an unsolicited transfer that's going to require coherent memory, that I can't say. It does seem to be possible, though.

James

#2 lore raw
In reply to Adam J. Richter

Hi Adam,

Note that this "add gfp flags to dma_alloc_coherent()" issue is a tangent to the dma_pool topic ... it's a different "generic device DMA" issue.

We already have the pci_pool allocator that knows how to cope (timeout and retry) with the awkward semantics of pci_alloc_consistent() ... likewise, we can tell that those semantics are problematic, both because they need that kind of workaround and because they complicate reusing "better" allocator code (like mm/slab.c) on top of the DMA page allocators.

Quoted 4 lines

Let me clarify or revise my request. By "show me or invent an
example" I mean describe a case where this would be used, as in specific hardware devices that Linux has trouble supporting right now, or specific programs that can't be run efficiently under Linux, etc.

That doesn't really strike me as a reasonable revision, since that wasn't an issue an improved dma_alloc_coherent() syntax was intended to address directly.

To the extent that it's reasonable, you should also be considering this corresponding issue: ways that removing gfp_flags from the corresponding generic memory allocator, __get_free_pages(), would be improving those characteristics of Linux. (IMO, it wouldn't.)

Quoted 5 lines

I have trouble understanding why, for example, a USB hard
disk driver would want anything more than a fixed size pool of transfer descriptors. At some point you know that you've queued enough IO so that the driver can be confident that it will be called again before that queue is completely emptied.

For better or worse, that's not how it works today and it's not likely to change in the 2.5 kernels. "Transfer Descriptors" are resources inside host controller drivers (bus drivers), allocated dynamically (GFP_KERNEL in many cases, normally using a pci_pool) when USB device drivers (like usb-storage) submit requests (URBs).

They are invisible to usb device drivers, except implicitly as another reason that submitting an urb might trigger -ENOMEM.

And for that matter, the usb-storage driver doesn't "fire and forget" as you described; that'd be a network driver model. The storage driver needs to block till its request completes.

Quoted 5 lines

Also, your use of the term GFP_KERNEL is potentially
ambiguous. In some cases GFP_KERNEL seems to mean "wait indifinitely until memory is available; never fail." In other cases it means "perhaps wait a second or two if memory is unavailable, but fail if memory is not available by then."

Hmm, I was unaware that anyone expected GFP_KERNEL (or rather, __GFP_WAIT) to guarantee that memory was always returned. It's not called __GFP_NEVERFAIL, after all.

I've always seen such fault returns documented as unrelated to allocator parameters ... and treated callers that break on fault returns as buggy, regardless of GFP_* parameters in use. A random sample of kernel docs agrees with me on that: both in Documentation/* (like the i2c stuff) or the O'Reilly book on device drivers.

- Dave