[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211019000015.1666608-21-krisman@collabora.com>
Date: Mon, 18 Oct 2021 21:00:03 -0300
From: Gabriel Krisman Bertazi <krisman@...labora.com>
To: jack@...e.com, amir73il@...il.com
Cc: djwong@...nel.org, tytso@....edu, david@...morbit.com,
dhowells@...hat.com, khazhy@...gle.com,
linux-fsdevel@...r.kernel.org, linux-ext4@...r.kernel.org,
linux-api@...r.kernel.org,
Gabriel Krisman Bertazi <krisman@...labora.com>,
kernel@...labora.com
Subject: [PATCH v8 20/32] fanotify: Dynamically resize the FAN_FS_ERROR pool
Allow the FAN_FS_ERROR group mempool to grow up to an upper limit
dynamically, instead of starting already at the limit. This doesn't
bother resizing on mark removal, but next time a mark is added, the slot
will be either reused or resized. Also, if several marks are being
removed at once, most likely the group is going away anyway.
Signed-off-by: Gabriel Krisman Bertazi <krisman@...labora.com>
---
fs/notify/fanotify/fanotify_user.c | 26 +++++++++++++++++++++-----
include/linux/fsnotify_backend.h | 1 +
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index f77581c5b97f..a860c286e885 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -959,6 +959,10 @@ static int fanotify_remove_mark(struct fsnotify_group *group,
removed = fanotify_mark_remove_from_mask(fsn_mark, mask, flags,
umask, &destroy_mark);
+
+ if (removed & FAN_FS_ERROR)
+ group->fanotify_data.error_event_marks--;
+
if (removed & fsnotify_conn_mask(fsn_mark->connector))
fsnotify_recalc_mask(fsn_mark->connector);
if (destroy_mark)
@@ -1057,12 +1061,24 @@ static struct fsnotify_mark *fanotify_add_new_mark(struct fsnotify_group *group,
static int fanotify_group_init_error_pool(struct fsnotify_group *group)
{
- if (mempool_initialized(&group->fanotify_data.error_events_pool))
- return 0;
+ int ret;
+
+ if (group->fanotify_data.error_event_marks >=
+ FANOTIFY_DEFAULT_MAX_FEE_POOL)
+ return -ENOMEM;
- return mempool_init_kmalloc_pool(&group->fanotify_data.error_events_pool,
- FANOTIFY_DEFAULT_MAX_FEE_POOL,
- sizeof(struct fanotify_error_event));
+ if (!mempool_initialized(&group->fanotify_data.error_events_pool))
+ ret = mempool_init_kmalloc_pool(
+ &group->fanotify_data.error_events_pool,
+ 1, sizeof(struct fanotify_error_event));
+ else
+ ret = mempool_resize(&group->fanotify_data.error_events_pool,
+ group->fanotify_data.error_event_marks + 1);
+
+ if (!ret)
+ group->fanotify_data.error_event_marks++;
+
+ return ret;
}
static int fanotify_add_mark(struct fsnotify_group *group,
diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
index 9941c06b8c8a..96e1d31394ce 100644
--- a/include/linux/fsnotify_backend.h
+++ b/include/linux/fsnotify_backend.h
@@ -247,6 +247,7 @@ struct fsnotify_group {
int f_flags; /* event_f_flags from fanotify_init() */
struct ucounts *ucounts;
mempool_t error_events_pool;
+ unsigned int error_event_marks;
} fanotify_data;
#endif /* CONFIG_FANOTIFY */
};
--
2.33.0
Powered by blists - more mailing lists