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

optimize: added a tail pointer in mntinfo_add_list #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 1 commit
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 mount_info *tail;
Copy link
Member

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.

Copy link
Author

@ankushT369 ankushT369 Feb 8, 2025

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

Copy link
Member

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.

Copy link
Author

@ankushT369 ankushT369 Feb 11, 2025

Choose a reason for hiding this comment

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

I'm sorry if this conversation is taking long.. the thing is the list_head is of different type in order to store the tail of a struct mount_info* shouldn't we use the struct mount_info* type?? because in the code mount.c (where I have changed code) the struct mount_info *mntinfo was the single linked list as it was told in the comment (file : mount.c, line : 110) and the struct mount_info *new has to traverse the struct mount_info *mntinfo (file : mount.c, line : 122) in order to find the tail of it ( if the *mntinfo wasn't empty) thats why I created a struct mount_info* tail in order to hold the pointer to tail. Any node of type struct mount_info* can have its tail stored in it so that it can fetch in O(1) time. I know its reinventing a bicycle but the thing is I can't understand how can I use the struct list_head cause there is a mismatch in type in order to hold the tail of anything of type struct mount_info*. Maybe I can wrong here by misunderstanding what you tried to say you can rectify me I am a beginner currently learning things.

struct ns_id *nsid;

char *external;
Expand Down
20 changes: 12 additions & 8 deletions criu/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,25 @@ struct mount_info *mntinfo;

static void mntinfo_add_list(struct mount_info *new)
{
if (!mntinfo)
if (!mntinfo) {
mntinfo = new;
mntinfo->tail = new->tail;
}
else {
struct mount_info *pm;

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

struct mount_info *tail_buffer;

void mntinfo_add_list_before(struct mount_info **head, struct mount_info *new)
{
new->next = *head;
if(!*head)
ankushT369 marked this conversation as resolved.
Show resolved Hide resolved
tail_buffer = new;

new->next = *head;
new->tail = tail_buffer;
*head = new;
}

Expand Down