-
Notifications
You must be signed in to change notification settings - Fork 1.5k
filep Reference count #13296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filep Reference count #13296
Conversation
|
Sorry, due to my irregular rebase, this PR is closed and a new trace is used. ./tools/configure.sh -l stm3240g-eval:knxwm |
the code size exceeds the reserved space, either:
|
anchao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a complete feature,please merge all patches into one
|
@anchao ./tools/configure.sh -l stm3240g-eval:knxwm |
You could set the Kconfig default value of CONFIG_FS_REFCOUNT to n to keep the original configuration without any overhead. |
5873bd9 to
a356d27
Compare
329589d to
a356d27
Compare
|
@Zhangshoukui please fix the conflict. |
…eading writing... Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
60 | FAR struct inode *inode;
| ^~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
task1: The refs is 0 but the inode has not been released task2: Executing files_duplist, get filep with refs is zero, but the inode has not yet released. [ 0.530600] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: backtrace: [ 0.530800] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4045172>] backtrace_unwind+0x241/0x244 [ 0.531200] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4009150>] sched_backtrace+0x27/0x4c [ 0.531500] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x402f0fa>] sched_dumpstack+0x3d/0xa0 [ 0.531700] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4002c90>] _assert+0x1e3/0x564 [ 0.532000] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x40221f6>] __assert+0x19/0x24 [ 0.532200] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x41fe376>] tcp_stop_monitor+0x61/0x6c [ 0.532500] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x41fe19e>] tcp_close+0xad/0xdc [ 0.532700] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x41ecc18>] inet_close+0x7b/0x8c [ 0.533000] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x41ec374>] psock_close+0x27/0x70 [ 0.533300] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x420b68e>] sock_file_close+0x15/0x3c [ 0.533500] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4206704>] file_close+0x1f/0x80 [ 0.533800] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4205278>] files_duplist+0x39f/0x45c [ 0.534100] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4000e3c>] group_setuptaskfiles+0x57/0xc0 [ 0.534300] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x400bc6c>] nxtask_init+0x5b/0x13c Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
a356d27 to
3691ab7
Compare
done |
|
@anchao help me review this PR. thanks |
please set CONFIG_FS_REFCOUNT default value to n to keep the original configuration, we should not add unnecessary code size loads to IoT developers, especially for some chips that may only have 32k available RAM |
|
@anchao I do not think this code is unnecessary, for the operation of a system security is the first.At present, CI has passed, I think it can be approve |
The default value should keep as safe as possible, since not all users understand the fs internal implementation. @Zhangshoukui let's change default value to !DEFAULT_SMALL. |
3691ab7 to
da01077
Compare
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
arm-none-eabi-ld: /github/workspace/sources/nuttx/nuttx section `.bss' will not fit in region `ksram' arm-none-eabi-ld: region `ksram' overflowed by 16 bytes Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
da01077 to
d4c6513
Compare
|
@xiaoxiang781216 help me review this PR.thanks |
what happens w/o this enabled? a crash? |
| default !DEFAULT_SMALL | ||
| ---help--- | ||
| Enable will Records the number of filep references. The file is | ||
| actually closed when the count reaches 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my impression is that this kind of things should not be a user-visible option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, it should be used by default and should not be configured by the user, but it actually increases the code size, so it is configurable.Any better suggestions? I can try to optimize
Prevent multithreaded operations on the same filep when one is in r/w and the other is closed |
my question is, why do you need to prevent it? |
This commit can solve the above problem and avoid the crash, in turn, why let such an operation crash? Reference counting makes the read and write process more robust |
if this is to fix a crash, i don't understand why it should be optional. |
|
The patch tries to fix this common issue: thread 1 call read(fd, ...) and block, thread2 call close(fd). |
Yes, I also think it should be always enabled, but @anchao think this is a corner case and should give the user the freedom to disable it. |
But this feature consumes a lot of rom size. e.g on ARM32 platform, the flash usage will increase by ~500 bytes caused by bl/blx instructions are inserted in many places in the fs. |
|
We should ensure that NuttX remains compact and lightweight, rather than expanding endlessly like Linux. @xiaoxiang781216 @yamt |
do you have a suggestion of an alternative fix for the crash? |
i agree. |
|
Most RTOS developers typically do not do the following things:
FS_REFCOUNT enhances the detection of such issues.
if disable FS_REFCOUNT, I think we could add some error catch and print error log on failure case, which will help developers identify issues more quickly. |
i guess what you need is a config option or whatever which allows users to as we don't have such a mechanism right now, i suppose we need to enable this reference counting
do you have an idea how to detect the failure cases? |


Summary
ncrease the reference count of filep,fs_getfilep adds +1 to the reference count. After the call is complete, run the fs_putfilep command to release the reference count.When the reference count reaches 0, the file is actually closed.
Impact
This prevents the file from being closed while it is being read or written
Testing