[QUESTION] Need some explanations in regard to memory alignment ofrequests that a block device receives

From: Maxim Levitsky
Date: Fri Aug 13 2010 - 09:28:07 EST


Hi,

I currently am writing a block driver for Legacy Memory sticks.

I have few questions about that type of data my ->request will receive
from kernel.

First of all I think that by default, driver receives requests that
contains just one sector and it isn't in high memory.

However I am opting in to allow to receive requests that have many
sectors span several memory regions, and be in highmem).
The request is converted to scatterlist upon which I operate.
(Untill this point I did the same think Alex does in mspro_blk.c)

For simplicity lets assume 512 byte hardware sector size.

However is there a guarantee that incoming memory segments will be
aligned on 512 byte boundary?

If this isn't true I run into 2 problems:

1. Sector can span 2 pages. Therefore if I decide to do pio, and I use
kmap_atomic (because of highmem), I need first map 1st page, read/write
it, unmap it, and then then do the same with 2nd page.


2. Sectors can span 2 memory regions.
This is even worse. For DMA I would need to bounce the sector.
Also it becames very difficult to handle input on sector by sector basis
(short of bouncing everything...)


If the above is true (I hope), then I have different problem.

The problem is that I will have small buffer that will contain few
hardware sectors.
I currently allocate it using kmalloc.
However I want to send that buffer to same functions that deal with IO,
therefore I need it to be aligned on 512 byte boundary.

Is there a way to allocate aligned memory (short of allocating more and
aligning pointer manually which I hate to do)
Maybe I should just use __get_free_pages?
(I will need a buffer of page or two (once per driver load) I think).

Best regards,
Maxim Levitsky


--
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/