Skip to contentSkip to conversation

fsnotify-do-not-share-events-between-notification-groups.patch removed from -mm tree

merged [email protected] 1 participant 1 message Jan 22, 2014

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

Subject: [merged] fsnotify-do-not-share-events-between-notification-groups.patch removed from -mm tree
To: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
From: [email protected]
Date: Wed, 22 Jan 2014 12:11:25 -0800

The patch titled
Subject: fsnotify: do not share events between notification groups
has been removed from the -mm tree. Its filename was
fsnotify-do-not-share-events-between-notification-groups.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Jan Kara <[email protected]>
Subject: fsnotify: do not share events between notification groups

Currently fsnotify framework creates one event structure for each notification event and links this event into all interested notification groups. This is done so that we save memory when several notification groups are interested in the event. However the need for event structure shared between inotify & fanotify bloats the event structure so the result is often higher memory consumption.

Another problem is that fsnotify framework keeps path references with outstanding events so that fanotify can return open file descriptors with its events. This has the undesirable effect that filesystem cannot be unmounted while there are outstanding events - a regression for inotify compared to a situation before it was converted to fsnotify framework. For fanotify this problem is hard to avoid and users of fanotify should kind of expect this behavior when they ask for file descriptors from notified files.

This patch changes fsnotify and its users to create separate event structure for each group. This allows for much simpler code (~400 lines removed by this patch) and also smaller event structures. For example on 64-bit system original struct fsnotify_event consumes 120 bytes, plus additional space for file name, additional 24 bytes for second and each subsequent group linking the event, and additional 32 bytes for each inotify group for private data. After the conversion inotify event consumes 48 bytes plus space for file name which is considerably less memory unless file names are long and there are several groups interested in the events (both of which are uncommon). Fanotify event fits in 56 bytes after the conversion (fanotify doesn't care about file names so its events don't have to have it allocated). A win unless there are four or more fanotify groups interested in the event.

The conversion also solves the problem with unmount when only inotify is used as we don't have to grab path references for inotify events.

[[email protected]: fanotify: fix corruption preventing startup]
Cc Eric Paris <[email protected]>
Cc Al Viro <[email protected]>

---

 fs/notify/dnotify/dnotify.c          |   11 
 fs/notify/fanotify/fanotify.c        |  211 +++++++--------
 fs/notify/fanotify/fanotify.h        |   23 +
 fs/notify/fanotify/fanotify_user.c   |   41 +--
 fs/notify/fsnotify.c                 |   37 --
 fs/notify/group.c                    |    1 
 fs/notify/inotify/inotify.h          |   21 +
 fs/notify/inotify/inotify_fsnotify.c |  125 +++------
 fs/notify/inotify/inotify_user.c     |   86 +-----
 fs/notify/notification.c             |  334 ++-----------------------
 include/linux/fsnotify_backend.h     |  114 ++------
 kernel/audit_tree.c                  |    8 
 kernel/audit_watch.c                 |   14 -
 13 files changed, 318 insertions(+), 708 deletions(-)
fs/notify/dnotify/dnotify.c renamed from fs/notify/dnotify/dnotify.c~fsnotify-do-not-share-events-between-notification-groups +5 -6
diff -puN fs/notify/dnotify/dnotify.c~fsnotify-do-not-share-events-between-notification-groups fs/notify/dnotify/dnotify.c
@@ -82,21 +82,20 @@ static void dnotify_recalc_inode_mask(st
  * events.
  */
 static int dnotify_handle_event(struct fsnotify_group *group,
+				struct inode *inode,
 				struct fsnotify_mark *inode_mark,
 				struct fsnotify_mark *vfsmount_mark,
-				struct fsnotify_event *event)
+				u32 mask, void *data, int data_type,
+				const unsigned char *file_name)
 {
 	struct dnotify_mark *dn_mark;
-	struct inode *to_tell;
 	struct dnotify_struct *dn;
 	struct dnotify_struct **prev;
 	struct fown_struct *fown;
-	__u32 test_mask = event->mask & ~FS_EVENT_ON_CHILD;
+	__u32 test_mask = mask & ~FS_EVENT_ON_CHILD;
 
 	BUG_ON(vfsmount_mark);
 
-	to_tell = event->to_tell;
-
 	dn_mark = container_of(inode_mark, struct dnotify_mark, fsn_mark);
 
 	spin_lock(&inode_mark->lock);
@@ -155,7 +154,7 @@ static struct fsnotify_ops dnotify_fsnot
 	.should_send_event = dnotify_should_send_event,
 	.free_group_priv = NULL,
 	.freeing_mark = NULL,
-	.free_event_priv = NULL,
+	.free_event = NULL,
 };
 
 /*
fs/notify/fanotify/fanotify.c renamed from fs/notify/fanotify/fanotify.c~fsnotify-do-not-share-events-between-notification-groups +104 -107

280 lines not on this page · raw message

fs/notify/fanotify/fanotify.h new file +23 -0
diff -puN /dev/null fs/notify/fanotify/fanotify.h
@@ -0,0 +1,23 @@
+#include <linux/fsnotify_backend.h>
+#include <linux/path.h>
+#include <linux/slab.h>
+
+extern struct kmem_cache *fanotify_event_cachep;
+
+struct fanotify_event_info {
+	struct fsnotify_event fse;
+	/*
+	 * We hold ref to this path so it may be dereferenced at any point
+	 * during this object's lifetime
+	 */
+	struct path path;
+	struct pid *tgid;
+#ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
+	u32 response;	/* userspace answer to question */
+#endif
+};
+
+static inline struct fanotify_event_info *FANOTIFY_E(struct fsnotify_event *fse)
+{
+	return container_of(fse, struct fanotify_event_info, fse);
+}
fs/notify/fanotify/fanotify_user.c renamed from fs/notify/fanotify/fanotify_user.c~fsnotify-do-not-share-events-between-notification-groups +20 -21

128 lines not on this page · raw message

fs/notify/fsnotify.c renamed from fs/notify/fsnotify.c~fsnotify-do-not-share-events-between-notification-groups +12 -25
diff -puN fs/notify/fsnotify.c~fsnotify-do-not-share-events-between-notification-groups fs/notify/fsnotify.c
@@ -128,8 +128,7 @@ static int send_to_group(struct inode *t
 			 struct fsnotify_mark *vfsmount_mark,
 			 __u32 mask, void *data,
 			 int data_is, u32 cookie,
-			 const unsigned char *file_name,
-			 struct fsnotify_event **event)
+			 const unsigned char *file_name)
 {
 	struct fsnotify_group *group = NULL;
 	__u32 inode_test_mask = 0;
@@ -170,10 +169,10 @@ static int send_to_group(struct inode *t
 
 	pr_debug("%s: group=%p to_tell=%p mask=%x inode_mark=%p"
 		 " inode_test_mask=%x vfsmount_mark=%p vfsmount_test_mask=%x"
-		 " data=%p data_is=%d cookie=%d event=%p\n",
+		 " data=%p data_is=%d cookie=%d\n",
 		 __func__, group, to_tell, mask, inode_mark,
 		 inode_test_mask, vfsmount_mark, vfsmount_test_mask, data,
-		 data_is, cookie, *event);
+		 data_is, cookie);
 
 	if (!inode_test_mask && !vfsmount_test_mask)
 		return 0;
@@ -183,14 +182,9 @@ static int send_to_group(struct inode *t
 					  data_is) == false)
 		return 0;
 
-	if (!*event) {
-		*event = fsnotify_create_event(to_tell, mask, data,
-						data_is, file_name,
-						cookie, GFP_KERNEL);
-		if (!*event)
-			return -ENOMEM;
-	}
-	return group->ops->handle_event(group, inode_mark, vfsmount_mark, *event);
+	return group->ops->handle_event(group, to_tell, inode_mark,
+					vfsmount_mark, mask, data, data_is,
+					file_name);
 }
 
 /*
@@ -205,7 +199,6 @@ int fsnotify(struct inode *to_tell, __u3
 	struct hlist_node *inode_node = NULL, *vfsmount_node = NULL;
 	struct fsnotify_mark *inode_mark = NULL, *vfsmount_mark = NULL;
 	struct fsnotify_group *inode_group, *vfsmount_group;
-	struct fsnotify_event *event = NULL;
 	struct mount *mnt;
 	int idx, ret = 0;
 	/* global tests shouldn't care about events on child only the specific event */
