Increase the number of directories Linux can monitor (Notify)

server-linux-tips

#1

The default size of the Linux iNotify table is 8192 directories. 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.

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
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.


Constantly stopping and restarting
PLEX Media Server docker is ~1 year behind: worthwhile upgrade?
#2