Linux Tips

Increase the number of directories Linux can monitor (inotify) for PMS

The default size of the Linux inotify table is 8192 directories (*1). When PMS is configured to update automatically when media is added, with properly organized media, especially music, this table rapidly fills and exceeds the default allocation requiring you to increase it.

The solution to this is straight forward. Increasing the table size is easy. The first step is to determine how many directories to allocate,

A. Determine how many directories are currently in use:

sudo find /dir1 /dir2 /dir3 -type d -print | wc -l (use your actual directory names and not dir1, dir2, or dir3. You may add as many top level directories as you need)

B. Determine how many directories to actually allocate

Round up to the next multiple of 32768 (32K). This is done to maximize memory page alignment and keep the maximum amount of memory available for hardware transcoding (if used). This number is called NEW_MAX_DIRECTORIES in the example below.

C. Calculate and verify memory utlization

Multiply the number of entries from above by 512 (worst case size of an inode entry). This tells you how much kernel memory will be permanently allocated and not available to other applications such as PMS. If this results in more memory allocated than you are comfortable allocating, a decision must be made to a) Add more memory to the system or b) reduce the number of directories PMS can automatically monitor. In most cases, increasing system memory is more desirable and yields better overall performance.

D. Implement the change
With calculations complete, it is time to implement the configuration change.

Procedure:

sudo sh
echo  fs.inotify.max_user_watches=NEW_MAX_DIRECTORIES  >> /etc/sysctl.conf
sysctl -p

Example: Allocate 256K (262144) directory entries for the iNotify table


sudo sh
find /nas/movies /nas/tv /nas/music -type d -print | wc -l
201322
#
#
# Round 201322 up to 256K  (262144)
echo  fs.inotify.max_user_watches=262144  >> /etc/sysctl.conf
sysctl -p

In the above example, the table was configured for 262144 (256K) directories on a system with 8GB of main memory.

sysctl was then invoked to make the change immediate (-p).
The system can also be rebooted to make the change take effect.

Notes:

*1 - The default for older Linux systems is 8192. Effective November 2020 Linux kernel, this value is dynamic based on memory and up to 1048576 at start. Most users, with 32GB or more will see the immediate increase to 65536 without making any kernel tuning changes.

Back to top

1 Like
Stuck indefinitely on “… Waiting to be converted”
Libraries not auto scanning on new media being added
Library scans entire library
Transcoder error - EAE Timeout?
Transcoding failed, The log is as follows
Plex transcoding stopped working?
No access to Plex server and or Interface
Plex randomly stopped detecting new media that's added, but a scan of the library will see it
Error reading output: -5 (I/O error) EAE not running (Solved)
Plex EAC3 5.1 Problem
Movie matching seems broken
Library change detection is not working correctly
Audio not playing on any client devices for a particular file
Ignore during Library Scan
Recent Playback Problems EAE
Plex Musik-Mediathek neues Album
Automatic Library Updates
Apple TV STILL can't play some mkvs
Libraries not auto-updating
SRT subtitles not being picked op anymore
Library not scanning automatically
New movies not automatically added
Getting frustrated with local & remote buffering after new hard drives & new computer build last yea
Plex Media Server[1295760]: Jobs: failed to set priority, errno=13
Remote access stopped working
Automatic library scanning doesn't seem to work any more (Ubuntu)
Plex not recognizing many of my MKV files
Intermittent issues with transcoding on NVIDIA gpu
SLOW QUERY errors
PMS won't play EAC3 items. Tried multiple PMS versions
Can't get sound working after reinstalling the server and app
Linux watched directories limit -- perhaps not as bad as you thought, and easy to change
It is not possible to play a movie with Enhanced AC-3 sound
Look for new added files
Only EAC3: EAE timeout! EAE not running, or wrong folder? Could not read
Cannot stream DVR/Live TV to any Chromecast 3rd gen: Error code: h4 (Not Supported)
Tv Shows library no longer detecting changes to folders automatically
SOLVED! - Plex gets stuck spinning at 33% with all videos with EAC3 EAC audio (Plex recently stopped playing EAC3)
Scanning is randomly failing - Marking media unavailable
"TV" is empty - but it's not
EasyAudioEncoder Issues
New music library not updating after adding album
Plex showing season "unavailable" but it is available and I can play the episodes
Transcoding Errors
An error occurred while attempting to play this video check the connection and try again
Increase Number of Monitored Folders WDMyCloud NAS
Server unreachable even in bundled web app
DVR Recordings completed and added to library, but still appear as in progress
EAE Timeout
[How To] Installing Plex Media Server on Ubuntu Linux
[How To] Installing Plex Media Server on Ubuntu Linux
EAC3 decoder not working
Automatic scan of new TV shows not working most of the time
Automatic scan of new TV shows not working most of the time
Random files not playing, most still play, Easy Audio Codec error?
Plex server with error on console
Transcode runner appears to have died (automatic conversion)
Auto Detect of New Media No Longer Working (Windows and Linux)
Transcoding problem when only audio is being transcoded
FireTV Stick 4K won't play some videos with eac3 5.1 audio
Everything was working now Plex tv shows wont play but movies will
Metadata not loaded automatically for new files (anymore)
"EAE timeout! EAE not running, or wrong folder?" Debian Plex Server - TCL Roku TV
Problem of unable to transcode and play
EAC3 Transcodes completely broken. "EAE timeout! EAE not running, or wrong folder?"
Large music library keeps removing then adding albums
Local Files for TV Show Trailers and Extras
TrueHD audio transcoding BUG = error not enough space
MKV with Dolby Audio not playing