-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
rename lib_pathbuffer to lib_tempbuffer #15326
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
…CONFIG_LINE_MAX Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
[Experimental Bot, please feedback here] No, this PR does not fully meet the NuttX requirements. While it provides some information, it lacks crucial details. Here's what's missing:
In short, the PR needs to be significantly more detailed to meet the NuttX requirements. It needs to explain the rationale behind the change, justify the claimed lack of impact, and provide concrete evidence of testing. |
{ | ||
for (; ; ) | ||
if (nbytes <= TEMP_MAX_SIZE) |
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.
I don't understand this change. If the required path buffer size is large than PATH_MAX, why not just call malloc() in application? Why must use this API?
I haven't seen lib_get_pathbuffer() used anywhere else except the kernel, 100% of the source code is using PATH_MAX, why add this redundant check?
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.
- nbytes <= TEMP_MAX_SIZE: Make sure don't cross the line
- At present, parameter passing is supported, and the code under the following app uses this interface to optimize the use of the stack. The new feature of nshlib has exceeded the call stack of 2k.
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.
You should call malloc in nshlib instead of making the interface so ugly
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.
many places (especially in nsh) need allocate temp buffer (e.g. path or line) only in function scope, both follow approach isn't perfect:
- Allocate from stack, which already cause the default 2KB stack is unusable in many cases:
{bp-15165} rv-virt/citest: Increase init task stack size to 3072 #15173
esp32s3: Increase the init task stask size when using NSH #14501 - Allocate from heap, which may increase memory fragment and impact performance
so, it's reasonable to extend pathbuffer to tempbuffer, and let's caller utilize the general buffer facility when they find some function occupy too much stack space.
You should call malloc in nshlib instead of making the interface so ugly
It's natural to add size argument to a buffer allocation function. Do you feel ugly malloc with size or not strange malloc without size?
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.
The implementation of pathbuffer is a memory pool with a limited length. Currently, all the kernel code is using the length of PATH_MAX. From the kernel perspective, add length parameter is a strange design, because the kernel code can ensure that all locations(100%) that call pathbuffer only use PATH_MAX:
FAR char *lib_get_pathbuffer(void);
-> FAR char *lib_get_tempbuffer(size_t nbytes); <- why?
If the customized length in the application exceeds PATH_MAX, we should manage the life cycle of this memory segment by application self. If the stack occupies too much, we can choose to define it statically or call malloc:
https://github.com/apache/nuttx-apps/blob/master/nshlib/nsh_console.h#L157
The design of the API should be more reasonable and easy to use. If 99% of the code is using PATH_MAX as the expected value, why should these codes bear the overhead of parameter passing and parameter checking? This is unreasonable
include/nuttx/lib/lib.h
Outdated
@@ -38,6 +38,12 @@ | |||
* Pre-processor Definitions | |||
****************************************************************************/ | |||
|
|||
#if CONFIG_PATH_MAX > CONFIG_LINE_MAX |
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.
keep in the soure code
include/nuttx/lib/lib.h
Outdated
#else | ||
# define lib_get_pathbuffer() alloca(PATH_MAX) | ||
# define lib_put_pathbuffer(b) | ||
# define lib_get_tempbuffer(f) alloca(TEMP_MAX_SIZE) |
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.
# define lib_get_tempbuffer(n) alloca(n)
{ | ||
for (; ; ) | ||
if (nbytes <= TEMP_MAX_SIZE) |
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.
many places (especially in nsh) need allocate temp buffer (e.g. path or line) only in function scope, both follow approach isn't perfect:
- Allocate from stack, which already cause the default 2KB stack is unusable in many cases:
{bp-15165} rv-virt/citest: Increase init task stack size to 3072 #15173
esp32s3: Increase the init task stask size when using NSH #14501 - Allocate from heap, which may increase memory fragment and impact performance
so, it's reasonable to extend pathbuffer to tempbuffer, and let's caller utilize the general buffer facility when they find some function occupy too much stack space.
You should call malloc in nshlib instead of making the interface so ugly
It's natural to add size argument to a buffer allocation function. Do you feel ugly malloc with size or not strange malloc without size?
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
Summary
rename lib_pathbuffer to lib_tempbuffer
Impact
None
Testing
./tools/configure.sh -l sim:nsh
make -j7