Skip to content

Values and units

A value in nvs.toml is a number with a unit, and the key decides which unit the value has.

There are four units. A size is a whole number with K, M, G or T, and a number without a letter is bytes. Upper case and lower case are the same. A duration is a whole number with ns, us, ms, s, m, h or d, and a number without a letter is seconds. A count is a whole number. A ratio is a number from 0 to 1.

The same letter can mean two things. m means mebibytes for memory and minutes for wall_time.

A value has one number and one suffix. 90 and 2m are valid durations. 1m30s and 1.5m are not valid. false for a ceiling key means that there is no ceiling.

Good to know: nvs run and nvs config check do not report a value that is not valid for its unit. Novis then enforces nothing for that key. Core\Config::set returns false for such a value.

Examples

The examples below run with this configuration file.

nvs.toml
# `memory` is a size, so `256M` is 256 megabytes.
# `wall_time` is a time, so `30s` is 30 seconds.
[limits]
memory = "256M"
wall_time = "30s"
# A program may raise its own limits up to these values.
[limits.hard]
memory = "512M"
wall_time = "5m"

Writing a size and a time

<?nvs
// Shows how to write a size and a time for a limit.
// A size is a whole number and a letter: `K`, `M`, `G` or `T`. Upper or lower case both work.
// This prints `yes` and then `512m`.
echo Core\Config::set('memory', '512m') ? 'yes' : 'no', "\n";
echo Core\Config::get('memory'), "\n";
// For a time, `m` means minutes. So `2m` is two minutes, and this prints `yes`.
echo Core\Config::set('wall_time', '2m') ? 'yes' : 'no', "\n";
// A time with no letter is in seconds. So `90` is 90 seconds, and this prints `yes`.
echo Core\Config::set('wall_time', '90') ? 'yes' : 'no', "\n";
// A value has one number and one letter. `1m30s` has two, so this prints `no`.
// The time stays at `90`.
echo Core\Config::set('wall_time', '1m30s') ? 'yes' : 'no', "\n";
echo Core\Config::get('wall_time'), "\n";
Output
yes
512m
yes
yes
no
90