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 #2593

Open
wants to merge 3 commits into
base: criu-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions criu/include/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

You need to replace next and tail with struct list_head node and then use standard operation like list_add, list_del, list_for_each_entry (./include/common/list.h).

Copy link
Author

Choose a reason for hiding this comment

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

okk I will

struct ns_id *nsid;

char *external;
Expand Down
16 changes: 11 additions & 5 deletions criu/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,29 @@ static char *ext_mount_lookup(char *key)
* Single linked list of mount points get from proc/images
*/
struct mount_info *mntinfo;
struct mount_info *tailbuffer;

static void mntinfo_add_list(struct mount_info *new)
{
if (!mntinfo)
mntinfo = new;
else {
struct mount_info *pm;
struct list_head *_tail = mntinfo->tail.next;
tailbuffer = list_entry(_tail, struct mount_info, tail);

/* Add to the tail. (FIXME -- make O(1) ) */
for (pm = mntinfo; pm->next != NULL; pm = pm->next)
;
pm->next = new;
tailbuffer->next = new;
mntinfo->tail = new->tail;
}
}

void mntinfo_add_list_before(struct mount_info **head, struct mount_info *new)
{
if (!*head)
tailbuffer = new;

INIT_LIST_HEAD(&new->tail);
list_add_tail(&tailbuffer->tail, &new->tail);

new->next = *head;
*head = new;
}
Expand Down