Skip to contentSkip to conversation

UBI: Unsorted Block Images

PATCH In review Artem Bityutskiy 11 participants 88 messages Mar 14, 2007 – Mar 26, 2007 Page 2 of 2

Subsystems (3)
lore
Share & tools
lore
#49 lore raw
In reply to David Woodhouse
Quoted 16 lines · David Woodhouse
Quoted 2 lines · Artem Bityutskiy

Guess why we still do not have a decent FTL? Because it is _difficult_.

No. We don't have a decent FTL because it's _pointless_. We've got basic implementations of FTL, NFTL, INFTL etc. for compatibility with PCMCIA stuff and DiskOnChip, but the fact remains that pretending to be a normal block device with atomically-overwritten 512-byte sectors is just _stupid_. You end up implementing a kind of pseudo-filesystem to do that, and then on top of that you put a 'normal' filesystem with no real knowledge about what's underneath. It's crap -- and as we currently have it, the top level file system doesn't even get to tell the underlying FTL that a given block can be discarded because it's no longer used. So during garbage collection the FTL even ends up copying crap around the medium that's no longer relevant.

Quoted 3 lines

This isn't DOS. We don't have to make our storage available through the restricted interface that INT 13h offers us. We can, and do, do better than that. And that's why we don't have a decent FTL implementation.

While I agree with you, I still think decent FTL (a) makes sense and is
(b) difficult.

a. Some people may be satisfied with FTL and enjoy all the block device-related software, which is huge benefit, although costs you performance. Yes, FTL moves garbage around, but who cares as long as the performance fits the system requirements.

b. It is certainly not easy.

But anyway, I agree with what you say, although you seem to be too assertive.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
maintainer
#50 lore raw
In reply to David Lang
Quoted 3 lines · David Lang

What Matt and Ted are looking at is the question 'are flash devices close enough to other block devices that it would make sense to change the existing linux definition of a block device to handle the special requirements of flash'

I've seen no real proposals about how this could be done, so it's a purely academic question. But I'm dubious. The block layer is optimised, perhaps unsurprisingly, for block devices. Making it handle our special case might be possible, but I don't really think it's likely to fly once it becomes real code and not just mental self-abuse. Hell, we haven't even got block _discard_ support merged yet, because it's too esoteric for people to care about.

The MTD API does need to be re-thought. It's no longer quite so unthinkable that we'll encounter flash sizes above 4GiB, and the way we (theoretically) handle asynchronous erases while read and write are synchronous is a bit icky. I'm not averse to using queues and making it look a _bit_ like block devices in some respects, but in practice I don't think it'll be very close at all.

The MTD API is intended to represent the raw capabilities of the underlying flash devices, with all the bizarre restrictions and features that the various types of flash chip have. If you want to use it as a block device, that's what translation layers are for.

Signature · 1 line
dwmw2
#51 lore raw

*sigh*

I really did not want to become involved in this. So please be nice and leave the flamethrower in your weapon closet or I will disappear again before you can say "fire".

Quoted 7 lines · David Woodhouse
Quoted 3 lines · David Lang

What Matt and Ted are looking at is the question 'are flash devices close enough to other block devices that it would make sense to change the existing linux definition of a block device to handle the special requirements of flash'

I've seen no real proposals about how this could be done, so it's a purely academic question.

What you have seen and shot down were patches to make mtd more generic. So let me just assume both mtd and jffs2 were generic, even though they currently aren't.

In very broad terms, an mtd is a device with:
1. a read operation
2. a write operation
3. an erase operation
4. a minimal write blocksize
5. a minimal erase blocksize
6. a method to query bad eraseblocks
7. a method to mark bad eraseblocks

Anything else? There are many more fields, but I believe this is the essential. point() and unpoint() were omitted, because they are just one option to provide XIP. filemap_xip.c is another used for block devices.

In very broad terms, a block device has:
1. a read operation
2. a write operation
3. some devices have an ioctl() for erase, but that is uncommon
4. a blocksize

What is missing? Obviously the erase operation needs to become a first-class citizen and block devices need two fields for the two meaningful blocksizes. And they need methods to query and set bad blocks.

So far it looks simple enough. Obviously there are many messy details left out, so it will be a lot of work in practice. So the question is:
is it worth it?

What are the gains from combining mtd and block devices?

[ And at this point I would like to state again that I don't want to become involved in the UBI discussion. The question whether two seperate subsystems make sense is quite independent and I don't want both discussions to get mixed up. ]

Jörn

Signature · 3 lines
He who knows others is wise.
He who knows himself is enlightened.
-- Lao Tsu
#52 lore raw
In reply to Josh Boyer
Quoted 1 line · Josh Boyer

Sure. But the larger question is *should* it be extended to do so.

Absolutely, and so let's focus on that.

Quoted 2 lines

Except that flash filesystems don't use block devices at all. They use MTD interfaces.

Yes, so that would be first issue. We would need to change the flash filesystems to the block interface issue, and expand the block device to use MTD. Now, maybe Matt is conversant about what would be involved to do this, but I will admit to being MTD ignorant. But if that's there is a huge impendance mismatch right there, that that might be enough to kill it right there.

Quoted 11 lines
Quoted 7 lines

high-level architecture of what UBI is trying to achieve. What are the interfaces at the top and the bottom of the stack? For example, the fact that UBI exports Logical Erase blocks that are not a power-of-two (possibly 128k minus 128 bytes) means that it certainly might not be a good match for the dm stack. But why is that the case? I can imagine good reasons for it, but a high-level description of the design decisions would be very useful.

Basically because you need to store metadata in each eraseblock (and not in OOB). That metadata consumes space reducing the usable storage in each eraseblock by an amount and making it no longer a power-of-two.

