Hello,

Since our older flash chips have 256KB erase sectors, we could never use the FTL as the erase buffer would have not fit the available ram of the mcu.

So we've always used our own driver, which is directly wrapping an mtd device with ioctl calls. And it works, so we're not going to change it.


It sounds like a good generic idea. What are the impacts on memory allocation for these new flags? Can the driver force all users to use O_DIRECT to avoid any erase-block sized allocations? That would have been very welcome for this antique flash chip, from Micron IIRC.

Best regards,

Sebastien


On 10/07/2025 19:15, Tomek CEDRO wrote:
Hello world :-)

There is interesting update PR to bch / mtd / ftl / fs subsystems that
increased granularity of control and improved performance (write).
Please take a look, any hints are welcome especially from people using
them that may be affected or verify the improvement :-)

The solution provides backward compatible behavior but the functions
API will be changed with new flags field added so build errors may pop
up after this change.

https://github.com/apache/nuttx/pull/16642

Summary

**To save more space (equivalent to the size of one erase sector of
MTD device) and to achieve faster read and write speeds, a method for
direct writing was introduced at the FTL layer. This can be
accomplished simply by using the following oflags during
the open operation:

     O_DIRECT. when this flag is passed in, ftl internally uses the
direct write strategy and no read cache is used in ftl;
     otherwise, each write will be executed with the minimum
granularity of flash erase sector size which means a
     "sector read back - erase sector - write sector" operation is
performed by using a read cache buffer in heap.

     O_SYNC. When this flag is passed in, we assume that the flash has
been erased in advance and no erase operation
     will be performed internally within ftl. O_SYNC will take effect
only when both O_DIRECT and O_SYNC are passed in
     simultaneously.

     For uniformity, we remapped the mount flag in mount.h and unified
it with the open flag in fcntl.h. The repetitive
     parts of their definitions were reused, and the remaining part of
the mount flag redefine to the unused bit of open
     flags.**

Impact

When an application wants to bypass the following logic in the FTL
layer during the process of writing to Flash: using the sector size as
the buffer for "read-back - erase - write", the MTD device node can be
opened with the O_DIRECT flag. At this point, the FTL will directly
write to the MTD device. The open method is as follows:
fd = open("/dev/mtd_device", O_RDWR | O_DIRECT);

If the application ensures that the flash has been erased in advance,
then adding the O_SYNC logic can control the FTL not to perform
erasure. The open method is as follows:
fd = open("/dev/mtd_device", O_RDWR | O_DIRECT | O_SYNC);

Reply via email to