In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to achieve Yaffs_guts garbage collection", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to achieve Yaffs_guts garbage collection.
1. Garbage collection
1.static int yaffs_InitialiseBlocks (yaffs_Device * dev,int nBlocks) / / Block initialization
Dev- > chunkBitmapStride = (dev- > nChunksPerBlock+7) / 8. Why + 7?
Oh, in order to prevent the number of pages from being less than 8, still assign a Stride
2.static int yaffs_FindDirtiestBlock (yaffs_Device * dev,int aggressive) / / find the dirtiest fast, for GC
Personal feeling: this should be what the sacrifice block selection algorithm needs to do.
If (bi- > blockState = = YAFFS_BLOCK_STATE_FULL & &
(bi- > pagesInUse-bi- > softDeletions)
< pagesInUse) //pages_in_use:该擦除块中被使用的chunk数目,包括已经被soft delete的chunk { dirtiest = b; pagesInUse = (bi->PagesInUse-bi- > softDeletions)
}
If you can't find it, return-1.
3.static void yaffs_BlockBecameDirty (yaffs_Device * dev,int blockNo) / / turn a piece into a dirty block
4.static int yaffs_FindBlockForAllocation (yaffs_Device * dev) / / looking for allocable blocks
5.static int yaffs_AllocateChunk (yaffs_Device * dev,int useReserve)
UseReserve indicates whether to use reserved space. The yaffs2 file system does not use all the storage space to store file system data, but frees up part of the block for garbage collection. In general, this parameter is 0, and it is set to 1 only if storage space needs to be allocated for garbage collection.
6.static int yaffs_GarbageCollectBlock (yaffs_Device * dev,int block)
For (chunkInBlock = 0 dev- = block * Chunk > nChunksPerBlock
ChunkInBlock
< dev->NChunksPerBlock & & yaffs_StillSomeChunkBits (dev,block)
ChunkInBlock++, oldChunk++) / / detect blocks to be erased until all pages have been traversed through valid pages
·if (yaffs_CheckChunkBit (dev,block,chunkInBlock)) / / if there is content in the scanned page
V if (object & & object- > deleted & & tags.chunkId! = 0) / / if there is data in the page
{Delete the data and delete the corresponding Object}
If (tags.chunkId = = 0)
{
Object- > chunkId = newChunk
Object- > serial = tags.serialNumber
}
Else
{
/ / it is a data chunk
Yaffs_PutChunkIntoFile (object, tags.chunkId, newChunk,0)
}
Finally, delete the page yaffs_DeleteChunk (dev,oldChunk,markNAND)
SerialNumber: used to identify which Chunk is the latest Chunk. When updating this Chunk, serialNumber will add 1 and write to the Chunk of other Block, and set the original Chunk to Invalid (this Data Chunk is no longer valid). However, if a power outage (Power Lost) occurs before the Chunk is set to Invalid, when the power supply resumes and rescanns the Flash Memory, it will check a yaffs_Object to have two identical Chunk (its ChunkID is the same), but its serialNumber is different, then the serialNumber of the two chunks will be compared. To identify which Chunk is the newer Data, and set the Chunk of the older Data to Invalid.
7.static int yaffs_CheckGarbageCollection (yaffs_Device * dev)
/ / yaffs checks whether garbage collection is successful
2.TAGS
1.static void yaffs_LoadTagsIntoSpare (yaffs_Spare * sparePtr, yaffs_Tags * tagsPtr) / / populate tags into the spare depot
2.yaffs_CheckECCOnTags (tagsPtr); / / returns a recoverable error of 1 and an unrecoverable error of-1
3.static void yaffs_GetTagsFromSpare (yaffs_Device * dev, yaffs_Spare * sparePtr,yaffs_Tags * tagsPtr)
/ / if (result > 0) dev- > tagsEccFixed++
/ / if (result tagsEccUnfixed++
4.static int yaffs_ReadChunkTagsFromNAND (yaffs_Device * dev,int chunkInNAND, yaffs_Tags * tags, int * chunkDeleted)
5.static int yaffs_WriteNewChunkWithTagsToNAND (yaffs_Device * dev, const _ _ U8 * buffer, yaffs_Tags * tags, int useReserve)
6.static int yaffs_TagsMatch (const yaffs_Tags * tags, int objectId, int chunkInObject, int chunkDeleted) / / matches object. If 1 is returned correctly, 0 is returned otherwise.
7.int yaffs_FindChunkInFile (yaffs_Object * in,int chunkInInode,yaffs_Tags * tags) / / look for chunk in the file. Return theChunk if found, or-1 if not found.
8.int yaffs_FindAndDeleteChunkInFile (yaffs_Object * in,int chunkInInode,yaffs_Tags * tags) / / Delete the page in the file, return theChunk if it is found, or-1 if it is not found
9.static int yaffs_CheckFileSanity (yaffs_Object * in) / / checks whether the file is normal. If it returns 1 normally, 0 will be returned otherwise.
10.static int yaffs_PutChunkIntoFile (yaffs_Object * in,int chunkInInode, int chunkInNAND, int inScan) / / in order to prevent duplicate pages in the event of a power failure, set the inScan flag to determine
11.int yaffs_ReadChunkDataFromObject (yaffs_Object * in,int chunkInInode, _ _ U8 * buffer)
12.static void yaffs_DeleteChunk (yaffs_Device * dev,int chunkId,int markNAND) / / removes the page from the file, and then determines whether all the pages on the block are invalid, the block is marked as a dirty block and can be erased
13.int yaffs_WriteChunkDataToObject (yaffs_Object * in,int chunkInInode, const _ _ U8 * buffer,int nBytes,int useReserve)
14.int yaffs_UpdateObjectHeader (yaffs_Object * in,const char * name, int force)
3. Read and write files
1.int yaffs_ResizeFile (yaffs_Object * in, int newSize) / / modify the file size. Return newSize if newSize is less than oldSize, and oldSize if oldSize is greater than newSize
2.int yaffs_GetFileSize (yaffs_Object * obj) / / give the object to get the file size
4.Scanning
1.static int yaffs_IsBlockBad (yaffs_Device * dev, int blk) / / check only the first two pages
At this point, I believe you have a deeper understanding of "how to achieve Yaffs_guts garbage collection". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.