So this is probably a stupid question, but what drives the design decision to store the metadata in-band instead of out-of-band (and you don't have to answer me here; putting it in the overall system architecture document is just as good, and probably better. :-)

Quoted 7 lines
Quoted 4 lines

It would also help people understand why there are so many "units" in UBI, since hopefully the high-level documentation would explain why they fit together, and perhaps why some of the units weren't folded together. What value do they add as separate components?

Artem is reworking the units per your (and other's) suggestions. The debugging code is also being worked on.

As I mentioned to you in IRC, in the future if there is pending changes in response to reviewer comments, it might be a good idea to mention that, so that reviewers know not make those comments again, or worry that the comments had been ignored.

Quoted 11 lines
Quoted 5 lines

There are hints of the overall system architecture in some of the indivdual comments for data structures, but even reading all of those, there isn't quite enough for people to figure out what it is; and that may be causing some of these comments of people saying there's too much code to evaluate, or why didn't you do it *this* way?

Some of that can probably be added, sure. Though to be fair, it'll add even more lines to the patch and those links have been posted 4 times already. They're even posted at the start of _this_ thread. Having it in the patch under Documentation/ is a good idea, but you can't force people to read that before they comment on things.

Well, having spent some time looking at the FAQ's and all of the comments kernel docs embedded in the header files and source files, there are sections that I would move to an overall system architecture documentation, but there is still a lot that was missing that makes it hard to review the patches. I'm sure a lot of it is my own ignorance, but that's probably one of the challenges with the UBI layer; not as more people have a basic background in say say scheduling or VM or filesystem than there are people who have a basic background in flash devices.

Regards,

- Ted

#53 lore raw
Quoted 4 lines · Theodore Tso

So this is probably a stupid question, but what drives the design decision to store the metadata in-band instead of out-of-band (and you don't have to answer me here; putting it in the overall system architecture document is just as good, and probably better. :-)

Because
a. Many flashes have no out-of-band. We want to support them as well b. Modern MLC NAND flashes use _whole_ OOB for ECC and this is the modern trend.

I will update FAQ and add this there later.

Quoted 4 lines

As I mentioned to you in IRC, in the future if there is pending changes in response to reviewer comments, it might be a good idea to mention that, so that reviewers know not make those comments again, or worry that the comments had been ignored.

Teo, I wrote you 2 times that your point was understood and this would be fixed. You should not think your comments are ignored because they are not.

Quoted 9 lines

Well, having spent some time looking at the FAQ's and all of the comments kernel docs embedded in the header files and source files, there are sections that I would move to an overall system architecture documentation, but there is still a lot that was missing that makes it hard to review the patches. I'm sure a lot of it is my own ignorance, but that's probably one of the challenges with the UBI layer; not as more people have a basic background in say say scheduling or VM or filesystem than there are people who have a basic background in flash devices.

Docs and FAQ will be improved, this is a question of time.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#54 lore raw
Quoted 8 lines · Artem Bityutskiy
Quoted 4 lines

As I mentioned to you in IRC, in the future if there is pending changes in response to reviewer comments, it might be a good idea to mention that, so that reviewers know not make those comments again, or worry that the comments had been ignored.

Teo, I wrote you 2 times that your point was understood and this would be fixed. You should not think your comments are ignored because they are not.

Artem, no need to be defensive. You did tell me that you were going to address them; but then you resubmitted patches where they weren't address. Normally, patch authors take all of the comments, clear them all, and then in the next repost of the patch, either explain why it wasn't feasible to handle some of the comments, *OR* why some of the comments were so hard to handle that they wouldn't be handled until a future version of the patch. Furthermore, in a patch of the size that you are submitting, a listing of what you *did* fix would also be good.

And at this point, I don't doubt that you will at some point going to heed my comments --- but note that doing so will involve a massive refactorization of the code, which will tend to invalidate the reviews done of this current (take 3) version of the patches; so I am bit curious what was your motiviation in reposting this round of the patches.

Believe it or not, the people who are responding on this thread are trying to help. Otherwise they would just be ignoring you and UBI. Keeping this thought in mind and trying to help them, where in some cases perhaps they are lacking in the same knowledge and experience and those who have been working on UBI and have spent many months thinking about the problem, may help keep things more constructive.

Regards,

- Ted

#55 lore raw
Quoted 7 lines · Theodore Tso

And at this point, I don't doubt that you will at some point going to heed my comments --- but note that doing so will involve a massive refactorization of the code, which will tend to invalidate the reviews done of this current (take 3) version of the patches; so I am bit curious what was your motiviation in reposting this round of the patches.

Yes. However, nobody has actually reviewed any of the _code_ in this round. So while it may have been somewhat superfluous from a submission standpoint, at least no code review has been wasted and we are getting some fairly decent design discussions.

josh

#56 lore raw
In reply to Theodore Tso
Quoted 6 lines · Theodore Tso

And at this point, I don't doubt that you will at some point going to heed my comments --- but note that doing so will involve a massive refactorization of the code, which will tend to invalidate the reviews done of this current (take 3) version of the patches; so I am bit curious what was your motiviation in reposting this round of the patches.

Well, in take 3 I _already_ removed quite _a lot_ of itsy-bitsy units, and I thought it is enough, so I've submitted it. But later I've realized that I should go further (e.g., dispose of per-unit data structures), and started more re-work. Yes, I should have notified about this new re-work, apologies.

Point taken, will be fixed :-)

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#57 lore raw
In reply to Theodore Tso

Hi Ted,

Quoted 4 lines · Theodore Tso

Keeping this thought in mind and trying to help them, where in some cases perhaps they are lacking in the same knowledge and experience and those who have been working on UBI and have spent many months thinking about the problem, may help keep things more constructive.

since I am one of those who are working on UBI together with Artem, I would like to try to describe how we are using UBI and how it solves some problems, we could not solve to our satisfaction with existing solutions.

Our system is using only NAND flashes and we use a nand-flash-controller for the 1st stage boot-code (we called it IPL - initial program loader) to appear contiguous in memory. The size of the IPL is limited to 4 KiB.

In these 4KiB code we initialize the processor, and scan the NAND flash for copies of our 2nd stage boot-loader (SPL), which is stored in one or even redundantly in multiple static UBI volumes. If the SPL has one-bit flips we can correct them in the IPL before loading it into RAM.

We want to correct bit-flips as soon as possible to avoid getting uncorrectable errors. UBI is doing that transparently for us by copying the block with the bitflip to a free block. The logic in the IPL is able to cope with the situation where UBI is interrupted when doing that.

Imagine if you have boot-code at a fixed location (skipping bad blocks of course too): if you erase a block of the SPL to write it back to the same block (to remove bit-errors), you will not be robust against power-loss anymore! You could put a 2nd temporary SPL before you could do this, but that is not nice too.

The static UBI volumes are so simple structured, that it is possible to load them to RAM using only a few KiB of code. We do not even look at UBIs volume information table to be able to do this.

UBI solves here:
1. possiblitly to boot a controller with limited resources using NAND
2. transparent bitflip correction on read only data e.g. boot-code, kernel, initrd. Note that the mechanisms here are robust against power-loss, that is also very important to us

We wanted to use JFFS2 and found that the traditional update mechanisms did not ensure that an interrupted update attempt can be detected as such. The UBI volume update ensures, that the volume is only usable after it was updated completely.

3. Update mechanism which ensures that incomplete data cannot be used

We found that putting certain flash content at fixed locations with fixed size is especially cumbersome if raw NAND is used e.g. if you consider that bad blocks have to be skipped. Resizing partitions is a pain.

UBI helps us to get rid of those limitations. We can resize the UBI volumes and because UBI takes care to find the volume data even our second stage boot-code can be located anywhere on the chip.

4. Volume resizing is easy

Because we want to ensure that we gain maximum lifetime for our systems, we want that bitflips are corrected immediately when they are found. Feature 2. of UBI does this for us.

I think that the largest portion of what we put in our NAND flashes is code and data and basically read-only. Nevertheless data is written during operation and, as already pointed out, maximum lifetime is important for us, and wear-leveling across the whole flash chip helps espcially with our usage-pattern. UBIs ability to copy blocks transparently e.g. a read-only block with small erase count to a free block with relatively high erase count, helps to get this done.

5. wear-leveling across the whole flash chip

We found that being able to use the same code update mechanisms for NAND/NOR/? based systems is a nice side effect too. That was one reason beside others (see previous mails) to up the UBI meta data into the data section of the flashes and sacrifice therefore some space for data and of course that the usable size of a block is not n^2 anymore. I think it was a good decision, because if we would have put in in NAND OOB area, the discussion here might be limited to NAND users only.

Regards,

Frank Haverkamp

#58 lore raw

On Wed, 21 Mar 2007, Frank Haverkamp wrote:

several of these things sound like they would be useful to other block devices as well

Quoted 10 lines

UBI solves here:
1. possiblitly to boot a controller with limited resources using NAND
2. transparent bitflip correction on read only data e.g. boot-code, kernel, initrd. Note that the mechanisms here are robust against power-loss, that is also very important to us

We wanted to use JFFS2 and found that the traditional update mechanisms did not ensure that an interrupted update attempt can be detected as such. The UBI volume update ensures, that the volume is only usable after it was updated completely.

a dm layer that detects and remaps soft errors before they become hard errors is useful for hard drives as well.

Quoted 17 lines

3. Update mechanism which ensures that incomplete data cannot be used

We found that putting certain flash content at fixed locations with fixed size is especially cumbersome if raw NAND is used e.g. if you consider that bad blocks have to be skipped. Resizing partitions is a pain.

UBI helps us to get rid of those limitations. We can resize the UBI volumes and because UBI takes care to find the volume data even our second stage boot-code can be located anywhere on the chip.

4. Volume resizing is easy

Because we want to ensure that we gain maximum lifetime for our systems, we want that bitflips are corrected immediately when they are found. Feature 2. of UBI does this for us.

Quoted 7 lines

I think that the largest portion of what we put in our NAND flashes is code and data and basically read-only. Nevertheless data is written during operation and, as already pointed out, maximum lifetime is important for us, and wear-leveling across the whole flash chip helps espcially with our usage-pattern. UBIs ability to copy blocks transparently e.g. a read-only block with small erase count to a free block with relatively high erase count, helps to get this done.

both of these also sound useful as dm layers (in fact lvm already does some of the resizing things)

Quoted 9 lines

5. wear-leveling across the whole flash chip

We found that being able to use the same code update mechanisms for NAND/NOR/? based systems is a nice side effect too. That was one reason beside others (see previous mails) to up the UBI meta data into the data section of the flashes and sacrifice therefore some space for data and of course that the usable size of a block is not n^2 anymore. I think it was a good decision, because if we would have put in in NAND OOB area, the discussion here might be limited to NAND users only.

wear leveling would also be useful on other block devices (think CD-RAM for example)

cross-device wear leveling sounds a lot like putting the wear leveling layer above a lvm-like layer that stitches the seperate flash chips togeather into one logical device.

additionally, if wear leveling is an optional layer in dm then it can be left out when it's not appropriate (like when the FS has features that make it unnessasary, or when it's read-only so you don't have writes to worry about (or even if it's read-only 99.9999% of the time so writes are so rare that all the writes in the expected lifetime of the device won't cause problems)

David Lang

#59 lore raw
In reply to Matt Mackall
Quoted 6 lines · Matt Mackall
Quoted 1 line

(UBI also has static volumes which LVM doesn't but that is an aside.)

If a static volume is simply a non-dynamic volume, then device mapper can do that too. And countless other things. Which is not an aside. UBI growing to do all the things that device mapper does is exactly the thing we should be seeking to avoid.

No it can't and device mapper sits on top of block devices. FLASH is no block device. Period.

Device mapper can not provide a simple easy to decode scheme for boot loaders. We need to be able to boot out of 512 - 2048 byte of NAND FLASH and be able to find the kernel or second stage boot loader in this unordered device.

And no, fixed addresses do not work. Do you want to implement device mapper into your Initialial Bootloader stage ?

Quoted 7 lines
Quoted 6 lines

That's why I suggested fixing the MTD layers that present block devices first in the part of my reply that you cut off. It seems to me that you're really after getting flash to look like a block device, which would enable device mapper to be used for something similar to UBI. That's fine, but until someone does that work UBI fills a need, has users, and has an existing implementation.

Quoted 8 lines

False starts that get mainlined delay or prevent things getting done right. The question is and remains "is UBI the right way to do things?" Not "is UBI the easiest way to do things?" or "is UBI something people have already adopted?"

If the right way is instead to extend the block layer and device mapper to encompass the quirks of NAND in a sensible fashion, then UBI should not go in.

No, block layer on top of FLASH needs 80% of the functionality of UBI in the first place. You need to implement a clever journalling block device emulator in order to keep the data alive and the FLASH not weared out within no time. You need the wear levelling, otherwise you can throw away your FLASH in no time.

Quoted 20 lines

Let me draw a picture so we have something to argue about:

                     iSCSI/nbd(6)
                          |
filesystem {        swap  |  ext3        ext3     jffs2
                      \   |   |            |       /
               /       \  | dm-crypt->snapshot(5) /
device mapper -|        \ \   |                  /
               |         partitioning           /
               |              |          partitioning(4)
               |        wear leveling(3)  /
               |              |          /
               |      block concatenation
               |       |    |    |     |
               \      bad block remapping(2)   
                       |    |    |     |
MTD raw block {     raw block devices with no smarts(1)
                      /     |     \      \
hardware {         NAND    NAND   NAND   NAND
Quoted 4 lines

Notes:
1. This would provide a block device that allowed writing pages and a secondary method for erasing whole blocks as well as a method for querying/setting out of band information.

Forget about OOB data. OOB data is reserved for ECC. Please read the recommendations of the NAND FLASH manufacturers. NAND gets less reliable with higher density devices and smaller processes.

Quoted 3 lines

2. This would hide erase blocks either by using an embedded table or out of band info. This could stack on top of block concatenation if desired.

Hide erase blocks ? UBI does not hide anything. It maps logical eraseblocks, which are exposed to the clients to arbitrary physical eraseblocks on the FLASH device in order to provide across device wear levelling.

This is fundamentaly different to device mapper.

Quoted 4 lines

3. This would provide wear leveling, and probably simultaneously provide relatively efficient and safe access to write sector and page-sized I/O. Below this level, things had better be comfortable with the limitations of NAND if they want to work well.

I don't see how this provides across device wear levelling.

Quoted 2 lines

4. JFFS2 has its own wear-leving scheme, as do several other filesystems, so they probably want to bypass this piece of the stack.

JFFS2 on top of UBI delegates the wear levelling to UBI, as JFFS2s own wear levelling sucks.

Quoted 2 lines

5. We don't reimplement higher pieces of the stack (dm-crypt, snapshot, etc.).

Why should we reimplement that ?

Quoted 7 lines

6. We make some things possible that simply aren't otherwise.

And this picture isn't even interesting yet. Imagine a dm-cache layer that caches data read from disks in high-speed flash. Or using dm-mirror to mirror writes to local flash over NBD or to a USB drive. Neither of these can be done 'right' in a stack split between device mapper and UBI.

Err. Implement a clever block layer on top of UBI and use all the goodies you want including device mapper.

tglx

#60 lore raw
Quoted 10 lines · Thomas Gleixner
Quoted 6 lines · Matt Mackall
Quoted 1 line

(UBI also has static volumes which LVM doesn't but that is an aside.)

If a static volume is simply a non-dynamic volume, then device mapper can do that too. And countless other things. Which is not an aside. UBI growing to do all the things that device mapper does is exactly the thing we should be seeking to avoid.

No it can't and device mapper sits on top of block devices. FLASH is no block device. Period.

Which of the following two properties does it lack?

- discrete blocks
- non-sequential access to blocks

When you do the obvious s/blocks/eraseblocks/, this appears to be true.

Saying "but I can't do I/O smaller than the blocksize" doesn't change this any more than it would for disks.

Saying "but I can do smaller I/O efficiently in some circumstances" also doesn't change it.

In historical UNIX, some tapes were block devices too. Because they supported seek().

Quoted 7 lines

Device mapper can not provide a simple easy to decode scheme for boot loaders. We need to be able to boot out of 512 - 2048 byte of NAND FLASH and be able to find the kernel or second stage boot loader in this unordered device.

And no, fixed addresses do not work. Do you want to implement device mapper into your Initialial Bootloader stage ?

This is exactly the same problem as booting on a desktop PC. But somehow LILO manages. My first Linux box had a hell of a lot less disk than the platform I bootstrapped (and wrote NAND drivers for) last month had in NAND.

Quoted 12 lines
Quoted 12 lines
Quoted 6 lines

That's why I suggested fixing the MTD layers that present block devices first in the part of my reply that you cut off. It seems to me that you're really after getting flash to look like a block device, which would enable device mapper to be used for something similar to UBI. That's fine, but until someone does that work UBI fills a need, has users, and has an existing implementation.

False starts that get mainlined delay or prevent things getting done right. The question is and remains "is UBI the right way to do things?" Not "is UBI the easiest way to do things?" or "is UBI something people have already adopted?"

Quoted 6 lines
Quoted 3 lines

If the right way is instead to extend the block layer and device mapper to encompass the quirks of NAND in a sensible fashion, then UBI should not go in.

No, block layer on top of FLASH needs 80% of the functionality of UBI in the first place.

Incorrect. A block-based filesystem on top of flash needs this functionality. But a block device suitable to device mapper layering (which then provides the functionality) does not.

Quoted 4 lines

You need to implement a clever journalling block device emulator in order to keep the data alive and the FLASH not weared out within no time. You need the wear levelling, otherwise you can throw away your FLASH in no time.

And that's why it's in my picture.

Quoted 29 lines
Quoted 20 lines

Let me draw a picture so we have something to argue about:

                     iSCSI/nbd(6)
                          |
filesystem {        swap  |  ext3        ext3     jffs2
                      \   |   |            |       /
               /       \  | dm-crypt->snapshot(5) /
device mapper -|        \ \   |                  /
               |         partitioning           /
               |              |          partitioning(4)
               |        wear leveling(3)  /
               |              |          /
               |      block concatenation
               |       |    |    |     |
               \      bad block remapping(2)   
                       |    |    |     |
MTD raw block {     raw block devices with no smarts(1)
                      /     |     \      \
hardware {         NAND    NAND   NAND   NAND
Quoted 4 lines

Notes:
1. This would provide a block device that allowed writing pages and a secondary method for erasing whole blocks as well as a method for querying/setting out of band information.

Forget about OOB data. OOB data is reserved for ECC. Please read the recommendations of the NAND FLASH manufacturers. NAND gets less reliable with higher density devices and smaller processes.

Quoted 8 lines
Quoted 3 lines

2. This would hide erase blocks either by using an embedded table or out of band info. This could stack on top of block concatenation if desired.

Hide erase blocks ? UBI does not hide anything. It maps logical eraseblocks, which are exposed to the clients to arbitrary physical eraseblocks on the FLASH device in order to provide across device wear levelling.

Sorry, I meant hiding bad blocks here. That's why this layer was labeled "bad block remapping".

Quoted 6 lines
Quoted 4 lines

3. This would provide wear leveling, and probably simultaneously provide relatively efficient and safe access to write sector and page-sized I/O. Below this level, things had better be comfortable with the limitations of NAND if they want to work well.

I don't see how this provides across device wear levelling.

Because the layer immediately beneath it ("block concatenation") takes N devices and presents one logical device.

Quoted 5 lines
Quoted 2 lines

4. JFFS2 has its own wear-leving scheme, as do several other filesystems, so they probably want to bypass this piece of the stack.

JFFS2 on top of UBI delegates the wear levelling to UBI, as JFFS2s own wear levelling sucks.

Ok, fine. How about LogFS, then?

Quoted 4 lines
Quoted 2 lines

5. We don't reimplement higher pieces of the stack (dm-crypt, snapshot, etc.).

Why should we reimplement that ?

So that you can get encryption and snapshot, etc.?

Quoted 10 lines
Quoted 7 lines

6. We make some things possible that simply aren't otherwise.

And this picture isn't even interesting yet. Imagine a dm-cache layer that caches data read from disks in high-speed flash. Or using dm-mirror to mirror writes to local flash over NBD or to a USB drive. Neither of these can be done 'right' in a stack split between device mapper and UBI.

Err. Implement a clever block layer on top of UBI and use all the goodies you want including device mapper.

If I wanted to have both device mapper and device mapper's little brother in my kernel, I wouldn't have started this thread.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#61 lore raw
Quoted 8 lines · Matt Mackall
Quoted 7 lines
Quoted 4 lines

If a static volume is simply a non-dynamic volume, then device mapper can do that too. And countless other things. Which is not an aside. UBI growing to do all the things that device mapper does is exactly the thing we should be seeking to avoid.

No it can't and device mapper sits on top of block devices. FLASH is no block device. Period.

Quoted 7 lines

Which of the following two properties does it lack?

- discrete blocks
- non-sequential access to blocks

When you do the obvious s/blocks/eraseblocks/, this appears to be true.

It appears to be, but it is not. You enforce semantics on a device, which it does not have.

Quoted 2 lines

Saying "but I can't do I/O smaller than the blocksize" doesn't change this any more than it would for disks.

There is a huge difference. Disk block size is 512 byte and FLASH block size is min 16KiB and up to 256KiB.

Just do the math:

Write sampling data streams in 2KiB chunks to your uber devicemapper on a 1GiB device with 64KiB erase block size:

Fine grained FLASH aware writes allow 32 chunks in a block without erasing the block.

Your method erases the block 32 times to write the same amount of data.

Result: You wear out the flash 32 times faster. Cool feature.

Quoted 2 lines

Saying "but I can do smaller I/O efficiently in some circumstances" also doesn't change it.

We can do it under _any_ circumstances and that _does_ change it. Implementing a clever block device layer on top of UBI is simple and would provide FLASH page sized I/O, i.e. 2Kib in the above example.

Quoted 2 lines

In historical UNIX, some tapes were block devices too. Because they supported seek().

I'm impressed. How exactly are "some tapes" comparable to FLASH chips ?

Your next proposal is to throw away MTD-utils and use "mt" instead ?

Quoted 5 lines
Quoted 5 lines

Device mapper can not provide a simple easy to decode scheme for boot loaders. We need to be able to boot out of 512 - 2048 byte of NAND FLASH and be able to find the kernel or second stage boot loader in this unordered device.

Quoted 7 lines
Quoted 2 lines

And no, fixed addresses do not work. Do you want to implement device mapper into your Initialial Bootloader stage ?

This is exactly the same problem as booting on a desktop PC. But somehow LILO manages. My first Linux box had a hell of a lot less disk than the platform I bootstrapped (and wrote NAND drivers for) last month had in NAND.

No, it is not. You get the absolute sector address of your second stage and this is a complete nobrainer. The translation is done in the DISK device.

You simply ignore the fact, that inside each disk, USB Stick, CF-CARD, whatever - there is a more or less intellegent controller device, which does the mapping to the physical storage location. There is _NO_ such thing on a bare FLASH chip.

It does not matter, whether your embedded device had more NAND space than my old CP/M machines floppy. It simply matters, that even the old CP/M floppy device had some rudimentary intellence on board.

Furthermore I want to be able to get the bitflip correction on my second stage loader / kernel in the same safe way as we do it for everything else and still be able to bootstrap that from an extremly small bootloader.

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

If the right way is instead to extend the block layer and device mapper to encompass the quirks of NAND in a sensible fashion, then UBI should not go in.

No, block layer on top of FLASH needs 80% of the functionality of UBI in the first place.

Incorrect. A block-based filesystem on top of flash needs this functionality. But a block device suitable to device mapper layering (which then provides the functionality) does not.

How exactly does device mapper:

A) across device wear levelling ?
B) dynamic partitioning for FLASH aware file systems ?
C) across device wear levelling for FLASH aware file systems ?
D) background bit-flip corrections (copying affected blocks and recylce the old one) ?
E) allow position independent placement of the second stage bootloader ?

Quoted 6 lines
Quoted 4 lines

You need to implement a clever journalling block device emulator in order to keep the data alive and the FLASH not weared out within no time. You need the wear levelling, otherwise you can throw away your FLASH in no time.

And that's why it's in my picture.

Yes, it is in your picture, but:

1) it excludes FLASH aware file systems and UBI does not.
2) your picture does still not explain how it does achive the above A), B), C), D) and E)

Your extra path for partitioning(4) and JFFS2 is just a weird hack, which makes your proposal completely absurd.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

Let me draw a picture so we have something to argue about:

                     iSCSI/nbd(6)
                          |
filesystem {        swap  |  ext3        ext3     jffs2
                      \   |   |            |       /
               /       \  | dm-crypt->snapshot(5) /
device mapper -|        \ \   |                  /
               |         partitioning           /
               |              |          partitioning(4)
               |        wear leveling(3)  /
               |              |          /
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

| block concatenation
| | | | |
\ bad block remapping(2)
| | | |
MTD raw block { raw block devices with no smarts(1)

                      /     |     \      \
hardware {         NAND    NAND   NAND   NAND

Notes:

Let me draw an UBI picture:

VFS -Layer
|
(Future VFS-crypto)
/ \
| |
______ device mapper / fs |
/ | |
/ | |
| Do whatever you don't |
| want to do with FLASH |
| whether it makes sense |
| or not. |
| | |
Block layer UBI block device Flash aware filesystems
| \ /
device \ /

   driver                      |
     |                         |
_____|_______                  |
|           |                  |
| Device    |                 UBI
| resident  |                  |
| "UBI"     |                  |
|___________|                  |
                               |                     

MTD-CORE
|
nand base driver
/ | \
device driver device driver device driver
| |
NAND NAND NAND

No notes: it's simple and self explaining.

Quoted 12 lines
Quoted 12 lines
Quoted 3 lines

1. This would provide a block device that allowed writing pages and a secondary method for erasing whole blocks as well as a method for querying/setting out of band information.

Forget about OOB data. OOB data is reserved for ECC. Please read the recommendations of the NAND FLASH manufacturers. NAND gets less reliable with higher density devices and smaller processes.

Quoted 3 lines

2. This would hide erase blocks either by using an embedded table or out of band info. This could stack on top of block concatenation if desired.

Quoted 7 lines
Quoted 4 lines

Hide erase blocks ? UBI does not hide anything. It maps logical eraseblocks, which are exposed to the clients to arbitrary physical eraseblocks on the FLASH device in order to provide across device wear levelling.

Sorry, I meant hiding bad blocks here. That's why this layer was labeled "bad block remapping".

Oh well, a seperate bad block remapper. And how is the logical mapping of wear levelled erase blocks done ?

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

3. This would provide wear leveling, and probably simultaneously provide relatively efficient and safe access to write sector and page-sized I/O. Below this level, things had better be comfortable with the limitations of NAND if they want to work well.

I don't see how this provides across device wear levelling.

Because the layer immediately beneath it ("block concatenation") takes N devices and presents one logical device.

And how is the wear levelling done on this logical device in devicemapper ?

How is ensured, that the wear average is maintained also across the partitions which are used by JFFS2 or other FLASH aware filesystems ?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

4. JFFS2 has its own wear-leving scheme, as do several other filesystems, so they probably want to bypass this piece of the stack.

JFFS2 on top of UBI delegates the wear levelling to UBI, as JFFS2s own wear levelling sucks.

Ok, fine. How about LogFS, then?

LogFS can easily leverage UBI's wear algorithm.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

5. We don't reimplement higher pieces of the stack (dm-crypt, snapshot, etc.).

Why should we reimplement that ?

So that you can get encryption and snapshot, etc.?

1. On top of a clever block device.

2. UBI can do snapshots by design.

3. Encryption should be done on the VFS layer and not below the filesystem layer. Doing it inside the block layer or the device mapper is broken by design.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

6. We make some things possible that simply aren't otherwise.

And this picture isn't even interesting yet. Imagine a dm-cache layer that caches data read from disks in high-speed flash. Or using dm-mirror to mirror writes to local flash over NBD or to a USB drive. Neither of these can be done 'right' in a stack split between device mapper and UBI.

Quoted 5 lines
Quoted 2 lines

Err. Implement a clever block layer on top of UBI and use all the goodies you want including device mapper.

If I wanted to have both device mapper and device mapper's little brother in my kernel, I wouldn't have started this thread.

You still did not explain how devicemapper does:

- across device wear levelling
- dynamic partitioning for FLASH aware file systems
- across device wear levelling for FLASH aware file systems
- simple boot loader support
- fine grained I/O

UBI is not devicemappers little brother. It is the software version of the silicon in a CF-CARD / USB-Stick, but it does a better job and allows clever usage of FLASH aside of enforcing eraseblock sized I/O units. Does your CF-Card / USB-Stick do that ?

Just think about the 1GiB USB stick, which would present you 64KiB I/O units instead of 2KiB ones.

Your signature is a nice intellectual signboard, but the ancient simple rule of three just tells me, that you are off by factor 32.

tglx

#62 lore raw
Quoted 28 lines · Thomas Gleixner
Quoted 8 lines · Matt Mackall
Quoted 7 lines
Quoted 4 lines

If a static volume is simply a non-dynamic volume, then device mapper can do that too. And countless other things. Which is not an aside. UBI growing to do all the things that device mapper does is exactly the thing we should be seeking to avoid.

No it can't and device mapper sits on top of block devices. FLASH is no block device. Period.

Quoted 7 lines

Which of the following two properties does it lack?

- discrete blocks
- non-sequential access to blocks

When you do the obvious s/blocks/eraseblocks/, this appears to be true.

It appears to be, but it is not. You enforce semantics on a device, which it does not have.

Quoted 2 lines

Saying "but I can't do I/O smaller than the blocksize" doesn't change this any more than it would for disks.

There is a huge difference. Disk block size is 512 byte and FLASH block size is min 16KiB and up to 256KiB.

Just do the math:

Quoted 7 lines

Write sampling data streams in 2KiB chunks to your uber devicemapper on a 1GiB device with 64KiB erase block size:

Fine grained FLASH aware writes allow 32 chunks in a block without erasing the block.

Your method erases the block 32 times to write the same amount of data.

Sigh. That's the current /dev/mtdblock method, not my method. You're too fixated on what you think I'm saying to hear what I'm saying.

Quoted 6 lines
Quoted 2 lines

Saying "but I can do smaller I/O efficiently in some circumstances" also doesn't change it.

We can do it under _any_ circumstances and that _does_ change it. Implementing a clever block device layer on top of UBI is simple and would provide FLASH page sized I/O, i.e. 2Kib in the above example.

Yes. I know. I've written a complete (non-Linux) FTL. I know what's entailed.

Quoted 6 lines
Quoted 2 lines

In historical UNIX, some tapes were block devices too. Because they supported seek().

I'm impressed. How exactly are "some tapes" comparable to FLASH chips ?

Your next proposal is to throw away MTD-utils and use "mt" instead ?

Don't be an ass. I'm pointing out that not all block devices are disks.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Device mapper can not provide a simple easy to decode scheme for boot loaders. We need to be able to boot out of 512 - 2048 byte of NAND FLASH and be able to find the kernel or second stage boot loader in this unordered device.

And no, fixed addresses do not work. Do you want to implement device mapper into your Initialial Bootloader stage ?

Quoted 8 lines
Quoted 4 lines

This is exactly the same problem as booting on a desktop PC. But somehow LILO manages. My first Linux box had a hell of a lot less disk than the platform I bootstrapped (and wrote NAND drivers for) last month had in NAND.

No, it is not. You get the absolute sector address of your second stage and this is a complete nobrainer. The translation is done in the DISK device.

LILO and friends manage to boot systems that use software RAID and LVM. There are multiple methods. Some use block lists, some use tiny boot partitions, etc. All of them are applicable to controllerless NAND.

Quoted 4 lines

You simply ignore the fact, that inside each disk, USB Stick, CF-CARD, whatever - there is a more or less intellegent controller device, which does the mapping to the physical storage location. There is _NO_ such thing on a bare FLASH chip.

How many times do I have to tell you that I wrote a driver for controllerless NAND just last month?

Quoted 3 lines

How exactly does device mapper:

A) across device wear levelling ?

The same way UBI does, but encapsulated in a device mapper layer.

Quoted 1 line

B) dynamic partitioning for FLASH aware file systems ?

See above.

Quoted 1 line

C) across device wear levelling for FLASH aware file systems ?

See above.

Quoted 2 lines

D) background bit-flip corrections (copying affected blocks and recylce the old one) ?

See above.

Quoted 1 line

E) allow position independent placement of the second stage bootloader ?

See way above to my LILO response.

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

You need to implement a clever journalling block device emulator in order to keep the data alive and the FLASH not weared out within no time. You need the wear levelling, otherwise you can throw away your FLASH in no time.

And that's why it's in my picture.

Quoted 8 lines

Yes, it is in your picture, but:

1) it excludes FLASH aware file systems and UBI does not.
2) your picture does still not explain how it does achive the above A), B), C), D) and E)

Your extra path for partitioning(4) and JFFS2 is just a weird hack, which makes your proposal completely absurd.

No, it's just there to show the flexibility of device mapper. But I have the sneaking suspicion you have no idea how device mapper works.

In brief: device mapper takes one or more devices, applies a mapping to them, and returns a new device. For example, take various spans of /dev/hda1 and /dev/sda3 and present them as new-device1. Take new-device1 and transform it with dm-crypt to get new-device2. The kernel doesn't decide how to do this, any more than it decides where to mount your filesystems. Userspace does.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

5. We don't reimplement higher pieces of the stack (dm-crypt, snapshot, etc.).

Why should we reimplement that ?

So that you can get encryption and snapshot, etc.?