@@ -258,18 +251,18 @@ int fsnotify(struct inode *to_tell, __u3
 
 		if (inode_group > vfsmount_group) {
 			/* handle inode */
-			ret = send_to_group(to_tell, inode_mark, NULL, mask, data,
-					    data_is, cookie, file_name, &event);
+			ret = send_to_group(to_tell, inode_mark, NULL, mask,
+					    data, data_is, cookie, file_name);
 			/* we didn't use the vfsmount_mark */
 			vfsmount_group = NULL;
 		} else if (vfsmount_group > inode_group) {
-			ret = send_to_group(to_tell, NULL, vfsmount_mark, mask, data,
-					    data_is, cookie, file_name, &event);
+			ret = send_to_group(to_tell, NULL, vfsmount_mark, mask,
+					    data, data_is, cookie, file_name);
 			inode_group = NULL;
 		} else {
 			ret = send_to_group(to_tell, inode_mark, vfsmount_mark,
-					    mask, data, data_is, cookie, file_name,
-					    &event);
+					    mask, data, data_is, cookie,
+					    file_name);
 		}
 
 		if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS))
@@ -285,12 +278,6 @@ int fsnotify(struct inode *to_tell, __u3
 	ret = 0;
 out:
 	srcu_read_unlock(&fsnotify_mark_srcu, idx);
-	/*
-	 * fsnotify_create_event() took a reference so the event can't be cleaned
-	 * up while we are still trying to add it to lists, drop that one.
-	 */
-	if (event)
-		fsnotify_put_event(event);
 
 	return ret;
 }
fs/notify/group.c renamed from fs/notify/group.c~fsnotify-do-not-share-events-between-notification-groups +1 -0
diff -puN fs/notify/group.c~fsnotify-do-not-share-events-between-notification-groups fs/notify/group.c
@@ -99,6 +99,7 @@ struct fsnotify_group *fsnotify_alloc_gr
 	INIT_LIST_HEAD(&group->marks_list);
 
 	group->ops = ops;
+	fsnotify_init_event(&group->overflow_event, NULL, FS_Q_OVERFLOW);
 
 	return group;
 }
fs/notify/inotify/inotify.h renamed from fs/notify/inotify/inotify.h~fsnotify-do-not-share-events-between-notification-groups +16 -5
diff -puN fs/notify/inotify/inotify.h~fsnotify-do-not-share-events-between-notification-groups fs/notify/inotify/inotify.h
@@ -2,11 +2,12 @@
 #include <linux/inotify.h>
 #include <linux/slab.h> /* struct kmem_cache */
 
