UBI: optimize erase-header read checks
Subsystems (2)
From: "Gupta, Pekon" <[email protected]>
During mounting of UBI volume, all PEB headers are scanned and checked. This scanning of PEB header is done
- To re-creating PEB to LEB map table.
- To filter out bad PEB or alien (non-UBI) PEB.
- recover corrupt PEB effected by sudden power-failure.
During this scanning both erase_header and volume_id_header are scanned. This volume recovery time is critical for some safety use-cases where system should recover as soon as possible after the fault.
This patch tries to optimize erase-header checks done during scan by:
- re-ordering data checks based on below analysis.
- removing ubi_check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)
(checking of 0xFF in page-data) - REASON1: even if first few bytes 'sizeof(ec_hdr)' of page-data are 0xFF, still it does not guarantee that page is erased | blank. - REASON2: As per analysis below, pages with invalid magic-number need to be erased in most of the conditions. Thus explicit checking of 0xFF in page-data can be avoided.
MTD device driver can return following return-code for read access (mtd_read)
--------------------------------------------------------------------------RETURN_VALUE REASON NEXT STEP
--------------------------------------------------------------------------
0 no errors or bit-flips detected parse data
EUCLEAN correctable bit-flips detected parse data & scrub PEB
EBADMSG uncorrectable bit-flip detected parse data & scrub PEB
<others> device error or incomplete data reject data
--------------------------------------------------------------------------
Parsing the read_data can result in following combinations:
--------------------------------------------------------------------------
MAGIC
ECC HDR_CRC NUMBER CONCLUSION NEXT STEP
--------------------------------------------------------------------------
OK valid valid* valid UBI erase_header parse header
EUCLEAN valid valid* valid UBI erase_header parse header
EBADMSG valid valid* valid UBI erase_header parse header
OK invalid valid corrupted UBI erase_header depends on vid_hdr
EUCLEAN invalid valid corrupted UBI erase_header depends on vid_hdr
EBADMSG invalid -- undeterministic_data** schedule for erase
OK invalid invalid undeterministic_data** schedule for erase
EUCLEAN invalid invalid undeterministic_data** schedule for erase
EBADMSG invalid invalid undeterministic_data** schedule for erase
--------------------------------------------------------------------------
where
'valid*': As hdr_crc covers magic-number field so matching of hdr_crc
implicitely indicates matching of magic=number.
underministic_data**: page-data can be any of the following
(a) programmed page (non-UBI)
(b) programmed page (all 0xFF
(c) erased page without bit-flips
(d) erased page with bit-flips
(d) valid UBI erase_header with un-recoverable bit-flips corrupting erase-header content.
--- drivers/mtd/ubi/attach.c | 10 ++++ drivers/mtd/ubi/io.c | 126 +++++++++++++++++++---------------------------- 2 files changed, 62 insertions(+), 74 deletions(-)
drivers/mtd/ubi/attach.c +10 -0
@@ -848,6 +848,16 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,return add_to_list (ai, pnum,UBI_UNKNOWN ,UBI_UNKNOWN ,UBI_UNKNOWN ,1 , &ai->erase);case UBI_IO_BAD_HDR_EBADMSG : +/* un=recoverable erase-header +* unknown erase-count: can reset to mean erase-count after erase +* unknown image_seq: cannot determine if PEB was programmed +* unknown version: cannot determine UBI protocol to use +* So no point in checking vid_hdr, schedule this PEB for erase. +*/ + ai->empty_peb_count +=1 ; +return add_to_list (ai, pnum,UBI_UNKNOWN ,UBI_UNKNOWN , +UBI_UNKNOWN ,1 , &ai->erase); +case UBI_IO_BAD_HDR :/* * We have to also look at the VID header, possibly it is not
drivers/mtd/ubi/io.c +52 -74
152 lines not on this page · raw message
Signature · 1 line
1.8.1
Hi Pekon,
thanks for the patch. Generally, I am fine to change the reading/scanning path, but carefully.
Quoted 64 lines · Pekon
From: "Gupta, Pekon" <[email protected]>
During mounting of UBI volume, all PEB headers are scanned and checked. This scanning of PEB header is done
- To re-creating PEB to LEB map table.
- To filter out bad PEB or alien (non-UBI) PEB.
- recover corrupt PEB effected by sudden power-failure.
During this scanning botherase_headerandvolume_id_headerare scanned. This volume recovery time is critical for some safety use-cases where system should recover as soon as possible after the fault.This patch tries to optimize erase-header checks done during scan by:
- re-ordering data checks based on below analysis.
- removingubi_check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)(checking of 0xFF in page-data) - REASON1: even if first few bytes 'sizeof(ec_hdr)' of page-data are 0xFF, still it does not guarantee that page is erased | blank. - REASON2: As per analysis below, pages with invalid magic-number need to be erased in most of the conditions. Thus explicit checking of 0xFF in page-data can be avoided.MTD device driver can return following return-code for read access (
mtd_read)
--------------------------------------------------------------------------RETURN_VALUEREASON NEXT STEP
--------------------------------------------------------------------------
0 no errors or bit-flips detected parse dataEUCLEAN correctable bit-flips detected parse data & scrub PEB
EBADMSG uncorrectable bit-flip detected parse data & scrub PEB
<others> device error or incomplete data reject data
--------------------------------------------------------------------------Parsing the
read_datacan result in following combinations:
--------------------------------------------------------------------------
MAGIC
ECCHDR_CRCNUMBER CONCLUSION NEXT STEP
--------------------------------------------------------------------------
OK valid valid* valid UBIerase_headerparse header
EUCLEAN valid valid* valid UBIerase_headerparse header
EBADMSG valid valid* valid UBIerase_headerparse headerOK invalid valid corrupted UBI
erase_headerdepends onvid_hdr
EUCLEAN invalid valid corrupted UBIerase_headerdepends onvid_hdr
EBADMSG invalid -- undeterministic_data** schedule for eraseOK invalid invalid undeterministic_data** schedule for erase
EUCLEAN invalid invalid undeterministic_data** schedule for erase
EBADMSG invalid invalid undeterministic_data** schedule for erase
--------------------------------------------------------------------------where
'valid*': Ashdr_crccovers magic-number field so matching ofhdr_crc
implicitely indicates matching of magic=number.underministic_data**: page-data can be any of the following
(a) programmed page (non-UBI)
(b) programmed page (all0xFF
(c) erased page without bit-flips
(d) erased page with bit-flips
(d) valid UBIerase_headerwith un-recoverable bit-flips corrupting erase-header content.
Quoted 1 line
Signed-off-by Gupta, Pekon <[email protected]>
So the subject says this is an optimization, but I do not really see what did you optimize? Speed? If yes, some numbers?
Or this is about improving robustness? May be some clear explanations about that?
Or this is just simplifying the code and making it more clear?
I am fine with all of that, just want to clearly see this explained in the commit message.
Also, the patch is a bit too big. Can you try to figure out smaller steps and split it on smaller pieces?
There are also minor cosmetic things, but I do not want to touch them now.
Note: I am processing the mtd mailing list from oldest e-mails to newest, with few exceptions. But when I answer an e-mail, and the person re-sends patches, I usually jump to the new version right away. So if you resend, I should look at them with a lot smaller delay :-)
Signature · 2 lines
Best Regards, Artem Bityutskiy
Hi Artem,
Quoted 6 lines
Hi Pekon,
thanks for the patch. Generally, I am fine to change the reading/scanning path, but carefully.
[Pekon]: Yes I understand, that this patch should not break something already working.
Though I have tested this with various scenarios mention in previous mail. But still I was waiting a 'Ack' from Brain.
http://lists.infradead.org/pipermail/linux-mtd/2013-May/046738.html
But if others can test it also, It would be good.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Gupta, Pekon <[email protected]>So the subject says this is an optimization, but I do not really see what did you optimize? Speed? If yes, some numbers?
Quoted 8 lines
Or this is about improving robustness? May be some clear explanations about that?
Or this is just simplifying the code and making it more clear?
I am fine with all of that, just want to clearly see this explained in the commit message.
[Pekon]: Its more of simplifying code, I'll re-word the commit. It should also improve some speed, in some scenarios, as I have removed all 0xFF header check. I'll try to get numbers for that.
Quoted 3 lines
Also, the patch is a bit too big. Can you try to figure out smaller steps and split it on smaller pieces?
[Pekon]: Yes, I tried this, but majority chunk of patch is change in 'ubi_io_read_ec_hdr()', which was completely re-written, in order to simplify code. I'll try to split the patch, but then it might not be logical split, and there would be dependency between patches.
Quoted 3 lines
There are also minor cosmetic things, but I do not want to touch them now.
[Pekon]: I'll re-base them on 3.10-rcx. So its easy for you to check. But right now I'm caught in other clean-up work, so re-submission would be bit delayed..
Quoted 6 lines
Note: I am processing the mtd mailing list from oldest e-mails to newest, with few exceptions. But when I answer an e-mail, and the person
re-sends patches, I usually jump to the new version right away. So if you resend, I should look at them with a lot smaller delay :-)
[Pekon]: No issues for me..
I don't see these patches as emergency, but good to have from a long term prospective. And I'm more than happy to receive feedbacks.
with regards, pekon