1. On top of a clever block device.

2. UBI can do snapshots by design.

Oh, so you HAVE reimplemented it.

Quoted 3 lines

3. Encryption should be done on the VFS layer and not below the filesystem layer. Doing it inside the block layer or the device mapper is broken by design.

That's highly debatable and not a topic for this thread.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#63 lore raw
Quoted 7 lines · Matt Mackall
Quoted 6 lines · Thomas Gleixner
Quoted 4 lines · Matt Mackall

This is exactly the same problem as booting on a desktop PC. But somehow LILO manages. My first Linux box had a hell of a lot less disk than the platform I bootstrapped (and wrote NAND drivers for) last month had in NAND.

Quoted 7 lines
Quoted 3 lines

No, it is not. You get the absolute sector address of your second stage and this is a complete nobrainer. The translation is done in the DISK device.

LILO and friends manage to boot systems that use software RAID and LVM. There are multiple methods. Some use block lists, some use tiny boot partitions, etc. All of them are applicable to controllerless NAND.

Yes, by using fixed addresses, which is not what I want.

Quoted 7 lines
Quoted 4 lines

You simply ignore the fact, that inside each disk, USB Stick, CF-CARD, whatever - there is a more or less intellegent controller device, which does the mapping to the physical storage location. There is _NO_ such thing on a bare FLASH chip.

How many times do I have to tell you that I wrote a driver for controllerless NAND just last month?

Wow. I'm impressed because I'm pulling my opinion out of thin air.

Quoted 5 lines
Quoted 3 lines

How exactly does device mapper:

A) across device wear levelling ?

The same way UBI does, but encapsulated in a device mapper layer.

Does the device mapper do that ?

Quoted 3 lines
Quoted 1 line

B) dynamic partitioning for FLASH aware file systems ?

See above.

Does the device mapper do that ?

Quoted 3 lines
Quoted 1 line

C) across device wear levelling for FLASH aware file systems ?

See above.

Look at your own drawing.

Quoted 4 lines
Quoted 2 lines

D) background bit-flip corrections (copying affected blocks and recylce the old one) ?

See above.

Repeating patterns do not impress me. Your drawing tells otherwise

Quoted 3 lines
Quoted 1 line

E) allow position independent placement of the second stage bootloader ?

See way above to my LILO response.

Neither LILO nor GRUB have search capabilities for randomly located second stage loaders.

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines
Quoted 4 lines

You need to implement a clever journalling block device emulator in order to keep the data alive and the FLASH not weared out within no time. You need the wear levelling, otherwise you can throw away your FLASH in no time.

And that's why it's in my picture.

Yes, it is in your picture, but:

1) it excludes FLASH aware file systems and UBI does not.
2) your picture does still not explain how it does achive the above A), B), C), D) and E)

Quoted 5 lines
Quoted 2 lines

Your extra path for partitioning(4) and JFFS2 is just a weird hack, which makes your proposal completely absurd.

No, it's just there to show the flexibility of device mapper. But I have the sneaking suspicion you have no idea how device mapper works.

Sigh. Layering violation == flexibility.

Quoted 6 lines

In brief: device mapper takes one or more devices, applies a mapping to them, and returns a new device. For example, take various spans of /dev/hda1 and /dev/sda3 and present them as new-device1. Take new-device1 and transform it with dm-crypt to get new-device2. The kernel doesn't decide how to do this, any more than it decides where to mount your filesystems. Userspace does.

I know how it works. But your blurb does not answer any of my questions.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

5. We don't reimplement higher pieces of the stack (dm-crypt, snapshot, etc.).

Why should we reimplement that ?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

So that you can get encryption and snapshot, etc.?

1. On top of a clever block device.

2. UBI can do snapshots by design.

Oh, so you HAVE reimplemented it.

No, it already works

Quoted 5 lines
Quoted 3 lines

3. Encryption should be done on the VFS layer and not below the filesystem layer. Doing it inside the block layer or the device mapper is broken by design.

That's highly debatable and not a topic for this thread.

I see, you define, what has to be discussed.

tglx

#64 lore raw
In reply to Thomas Gleixner
Quoted 11 lines · Thomas Gleixner
Quoted 7 lines · Matt Mackall
Quoted 5 lines
Quoted 2 lines

4. JFFS2 has its own wear-leving scheme, as do several other filesystems, so they probably want to bypass this piece of the stack.

JFFS2 on top of UBI delegates the wear levelling to UBI, as JFFS2s own wear levelling sucks.