-extern struct kmem_cache *event_priv_cachep;
-
-struct inotify_event_private_data {
-	struct fsnotify_event_private_data fsnotify_event_priv_data;
+struct inotify_event_info {
+	struct fsnotify_event fse;
 	int wd;
+	u32 sync_cookie;
+	int name_len;
+	char name[];
 };
 
 struct inotify_inode_mark {
@@ -14,8 +15,18 @@ struct inotify_inode_mark {
 	int wd;
 };
 
+static inline struct inotify_event_info *INOTIFY_E(struct fsnotify_event *fse)
+{
+	return container_of(fse, struct inotify_event_info, fse);
+}
+
 extern void inotify_ignored_and_remove_idr(struct fsnotify_mark *fsn_mark,
 					   struct fsnotify_group *group);
-extern void inotify_free_event_priv(struct fsnotify_event_private_data *event_priv);
+extern int inotify_handle_event(struct fsnotify_group *group,
+				struct inode *inode,
+				struct fsnotify_mark *inode_mark,
+				struct fsnotify_mark *vfsmount_mark,
+				u32 mask, void *data, int data_type,
+				const unsigned char *file_name);
 
 extern const struct fsnotify_ops inotify_fsnotify_ops;
fs/notify/inotify/inotify_fsnotify.c renamed from fs/notify/inotify/inotify_fsnotify.c~fsnotify-do-not-share-events-between-notification-groups +49 -76

171 lines not on this page · raw message

fs/notify/inotify/inotify_user.c renamed from fs/notify/inotify/inotify_user.c~fsnotify-do-not-share-events-between-notification-groups +21 -65

158 lines not on this page · raw message

fs/notify/notification.c renamed from fs/notify/notification.c~fsnotify-do-not-share-events-between-notification-groups +28 -306

422 lines not on this page · raw message

include/linux/fsnotify_backend.h renamed from include/linux/fsnotify_backend.h~fsnotify-do-not-share-events-between-notification-groups +27 -87

167 lines not on this page · raw message

kernel/audit_tree.c renamed from kernel/audit_tree.c~fsnotify-do-not-share-events-between-notification-groups +5 -3
diff -puN kernel/audit_tree.c~fsnotify-do-not-share-events-between-notification-groups kernel/audit_tree.c
@@ -912,9 +912,11 @@ static void evict_chunk(struct audit_chu
 }
 
 static int audit_tree_handle_event(struct fsnotify_group *group,
+				   struct inode *to_tell,
 				   struct fsnotify_mark *inode_mark,
-				   struct fsnotify_mark *vfsmonut_mark,
-				   struct fsnotify_event *event)
+				   struct fsnotify_mark *vfsmount_mark,
+				   u32 mask, void *data, int data_type,
+				   const unsigned char *file_name)
 {
 	BUG();
 	return -EOPNOTSUPP;
@@ -945,7 +947,7 @@ static const struct fsnotify_ops audit_t
 	.handle_event = audit_tree_handle_event,
 	.should_send_event = audit_tree_send_event,
 	.free_group_priv = NULL,
-	.free_event_priv = NULL,
+	.free_event = NULL,
 	.freeing_mark = audit_tree_freeing_mark,
 };
 
kernel/audit_watch.c renamed from kernel/audit_watch.c~fsnotify-do-not-share-events-between-notification-groups +7 -7
diff -puN kernel/audit_watch.c~fsnotify-do-not-share-events-between-notification-groups kernel/audit_watch.c
@@ -475,25 +475,25 @@ static bool audit_watch_should_send_even
 
 /* Update watch data in audit rules based on fsnotify events. */
 static int audit_watch_handle_event(struct fsnotify_group *group,
+				    struct inode *to_tell,
 				    struct fsnotify_mark *inode_mark,
 				    struct fsnotify_mark *vfsmount_mark,
-				    struct fsnotify_event *event)
+				    u32 mask, void *data, int data_type,
+				    const unsigned char *dname)
 {
 	struct inode *inode;
-	__u32 mask = event->mask;
-	const char *dname = event->file_name;
 	struct audit_parent *parent;
 
 	parent = container_of(inode_mark, struct audit_parent, mark);
 
 	BUG_ON(group != audit_watch_group);
 
-	switch (event->data_type) {
+	switch (data_type) {
 	case (FSNOTIFY_EVENT_PATH):
-		inode = event->path.dentry->d_inode;
+		inode = ((struct path *)data)->dentry->d_inode;
 		break;
 	case (FSNOTIFY_EVENT_INODE):
-		inode = event->inode;
+		inode = (struct inode *)data;
 		break;
 	default:
 		BUG();
@@ -516,7 +516,7 @@ static const struct fsnotify_ops audit_w
 	.handle_event = 	audit_watch_handle_event,
 	.free_group_priv = 	NULL,
 	.freeing_mark = 	NULL,
-	.free_event_priv = 	NULL,
+	.free_event = 		NULL,
 };
 
 static int __init audit_watch_init(void)

_

Patches currently in -mm which might be from [email protected] are

origin.patch
fs-pipec-skip-file_update_time-on-frozen-fs.patch rbtree-test-move-rb_node-to-the-middle-of-the-test-struct.patch rbtree-test-test-rbtree_postorder_for_each_entry_safe.patch net-netfilter-ipset-ip_set_hash_netifacec-use-rbtree-postorder-iteration-instead-of-opencoding.patch fs-ubifs-use-rbtree-postorder-iteration-helper-instead-of-opencoding.patch fs-ext4-use-rbtree-postorder-iteration-helper-instead-of-opencoding.patch fs-jffs2-use-rbtree-postorder-iteration-helper-instead-of-opencoding.patch fs-ext3-use-rbtree-postorder-iteration-helper-instead-of-opencoding.patch fs-ext3-use-rbtree-postorder-iteration-helper-instead-of-opencoding-fix.patch arch-sh-kernel-dwarfc-use-rbtree-postorder-iteration-helper-instead-of-solution-using-repeated-rb_erase.patch userns-relax-the-posix_acl_valid-checks.patch
linux-next.patch
block-blk-mq-cpuc-use-hotcpu_notifier.patch kernel-use-lockless-list-for-smp_call_function_single.patch mm-add-strictlimit-knob-v2.patch