-
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 <[email protected]>
…CONFIG_LINE_MAX Signed-off-by: zhangshoukui <[email protected]>
[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
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'm not sure how it's different from malloc either.
Allocate from heap, which may increase memory fragment and impact performance
do you mean line buffer allocation in nsh is performance critical? really?
also, as far as the allocation lifetime is very short, fragmentation is not a big concern i suspect.
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?
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.
@Zhangshoukui I think we need to simplify the LINELEN / LINEMAX instead of creating a new one, currently there are many configs to that:
CONFIG_SYSTEM_CLE_CMD_HISTORY_LINELEN
CONFIG_SYSTEM_CLE_CMD_HISTORY_LEN
CONFIG_NSH_LINELEN
CONFIG_PROCFS_LINELEN
CONFIG_HELP_LINELEN
Having a LINELEN for each application could be more flexible, but it is also a lot a code duplication. It should be nice to have a single LINE_MAX to be the standard LINELEN
@acassis Yes, the next step is to optimize and remove the above configuration to use LINE_MAX. |
@@ -1531,7 +1531,7 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, | |||
|
|||
if (len > 0 && relpath[len - 1] == '/') | |||
{ | |||
path = lib_get_pathbuffer(); | |||
path = lib_get_tempbuffer(PATH_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.
i feel it's simpler to make
#define lib_get_pathbuffer() lib_get_tempbuffer(PATH_MAX)
instead of modifying all callers.
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 feel it's simpler to make
#define lib_get_pathbuffer() lib_get_tempbuffer(PATH_MAX)
instead of modifying all callers.
that way we can go back to the fixed-sized allocataion easily if/when this change turned out to be a bad idea. :-)
{ | ||
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'm not sure how it's different from malloc either.
Allocate from heap, which may increase memory fragment and impact performance
do you mean line buffer allocation in nsh is performance critical? really?
also, as far as the allocation lifetime is very short, fragmentation is not a big concern i suspect.
sched/Kconfig
Outdated
default 64 if DEFAULT_SMALL | ||
default 80 if !DEFAULT_SMALL | ||
---help--- | ||
The maximum size of line. |
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.
please add explanation about what "line" here is.
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.
done
Signed-off-by: zhangshoukui <[email protected]>
Summary
rename lib_pathbuffer to lib_tempbuffer
Impact
None
Testing
./tools/configure.sh -l sim:nsh
make -j7