linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] inotify: Increase default inotify.max_user_watches limit to 1048576
@ 2020-10-26 20:44 Waiman Long
  2020-10-27  8:19 ` Amir Goldstein
  2020-10-27 16:00 ` Jan Kara
  0 siblings, 2 replies; 4+ messages in thread
From: Waiman Long @ 2020-10-26 20:44 UTC (permalink / raw)
  To: Jan Kara, Amir Goldstein
  Cc: linux-fsdevel, linux-kernel, Luca BRUNO, Waiman Long

The default value of inotify.max_user_watches sysctl parameter was set
to 8192 since the introduction of the inotify feature in 2005 by
commit 0eeca28300df ("[PATCH] inotify"). Today this value is just too
small for many modern usage. As a result, users have to explicitly set
it to a larger value to make it work.

After some searching around the web, these are the
inotify.max_user_watches values used by some projects:
 - vscode:  524288
 - dropbox support: 100000
 - users on stackexchange: 12228
 - lsyncd user: 2000000
 - code42 support: 1048576
 - monodevelop: 16384
 - tectonic: 524288
 - openshift origin: 65536

Each watch point adds an inotify_inode_mark structure to an inode to be
watched. Modeled after the epoll.max_user_watches behavior to adjust the
default value according to the amount of addressable memory available,
make inotify.max_user_watches behave in a similar way to make it use
no more than 1% of addressable memory within the range [8192, 1048576].

For 64-bit archs, inotify_inode_mark should have a size of 80 bytes. That
means a system with 8GB or more memory will have the maximum value of
1048576 for inotify.max_user_watches. This default should be big enough
for most of the use cases.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 fs/notify/inotify/inotify_user.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
index 186722ba3894..2da8b7a84b12 100644
--- a/fs/notify/inotify/inotify_user.c
+++ b/fs/notify/inotify/inotify_user.c
@@ -801,6 +801,18 @@ SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd)
  */
 static int __init inotify_user_setup(void)
 {
+	unsigned int watches_max;
+	struct sysinfo si;
+
+	si_meminfo(&si);
+	/*
+	 * Allow up to 1% of addressible memory to be allocated for inotify
+	 * watches (per user) limited to the range [8192, 1048576].
+	 */
+	watches_max = (((si.totalram - si.totalhigh) / 100) << PAGE_SHIFT) /
+			sizeof(struct inotify_inode_mark);
+	watches_max = min(1048576U, max(watches_max, 8192U));
+
 	BUILD_BUG_ON(IN_ACCESS != FS_ACCESS);
 	BUILD_BUG_ON(IN_MODIFY != FS_MODIFY);
 	BUILD_BUG_ON(IN_ATTRIB != FS_ATTRIB);
@@ -827,7 +839,7 @@ static int __init inotify_user_setup(void)
 
 	inotify_max_queued_events = 16384;
 	init_user_ns.ucount_max[UCOUNT_INOTIFY_INSTANCES] = 128;
-	init_user_ns.ucount_max[UCOUNT_INOTIFY_WATCHES] = 8192;
+	init_user_ns.ucount_max[UCOUNT_INOTIFY_WATCHES] = watches_max;
 
 	return 0;
 }
-- 
2.18.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-29 14:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 20:44 [PATCH] inotify: Increase default inotify.max_user_watches limit to 1048576 Waiman Long
2020-10-27  8:19 ` Amir Goldstein
2020-10-27 16:00 ` Jan Kara
2020-10-29 14:25   ` Waiman Long

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).