Hi! I have some questions on file descriptor and NOFILE limit

Nhan Le Thanh:
Hi! I have some questions on file descriptor and NOFILE limit.

Nhan Le Thanh:
What are the resources required to handle these file descriptors ? Why doesn’t Linux is just set it to 1 million or unlimited by default?

I can see that many database performance tunings need increasing in NOFILE limit. Linux does has a default limit of 1024, while the recommended one for many services is 65k minimum. Why? Why not 1m by default? Is this resource consuming ? Is there a max number of file descriptor that a Linux os can handle ( like 2^64 or something ) or there is no max, and the more resources one has the more file descriptor a server can handle?
Thanks!

Aaron Lockhart:
The default limit should have been changed to 4096 a long time ago, if I recall correctly.

The reason not to set it much higher by default is to avoid excess memory consumption by buggy programs, so it’s more of a safeguard. We don’t want something aggressively claiming memory space.

As for the limit, it should be a 32-bit unsigned integer in C, so the upper limit should be 2^32 or 4,294,967,295 maximum open files/descriptors. Unlimited would be impractical, as it’ll have to be stored as a value somewhere, and that variable type will always have a limit.

If you used a variable type that held 2^64 or higher, you’d probably hit a resource limit in something else first.

Nhan Le Thanh:
Thank you