ubifs write buffer


UBIFS write-buffer

UBIFS write-buffer

UBIFS is asynchronous file-system (readthis section for more information). Asother Linux file-system, it utilizes the page cache. The page cache isa generic Linux memory-management mechanism. It may be very large and cache alot of data. When you write to a file, the data are written to the page cache,marked as dirty, and the write returns (unless the file is synchronous). Laterthe data are written-back.

Write-buffer is an additional UBIFS buffer, which is implemented insideUBIFS, and it sits between the page cache and the flash. This means thatwrite-back actually writes to the write-buffer, not directly to the flash.

The write-buffer is designated to speed-up UBIFS on NAND flashes. NANDflashes consist of NAND pages, which are usually 512, 2KiB or 4KiB in size.NAND page is the minimal read/write unit of NAND flash (seethis section).

Write-buffer size is equivalent to NAND page size (so it is tiny comparingto the page cache). It's purpose is to accumulate small writes, and write fullNAND pages instead of partially filled. Indeed, imagine we have to write 4512-byte nodes with half a second interval, and NAND page size is 2KiB. Withoutwrite-buffer we would have to write 4 NAND pages and waste 6KiB of flash space,while write-buffer allows us to write only once and waste nothing. This meanswe write less, we create less dirty space so UBIFS garbage collector will haveto do less work, we save power.

Well, the example shows an ideal situation, and even with the write-bufferwe may waste space, for example in case of synchronous I/O, or if the dataarrives with long time intervals. This is because the write-buffer has anassociated timer, which flushes it every 3-5 seconds, even if it isn't full.We do this for data integrity reasons.

Of course, when UBIFS has to write a lot of data, it does not use writebuffer. Only the last part of the data which is smaller than the NAND page endsup in the write-buffer and waits more for data, until it is flushed by thetimer.

The write-buffer implementation is a little more complex, and we actuallyhave several of them - one for each journal head. But this does not change thebasic idea behind the write-buffer.

Few notes with regards to synchronization:

  • "sync()" also synchronizes all write-buffers;
  • "fsync(fd)" also synchronizes all write-buffers whichcontain pieces of "fd";
  • synchronous files, as well as files opened with"O_SYNC", bypass write-buffers, so the I/O is indeedsynchronous for this files;
  • write-buffers are also bypassed if the file-system is mounted withthe "-o sync" mount option.

Take into account that write-buffers delay the data synchronization timeoutdefined by "dirty_expire_centisecs" (seehere) by 3-5 seconds. However, sincewrite-buffers are small, only few data are delayed.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值