-
Notifications
You must be signed in to change notification settings - Fork 628
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
mnt: Optimize mntinfo_add_list to O(1) using a tail pointer #2593
base: criu-dev
Are you sure you want to change the base?
Conversation
criu/include/mount.h
Outdated
@@ -90,6 +90,7 @@ struct mount_info { | |||
int deleted_level; | |||
struct list_head deleted_list; | |||
struct mount_info *next; | |||
struct mount_info *tail; |
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 think it is better to user the list_head structure here.
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 mean instead of mount_info *tail should I make it list_head tail
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 mean we can use the standard list here instead of reinventing a bicycle.
@avagin What changes should I make to the code overall? |
Here is just one logical change, so it should be just one patch. The subject line starts with the subsystem prefix. In this case, it is |
ok got it I am gonna fix this!! |
This patch optimizes the
mntinfo_add_list
function from O(n) to O(1) by introducing a tail pointer (tailbuffer
) to track the end of the linked list. Previously, adding a newmount_info
node required traversing the entire list to find the tail, which was inefficient for large lists.Changes:
struct list_head tail
to themount_info
struct to maintain the tail pointer.tailbuffer
to store the current tail of the list.mntinfo_add_list
to usetailbuffer
for O(1) insertion at the tail.mntinfo_add_list_before
to initialize the tail pointer and maintain consistency when adding nodes at the head.The optimization significantly improves performance for operations involving large lists of mount information. This change also ensures that the list remains consistent and correctly updated during insertions.