Memory requirements

The amount of RAM required by Yaffs to hold its in-memory data structures grows with the number of objects (files and directories) in your filesystem. You are recommended to test your application thoroughly to ensure that sufficient memory exists for Yaffs to operate with the most complicated filesystem it is likely to encounter.

If you wish to estimate your RAM usage, the Yaffs author provides the following calculation:

  • The partition itself requires a yaffs_DeviceStruct of 3608 bytes.

  • If CYGNUM_FS_YAFFS_SHORTOP_CACHES is enabled, each is the size of a NAND page plus 28 bytes.

  • Every object (file, directory or hardlink) in the filesystem takes a yaffs_Object struct, which is 124 bytes.

  • Every page of every file requires a Tnode entry, but they are always allocated in groups of 16 at a time.

    • The size of a single Tnode entry is the number of bits required to number all the pages in the NAND partition Yaffs is using, numbering from one; this is rounded up to a multiple of 2, and has an absolute minimum of sixteen bits.

    • For example: on a partition with 65536 pages, seventeen bits are required for the numbering, which round up to 18. Therefore each file takes 288 bits (36 bytes) per group of Tnodes, and one group of Tnodes will cover up to sixteen pages of data.

Note: Actual memory consumption will be slightly higher than suggested by the above. This arises from the tree structure holding the Tnodes, overheads from the heap itself, and so on.

Yaffs calls the standard malloc function to allocate memory and free to release it. Normally, the eCos heap occupies all spare RAM not needed for the program, its static data or the stacks. Therefore, most applications will not need to do anything special beyond ensuring there is enough spare RAM available on the platform.

Tip: If you wish to experiment with restricted-size heaps to determine much memory your application actually uses under Yaffs, you may find the option CYGSEM_MEMALLOC_INVOKE_OUT_OF_MEMORY of use.

Worked example

Consider a Yaffs filesystem hosted by a NAND partition with 65536 pages, each of size 2k, using the default setting of ten short-op caches. On this filesystem we shall store 10000 files each of size 10240 bytes, hence each requires a single group of Tnodes.

Table 49-1. Yaffs RAM use worked example

ConsumerRAM used (bytes)
yaffs_DeviceStruct 3,608
Short-op caches @ 10 x (2048+28) 20,760
yaffs_Objects @ 10,000 x 124 1,240,000
Tnode groups @ 10,000 x 36 (see above) 360,000
Total 1,624,368

This example is a close match to the actual consumption measured by eCosCentric during testing. (The measured consumption as reported by mallinfo was 1,681,112 bytes, which includes the heap's own overheads.)

Documentation license for this page: eCosPro License