[Yaffs] Optimizing the number of reads and writes to flash

Reggiani, Adamo areggiani@ferrari.it
Mon, 11 Oct 2004 15:24:42 +0200


Hi Daniel,
uncomment the define of this two labels in the makefile:
CONFIG_YAFFS_DISABLE_CHUNK_ERASED_CHECK
CONFIG_YAFFS_DISABLE_WRITE_VERIFY

In this way you avoid to re-read every chunk before write (to control if =
it's blank) and to re-read after a succesfull write.
I've also made a little modification of the yaffs_WriteNewChunkToNAND, =
to completely avoid chunks read after write (the original code avoids =
yaffs_VerifyCompare only).
Check the following code against cvs one.


static int yaffs_WriteNewChunkToNAND(struct yaffs_DeviceStruct *dev, =
const __u8 *data, yaffs_Spare *spare,int useReserve)
{
	int chunk;

	int writeOk =3D 1;
	int attempts =3D 0;

	do{
		chunk =3D yaffs_AllocateChunk(dev,useReserve);

		if(chunk >=3D 0)
		{

			// First check this chunk is erased...
#ifndef CONFIG_YAFFS_DISABLE_CHUNK_ERASED_CHECK
			writeOk =3D yaffs_CheckChunkErased(dev,chunk);
#endif
			if(!writeOk)
			{
				T(YAFFS_TRACE_ERROR,(TSTR("**>> yaffs chunk %d was not erased" =
TENDSTR),chunk));
			}
			else
			{
				writeOk =3D  yaffs_WriteChunkToNAND(dev,chunk,data,spare);
			}
			attempts++;
#ifndef CONFIG_YAFFS_DISABLE_WRITE_VERIFY
			if(writeOk)
			{
				unsigned char rbData[YAFFS_BYTES_PER_CHUNK];
				yaffs_Spare rbSpare;

				// Readback & verify
				// If verify fails, then delete this chunk and try again
				// To verify we compare everything except the block and
				// page status bytes.
				// NB We check a raw read without ECC correction applied

				yaffs_ReadChunkFromNAND(dev,chunk,rbData,&rbSpare,0);

				if(!yaffs_VerifyCompare(data,rbData,spare,&rbSpare))
				{
					// Didn't verify
					T(YAFFS_TRACE_ERROR,(TSTR("**>> yaffs write verify failed on chunk =
%d" TENDSTR), chunk));

					writeOk =3D 0;
				}

			}
#endif
			if(writeOk)
			{
				// Copy the data into the write buffer.
				// NB We do this at the end to prevent duplicates in the case of a =
write error.
				//Todo
				yaffs_HandleWriteChunkOk(dev,chunk,data,spare);
			}
			else
			{
				yaffs_HandleWriteChunkError(dev,chunk);
			}
		}

	} while(chunk >=3D 0 && ! writeOk);

	if(attempts > 1)
	{
		T(YAFFS_TRACE_ERROR,(TSTR("**>> yaffs write required %d attempts" =
TENDSTR),attempts));
		dev->nRetriedWrites+=3D (attempts - 1);
	}

	return chunk;
}


To reduce writes I think you must wait (or aid ;) for Yaffs2, which will =
use a zero page rewrites to spare area and will have generally better =
performance over Yaffs.
Look at www.aleph1.co.uk/yaffs/yaffs2.html


Regards
Adamo



> -----Original Message-----
> From: yaffs-admin@stoneboat.aleph1.co.uk
> [mailto:yaffs-admin@stoneboat.aleph1.co.uk]On Behalf Of Daniel
> Gustafsson
> Sent: luned=EC 11 ottobre 2004 14.47
> To: yaffs@stoneboat.aleph1.co.uk
> Subject: [Yaffs] Optimizing the number of reads and writes to flash
>=20
>=20
>=20
>=20
> I am using yaffs/direct and I want to reduce the reads and=20
> writes towards
> the flash to an absolute minimum. I do not want any=20
> verifications of flash
> etc. I don not want to use ECC.
>=20
> I would greatly appreatiate any tips regarding the above=20
> issue but also how
> to reduce the footprint in RAM and size.=20
>=20
> Further more I am interested in some documetation what=20
> happens (reads/writes
> to flash) when performing some simple fs operations like=20
> read/write/open
> etc.
>=20
>=20
> I hope someone have the answers I am looking for,
>=20
> Best Regards
> Daniel Gustavsson
>=20
>=20
> _______________________________________________
> yaffs mailing list
> yaffs@stoneboat.aleph1.co.uk
> http://stoneboat.aleph1.co.uk/cgi-bin/mailman/listinfo/yaffs
>=20