Question about CFI allocation

Josh Boyer jwboyer at gmail.com
Wed Jan 26 09:43:12 EST 2011


On Wed, Jan 26, 2011 at 6:09 AM, Mitsutaka Amano
<mitsutaka.amano at gmail.com> wrote:
> Hi all, I'm a newbie about mtd.
>
> I'm trying to use the cfi on the mpc85xx board. Part of mtdblock is
> used by rootfs. So I have questions.
>
> Why does CFI(or other flash memory) have to alloc to the vmalloc
> area(such as PHYSMAP or PHYSMAP_OF)?

The CFI code is not calling vmalloc explicitly.  It's calling ioremap,
which happens to come from vmalloc space on most (all?) architectures.
 It has to do that because otherwise the CFI driver can't get access
to the physical flash because of the MMU.

The mtdblock driver does call vmalloc explicitly and that is because
it creates a DRAM cache of the current eraseblock being written to.
If it didn't do that, every write to the block device would generate a
read/modify/erase/write cycle, which is fairly suboptimal.  So it will
cache the writes to that block until it moves onto the next block, at
which point it will flush the whole buffer back.  That helps with
performance and flash lifetime (somewhat), but it does mean that usage
of mtdblock can be prone to data loss in the event of a power failure,
panic, or some other reset.

It uses vmalloc because getting physically contiguous pages to cover a
whole eraseblock (often 128KiB in size), is both unnecessary and will
quite often fail after the board has been running for a bit due to
page fragmentation.

josh



More information about the linux-mtd mailing list