diff options
author | Amir Goldstein <amir73il@gmail.com> | 2021-03-04 13:48:23 +0300 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2021-03-16 18:14:28 +0300 |
commit | 8988f11abb820bacfcc53d498370bfb30f792ec4 (patch) | |
tree | 00f938ddb78faf853b1ffe3c8ca21e58f670e781 /fs/notify/fanotify/fanotify.c | |
parent | 6f73171e192366ff7c98af9fb50615ef9615f8a7 (diff) | |
download | linux-8988f11abb820bacfcc53d498370bfb30f792ec4.tar.xz |
fanotify: reduce event objectid to 29-bit hash
objectid is only used by fanotify backend and it is just an optimization
for event merge before comparing all fields in event.
Move the objectid member from common struct fsnotify_event into struct
fanotify_event and reduce it to 29-bit hash to cram it together with the
3-bit event type.
Events of different types are never merged, so the combination of event
type and hash form a 32-bit key for fast compare of events.
This reduces the size of events by one pointer and paves the way for
adding hashed queue support for fanotify.
Link: https://lore.kernel.org/r/20210304104826.3993892-3-amir73il@gmail.com
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/notify/fanotify/fanotify.c')
-rw-r--r-- | fs/notify/fanotify/fanotify.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 1192c9953620..8a2bb6954e02 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -88,16 +88,12 @@ static bool fanotify_name_event_equal(struct fanotify_name_event *fne1, return fanotify_info_equal(info1, info2); } -static bool fanotify_should_merge(struct fsnotify_event *old_fsn, - struct fsnotify_event *new_fsn) +static bool fanotify_should_merge(struct fanotify_event *old, + struct fanotify_event *new) { - struct fanotify_event *old, *new; + pr_debug("%s: old=%p new=%p\n", __func__, old, new); - pr_debug("%s: old=%p new=%p\n", __func__, old_fsn, new_fsn); - old = FANOTIFY_E(old_fsn); - new = FANOTIFY_E(new_fsn); - - if (old_fsn->objectid != new_fsn->objectid || + if (old->hash != new->hash || old->type != new->type || old->pid != new->pid) return false; @@ -133,10 +129,9 @@ static bool fanotify_should_merge(struct fsnotify_event *old_fsn, static int fanotify_merge(struct list_head *list, struct fsnotify_event *event) { struct fsnotify_event *test_event; - struct fanotify_event *new; + struct fanotify_event *old, *new = FANOTIFY_E(event); pr_debug("%s: list=%p event=%p\n", __func__, list, event); - new = FANOTIFY_E(event); /* * Don't merge a permission event with any other event so that we know @@ -147,8 +142,9 @@ static int fanotify_merge(struct list_head *list, struct fsnotify_event *event) return 0; list_for_each_entry_reverse(test_event, list, list) { - if (fanotify_should_merge(test_event, event)) { - FANOTIFY_E(test_event)->mask |= new->mask; + old = FANOTIFY_E(test_event); + if (fanotify_should_merge(old, new)) { + old->mask |= new->mask; return 1; } } @@ -533,6 +529,7 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, struct mem_cgroup *old_memcg; struct inode *child = NULL; bool name_event = false; + unsigned int hash = 0; if ((fid_mode & FAN_REPORT_DIR_FID) && dirid) { /* @@ -600,8 +597,10 @@ static struct fanotify_event *fanotify_alloc_event(struct fsnotify_group *group, * Use the victim inode instead of the watching inode as the id for * event queue, so event reported on parent is merged with event * reported on child when both directory and child watches exist. + * Hash object id for queue merge. */ - fanotify_init_event(event, (unsigned long)id, mask); + hash = hash_ptr(id, FANOTIFY_EVENT_HASH_BITS); + fanotify_init_event(event, hash, mask); if (FAN_GROUP_FLAG(group, FAN_REPORT_TID)) event->pid = get_pid(task_pid(current)); else |