The Time Namespace Appears To Finally Be On-Deck For The Mainline Linux Kernel

Written by Michael Larabel in Linux Kernel on 14 January 2020 at 11:32 AM EST. 15 Comments
LINUX KERNEL
Back in 2018 a time namespace was proposed for the Linux kernel and now in 2020 it looks like this kernel functionality will be merged for mainline, likely with the upcoming Linux 5.6 cycle.

A few hours ago the time namespace patches were queued in the timers/core Git branch ahead of the Linux 5.6 merge window opening at the start of February.

The time namespace allows for per-namespace offsets to the system monotonic and boot-time clocks. The time namespace is suited for Linux containers usage for allowing the date/time to be changed within a container and for adjusting clocks within a container following restoration from a checkpoint/snapshot.

The patch introducing the time namespace further explains:
For many users, the time namespace means the ability to changes date and time in a container (CLOCK_REALTIME). Providing per namespace notions of CLOCK_REALTIME would be complex with a massive overhead, but has a dubious value.

But in the context of checkpoint/restore functionality, monotonic and boottime clocks become interesting. Both clocks are monotonic with unspecified starting points. These clocks are widely used to measure time slices and set timers. After restoring or migrating processes, it has to be guaranteed that they never go backward. In an ideal case, the behavior of these clocks should be the same as for a case when a whole system is suspended. All this means that it is required to set CLOCK_MONOTONIC and CLOCK_BOOTTIME clocks, which can be achieved by adding per-namespace offsets for clocks.

A time namespace is similar to a pid namespace in the way how it is created: unshare(CLONE_NEWTIME) system call creates a new time namespace, but doesn't set it to the current process. Then all children of the process will be born in the new time namespace, or a process can use the setns() system call to join a namespace.

Following that initial patch are many follow-up patches as part of this series for making other elements of the Linux kernel timing code namespace aware and properly exposing the namespaced times. Tests are also included as part of this big rework.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week