Comments (6)
Hi @yamt, thanks for opening an issue.
I'm glad you proposed this, because I only learned pread/pwrite are in standard POSIX recently. It makes sense as an API and I think it would be good to add.
pread/pwrite also shouldn't add much code cost as most of the logic should be shared behind the scenes.
it's likely inefficient as littlefs's seek also moves cache position
The reason littlefs's seek moves the cache is because we usually need it for reading/writing, so I don't think pread/pwrite will escape this cost. Maybe when pread/pwrite bypasses the cache.
That being said, non-disk-format related API changes are low priority at the moment. So it may take some time for this to land.
from littlefs.
it's likely inefficient as littlefs's seek also moves cache position
The reason littlefs's seek moves the cache is because we usually need it for reading/writing, so I don't think pread/pwrite will escape this cost. Maybe when pread/pwrite bypasses the cache.
i meant that, a straightforward emulation with lseek like the following would be inefficient as it moves
the position back and forth. a native implementation can be better.
lfs_file_pread(off) {
orig_pos = lfs_file_seek(CUR);
lfs_file_seek(off, SET);
lfs_file_read();
lfs_file_seek(orig_pos, SET);
}
from littlefs.
A native implementation could save a CTZ skip-list lookup, that's true. And there may be other opportunities for minor optimizations.
But caching is a bit of a harder problem, since lfs_file_pread
doesn't know what the next operation will be. It may be followed by a pread
immediately after if above layers emulate read
with multiple pread
calls, for example.
from littlefs.
But caching is a bit of a harder problem, since
lfs_file_pread
doesn't know what the next operation will be. It may be followed by apread
immediately after if above layers emulateread
with multiplepread
calls, for example.
are you concerning cache-hit rate here?
from littlefs.
Ah yeah. Cases like these:
// write blob
pwrite(f, 0, <data_blob>)
// scan for start of payload
lfs_off_t payload_start = 0;
while (true) {
pread(f, payload_start, buf, strlen("<header>"));
if (strcmp(buf, "<header>") == 0) {
break;
}
payload_start += 1;
}
You could argue this should be done with seek
+ read
, but I'm not sure that's always possible when other OS layers get involved. FUSE for example only talks in pread
/pwrite
(fuse_lowlevel_ops.read).
Though, as an "optimization problem", there may not be a single correct impl here.
from littlefs.
Though I suppose you could also argue the FUSE impl should still call seek
+ read
if only for cache reasons.
Maybe the best option is unclear. Not moving the cache in pread
/pwrite
at least gives users more control, even though the performance differences may be initially confusing to users.
from littlefs.
Related Issues (20)
- Block count defined twice HOT 1
- What is the "bd" folder? HOT 1
- why t1_buf is sample of t2_buf at sometime?
- Expanding superblock deletes File HOT 7
- '-fcallgraph-info=su' breaking builds on some platforms HOT 9
- All the data is lost after update from disk 2.0 to disk 2.1 HOT 3
- v2.7 : long delay in open/close for spi nor HOT 8
- Data Flash values after erase is "undefined" - Would LittleFS work? HOT 1
- Do we really need directory structures in meta data layer for simple structure variable read/write? HOT 1
- running into RAM limitations for freertos tasks HOT 1
- LittleFS Display Directory Content HOT 3
- File creation with full path in the name HOT 2
- Query: failing to find files after a soak test HOT 8
- Usage of lfs_dir_seek HOT 2
- File system corruption when creating directories HOT 2
- used and free memory HOT 2
- issue when append data to a file HOT 2
- Wrong printf specifiers
- examples about use BDs provided (in particular lfs_filebd)
- Where do we find the version in the code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from littlefs.