Skip to content

feat: add agent exec pkg #15577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Nov 25, 2024
Merged

feat: add agent exec pkg #15577

merged 17 commits into from
Nov 25, 2024

Conversation

sreya
Copy link
Collaborator

@sreya sreya commented Nov 18, 2024

This PR adds an agentexec pkg with the intention of eventually replacing the current way we manage process priority in workspaces. The intent is for every invocation of exec.Command() to be wrapped by agentexec.Command to ensure that we adjust the niceness and oom_score appropriately.

@sreya sreya requested a review from deansheather November 20, 2024 22:26
@sreya sreya marked this pull request as ready for review November 20, 2024 22:26
@sreya sreya requested a review from deansheather November 21, 2024 21:19
@sreya sreya requested a review from spikecurtis November 22, 2024 15:44
@sreya
Copy link
Collaborator Author

sreya commented Nov 22, 2024

@spikecurtis @deansheather should our inability to adjust scores for oom or niceness result in a fatal error? If you misconfigure the numbers you've effectively bricked your template.

@deansheather
Copy link
Member

I would say no

@sreya sreya merged commit bbc549d into main Nov 25, 2024
27 checks passed
@sreya sreya deleted the jon/agentexec branch November 25, 2024 15:22
@sreya sreya restored the jon/agentexec branch November 27, 2024 14:36
@sreya sreya deleted the jon/agentexec branch November 27, 2024 14:36
return 0, xerrors.Errorf("get nice score: %w", err)
}
// See https://linux.die.net/man/2/setpriority#Notes
score = 20 - score
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get why we're translating from kernel to userspace scores here if we just call Setpriority() with this value. Shouldn't we need to translate back?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The getpriority man page says the following:

The getpriority system call returns nice values translated to the
range 40..1, since a negative return value would be interpreted
as an error. The glibc wrapper function for getpriority()
translates the value back according to the formula
unice = 20 - knice (thus, the 40..1 range returned by the kernel
corresponds to the range -20..19 as seen by user space).

Further up it says the following for setpriority:

The prio argument is a value in the range -20 to 19 (but see
NOTES below), with -20 being the highest priority and 19 being
the lowest priority. Attempts to set a priority outside this
range are silently clamped to the range. The default priority is
0; lower values give a process a higher scheduling priority.

Pretty confusing tbh

Copy link
Contributor

Choose a reason for hiding this comment

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

Woof. OK, initially read this as glibc doing the translation in both cases, but I guess it's only the get operation that has issues with negative numbers.

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