Architecting Containers Part 1 - Why Understanding User Space vs. Kernel Space Matters
Architecting Containers Part 1 - Why Understanding User Space vs. Kernel Space Matters
SHARE
Perhaps you've been charged with developing a container-based application infrastructure? If so,
you most likely understand the value that containers can provide to your developers, architects, and
operations team. In fact, you've likely been reading up on containers and are excited about exploring
the technology in more detail. However, before diving head-first into a discussion about the
architecture and deployment of containers in a production environment, there are three important
things that developers, architects, and systems administrators, need to know:
While containers are sometimes treated like virtual machines, it is important to note, unlike virtual
machines, the kernel is the only layer of abstraction between programs and the resources they need
access to. Let’s see why.
OK, so you understand what a process is, and that containers are processes, but what about the files
and programs that live inside a container image? These files and programs make up what is known as
user space. When a container is started, a program is loaded into memory from the container image.
Once the program in the container is running, it still needs to make system calls into kernel space.
The ability for the user space and kernel space to communicate in a deterministic fashion is critical.
Want to do more with Red Hat's Universal Base Image
(UBI)?
Download the e-book today!
User Space
User space refers to all of the code in an operating system that lives outside of the kernel. Most
Unix-like operating systems (including Linux) come pre-packaged with all kinds of utilities,
programming languages, and graphical tools - these are user space applications. We often refer to
this as “userland.”
Userland applications can include programs that are written in C, Java, Python, Ruby, and other
languages. In a containerized world, these programs are typically delivered in a container image
format such as Docker. When you pull down and run a Red Hat Enterprise Linux 7 container image
from the Red Hat Registry, you are utilizing a pre-packaged, minimal Red Hat Enterprise Linux 7
user space which contains utilities such as bash, awk, grep, and yum (so that you can install other
software).
Kernel Space
The kernel provides abstraction for security, hardware, and internal data structures. The open()
system call is commonly used to get a file handle in Python, C, Ruby and other languages. You
wouldn’t want your program to be able to make bit level changes to an XFS file system, so the kernel
provides a system call and handles the drivers. In fact, this system call is so common that is part of
the POSIX library.
Notice in the following drawing that bash makes a getpid() call which requests its own process
identity. Also, notice that the cat command requests access to /etc/hosts with a file open() call. In
the next article, we will dig into how this works in a containerized world, but notice that some code
lives in user space, and some lives in the kernel.
Regular user space programs evoke system calls all the time to get work done, for example:
ls
ps
top
bash
These are some user space programs that map almost directly to system calls, for example:
chroot
sync
mount/umount
swapon/swapoff
Digging one layer deeper, the following are some example system calls which are invoked by the
above listed programs. Typically these functions are called through libraries such as glibc, or through
an interpreter such as Ruby, Python, or the Java Virtual Machine.
open (files)
getpid (processes)
socket (network)
A typical program gets access to resources in the kernel through layers of abstraction similar to the
following diagram:
To get a feel for what system calls are available in a Linux kernel, check out the syscalls man page.
Interestingly, I am invoking this command on my Red Hat Enterprise Linux 7 laptop, but I am using a
Red Hat Enterprise Linux 6 container image (aka user space) because I want to see system calls
which were added/removed in the older kernel:
Notice from the man page, that certain system calls (aka interfaces) have been added and removed
in different versions of the kernel. Linus Torvalds et. al. take great care to keep the behavior of these
system calls well understood and stable. As of Red Hat Enterprise Linux 7 (kernel 3.10), there are
382 syscalls available. From time to time new system calls are added, and old system calls are
deprecated; this should be considered when thinking about the lifecycle of your container
infrastructure and the applications that will run within it.
Conclusion
There are some important take aways that you need to understand about the user space and kernel
space:
Over time, it will be challenging to guarantee that a container built today will run on the container
hosts of tomorrow. Imagine the year is 2024 (maybe we’ll finally have real hoverboards) and you still
have a container-based application that requires a Red Hat Enterprise Linux 7 user space running in
production. How can you safely upgrade the underlying container host and infrastructure? Will the
containerized application run equally well on any of the latest greatest container hosts available in
the market place?
In Architecting Containers Part 2: Why the User Space Matters, we will explore how the user space /
kernel space relationship affects architectural decisions and what you can do to minimize these
challenges.
BLOG POST
Not ready to upgrade from RHEL 7? 4 years of Extended Life Cycle Support is now available
BLOG POST
ORIGINAL SHOWS
Technically Speaking | Building trust in Enterprise AI
ORIGINAL SHOWS
Browse by channel
Automation
The latest on IT automation for tech, teams, and environments
Artificial intelligence
Updates on the platforms that free customers to run AI workloads anywhere
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
The latest on how we reduce risks across environments and technologies
Edge computing
Updates on the platforms that simplify operations at the edge
Infrastructure
The latest on the world’s leading enterprise Linux platform
Applications
Inside our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech