Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fanotify: limit number of event merge attempts

Event merges are expensive when event queue size is large, so limit the
linear search to 128 merge tests.

In combination with 128 size hash table, there is a potential to merge
with up to 16K events in the hashed queue.

Link: https://lore.kernel.org/r/20210304104826.3993892-6-amir73il@gmail.com
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>

authored by

Amir Goldstein and committed by
Jan Kara
b8cd0ee8 94e00d28

+6
+6
fs/notify/fanotify/fanotify.c
··· 148 148 return false; 149 149 } 150 150 151 + /* Limit event merges to limit CPU overhead per event */ 152 + #define FANOTIFY_MAX_MERGE_EVENTS 128 153 + 151 154 /* and the list better be locked by something too! */ 152 155 static int fanotify_merge(struct fsnotify_group *group, 153 156 struct fsnotify_event *event) ··· 158 155 struct fanotify_event *old, *new = FANOTIFY_E(event); 159 156 unsigned int bucket = fanotify_event_hash_bucket(group, new); 160 157 struct hlist_head *hlist = &group->fanotify_data.merge_hash[bucket]; 158 + int i = 0; 161 159 162 160 pr_debug("%s: group=%p event=%p bucket=%u\n", __func__, 163 161 group, event, bucket); ··· 172 168 return 0; 173 169 174 170 hlist_for_each_entry(old, hlist, merge_list) { 171 + if (++i > FANOTIFY_MAX_MERGE_EVENTS) 172 + break; 175 173 if (fanotify_should_merge(old, new)) { 176 174 old->mask |= new->mask; 177 175 return 1;