Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×

Which Filesystem is Best for CompactFlash? 100

HungWeiLo asks: "We're currently using a Debian-based distribution for an embedded device where we're placing our primary kernel and filesystem on a 1GB CompactFlash card. The kernel will be placed in a read-only partition, while the other partition will be used for logging actions in the system and hosting a flatfile database. The concern here is the need to journalize the data (ext2 corrupts pretty badly since we power it on and off), and the need to minimize thrashing of the CompactFlash (we're using industrial-strength, million-write-cycle+ versions, but that can quickly get us into trouble if the filesystem constantly writes to the flash). Does anyone have any experience using filesystems in this situation? Which one should I look into for this type of application? Ext2? Ext3? Reiser? JFFS2? Help!"
This discussion has been archived. No new comments can be posted.

Which Filesystem is Best for CompactFlash?

Comments Filter:
  • by notarus ( 216298 ) on Thursday October 19, 2006 @06:52PM (#16509757)

    I run about a dozen machines running pebble (and soon, voyage) which are both debian based CF distros, and we don't have much problem with them at all. They get powered on and off a lot, I do quite a few live updates of specific files, etc, no problems.

    Is it possible you're not actually suffering FS corruption but instead having problems with CF that just isn't suited for the task? We started this project using kingston, which is good flash for cameras, but we ran into lots of dead sectors. We've been using Lexar since, with no issues at all (of the 13 machines, i think we've lost 1 sector in 2 years).

  • by toby ( 759 ) * on Thursday October 19, 2006 @07:26PM (#16510145) Homepage Journal
    You probably want a filesystem tailored to Flash characteristics, such as YAFFS [aleph1.co.uk].
  • jffs was designed (Score:2, Informative)

    by elhedran ( 768858 ) on Thursday October 19, 2006 @07:28PM (#16510173)
    http://en.wikipedia.org/wiki/JFFS2 [wikipedia.org]

    If you did even a small amount of research you would have seen that JFFS2 was designed for flash memory devices, and has journaling. Its a little harder to make file systems for (at least the last time I was doing so) but given your criteria its what you are looking for.
  • by davidwr ( 791652 ) on Thursday October 19, 2006 @07:43PM (#16510363) Homepage Journal
    Before you settle on an answer, pick 2 or 3 possible solutions do some real-world experiments to make sure the chosen solution 1) works well and 2) isn't inferior to another candidate solution.

    Don't discount unsophisticated filesystems such as FAT and its variations.

    For the read-only filesystem, FAT, MINIX, or even a read-only OS like cramfs might be better under certain circumstances.

    Whatever filesystem you use, consider immediate-write-commit for file-system operations or better yet all operations rather than worrying about journaling. Write-on-commit everything is a little slow but it's hard to beat for data integrity after sudden power loss.

    As for thrashing due to memory limits - don't use swap space. Ante up for more memory and write your code so it fails gracefully if it is out of RAM.

    Consider having your power-down the desktop equivalent of "sleep" or "hibernate" rather than "off." That way, you either never save RAM or only save it at power-off. Use battery-backed-up RAM or NVRAM to make the "sleep" mode if you have to. These also mostly-solve the journaling problem, as you won't have a lot of unexpected fresh-starts.
  • by duguk ( 589689 ) <dug@frag.co.CURIEuk minus physicist> on Thursday October 19, 2006 @08:18PM (#16510777) Homepage Journal
    I had something similar with an SD Card, it would refuse to format and was unformattable. I found some app - smformat I've used before which has helped, I found it again linked here: http://ask.metafilter.com/mefi/22771 [metafilter.com]

    You can download the program from here [totalbiscuit.com] - even though its a totally unrelated problem I think this might help ya.

    Can't guarantee it'll work or if its not spyware but it's worked for me before :)
  • by oz_paulb ( 617486 ) on Thursday October 19, 2006 @08:45PM (#16511023)
    not sure exactly what you're saying, but I'll take a stab at answering...

    Media with built-in wear-levelling (CF Flash, for example) use whatever methods/structures/etc that they want to keep track of flash blocks, how often they've been written/erased/etc (the 'media' is actually storage media (like NAND flash) plus some sort of microcontroller to implement the wear levelling). This underlying physical structure is hidden from the application/filesystem code. Instead, a 'virtual disk drive' of "N" 512-byte logical sectors is presented to the application/FS code (for example, to the FAT filesystem).

    When FAT wants to update (example) 'sector 2' of the 'drive', it asks the CF drive to do this. The CF drive may end up moving a bunch of data around, erasing/rewriting physical blocks, discarding bad blocks, etc, and may actually write the updated data to 'block 500' on the flash array. The underlying CF structures keep track of where 'logical sector 2' exists in the physical media - even after things are rearranged.

    So, the app/FS code doesn't need to worry about wear levelling - it's taken care of.

    On the other hand, if the app/FS code is written with the underlying media type in mind (example: NAND flash), and does its own wear levelling/bad block management, it's possible that this would be more efficient/do a better job than the 'virtual layer' created by media like CF Flash.

  • by big daddy kane ( 731748 ) on Thursday October 19, 2006 @09:41PM (#16511497)
    YAFFS [aleph1.co.uk] might be a better choice. It only works on NAND flash memory (but IIRC compact flash is NAND), but should be a bit faster (mounts writes etc) than JFFS2. However, if you're using compact flash (which includes hardware block mapping) you DO NOT want to use a specialized file system. The point of block mapping flash memory is to present the drive as a traditional hard disk, so traditional FS's can be used on it. If you use a specialized (or write heavy) FS on a block mapped chip you'll most likley end up doing more harm than good. Plus, YAFFS in particular requires specific hardware functions of flash chips (such as OOB write access) that are abstracted by the block mapping layer.
  • by KonoWatakushi ( 910213 ) on Thursday October 19, 2006 @09:58PM (#16511613)
    Actually, there would be little wear from the uberblocks; there are 128 of them written in sequence every 5 seconds or so. As such, it would take nearly three years of constant use for them to reach their wear limit. Even with no wear leveling, ZFS would be an excellent filesystem for flash.

    Furthermore, when blocks inevitably do go bad, ZFS can detect and correct the faulty blocks. At present, this only applies to metadata, though it will be possible to replicate data as well in the future. ZFS uses replicated metadata for pool and filesystem structures, making it nearly impossible to damage an entire filesystem or pool. Even if data blocks are damaged, in addition to maintaining access to all other good data, you will know exactly what has been lost.

    While I'm not 100% certain, I don't think most flash uses ECC. Once blocks start going bad, other filesystems will simply fall apart.
  • by Anonymous Coward on Thursday October 19, 2006 @11:24PM (#16512287)
    I can testify from personal experience doing the same thing that if you power down a CF card while it is writing, you will get a bad sector. It can be recovered by rewriting it, but the sector is unreadable. (Tested on SanDisk and Lexar brand cards; that was enough to convince me that I needed a file system that could cope.)

    Thus, any classical fixed-location file system (inode or FAT style) is NOT suitable for embedded appliance use on compactFlash cards.

    This severely pissed me off, because the essence of wear-leveling is out-of-place writes, and I just assumed that any CF manufacturer with an ounce of brains would implement a two-phase commit, ao each sector write would be atomic: after a power cycle, either you'd see the new contents, or the old contents, but never anything else. The window is narrow, so I hadn't noticed it during development; we had shipped products and got field failures. :-( (And, of course, replacing the main file system is not a "quick patch.")

    It MAY be possible to adapt a block-based journaling FS like Ext3 to this brain-damage, since it can unconditionally replay the journal on power-up and overwrite the problematic sectors. You just need to ensure that single-block corruption can't mess up the journal. or the superblock. And you need to journal the data as well as the metadata.
  • by Ristretto ( 79399 ) <emery@@@cs...umass...edu> on Thursday October 19, 2006 @11:37PM (#16512383) Homepage
    Here's a transactional file system (& more) developed at UMass Amherst that sounds like it might fit your needs. I've boldfaced the key line.
    Recent gains in energy-efficiency of new-generation NAND flash storage have strengthened the case for in-network storage by data-centric sensor network applications. We argue that a simple file system abstraction is inadequate for realizing the full benefits of high-capacity low-power NAND flash storage in data-centric applications. Instead we advocate a rich object storage abstraction to support flexible use of the storage system for a variety of application needs and one that is specifically optimized for memory and energy-constrained sensor platforms. We propose Capsule, an energy-optimized log-structured object storage system for flash memories that enables sensor applications to exploit storage resources in amultitude of ways.
    1. Capsule features:
    2. Capsule provides the abstraction of typed storage objects to applications; supported object types include streams, indexes, stacks and queues. A novel aspect of Capsule is that it also allows composition of objects for instance, a stream and index object can be composed to archive sensed data. The objects expose a data structure-like interface, allowing applications to easily manipulate data.
    3. Capsule seamlessly supports storage on a multitude of platforms (both NAND and NOR flashes) with the help of a hardware abstraction layer; the same application can be used on any supported platform. Currently we support storage on the following platforms: Mica2, MicaZ, Mica2 Dot, Telos and our custom NAND flash board. However, the use of an abstraction layer allows supporting a new platform a breeze.
    4. Capsule supports checkpointing and rollback of storage objects, allowing the application to tolerate software faults and device failures. The application state is automatically restored when the device restarts.
    5. We provide our own file system implementation on Capsule that allows applications using Matchbox and ELF to be ported to Capsule.
    6. Flash offers a finite storage medium; once it fills up, free space needs to be created before any further data can be stored on it. Basic Capsule objects perform memory reclamation by supporting compaction.
    Click here for the Capsule site [umass.edu]. It's been deployed on a number of very small platforms (including turtles [umass.edu] (!)).

    -- Emery Berger [umass.edu], Dept. of Computer Science, UMass Amherst

  • by r00t ( 33219 ) on Friday October 20, 2006 @12:13AM (#16512595) Journal
    Normally, JFFS2 won't even run on a normal block device. It expects raw flash. There is a driver that adapts it though, but...

    CompactFlash looks like IDE, not raw flash. CompactFlash has built-in wear leveling. It's designed to support the typical FAT filesystem that normal people use. All the fancy wear-leveling things in JFFS2 will be wasted.

    Of course, the other filesystems are lame too. The others are optimized for rotating media, so they waste space and CPU time trying to avoid disk seeks.

    CompactFlash and similar devices really could use special filesystems optimized for the odd combination of near-free seeks and device-supplied wear leveling.
  • by MikeFM ( 12491 ) on Friday October 20, 2006 @01:25AM (#16512963) Homepage Journal
    I use ext3 but make the filesystems read-only and I don't record access times. I store temp files on ramdisks formatted as ext2. I simply avoid writing to the CF whenever posible as I know it'll shorten their life to do so and that CF will never be the best solution for real data storage. I use either normal hdd or network for data storage. CF does make for fast load time of apps in my experience so the OS and frequently used programs and libraries I do try to keep on the CF.
  • by mnmn ( 145599 ) on Friday October 20, 2006 @01:40AM (#16513029) Homepage
    He can always use the MR2A16A chips if he can make his own circuitboard.

    These are MRAM chips. Fast as flash but as reliable as ram. Write, page and thrash all you want.
  • by Anonymous Coward on Friday October 20, 2006 @06:21AM (#16514251)
    Alternatively, you could hack the Linux kernel to do write caching to battery-backed static RAM, then read it back in like a journal when the hardware comes back.
    There's no need to hack the kernel. Most journaling filesystems already support external journals, so all you need it a few megabytes of SRAM accessible as a block device. Many of the IPC boards that support Disc-On-Chip also support Battery buffered SRAM in the same socket.
  • by Not Invented Here ( 30411 ) on Friday October 20, 2006 @10:44AM (#16516097)
    Sadly, I can only provide a few tantalising hints. Not because I'm sitting on the information, but because very few people have written about this, and I haven't yet tried it myself.

    Wikipedia on xD cards [wikipedia.org]
    Instructions to fit an xD card to a Mattel Juicebox [elinux.org]
    A comment on LWN from Wookey, who knows a lot about flash [lwn.net]
    xD card pinout [pinouts.ru]

    My best advice is to ask people on the linux-mtd mailing list [infradead.org] for specific details.
  • by Anonymous Coward on Friday October 20, 2006 @02:12PM (#16519039)
    have you ever heard of tmpfs

UNIX is hot. It's more than hot. It's steaming. It's quicksilver lightning with a laserbeam kicker. -- Michael Jay Tucker

Working...