xiaoqizhan commented on code in PR #18767:
URL: https://github.com/apache/nuttx/pull/18767#discussion_r3121527518


##########
include/nuttx/fs/fs.h:
##########
@@ -502,6 +502,12 @@ struct fdlist
 
   FAR struct fd    *fl_prefd;
   struct fd         fl_prefds[CONFIG_NFILE_DESCRIPTORS_PER_BLOCK];
+
+#if CONFIG_FS_BACKTRACE > 0 && defined(CONFIG_FS_BACKTRACE_DYNAMIC)
+  atomic_t           fl_open_count;   /* Current open file descriptor count */

Review Comment:
    I agree that using a tg_flags switch is simpler and perfectly eliminates 
overhead when disabled. However, the main motivation for the dynamic threshold 
is 'Out-of-the-box fault capturing' for unexpected/random FD leaks.
    
    If we use a manual flag like TCB_FLAG_HEAP_CHECK, developers have to know a 
leak might happen beforehand and explicitly enable it. For long-running systems 
where an FD leak might occur randomly after days of running, a manual switch is 
hard to use because we usually don't have it enabled until the system has 
already crashed due to FD exhaustion.
    
    With the dynamic threshold (e.g., 60), the overhead is negligible for 
normal execution, but acts as a 'safety net'. If a task unexpectedly goes crazy 
and opens 1000 FDs, we automatically capture the backtrace for the leaky ones 
(from 61 to 1000) without any manual intervention, which is invaluable for 
post-mortem debugging (e.g., viewing in procfs or coredump).



-- 
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]

Reply via email to