romfs: expand file cache by CONFIG_FS_ROMFS_FCACHE_NSECTORS
The default size of file cache is size of a sector, it may not be good size for optimizing read/write speed in physical device. So we can set the config according to speed test profile to optimize access IO speed. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
c629fd1b00
commit
d6423b5527
@ -20,4 +20,11 @@ config FS_ROMFS_CACHE_NODE
|
||||
is mounted so that we can quick access entry of ROMFS
|
||||
filesystem on emmc/sdcard.
|
||||
|
||||
config FS_ROMFS_CACHE_FILE_NSECTORS
|
||||
int "The number of file cache sector"
|
||||
range 1 256
|
||||
default 1
|
||||
---help---
|
||||
The number of file cache sector
|
||||
|
||||
endif
|
||||
|
@ -424,7 +424,7 @@ static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer,
|
||||
*/
|
||||
|
||||
nsectors = SEC_NSECTORS(rm, buflen);
|
||||
if (nsectors > 0 && sectorndx == 0)
|
||||
if (nsectors >= rf->rf_ncachesector && sectorndx == 0)
|
||||
{
|
||||
/* Read maximum contiguous sectors directly to the user's
|
||||
* buffer without using our tiny read buffer.
|
||||
@ -460,7 +460,9 @@ static ssize_t romfs_read(FAR struct file *filep, FAR char *buffer,
|
||||
|
||||
/* Copy the partial sector into the user buffer */
|
||||
|
||||
bytesread = rm->rm_hwsectorsize - sectorndx;
|
||||
bytesread = (rf->rf_cachesector + rf->rf_ncachesector - sector) *
|
||||
rm->rm_hwsectorsize - sectorndx;
|
||||
sectorndx = rf->rf_ncachesector * rm->rm_hwsectorsize - bytesread;
|
||||
if (bytesread > buflen)
|
||||
{
|
||||
/* We will not read to the end of the buffer */
|
||||
|
@ -149,8 +149,10 @@ struct romfs_mountpt_s
|
||||
struct romfs_file_s
|
||||
{
|
||||
uint32_t rf_startoffset; /* Offset to the start of the file data */
|
||||
uint32_t rf_endsector; /* Last sector of the file data */
|
||||
uint32_t rf_size; /* Size of the file in bytes */
|
||||
uint32_t rf_cachesector; /* Current sector in the rf_buffer */
|
||||
uint32_t rf_cachesector; /* First sector in the rf_buffer */
|
||||
uint32_t rf_ncachesector; /* Number of sectors in the rf_buffer */
|
||||
FAR uint8_t *rf_buffer; /* File sector buffer, allocated if rm_xipbase==0 */
|
||||
uint8_t rf_type; /* File type (for fstat()) */
|
||||
char rf_path[1]; /* Path of open file */
|
||||
|
@ -574,17 +574,18 @@ int romfs_filecacheread(FAR struct romfs_mountpt_s *rm,
|
||||
{
|
||||
int ret;
|
||||
|
||||
finfo("sector: %" PRId32 " cached: %" PRId32
|
||||
finfo("sector: %" PRId32 " cached: %" PRId32 " ncached: %" PRId32 ""
|
||||
" sectorsize: %d XIP base: %p buffer: %p\n",
|
||||
sector, rf->rf_cachesector, rm->rm_hwsectorsize,
|
||||
rm->rm_xipbase, rf->rf_buffer);
|
||||
sector, rf->rf_cachesector, rf->rf_ncachesector,
|
||||
rm->rm_hwsectorsize, rm->rm_xipbase, rf->rf_buffer);
|
||||
|
||||
/* rf->rf_cachesector holds the current sector that is buffer in or
|
||||
* referenced by rf->rf_buffer. If the requested sector is the same as this
|
||||
* sector then we do nothing.
|
||||
*/
|
||||
|
||||
if (rf->rf_cachesector != sector)
|
||||
if (rf->rf_cachesector > sector ||
|
||||
rf->rf_cachesector + rf->rf_ncachesector <= sector)
|
||||
{
|
||||
/* Check the access mode */
|
||||
|
||||
@ -599,10 +600,15 @@ int romfs_filecacheread(FAR struct romfs_mountpt_s *rm,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sector + rf->rf_ncachesector - 1 > rf->rf_endsector)
|
||||
{
|
||||
sector = rf->rf_endsector + 1 - rf->rf_ncachesector;
|
||||
}
|
||||
|
||||
/* In non-XIP mode, we will have to read the new sector. */
|
||||
|
||||
finfo("Calling romfs_hwread\n");
|
||||
ret = romfs_hwread(rm, rf->rf_buffer, sector, 1);
|
||||
ret = romfs_hwread(rm, rf->rf_buffer, sector, rf->rf_ncachesector);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: romfs_hwread failed: %d\n", ret);
|
||||
@ -802,18 +808,29 @@ int romfs_fileconfigure(FAR struct romfs_mountpt_s *rm,
|
||||
{
|
||||
/* We'll put a valid address in rf_buffer just in case. */
|
||||
|
||||
rf->rf_cachesector = 0;
|
||||
rf->rf_buffer = rm->rm_xipbase;
|
||||
rf->rf_cachesector = 0;
|
||||
rf->rf_buffer = rm->rm_xipbase;
|
||||
rf->rf_ncachesector = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t nsectors;
|
||||
|
||||
rf->rf_endsector = SEC_NSECTORS(rm, rf->rf_startoffset + rf->rf_size);
|
||||
nsectors = rf->rf_endsector - SEC_NSECTORS(rm, rf->rf_startoffset) + 1;
|
||||
if (nsectors > CONFIG_FS_ROMFS_CACHE_FILE_NSECTORS)
|
||||
{
|
||||
nsectors = CONFIG_FS_ROMFS_CACHE_FILE_NSECTORS;
|
||||
}
|
||||
|
||||
/* Nothing in the cache buffer */
|
||||
|
||||
rf->rf_cachesector = (uint32_t)-1;
|
||||
rf->rf_ncachesector = nsectors;
|
||||
|
||||
/* Create a file buffer to support partial sector accesses */
|
||||
|
||||
rf->rf_buffer = (FAR uint8_t *)kmm_malloc(rm->rm_hwsectorsize);
|
||||
rf->rf_buffer = kmm_malloc(rm->rm_hwsectorsize * rf->rf_ncachesector);
|
||||
if (!rf->rf_buffer)
|
||||
{
|
||||
return -ENOMEM;
|
||||
|
Loading…
Reference in New Issue
Block a user