Yaffs Tuning

Submitted by Admin on 22 July, 2012 - 8:23pm


1 Yaffs Direct Configuration

Yaffs behaviour is dictated by compile time and run-time flags.

1.1 Initialisation Parameters

Each yaffs device is configured by a yaffs_DeviceParameterStruct structure which is part of the yaffs_DeviceStruct structure. This contains the following fields:


An optional name for the device


The number of bytes in the data area of the flash page. If inbandTags is not set then this whole area will be used to store data and the tags will be stored in the spare area. If inbandTags is set then part of this area will be used to store tags and the rest will be used to store data.


The number of available bytes in the spare area of the flash page. This excludes space used by ECC, bad block markers etc.


The first block in the partition to be used. 0 for first block.


The last block in the partition to be used.




Number of good blocks blocks reserved for garbage collection etc. Needs to be at least 2, but 5 would be a more typical number.


Yaffs2 only:Flag indicating whether tags should be stored in the data area. If inbandTags is set then the short Op cache must be enabled (ie nShortOpCaches must be non-zero.


Yaffs1 only: Flag indicating whether the driver performs ECC. If this is zero then Yaffs will perform ECC.


Yaffs2 only: Flag indicating whether the tags have ECC attached to them.


Flag indicating if this is using the Yaffs2 mechanism. If this is not set then Yaffs1 mode of operation is provided.




Number of chunks to store in the short operation cache. Zero disables caching. Typical value is 10 to 20 or so. Caching is required for inband tags.


Flag to delete all files in lost and found on mount.


Yaffs2 only: Flag to skip reading checkpoint on mount. If set then a re-scan is forced.


Yaffs2 only: Flag to skip writing checkpoint on sync or unmount.


Yaffs2 only: How often Yaffs should do a block refresh. Values less than 10 disable block refreshing. Typical values would be1000.




Pointer to function to initialise flash driver.


Pointer to function to de-initialise flash driver


Pointer to function to erase a flash block




Yaffs1 only: Pointer to function to write a chunk


Yaffs1 only: Pointer to function to read a chunk.




Yaffs2 only: Pointer to function to write a chunk plus tags


Yaffs2 only: Pointer to function to read a chunk plus tags


Yaffs2 only: Function to mark a block bad


Yaffs2 only: Function to query a block state




Callback function that returns the garbage collector control flags. This is optional.


Callback function called when an object is removed. This is set by the wrapper.


Callback function that is called when a clean file system is first modified. This is set by the wrapper.




Yaffs1 only. Debug only. Disables soft deletion if non-zero.




Debug only. Leave as zero


Debug only. Leave as zero.


Debug only. Leave as zero.




Used to defer directory updates.


1.2 Compile-time settings

These setting are used to apply compile-time configurations.


Normally Yaffs checks that chunks are erased only on the first chunk write to each block. This flag allows you to force all chunks to be checked. This is slower, but is worth using when doing early debugging.


When selected case insensitive name comparisons are used. Note that this will not magically change Yaffs to be case insensitive in a case sensitive OS. This needs to be set according to the OS policy. Typically this is only used in Windows CE.


Used when compiling Yaffs Direct.


Lazy loading is used to defer loading up object details until the objects are accessed. This makes mount time faster. This flag can disable lazy loading. Debug only.


This flag should only be used with old Linux MTD code which had a bug in the ECC byte ordering.


Used to say that only Yaffs2 operation should be compiled in. Not currently supported.


Set to configure Yaffs to store short object names in RAM. This is faster, but uses up more memory.


Set to configure Yaffs to use Unicode file names (eg. With WinCE).


By default, Yaffs uses qsort for sorting blocks at mount scanning time. This is faster. Using this flag forces Yaffs to use a slow internal sort instead. Debug only.


Used when compiling Yaffs for utilities.


Set when compiling Yaffs for WinCE.


Set when using Yaffs2 mode. At present this must always be set.


Used when compiling Yaffs Direct only.

2 Tracing mechanism

Yaffs has a lot of built in tracing to help debug and integrate. The tracing is controlled by yaffs_traceMask bitmask which allows various sets of tracing to be disabled or enabled at runtime.

The trace bits are specified in the yaffs_trace.h file.

The tracing mechanism has also been 'hijacked' to provide a control mask for extra verification code when the YAFFS_TRACE_VERIFYxxx trace bits are selected.

The tracing mechanism is readily integrated into the system via printf-like statements. Tracing is all done through macros which allow the strings to be converted into unicode or similar if need be.

3 Linux

3.1 Linux compile-time flags

The Linux compile time flags are documented in the Kconfig file and will not be duplicated here.

3.2 Linux: /proc/yaffs trace adjustment

Under Linux, the tracing mechanism is hooked up to both the /proc/yaffs and the sys interface. The /proc/yaffs interface is very user friendly.

#cat +os > /proc/yaffs # Enables YAFFS_TRACE_OS
#cat -all+gc > /proc/yaffs # Disables everything then enable YAFFS_TRACE_GC
#cat 0xf000 > /proc/yaffs # Set trace mask to specified bitmask.

3.3 Linux: /sys/ interface

The Linux /sys/ interface is used by many Linux OS components to access the state of control variables. Some Yaffs variables are available via /sys/module/yaffs2/parameters/ *. Values can be read and modified using standard shell commands or from application programs.

# ls /sys/module/yaffs2/parameters/ yaffs_auto_checkpoint yaffs_traceMask yaffs_wr_attempts
# cat /sys/module/yaffs2/parameters/yaffs_auto_checkpoint 1
# echo "2" > /sys/module/yaffs2/parameters/yaffs_auto_checkpoint
# cat /sys/module/yaffs2/parameters/yaffs_auto_checkpoint 2

Yaffs currently supports the following variables:

yaffs_auto_checkpoint: Controls when checkpoints should be written.

yaffs_traceMask: An alternative, and less user friendly,interface to modify tracing.

yaffs_wr_attempts: The number of attempts that Yaffs will make to write a chunk.

yaffs_gc_control: Controls the garbage collector.

3.4 Linux: /proc/yaffs state dumping

Some of the state of Yaffs mounts can be determined by reading the /proc/yaffs entry.

# cat /proc/yaffs
charles@charles-laptop:/opt/y/cvs/yaffs2$ cat /proc/yaffs
YAFFS built:Mar 16 2010 11:52:25
$Id: yaffs_fs.c,v 1.101 2010-03-15 22:27:15 charles Exp $
$Id: yaffs_guts.c,v 1.119 2010-03-12 02:48:34 charles Exp $

Device 0 "NAND simulator partition 0"

startBlock......... 0
endBlock........... 511
totalBytesPerChunk. 2048
useNANDECC......... 1
noTagsECC.......... 0
isYaffs2........... 1
inbandTags......... 0
emptyLostAndFound.. 1
disableLazyLoad.... 0
refreshPeriod...... 10000
nShortOpCaches..... 10
nReservedBlocks.... 5

nDataBytesPerChunk. 2048
chunkGroupBits..... 0
chunkGroupSize..... 1
nErasedBlocks...... 152
blocksInCheckpoint. 0

nTnodesCreated..... 2300
nFreeTnodes........ 1852
nObjectsCreated.... 2300
nFreeObjects....... 1842
nFreeChunks........ 27843

nPageWrites........ 65993
nPageReads......... 19631
nBlockErasures..... 1133
nGCCopies.......... 37
garbageCollections. 161
passiveGCs......... 137
nRetriedWrites..... 0
nRetireBlocks...... 0
eccFixed........... 0
eccUnfixed......... 0
tagsEccFixed....... 0
tagsEccUnfixed..... 0
cacheHits.......... 44110
nDeletedFiles...... 0
nUnlinkedFiles..... 42917
refreshCount....... 1
nBackgroudDeletions 0


4 Conclusions

Yaffs includes many options for changing speed or memory use, with specific flags for the Yaffs Direct Interface as well as Linux. Under Linux many of the control variables can be altered using standard Linux systems.