mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	Fixed excessive waste from overly large inline files
Before this, there were some safety limits, but there was no real default limit to the size of inline files other than the amount of RAM available. On PCs, this meant that inline files were free to fill up directory blocks to a little under the block size. However this is very wasteful in terms of storage space. Because of splitting limits to keep the compact runtime reasonable, each byte of an inline files uses 4x the amount. Fortunately we can find an optimal inline limit: Inline file waste for n bytes = 3n CTZ file waste for n bytes = B - n Where B = block size Solving for n = B/4 So the optimal inline limit is B/4. However, this assumes a perfect inline file and no metadata. We can decrease this to B/8 to give a bit more breathing room for directory+file metadata.
This commit is contained in:
		
							
								
								
									
										3
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -2710,7 +2710,8 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, | ||||
|  | ||||
|     if ((file->flags & LFS_F_INLINE) && | ||||
|             lfs_max(file->pos+nsize, file->ctz.size) > | ||||
|             lfs_min(lfs->cfg->cache_size, LFS_ATTR_MAX)) { | ||||
|             lfs_min(LFS_ATTR_MAX, lfs_min( | ||||
|                 lfs->cfg->cache_size, lfs->cfg->block_size/8))) { | ||||
|         // inline file doesn't fit anymore | ||||
|         file->off = file->pos; | ||||
|         int err = lfs_file_relocate(lfs, file); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user