What news from AWS re:Invent last week will have the most impact on you?
Amazon Q, an AI chatbot for explaining how AWS works.
Super-fast S3 Express storage.
New Graviton 4 processor instances.
Emily Freeman leaving AWS.
I don't use AWS, so none of this will affect me.
Linux / Software Development

An Intro to the Linux Memory Access Workload Simulator (masim)

It’s a userspace tool used to simulate intensive memory access workloads to test the behavior and performance of the memory system
Mar 10th, 2023 8:56am by
Featued image for: An Intro to the Linux Memory Access Workload Simulator (masim)

The memory subsystem is one of the most critical areas of the Linux kernel, and consequently, it must be performant, stable and reliable. Over the years, many tools and mechanisms have been developed to help improve the memory subsystem. These include HugePages, NUMA nodes/NUMA emulation, memory compaction, OOM killer, etc.

Another useful tool developed for the memory subsystem is masim, a userspace tool used to simulate intensive memory access workloads to test the behavior and performance of the memory system. It was introduced in 2018 by SeongJae Park.

As of early 2023, it is actively used in generating artificial workloads for testing damo, a userspace tool for DAMON, among other use cases. An important feature of masim is the ability to customize the workloads being generated. As a result, we can use masim to test multiple aspects of the memory.

Installing and Using Masim with a Predefined Config

Now, let us look at how we can use masim. To do that, we have first to download and install it, which can be done as follows:

This will generate the masim executable. Now we can start generating workloads by either using a predefined config in the configs folder or defining one ourselves. Let’s use one of the predefined configs –100mb.cfg.

Let’s look at what 100mb.cfg contains:

A config file contains multiple sections — regions, phases and access patterns. Let’s dissect each of them:


Regions define all the memory regions we wish to use for our workload. Each region has a name and size in bytes. The above example defines a single memory region named “a” and size 100 MB.


In the phases section, we can define the nature of memory accesses to be made by masim. The subsections of each phase are explained as follows:

  • Name of phase:
    • A user-supplied name of each phase. In the above example, the name is huge phase 1.
  • Time:
    • The time duration (in milliseconds) for which masim should run this phase.
  • Access patterns:
    • Here, we specify how a particular memory region should be accessed. In the above example, it is mentioned that masim should access region “a” with randomness set to 1 (0 refers to sequential access), stride of 64 means that there should be a gap of 64 bytes when reading or writing memory (relevant for sequential read/write) and probability refers to the share of total accesses that this particular pattern should get. If another access pattern was defined for this phase with a probability of 40, it would get a smaller share of memory accesses than the pattern defined above.

Defining a Custom Config

Let’s see how we can define our own config. For this example, we’ll be using another feature of masim — HugePages. Masim has the ability to use hugepages, alongside normal pages. Let’s first define a custom config to access 4MB of memory as follows:

Now let’s run this workload with HugePages:

In the above example, the -h flag instructs masim to use HugePages and the -p flag is just used to give detailed output.

Other Important Flags

We can see all the flags that can be passed to masim as follows:

We have already seen -h and -p, and the flags -d, -q and -? are self-explanatory. Let’s see the other flags.

  • -r: Specify the default mode to tune the memory access behavior of masim. We can specify read-only, write-only or read-write.
  • -t: Here, we can specify mlock or madvise. mlock prevents memory from being swapped to the swap area, and madvise directs the kernel about how the memory will be accessed to optimize the system performance.

Example Test Runs

Let us see some example test runs for the --hint and --default_rw_mode flags.

  1. Using mlock with read/write mode

In this example, we are generating a workload to read and write to memory and also use mlock to make sure that the memory used by the process does not get swapped out.

  1. Using madvise with write-only mode

In this example, we are generating a workload to only write to the memory and also use madvise to direct the kernel about memory access patterns and optimize performance. Masim ensures that the specified memory region in the config file is aligned as per the page size.


To summarize, we learned about what masim is, how it is used, and how it can be customized to generate custom workloads. We also learned about its internal working with the various flags and the config files.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Pragma.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.