Skip to content

Commit b8cd0ee

Browse files
amir73iljankara
authored andcommitted
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/[email protected] Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 94e00d2 commit b8cd0ee

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/notify/fanotify/fanotify.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,17 @@ static bool fanotify_should_merge(struct fanotify_event *old,
148148
return false;
149149
}
150150

151+
/* Limit event merges to limit CPU overhead per event */
152+
#define FANOTIFY_MAX_MERGE_EVENTS 128
153+
151154
/* and the list better be locked by something too! */
152155
static int fanotify_merge(struct fsnotify_group *group,
153156
struct fsnotify_event *event)
154157
{
155158
struct fanotify_event *old, *new = FANOTIFY_E(event);
156159
unsigned int bucket = fanotify_event_hash_bucket(group, new);
157160
struct hlist_head *hlist = &group->fanotify_data.merge_hash[bucket];
161+
int i = 0;
158162

159163
pr_debug("%s: group=%p event=%p bucket=%u\n", __func__,
160164
group, event, bucket);
@@ -168,6 +172,8 @@ static int fanotify_merge(struct fsnotify_group *group,
168172
return 0;
169173

170174
hlist_for_each_entry(old, hlist, merge_list) {
175+
if (++i > FANOTIFY_MAX_MERGE_EVENTS)
176+
break;
171177
if (fanotify_should_merge(old, new)) {
172178
old->mask |= new->mask;
173179
return 1;

0 commit comments

Comments
 (0)