public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* Why the alignemt to 4 bytes is necessary in jffs2_commit_write function
@ 2007-07-11 16:25 akorolev
  2007-07-11 16:35 ` David Woodhouse
  0 siblings, 1 reply; 3+ messages in thread
From: akorolev @ 2007-07-11 16:25 UTC (permalink / raw)
  To: Linux-MTD Mailing List, David Woodhouse

Hi All

I'm currently working on JFFS2 improving. I faced some issues with 
understanding why we need to align start offset to 4 bytes in 
jffs2_commit_write function?
Here is the part of this code:
=========================

    unsigned aligned_start = start & ~3;
    .........................................
    /* Adjust writtenlen for the padding we did, so we don't confuse our 
caller */
    if (writtenlen < (start&3))
        writtenlen = 0;
    else
        writtenlen -= (start&3);

===========================
What does the padding mean here?
If I properly understand the aligned_start is not related to offset of 
the fragment it is just offset within the file.  (Frag offset is aligned)
File offset is not necessary to keep aligned - so why not to kick off 
it. (I tried and didn't find anything wrong in tests).

Thanks,
Alexey

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Why the alignemt to 4 bytes is necessary in jffs2_commit_write function
  2007-07-11 16:25 Why the alignemt to 4 bytes is necessary in jffs2_commit_write function akorolev
@ 2007-07-11 16:35 ` David Woodhouse
  2007-07-11 16:43   ` akorolev
  0 siblings, 1 reply; 3+ messages in thread
From: David Woodhouse @ 2007-07-11 16:35 UTC (permalink / raw)
  To: akorolev; +Cc: Linux-MTD Mailing List

On Wed, 2007-07-11 at 20:25 +0400, akorolev wrote:
> If I properly understand the aligned_start is not related to offset of
> the fragment it is just offset within the file.  (Frag offset is
> aligned) File offset is not necessary to keep aligned - so why not to
> kick off it. (I tried and didn't find anything wrong in tests).

Consider:
	while (1)
		write(fd, "x", 1);

This is fairly much worst-case behaviour for JFFS2, and you end up with
a _large_ number of data nodes. One thing we've done to improve
behaviour in this situation is rewrite the entire page when we write the
last byte in a page -- but that doesn't fix _all_ cases.

Since data nodes _are_ aligned to 4 bytes, it doesn't hurt us at all to
write a full 4 bytes instead of only 1 byte. So you'll have a maximum of
1024 data nodes for a given 4KiB page even if you don't manage to
trigger the code which rewrites the page.

-- 
dwmw2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Why the alignemt to 4 bytes is necessary in jffs2_commit_write function
  2007-07-11 16:35 ` David Woodhouse
@ 2007-07-11 16:43   ` akorolev
  0 siblings, 0 replies; 3+ messages in thread
From: akorolev @ 2007-07-11 16:43 UTC (permalink / raw)
  To: David Woodhouse; +Cc: Linux-MTD Mailing List

Aghh I see.
Thank you very much!

> On Wed, 2007-07-11 at 20:25 +0400, akorolev wrote:
>   
>> If I properly understand the aligned_start is not related to offset of
>> the fragment it is just offset within the file.  (Frag offset is
>> aligned) File offset is not necessary to keep aligned - so why not to
>> kick off it. (I tried and didn't find anything wrong in tests).
>>     
>
> Consider:
> 	while (1)
> 		write(fd, "x", 1);
>
> This is fairly much worst-case behaviour for JFFS2, and you end up with
> a _large_ number of data nodes. One thing we've done to improve
> behaviour in this situation is rewrite the entire page when we write the
> last byte in a page -- but that doesn't fix _all_ cases.
>
> Since data nodes _are_ aligned to 4 bytes, it doesn't hurt us at all to
> write a full 4 bytes instead of only 1 byte. So you'll have a maximum of
> 1024 data nodes for a given 4KiB page even if you don't manage to
> trigger the code which rewrites the page.
>
>   

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-07-11 16:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-11 16:25 Why the alignemt to 4 bytes is necessary in jffs2_commit_write function akorolev
2007-07-11 16:35 ` David Woodhouse
2007-07-11 16:43   ` akorolev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox