Skip to content
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 #2599

Closed
wants to merge 1 commit into from

Conversation

ankushT369
Copy link

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 new mount_info node required traversing the entire list to find the tail, which was inefficient for large lists.

Changes:

  1. Added a struct list_head tail to the mount_info struct to maintain the tail pointer.
  2. Introduced a global tailbuffer to store the current tail of the list.
  3. Modified mntinfo_add_list to use tailbuffer for O(1) insertion at the tail.
  4. Updated 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.

@ankushT369
Copy link
Author

@avagin can you please review this PR?

@mihalicyn
Copy link
Member

Hi @ankushT369,

as far as I understand you work on the same fix in #2593
Why you created a second PR?

@mihalicyn
Copy link
Member

hint: you can use git rebase -i command to interactively edit your commits and then git push -f to update your existing PR the way you want.

@@ -90,6 +90,7 @@ struct mount_info {
int deleted_level;
struct list_head deleted_list;
struct mount_info *next;
struct list_head tail;
Copy link
Member

Choose a reason for hiding this comment

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

if you add this struct list_head member here, then you don't need to have struct mount_info *next member anymore as you can use tail.next to access to the next struct mount_info pointer, isn't it?

@ankushT369
Copy link
Author

@mihalicyn ok I will!!

@ankushT369 ankushT369 closed this Feb 19, 2025
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