Skip to content

Feat/fractional cpu on linux#369

Closed
Leay15 wants to merge 14 commits intosuperradcompany:mainfrom
AurIAL-Rocks:feat/fractional-cpu
Closed

Feat/fractional cpu on linux#369
Leay15 wants to merge 14 commits intosuperradcompany:mainfrom
AurIAL-Rocks:feat/fractional-cpu

Conversation

@Leay15
Copy link
Copy Markdown

@Leay15 Leay15 commented Feb 9, 2026

This pull request updates the handling of CPU allocation across the microsandbox codebase to support fractional CPU values (e.g., 0.5, 0.25), enabling more granular resource throttling.

The changes span the CLI, configuration, runtime, and VM builder layers, and introduce cgroup-based CPU throttling for fractional CPUs on Linux systems.

Tests are also added to ensure correct parsing and behavior for both integer and fractional CPU values.

Fractional CPU support in configuration and CLI:

  • Changed all relevant cpus and num_vcpus fields and arguments from integer types (u8, u32) to f32 in CLI argument definitions (msb.rs, msbrun.rs), core config structs, and builder APIs. Documentation updated to clarify support for fractional values and valid range (0.1 to 128.0). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18]

Runtime support for CPU throttling:

  • Added logic in MicroVmMonitor to apply CPU throttling using Linux cgroups v2 when a fractional CPU value (<1.0) is requested, including cgroup name sanitization, creation, and cleanup. Warnings are logged if cgroups v2 is unavailable or on non-Linux systems. [1] [2] [3] [4] [5] [6] [7]

Testing and validation:

  • Updated and added tests to verify that both integer and fractional CPU values are parsed and handled correctly in sandbox and build configurations. Tests also confirm that missing CPU values are handled as None. [1] [2] [3] [4]

These changes enable more flexible resource allocation for sandboxes and microVMs, and lay the groundwork for improved multi-tenancy and resource efficiency.

@Leay15
Copy link
Copy Markdown
Author

Leay15 commented Feb 9, 2026

PR created by request on #364

@toksdotdev
Copy link
Copy Markdown
Member

i'll like to better understand your use case before reviewing this. i don't feel strongly that this is a need (at least now), and further diverges the different platforms from each other.

also, the switch from u8 to f32 further keeps me hesitant (i'd rather lean towards separate flags for allocating cpu-period and cpu-quota respectively in the eventuality we ever wanted to explore this).

@Leay15
Copy link
Copy Markdown
Author

Leay15 commented Feb 14, 2026

Sure, I'll explain in a moment.

I'm currently testing Python agents that need separate test environments, as that's how they'll operate in production: one environment per tenant. However, there's a major limitation right now due to resource allocation, considering them as full units. For example, on an 8-core machine, only 4-6 sandboxes can be started, and the last ones to start will begin to fail at startup because the machine itself blocks the resource.

This problem also occurs in Kubernetes, which uses KVM, but it's solved by using fractional resource allocation, allowing initial usage that adjusts after a while, or allowing bursts rather than constantly having the resource occupied.

You can try replicating this behavior by running a msb server start command.

And from the API, make several startup requests. If they are concurrent, the failure will almost certainly occur.

On Mac it happens on the 2nd or 3rd test, on Linux I noticed it on the 6th (considering it has a processor with more cores)

@Leay15 Leay15 closed this Apr 1, 2026
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.

2 participants