Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1608987
| From | Jes Sorensen <jes.sorensen@gmail.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 5/5] inotify: Avoid taking spinlock for each event processed in read() |
| Date | 2017-03-24 22:40 +0100 |
| Message-ID | <toF69-7By-11@gated-at.bofh.it> (permalink) |
| References | <toF69-7By-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Splice off the notification list while processing read events, which allows
it to be processed without taking and releasing the spinlock for each
event.
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Reviewed-by: Josef Bacik <jbacik@fb.com>
---
fs/notify/inotify/inotify_user.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index 4a93750..45b1f69 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -224,22 +224,27 @@ static ssize_t inotify_read(struct file *file, char __user *buf,
struct fsnotify_group *group;
struct fsnotify_event *kevent;
char __user *start;
- int ret;
+ int ret, consumed = 0;
DEFINE_WAIT_FUNC(wait, woken_wake_function);
+ LIST_HEAD(tmp_list);
start = buf;
group = file->private_data;
mutex_lock(&group->inotify_data.consumer_mutex);
add_wait_queue(&group->notification_waitq, &wait);
+
+ spin_lock(&group->notification_lock);
+ list_splice_init(&group->notification_list, &tmp_list);
+ spin_unlock(&group->notification_lock);
+
while (1) {
- spin_lock(&group->notification_lock);
- kevent = get_one_event(&group->notification_list, count);
- spin_unlock(&group->notification_lock);
+ kevent = get_one_event(&tmp_list, count);
pr_debug("%s: group=%p kevent=%p\n", __func__, group, kevent);
if (kevent) {
+ consumed++;
ret = PTR_ERR(kevent);
if (IS_ERR(kevent))
break;
@@ -262,8 +267,23 @@ static ssize_t inotify_read(struct file *file, char __user *buf,
if (start != buf)
break;
+ spin_lock(&group->notification_lock);
+ list_splice_init(&tmp_list, &group->notification_list);
+ group->q_len -= consumed;
+ consumed = 0;
+ spin_unlock(&group->notification_lock);
+
wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
+
+ spin_lock(&group->notification_lock);
+ list_splice_init(&group->notification_list, &tmp_list);
+ spin_unlock(&group->notification_lock);
}
+ spin_lock(&group->notification_lock);
+ list_splice(&tmp_list, &group->notification_list);
+ group->q_len -= consumed;
+ spin_unlock(&group->notification_lock);
+
remove_wait_queue(&group->notification_waitq, &wait);
mutex_unlock(&group->inotify_data.consumer_mutex);
--
2.9.3
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 0/5] inofify: Reduce lock contention on read() Jes Sorensen <jes.sorensen@gmail.com> - 2017-03-24 22:40 +0100 [PATCH 5/5] inotify: Avoid taking spinlock for each event processed in read() Jes Sorensen <jes.sorensen@gmail.com> - 2017-03-24 22:40 +0100 [PATCH 1/5] notify: Call mutex_destroy() before freeing mutex memory Jes Sorensen <jes.sorensen@gmail.com> - 2017-03-24 22:40 +0100 [PATCH 2/5] inotify: Use mutex to prevent threaded clients reading events out of order Jes Sorensen <jes.sorensen@gmail.com> - 2017-03-24 22:40 +0100 [PATCH 4/5] inotify: switch get_one_event() to use fsnotify_list_*() helpers Jes Sorensen <jes.sorensen@gmail.com> - 2017-03-24 22:40 +0100 [PATCH 3/5] notify: Split up some fsnotify functions Jes Sorensen <jes.sorensen@gmail.com> - 2017-03-24 22:40 +0100
csiph-web