Skip to contentSkip to conversation

Database on JFFS2?

DISCUSSION Esben Nielsen 5 participants 11 messages Apr 14, 2003 – Apr 16, 2003 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

Is it posible to run a sql database (mysql forinstance) on a JFFS2 filesystem?

Running just a database as it is seems to be out of the question due to the many writes a database does. At least some tweaking is needed.

Do anyone have experience wth MySQL or other database engines running on a JFFS2 volume?

Esben Nielsen

#1 lore raw
Quoted 2 lines · Esben Nielsen

Is it posible to run a sql database (mysql forinstance) on a JFFS2 filesystem?

What kind of flash? NOR flash is very slow for writing, making some database solutions impractical.

People are using NAND with YAFFS in database-like solutions.

-- CHarles

#2 lore raw

Our flash is NOR (Intel statoflash). What we a going for is a standeard SQL solution - so it isn't enough that the filesystem has a database-like behaviour.

Someone from this list pointed out sqlite to me yesterday. I am looking into that now. It has a log system. The most optimal would be if the database could be tuned not to write too often and on other hand when it does it is flush to flash immediately to prevent datacorruption. I am not quite sure how to make it work with JFFS2. DoesJFFS2 write immediately on fsync() or it is buffered in ram making the database believe it is safe to delete it's transactionlog?

Esben

Quoted 10 lines · Charles Manning
Quoted 2 lines · Esben Nielsen

Is it posible to run a sql database (mysql forinstance) on a JFFS2 filesystem?

What kind of flash? NOR flash is very slow for writing, making some database solutions impractical.

People are using NAND with YAFFS in database-like solutions.

-- CHarles

#3 lore raw
Quoted 5 lines · Esben Nielsen

Our flash is NOR (Intel statoflash). What we a going for is a standeard SQL solution - so it isn't enough that the filesystem has a database-like behaviour.

Quoted 7 lines

Someone from this list pointed out sqlite to me yesterday. I am looking into that now. It has a log system. The most optimal would be if the database could be tuned not to write too often and on other hand when it does it is flush to flash immediately to prevent datacorruption. I am not quite sure how to make it work with JFFS2. DoesJFFS2 write immediately on fsync() or it is buffered in ram making the database believe it is safe to delete it's transactionlog?

afaik jffs2 writes immediately to flash, even without fsync, as long as you use NOR. NAND holds a buffer for 2s, I'd have to check when this is flushed exactly.

Jörn

Signature · 2 lines
Those who come seeking peace without a treaty are plotting.
-- Sun Tzu
#4 lore raw
In reply to Esben Nielsen
Quoted 3 lines

into that now. It has a log system. The most optimal would be if the database could be tuned not to write too often and on other hand when it does it is flush to flash immediately to prevent datacorruption.

That is simple to find out. sqllite is so small, you surely could add some printf() statements at the right place to find out when it writes date.

Hey, even "strace -efile" may help you. "man strace" is your friend.

#5 lore raw

Yes, but are those writes syncronices with actual flash writes such I am sure that a write is _physically_ complete when fsync() returns?
They certainly ought to be or many applications would get in trouble with corrupt data at a sudden reboot.

Let us assume it is so. Then I need to tweak sqlite to only force an fsync() when the JFFS2 layer is ready to commit anyway to avoid too many writes. Any idea of how to do that?

Esben

Quoted 14 lines · Holger Schurig
Quoted 3 lines

into that now. It has a log system. The most optimal would be if the database could be tuned not to write too often and on other hand when it does it is flush to flash immediately to prevent datacorruption.

That is simple to find out. sqllite is so small, you surely could add some printf() statements at the right place to find out when it writes date.

Hey, even "strace -efile" may help you. "man strace" is your friend.

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

#6 lore raw
Quoted 9 lines · Esben Nielsen

Yes, but are those writes syncronices with actual flash writes such I am sure that a write is _physically_ complete when fsync() returns?
They certainly ought to be or many applications would get in trouble with corrupt data at a sudden reboot.

Let us assume it is so. Then I need to tweak sqlite to only force an fsync() when the JFFS2 layer is ready to commit anyway to avoid too many writes. Any idea of how to do that?

On NOR, there is absolutely no point in avoiding many writes. Write the same amount of data in fewer bigger chunks and you have the same problems.

If you can reduce the amount of data written to flash, do that.

Jörn

Signature · 3 lines
Courage is not the absence of fear, but rather the judgement that
something else is more important than fear.
-- Ambrose Redmoon
#7 lore raw
Quoted 2 lines · Jörn Engel

On NOR, there is absolutely no point in avoiding many writes.

Unless it would cause many erases, which would slow things down a lot... If data integrity is the crucial issue (which it usually is) there's no way to avoid this, though.

The only other issue I can foresee is the overhead of the jffs structures at the start of each write; if there are only a few bytes being written each time, it quickly becomes very significant.

Jas.

#8 lore raw
Quoted 8 lines · Jasmine Strong
Quoted 2 lines · Jörn Engel

On NOR, there is absolutely no point in avoiding many writes.

Unless it would cause many erases, which would slow things down a lot... If data integrity is the crucial issue (which it usually is) there's no way to avoid
this, though.

Erases get triggered by garbage collection, which depends on the amount of data written, not the chunk size.

Quoted 5 lines

The only other issue I can foresee is the overhead of the jffs structures at the
start of each write; if there are only a few bytes being written each time, it
quickly becomes very significant.

Correct. iirc, node header was 70 Bytes, so writes below 700 Bytes will have significant overhead (10% in my book). Point taken.

Jörn

Signature · 3 lines
Fantasy is more important than knowlegde. Knowlegde is limited,
while fantasy embraces the whole world.
-- Albert Einstein
#9 lore raw
Quoted 4 lines · Jörn Engel
Quoted 1 line · Jasmine Strong

Unless it would cause many erases, which would slow things down a lot...

Erases get triggered by garbage collection, which depends on the amount of data written, not the chunk size.

yes. I think my two points were actually the same point taken twice :-) If you're only updating a few bytes of data you will end up writing a large proportion of log control data. That'll end up being responsible for most of the erase traffic.

Still, if you need to be powerfail-safe, I can't see any way of not doing this.

-Jas.

#10 lore raw
Quoted 11 lines · Jasmine Strong
Quoted 5 lines · Jörn Engel
Quoted 2 lines · Jasmine Strong

Unless it would cause many erases, which would slow things down a lot...

Erases get triggered by garbage collection, which depends on the amount of data written, not the chunk size.

yes. I think my two points were actually the same point taken twice :-) If you're only updating a few bytes of data you will end up writing a large proportion of log control data. That'll end up being responsible for most of the erase traffic.

Actually, that shouldn't matter too much. For comparison, I did some benchmarks using jffs2 (without compression) as a filesystem for a ramdisk.

The benchmark wrote data to jffs2, deleted it and repeated this several times to remove statistical noise. Horrible results. Then I got a clue and added "sleep 6" after both writing and deleting, getting roughly twice the performance. Why?

Under normal operation, the system is idle a lot and the garbage collector (GC) has plenty of time to clean up the mess you made. But the first benchmark was measuring a system without idle times, so all writes were waiting for GC to finally free some space. Wrong.

Back to the Database:
Even if you write data in very small chunks, the system should have enough free time to GC those fragments and reassemble them into larger chunks with less overhead, so this doesn't matter.

Unless you permanently operate near the limit. Without the free time for GC, this does matter.

Quoted 2 lines

Still, if you need to be powerfail-safe, I can't see any way of not doing this.

Right.

Jörn

Signature · 2 lines
Sometimes, asking the right question is already the answer.
-- Unknown