Ok, fine. How about LogFS, then?

LogFS can easily leverage UBI's wear algorithm.

Ok, now we have reached the absurd. UBI quite fundamentally cannot do wear leveling as good as LogFS can. Simply because UBI has zero knowledge of the _contents_ of its blocks. Knowing whether a block is 90% garbage or not makes a great difference.

Also LogFS currently requires erasesizes of 2^n.

Thomas, I can give you my opinion on this flamewar in private - after you have cooled off.

Jörn

Signature · 4 lines
When I am working on a problem I never think about beauty.  I think
only how to solve the problem.  But when I have finished, if the
solution is not beautiful, I know it is wrong.
-- R. Buckminster Fuller
#65 lore raw
Quoted 11 lines · Jörn Engel
Quoted 10 lines · Thomas Gleixner
Quoted 7 lines · Matt Mackall
Quoted 5 lines
Quoted 2 lines

4. JFFS2 has its own wear-leving scheme, as do several other filesystems, so they probably want to bypass this piece of the stack.

JFFS2 on top of UBI delegates the wear levelling to UBI, as JFFS2s own wear levelling sucks.

Ok, fine. How about LogFS, then?

Quoted 8 lines
Quoted 1 line

LogFS can easily leverage UBI's wear algorithm.

Ok, now we have reached the absurd. UBI quite fundamentally cannot do wear leveling as good as LogFS can. Simply because UBI has zero knowledge of the _contents_ of its blocks. Knowing whether a block is 90% garbage or not makes a great difference.

Also LogFS currently requires erasesizes of 2^n.

Last time I talked to you about that, you said it would be possible and fixable. We talked about several mechanisms, which would allow a filesystem or other users to hint such things to UBI.

Even if the LogFS wear levelling is so superior, it CAN'T do across device wear levelling.

tglx

#66 lore raw
Quoted 7 lines · Thomas Gleixner
Quoted 6 lines · Jörn Engel

Ok, now we have reached the absurd. UBI quite fundamentally cannot do wear leveling as good as LogFS can. Simply because UBI has zero knowledge of the _contents_ of its blocks. Knowing whether a block is 90% garbage or not makes a great difference.

Quoted 5 lines
Quoted 1 line

Also LogFS currently requires erasesizes of 2^n.

Last time I talked to you about that, you said it would be possible and fixable. We talked about several mechanisms, which would allow a filesystem or other users to hint such things to UBI.

Note the word "currently". And yes, we did talk about hints. Back then I still believed in UBI. That has changed and I would like to spare myself another flamewar, so please leave it at that.

Quoted 2 lines

Even if the LogFS wear levelling is so superior, it CAN'T do across device wear levelling.

Correct. And I don't see any problem with this. I see two classes of usecases for flash, with some amount of overlap in between.

1. Small amounts of flash.

Here the flash contains a large ratio of read-only data. Bootloader, kernel, etc. Having wear levelling across the device will gain you something. This is what you designed UBI for.

2. Large amounts of flash.

Just to be precise, large can go well into the Terabyte range and beyond. I don't mean large as in "the biggest embedded device I worked on last year" - that is still small.

Even if such flashes still contain a bootloader and a kernel, that will occupy less than 1% of the device. Wear leveling across the device is fairly pointless here. This is what I designed LogFS for.

There is some middle ground where a combination of UBI and LogFS may make sense. LogFS can still make sense for devices as small as 64MiB. But I'm not too concerned about that because flashes will continue to grow and the advantages of cross-device wear leveling will continue to diminish.

Jörn

Signature · 2 lines
"Security vulnerabilities are here to stay."
-- Scott Culp, Manager of the Microsoft Security Response Center, 2001
#67 lore raw
Quoted 3 lines · Jörn Engel

Even if such flashes still contain a bootloader and a kernel, that will occupy less than 1% of the device. Wear leveling across the device is fairly pointless here. This is what I designed LogFS for.

Still you need to have a solution for handling bitflips in those bootloader and kernel areas.

I don't dispute, that on a Terrabyte solid state disk which is used in a totally different way, UBI is not necessarily the right tool.

Quoted 5 lines

There is some middle ground where a combination of UBI and LogFS may make sense. LogFS can still make sense for devices as small as 64MiB. But I'm not too concerned about that because flashes will continue to grow and the advantages of cross-device wear leveling will continue to diminish.

Flashes will grow, but this will not change the embedded use case with a relativly small FLASH and the bootloader / kernel / rootfs / datafs scenario, where UBI is the right tool to use.

There is no hammer for all nails and I don't see device mapper doing what UBI does right now.

tglx

#68 lore raw
Quoted 7 lines · Thomas Gleixner
Quoted 3 lines · Jörn Engel

Even if such flashes still contain a bootloader and a kernel, that will occupy less than 1% of the device. Wear leveling across the device is fairly pointless here. This is what I designed LogFS for.

Still you need to have a solution for handling bitflips in those bootloader and kernel areas.

Correct. It may make sense to use UBI for that, I don't know. What I do know is that UBI cannot make wear leveling decisions as well as LogFS.

And that is all I care about wrt. this discussion.

Jörn

Signature · 2 lines
Joern's library part 8:
http://citeseer.ist.psu.edu/plank97tutorial.html
#69 lore raw
Quoted 3 lines · Jörn Engel

Correct. It may make sense to use UBI for that, I don't know. What I do know is that UBI cannot make wear leveling decisions as well as LogFS.

So lets discuss this in different thread when you post a request to include LogFS into mainline.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#70 lore raw
In reply to Thomas Gleixner
Quoted 6 lines · Thomas Gleixner

Last time I talked to you about that, you said it would be possible and fixable. We talked about several mechanisms, which would allow a filesystem or other users to hint such things to UBI.

Even if the LogFS wear levelling is so superior, it CAN'T do across device wear levelling.

Exactly. Although it is true that it cannot be _as good_ as FS, one can optimize this by means of asking FS beforehand and make it quite OK. And eraseblock movement is not so frequent event - we do it only once the erase counter difference is more then 4Ki (although it is tunable).

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#71 lore raw
In reply to Thomas Gleixner
Quoted 6 lines · Thomas Gleixner
Quoted 2 lines · Jörn Engel

Also LogFS currently requires erasesizes of 2^n.

Last time I talked to you about that, you said it would be possible and fixable.

Actually, no. LogFS is not broken, there is nothing to fix.

And there is no fundamental reason why UBI should export blocks with non-power-of-two sizes. UBI currently consists of two parts that are intimately intertwined in the current implementation, but have relatively little connection otherwise.

1. Logical volume management.
2. Static volumes.

Logical volume management can just as easily move its management information into a table, instead of having it spread across all blocks. Blocks can keep their original size. Since you have to scan flash anyway, you can also scan for a table, compare a magical number and do some extra check to protect yourself against a UBI image inside some logical volume. No big deal.

Static volumes can keep a header inside their volumes. The tiny first-stage bootloader is currently scanning flash and can continue to do so. But at least this header no longer causes trouble for LogFS or any other UBI user.

UBI is just as broken as LogFS is. It works with every user in mainline (which comes down to JFFS2). LogFS works with every MTD device in mainline. The only combination that doesn't work is LogFS on UBI - due to deliberate design decisions on both sides.

Jörn

Signature · 2 lines
Joern's library part 8:
http://citeseer.ist.psu.edu/plank97tutorial.html
#72 lore raw
Quoted 18 lines · Jörn Engel
Quoted 6 lines · Thomas Gleixner
Quoted 2 lines · Jörn Engel

Also LogFS currently requires erasesizes of 2^n.

Last time I talked to you about that, you said it would be possible and fixable.

Actually, no. LogFS is not broken, there is nothing to fix.

And there is no fundamental reason why UBI should export blocks with non-power-of-two sizes. UBI currently consists of two parts that are intimately intertwined in the current implementation, but have relatively little connection otherwise.

1. Logical volume management.
2. Static volumes.

Quoted 6 lines

Logical volume management can just as easily move its management information into a table, instead of having it spread across all blocks. Blocks can keep their original size. Since you have to scan flash anyway, you can also scan for a table, compare a magical number and do some extra check to protect yourself against a UBI image inside some logical volume. No big deal.

if you are being paranoid about write cycles putting the write count in the block you are writing avoids doing an erase/write elsewhere

although, since you can flip bits to 1 without requireing an erase you could sacrafice some space and say that your table has a normal counter for the number of times the block has been erased, but a 'tally counter' where you turn one bit on each time you erase the block, and when you fill up the tally block you re-write the entire table, clearing all the tallys. if you have relativly large eraseblocks it seems like you could afford to sacrafice the space in your master table to avoid erases of it

IIRC someone said that the count per block was 128 bits? if so you could have a master table with a 32 bit integer (4B writes) + 96 bits of tally so that you would only have to re-write the table when a block on the flash has been erased 96 times. with this approach the wear on your table is unlikely to be a factor until the point where you are loosing a lot of other eraseblocks due to wear (at which point you could shift to a different block for your table, or retire the flash)

David Lang

#73 lore raw
Quoted 8 lines · David Lang
Quoted 6 lines · Jörn Engel

Logical volume management can just as easily move its management information into a table, instead of having it spread across all blocks. Blocks can keep their original size. Since you have to scan flash anyway, you can also scan for a table, compare a magical number and do some extra check to protect yourself against a UBI image inside some logical volume. No big deal.

[ This was not a request for UBI to be changed. The only purpose was to illustrate that LogFS is not broken. The previous thread suggested otherwise and I just couldn't leave it at that. ]

Quoted 4 lines

if you are being paranoid about write cycles putting the write count in the block you are writing avoids doing an erase/write elsewhere

although, since you can flip bits to 1 without requireing an erase you

[ vice versa. you can flip bits to 0 without erasing. ]

Quoted 6 lines

could sacrafice some space and say that your table has a normal counter for the number of times the block has been erased, but a 'tally counter' where you turn one bit on each time you erase the block, and when you fill up the tally block you re-write the entire table, clearing all the tallys. if you have relativly large eraseblocks it seems like you could afford to sacrafice the space in your master table to avoid erases of it

Or you could have a table and any number of updates to it. Erase one block, append a small update marker to the table. There are plenty of options. All have in common that code would be more complicated.

Another advantage is that erase counts don't get reset if the race against a power failure during erase is lost.

Whether the advantaves of power-of-two blocksizes and safe erasecounts are worth it, I leave for others to decide.

Jörn

Signature · 3 lines
Fools ignore complexity.  Pragmatists suffer it.
Some can avoid it.  Geniuses remove it.
-- Perlis's Programming Proverb #58, SIGPLAN Notices, Sept.  1982
maintainer
#74 lore raw
Quoted 2 lines · Jörn Engel
Quoted 1 line

although, since you can flip bits to 1 without requireing an erase you

[ vice versa. you can flip bits to 0 without erasing. ]

And on NAND flash you can't just do it in multiple cycles one bit at a time. The 'tally' trick isn't viable there.

Signature · 1 line
dwmw2
#75 lore raw
Quoted 6 lines · David Woodhouse
Quoted 2 lines · Jörn Engel
Quoted 1 line

although, since you can flip bits to 1 without requireing an erase you

[ vice versa. you can flip bits to 0 without erasing. ]

And on NAND flash you can't just do it in multiple cycles one bit at a time. The 'tally' trick isn't viable there.

You can on NAND. ECC is done in software. And for a data structure as simple as the 'tally', foregoing ECC is not a huge problem - most bitflips are easily detected and the remaining only cause off-by-a-few on the erase count.

On NOR with transparent (hardware) ECC you can't.

Jörn

Signature · 2 lines
Homo Sapiens is a goal, not a description.
-- unknown
maintainer
#76 lore raw
Quoted 4 lines · Jörn Engel

You can on NAND. ECC is done in software. And for a data structure as simple as the 'tally', foregoing ECC is not a huge problem - most bitflips are easily detected and the remaining only cause off-by-a-few on the erase count.

You're only allowed a limited number of write cycles to each page though. So you can't just clear the bits in a 2112-byte page one at a time; typically when you clear the fifth bit, the contents of the whole page become undefined until the next erase cycle.

Signature · 1 line
dwmw2
#77 lore raw
Quoted 10 lines · David Woodhouse
Quoted 4 lines · Jörn Engel

You can on NAND. ECC is done in software. And for a data structure as simple as the 'tally', foregoing ECC is not a huge problem - most bitflips are easily detected and the remaining only cause off-by-a-few on the erase count.

You're only allowed a limited number of write cycles to each page though. So you can't just clear the bits in a 2112-byte page one at a time; typically when you clear the fifth bit, the contents of the whole page become undefined until the next erase cycle.

That limitation stems from ECC and ECC is done in software. Currently everyone and his dog is doing ECC in chunks of 256 bytes on NAND. So your minimum write size is 256 bytes _if you care about ECC_. If you don't care, you can write single bits on NAND, just as you can on NOR.

Controlling ECC in software means we are quite flexible. Given sufficient incentive, we can change the rules quite significantly.

Jörn

Signature · 4 lines
You can't tell where a program is going to spend its time. Bottlenecks
occur in surprising places, so don't try to second guess and put in a
speed hack until you've proven that's where the bottleneck is.
-- Rob Pike
maintainer
#78 lore raw
Quoted 4 lines · Jörn Engel

That limitation stems from ECC and ECC is done in software. Currently everyone and his dog is doing ECC in chunks of 256 bytes on NAND. So your minimum write size is 256 bytes _if you care about ECC_. If you don't care, you can write single bits on NAND, just as you can on NOR.

No, on NAND flash it's a limitation of the hardware. The number of write cycles you can perform to a given page is limited. Exceed it and the contents of that page become undefined due to leakage, until you next erase it.

Signature · 1 line
dwmw2
#79 lore raw
Quoted 5 lines · David Woodhouse

No, on NAND flash it's a limitation of the hardware. The number of write cycles you can perform to a given page is limited. Exceed it and the contents of that page become undefined due to leakage, until you next erase it.

Are you sure? Do you have any specs or similar that state this?

So far I have only encountered this limitation by word of mouth. And such a myth coming from ECC effects is nothing that would surprise me.

Jörn

Signature · 3 lines
The cheapest, fastest and most reliable components of a computer
system are those that aren't there.
-- Gordon Bell, DEC labratories
maintainer
#80 lore raw
Quoted 5 lines · Jörn Engel

Are you sure? Do you have any specs or similar that state this?

So far I have only encountered this limitation by word of mouth. And such a myth coming from ECC effects is nothing that would surprise me.

See pp 6 and 31 of http://david.woodhou.se/TC58DVAM72AF1FT_030124.pdf
for example.

Signature · 1 line
dwmw2
#81 lore raw
In reply to David Woodhouse
Quoted 10 lines · David Woodhouse
Quoted 4 lines · Jörn Engel

That limitation stems from ECC and ECC is done in software. Currently everyone and his dog is doing ECC in chunks of 256 bytes on NAND. So your minimum write size is 256 bytes _if you care about ECC_. If you don't care, you can write single bits on NAND, just as you can on NOR.

No, on NAND flash it's a limitation of the hardware. The number of write cycles you can perform to a given page is limited. Exceed it and the contents of that page become undefined due to leakage, until you next erase it.

Right and you cannot write to random locations in a page. The write chunks have to be in consecutive order. If you write 0xAA to offset 0, you cannot rewrite it to 0x00 later without risking corruption.

tglx

#82 lore raw
In reply to Jörn Engel
Quoted 2 lines · Jörn Engel

And there is no fundamental reason why UBI should export blocks with non-power-of-two sizes.

False. There is.

Quoted 3 lines

UBI currently consists of two parts that are
intimately intertwined in the current implementation, but have relatively little connection otherwise.

False. They do have connection.

Quoted 9 lines

1. Logical volume management.
2. Static volumes.

Logical volume management can just as easily move its management information into a table, instead of having it spread across all blocks. Blocks can keep their original size. Since you have to scan flash anyway, you can also scan for a table, compare a magical number and do some extra check to protect yourself against a UBI image inside some logical volume. No big deal.

First off, I see these no big deal statements for years already, and no decent implementation proved by usage in real world. Could we please, move these academic discussions to another thread?

Second, it is much more robust to kip erase counter and mapping information on per-eraseblock basis then to keep any on-flash table - you may always scan whole media and gracefully recover from errors and corruptions. And you do not loose use a lot in case of corruptions.

Third, it is much simpler then keeping any on-flash table, it is thus robust. We do not need a journal to update any table.

Third, if needed, on-flash table may be _added_ to increase scalability, so "since you have to scan flash anyway" may become false when there is real need in better scalability. For now scanning is OK. And still, scanning method will be a good fall-back way to recover from errors.

Quoted 4 lines

UBI is just as broken as LogFS is. It works with every user in mainline (which comes down to JFFS2). LogFS works with every MTD device in mainline. The only combination that doesn't work is LogFS on UBI - due to deliberate design decisions on both sides.

You are welcome to discuss other irrelevant things to this thread.

Signature · 2 lines
Best regards,
Artem Bityutskiy (Битюцкий Артём)
#83 lore raw
Quoted 9 lines · Artem Bityutskiy
Quoted 7 lines · Jörn Engel

Logical volume management can just as easily move its management information into a table, instead of having it spread across all blocks. Blocks can keep their original size. Since you have to scan flash anyway, you can also scan for a table, compare a magical number and do some extra check to protect yourself against a UBI image inside some logical volume. No big deal.

Quoted 3 lines

First off, I see these no big deal statements for years already, and no decent implementation proved by usage in real world. Could we please, move these academic discussions to another thread?

You could wait a day, then reread what I wrote. Maybe you will notice that what I wrote is not identical to what we have discussed about a year ago and you seem to have read.

You may also want to reread this:

||[ This was not a request for UBI to be changed.  The only purpose was to
||illustrate that LogFS is not broken.  The previous thread suggested
||otherwise and I just couldn't leave it at that. ]

Jörn

Signature · 2 lines
tglx1 thinks that joern should get a (TM) for "Thinking Is Hard"
-- Thomas Gleixner
#84 lore raw
In reply to Matt Mackall
Quoted 9 lines · Matt Mackall

False starts that get mainlined delay or prevent things getting done right. The question is and remains "is UBI the right way to do things?" Not "is UBI the easiest way to do things?" or "is UBI something people have already adopted?"

If the right way is instead to extend the block layer and device mapper to encompass the quirks of NAND in a sensible fashion, then UBI should not go in.

This is where we disagree obviously. However, getting UBI into mainline won't delay or prevent your proposal from getting done. That's like saying having ext3 in mainline prevents other filesystems from getting created. There is nothing wrong with having different subsystems that overlap in a few areas.

What you're proposing seems like it would take at least several weeks to even get close to what is needed in terms of reliability and the required wear-leveling if it is indeed possible to implement. And it would likely duplicate some of the wear-leveling and bad block handling code that is present in UBI anyway. In the meantime, the need for UBI exists today and there is a working, tested implementation available.

josh

#85 lore raw
In reply to Matt Mackall

Matt,

Quoted 12 lines · Matt Mackall
Quoted 11 lines · Josh Boyer
Quoted 10 lines · Matt Mackall

I'm well aware of all that. I wrote a NAND driver just last month. Let's consider this table:

HARD drives                          MTD device
Consists of sectors                  Consists of eraseblocks
Sectors are small (512, 1024 bytes)  Eraseblocks are larger (32KiB, 128KiB)
read sector and write sector         read, write, and erase block
Bad sectors are re-mapped            Bad eraseblocks are not hidden

HDD sectors don't wear out Eraseblocks get worn-out

Quoted 7 lines
Quoted 3 lines
 N/A                                   NAND flash addressed in pages
 N/A                                   NAND flash has OOB areas
 N/A (?)                               NAND flash requires ECC

Disks have OOB areas with ECC, it's just nicely hidden inside the drive. They also typically have physical sectors bigger than 512 bytes, again hidden.

The difference is that the harddrive has an intellegent controller, which hides all this away. NAND FLASH has not and we have to do it in software.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

If the end goal is to end up with something that looks like a block device (which seems to be implied by adding transparent wear leveling

Nope, not the end goal. It's more about wear-leveling across the entire flash chip than it is presenting a "block like" device.

It seems to be about spanning devices and repartitioning as well. Hence the analogy with LVM.

Yes, UBI is a kind of LVM for FLASH and we did think quite a time about reusing LVM before we went the UBI way.

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

and bad block remapping), then I don't see any reason it can't be done in device mapper. The 'smarts' of mtdblock could in fact be pulled up

There is nothing smart about mtdblock. And mtdblock has nothing to do with UBI.

Note the scare quotes. Device mapper runs on top of a block device. And mtdblock is currently the block interface that MTD exports. And it has 'smarts' that hide handling of sub-eraseblock I/O. I'm clearly talking about an approach that doesn't involve UBI at all.

MTD block has no 'smarts' at all. It is a stupid and broken hack, which you can utilize to lose data and wear your FLASH out.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

In the end, a block device is something which does random access block-oriented I/O. Disk and NAND both fit that description.

NAND very much doesn't fit the "random access" part of that. For writes you have to write in incrementing pages within eraseblocks.

And? You can't do I/O smaller than a sector on a disk.

Should we export block devices with 16/32/64/128 KiB size ? If not, we would need to put a lot of clever functionality into the mtd block device code, which we decided to put into UBI, so FLASH aware file systems can use this shared functionality too.

If someone wants to implement an intellegent mtd block device, which allows to run arbitrary filesystems, then it should be done on top of UBI. It's not rocket science, but nobody bothers as we have functional FLASH filesystems which do their job better w/o any notion of a block device.

A disk _IS_ fundamentally different to FLASH and all the magic which is done inside of CF-Cards and USB-Sticks is just hiding this away. Most of the controller chips in these devices are broken and I would never ever store any important data on such.

The main points of UBI are:

- wear levelling across the complete device
- background handling of bitflips
- safe updates
- handling of static volumes, which are easily accessible for bootloaders

Nothing of this is anyway near of LVM and disks. The only LVM alike feature is dynamic creation/deletion/resizing of volumes.

tglx

#86 lore raw
Quoted 45 lines · Thomas Gleixner

Matt,

Quoted 12 lines · Matt Mackall
Quoted 11 lines · Josh Boyer
Quoted 10 lines · Matt Mackall

I'm well aware of all that. I wrote a NAND driver just last month. Let's consider this table:

HARD drives                          MTD device
Consists of sectors                  Consists of eraseblocks
Sectors are small (512, 1024 bytes)  Eraseblocks are larger (32KiB, 128KiB)
read sector and write sector         read, write, and erase block
Bad sectors are re-mapped            Bad eraseblocks are not hidden

HDD sectors don't wear out Eraseblocks get worn-out

Quoted 7 lines
Quoted 3 lines
 N/A                                   NAND flash addressed in pages
 N/A                                   NAND flash has OOB areas
 N/A (?)                               NAND flash requires ECC

Disks have OOB areas with ECC, it's just nicely hidden inside the drive. They also typically have physical sectors bigger than 512 bytes, again hidden.

The difference is that the harddrive has an intellegent controller, which hides all this away. NAND FLASH has not and we have to do it in software.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

If the end goal is to end up with something that looks like a block device (which seems to be implied by adding transparent wear leveling

Nope, not the end goal. It's more about wear-leveling across the entire flash chip than it is presenting a "block like" device.

It seems to be about spanning devices and repartitioning as well. Hence the analogy with LVM.

Yes, UBI is a kind of LVM for FLASH and we did think quite a time about reusing LVM before we went the UBI way.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

and bad block remapping), then I don't see any reason it can't be done in device mapper. The 'smarts' of mtdblock could in fact be pulled up

There is nothing smart about mtdblock. And mtdblock has nothing to do with UBI.

Quoted 7 lines
Quoted 4 lines

Note the scare quotes. Device mapper runs on top of a block device. And mtdblock is currently the block interface that MTD exports. And it has 'smarts' that hide handling of sub-eraseblock I/O. I'm clearly talking about an approach that doesn't involve UBI at all.

MTD block has no 'smarts' at all. It is a stupid and broken hack, which you can utilize to lose data and wear your FLASH out.

I explained precisely what I meant by 'smarts' and why I put it in 'smarts' in quotes. And here you are repeat that same exact damn thing I responded to five lines up.

Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

In the end, a block device is something which does random access block-oriented I/O. Disk and NAND both fit that description.

NAND very much doesn't fit the "random access" part of that. For writes you have to write in incrementing pages within eraseblocks.

And? You can't do I/O smaller than a sector on a disk.

Should we export block devices with 16/32/64/128 KiB size ?

Sure, why not?

Quoted 2 lines

A disk _IS_ fundamentally different to FLASH and all the magic which is done inside of CF-Cards and USB-Sticks is just hiding this away.

And yet they're still both block devices. That our current block layer doesn't handle one as well as the other is something we should fix instead of inventing a whole new full-feature but incompatible block layer on the side.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#87 lore raw
Quoted 3 lines · Matt Mackall
Quoted 1 line

Should we export block devices with 16/32/64/128 KiB size ?

Sure, why not?

Simply because we want to have the ability to write fine grained in order to write data safe to FLASH. If we export those large sizes we lose this ability and have to write full erase blocks for a couple of bytes. This simply breaks JFFS2 and you can do the math yourself what that means for the life time of FLASH, when you write small data chunks in fast sequences and want to make sure that they are written to FLASH immidiately.

Quoted 7 lines
Quoted 2 lines

A disk _IS_ fundamentally different to FLASH and all the magic which is done inside of CF-Cards and USB-Sticks is just hiding this away.

And yet they're still both block devices. That our current block layer doesn't handle one as well as the other is something we should fix instead of inventing a whole new full-feature but incompatible block layer on the side.

And yet they are still broken and unreliable. And you can wear them out in no time, just because they are stupid and do full eraseblock updates when you write one sector.

No thanks. A bunch of people have done experiments with those beasts and they are unusable for environments, where we need to make sure, that data is on FLASH.

UBI is not an incompatible block layer. It allows to implement a very clever block layer on top. And you can use just one large partition and small ones for your kernel image and bootloader, which still get the benefits of data integrity (by doing background safe copies on bit flips) and the easy implementation in an IPL.

tglx