Skip to content

Fix missing condition for max_filedescriptors use - #2488

Open
yadij wants to merge 1 commit into
squid-cache:masterfrom
yadij:arc-fd-limit-ifdef
Open

Fix missing condition for max_filedescriptors use#2488
yadij wants to merge 1 commit into
squid-cache:masterfrom
yadij:arc-fd-limit-ifdef

Conversation

@yadij

@yadij yadij commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

The max_filedescriptors directive is only useful when the OS
setrlimit() API is available. Add markup to the squid.conf
definition that enables appropriate errors and documentation
automatically.

The max_filedescriptors directive is only useful when
the OS setrlimit() API is available. Add markup to the
squid.conf definition that enables appropriate errors
and documentation automatically.
Comment thread src/cf.data.pre

NAME: max_filedescriptors max_filedesc
TYPE: int
IFDEF: HAVE_SETRLIMIT&&(RLIMIT_NOFILE||RLIMIT_OFILE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! But would it be even nicer if the logic were moved to some header and here it used only a derived value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we all agree I can do that and the RLIMIT_OFILE hack in compat/compat_shared.h where the related SQUID_MAXFD_LIMIT is defined.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for me

@rousskov rousskov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description: The max_filedescriptors directive is only useful when the OS
setrlimit() API is available

I strongly disagree with that statement and, hence, this PR direction. If we continue to improve how Squid determines the maximum number of descriptors, max_filedescriptors should continue to be available in all Squid builds because it represents (or should represent) a fundamental limit/setting that is applicable to all builds, regardless of setrlimit() API availability.

@yadij

yadij commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

PR description: The max_filedescriptors directive is only useful when the OS
setrlimit() API is available

I strongly disagree with that statement and, hence, this PR direction.
If ...should ... should ...

Document what reality is, not what aspirations one has.

@rousskov: you "disagree" with this Squid code line:

#if HAVE_SETRLIMIT && defined(RLIMIT_NOFILE)

... all the logic using this directive for meaningful action is disabled (not even built). The directive is literally only useful when the OS setrlimit() API is available to the built binary.

@yadij
yadij requested a review from rousskov September 8, 2026 01:19
@yadij yadij added the S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box label Sep 8, 2026

@rousskov rousskov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description: The max_filedescriptors directive is only useful when the OS
setrlimit() API is available

I strongly disagree with that statement and, hence, this PR direction. If we continue to improve how Squid determines the maximum number of descriptors, max_filedescriptors should continue to be available in all Squid builds because it represents (or should represent) a fundamental limit/setting that is applicable to all builds, regardless of setrlimit() API availability.

Document what reality is, not what aspirations one has.

In many cases, documenting both is better, especially when it helps to clarify why one would want to move in the opposite direction of one's aspirations. Do you agree that we should aspire to honor max_filedescriptors directive when setrlimit() is unavailable?

@rousskov: you "disagree" with this Squid code line:

#if HAVE_SETRLIMIT && defined(RLIMIT_NOFILE)

Yes, that code is essentially a bug. I "disagree" that we should adjust existing max_filedescriptors directive metadata to match existing problematic code. The correct adjustment should go in the opposite direction (i.e. we should fix code rather than break metadata).

... all the logic using this directive for meaningful action is disabled (not even built). The directive is literally only useful when the OS setrlimit() API is available to the built binary.

I am aware of this existing implementation problem. When the backlog problem is addressed, we should fix that implementation.

P.S. In the official code, a bit of useful max_filedescriptors "logic using this directive for meaningful action" exists even when setrlimit() is unavailable.

@rousskov rousskov removed the S-waiting-for-reviewer ready for review: Set this when requesting a (re)review using GitHub PR Reviewers box label Sep 8, 2026
@kinkie

kinkie commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Thinking back about this PR, I wonder if it makes sense to leave max_filedescriptors in.
In the end, we should enable the administrator to have fewer FDs then the system allows,
and it boils down to making fd_table smaller than the system allows.

what do you think?

@rousskov

rousskov commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Thinking back about this PR, I wonder if it makes sense to leave max_filedescriptors in. In the end, we should enable the administrator to have fewer FDs then the system allows, and it boils down to making fd_table smaller than the system allows.

what do you think?

Yes, max_filedescriptors (the concept, not necessarily the current implementations) is meaningful in all environments, including:

  • environments where admin wants fewer FDs than the system allows (i.e. the case you outline above);
  • environments where admin wants more FDs than the system allows;
  • environments where admin wants the maximum number of FDs allowed by the system;
  • environments where Squid instance does not know what the system allows.

And the above list does not enumerate all important environments. To get closer to a comprehensive list, we at least need to "multiply" the above by what we think --with-filedescriptors concept means (including its default).

Once/if we agree on what those two directives/options should mean, we can adjust Squid code accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants