瀏覽代碼

fanotify: do not clone on merge unless needed

Currently if 2 events are going to be merged on the notication queue with
different masks the second event will be cloned and will replace the first
event.  However if this notification queue is the only place referencing
the event in question there is no reason not to just update the event in
place.  We can tell this if the event->refcnt == 1.  Since we hold a
reference for each queue this event is on we know that when refcnt == 1
this is the only queue.  The other concern is that it might be about to be
added to a new queue, but this can't be the case since fsnotify holds a
reference on the event until it is finished adding it to queues.

Signed-off-by: Eric Paris <eparis@redhat.com>
Eric Paris 15 年之前
父節點
當前提交
9dced01a09
共有 1 個文件被更改,包括 10 次插入0 次删除
  1. 10 0
      fs/notify/fanotify/fanotify.c

+ 10 - 0
fs/notify/fanotify/fanotify.c

@@ -46,6 +46,16 @@ static int fanotify_merge(struct list_head *list, struct fsnotify_event *event)
 			if (test_event->mask == event->mask)
 			if (test_event->mask == event->mask)
 				goto out;
 				goto out;
 
 
+			/*
+			 * if the refcnt == 1 this is the only queue
+			 * for this event and so we can update the mask
+			 * in place.
+			 */
+			if (atomic_read(&test_event->refcnt) == 1) {
+				test_event->mask |= event->mask;
+				goto out;
+			}
+
 			/* can't allocate memory, merge was no possible */
 			/* can't allocate memory, merge was no possible */
 			new_event = fsnotify_clone_event(test_event);
 			new_event = fsnotify_clone_event(test_event);
 			if (unlikely(!new_event)) {
 			if (unlikely(!new_event)) {