Skip to content

Replace kzalloc with mempool to reduce memory fragmentation #19

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yaodehaung
Copy link

Replace kzalloc with mempool to reduce memory fragmentation

Using mempool improves memory allocation stability and reduces fragmentation
in high-frequency allocation scenarios, especially under memory pressure.

@@ -7,6 +7,8 @@
#include "http_parser.h"
#include "http_server.h"

extern mempool_t *http_buf_pool;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use extern here. Honor the header instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue has been fixed. Thanks, professor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue has been fixed.

No, you didn't.

main.c Outdated
Comment on lines 161 to 169
static void *http_buf_alloc(gfp_t gfp_mask, void *pool_data)
{
return kzalloc(RECV_BUFFER_SIZE, gfp_mask);
}

static void http_buf_free(void *element, void *pool_data)
{
kfree(element);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the functions to the header as static inline ones.

main.c Outdated
return -ENOMEM;
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the blank line.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use git rebase -i to squash commits.

Signed-off-by: Nick Huang <sef1548@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants