jingfei195887 opened a new pull request, #22207:
URL: https://github.com/apache/nuttx/pull/22207
## Summary
- **fs/romfs: use a per-file lock for read and seek with XIP media.**
`romfs_read()` and `romfs_seek()` take the mount-level `rm_lock`, so
reads of different files on the same mount are serialized.
With XIP media (`rm_xipbase` set, e.g. a romdisk or memory-mapped flash)
a read only copies from the mapped address and touches only per-file
state (`f_pos`, `rf_buffer`, `rf_cachesector`). A new per-file mutex
`rf_lock` now protects read/seek there, so reads of different files run
in parallel while threads that share one open file are still serialized.
Without XIP the read goes through the block driver, which may rely on the
file system to serialize its requests (for example the FTL read-ahead
buffer is not locked unless `CONFIG_DRVR_WRITEBUFFER` is set), so the
mount lock is kept in that case.
## Impact
- New feature / API change: NO.
- Behavior: XIP romfs reads of different files no longer wait for each
other. Non-XIP mounts behave as before.
- Memory: one `mutex_t` per open romfs file.
- Build, hardware, documentation, security, compatibility: NO.
## Testing
Host: Ubuntu 22.04 x86_64, gcc 13.1.0. Base: master 37709a3995.
`sim:smp` (4 CPUs) with `CONFIG_FS_ROMFS`. A test app registers a 512 KB
romfs image with `romdisk_register()` (XIP) holding two 256 KB files with
a position-dependent pattern, then: one thread reads file `a` 200 times;
two threads read `a` and `b` 200 times each in parallel; two threads share
one open file and each 4 KB chunk is checked against its own position.
Three runs each:
| | one file | two files in parallel | shared fd |
|---|---:|---:|---|
| master | 77 / 70 / 139 ms | 16881 / 24618 / 24630 ms | 262144 B, 0 bad
chunks |
| this PR | 72 / 79 / 69 ms | 63 / 92 / 63 ms | 262144 B, 0 bad chunks |
Without this change the two-file case is far slower than twice the
one-file case: about 2000 contended `rm_lock` hand-overs cost roughly one
10 ms sim tick each, so the gap is exaggerated on sim; on hardware the
reads are still serialized, just with a cheaper hand-over. The shared-fd
case shows that read/seek on one open file stay serialized.
- `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
- `sim:nsh` with `CONFIG_FS_ROMFS`: Make and CMake builds pass with no
warnings in the changed files; `ostest` exits with status 0. `sim:smp`
builds with no warnings in the changed files.
- The non-XIP path keeps the mount lock and was only built, not measured.
- Verified on sim only.
## PR verification Self-Check
* [x] This PR introduces only one functional change.
* [x] I have updated all required description fields above.
* [x] My PR adheres to Contributing Guidelines and Documentation (git commit
title and message, coding standard, etc).
* [ ] My PR is still work in progress (not ready for review).
* [x] My PR is ready for review and can be safely merged into a codebase.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]