Skip to content

Os Memory Numa

DodaTech 1 min read

In this tutorial, you'll learn about How to Fix NUMA Memory Errors. We cover key concepts, practical examples, and best practices.

Fix numa memory errors when memory allocated on wrong NUMA node causes remote access latency.

Quick Fix

Wrong

# Process on node 0 allocates memory on node 1. Access crosses interconnect.

Remote NUMA node memory access is ~1.5-2x slower than local. Hurts performance.

import os
# Check NUMA topology:
try:
    with open('/sys/devices/system/node/online') as f:
        print(f'NUMA nodes: {f.read().strip()}')
except: print('Not NUMA')
# Use numactl to bind:
# os.system('numactl --cpunodebind=0 --membind=0 python app.py')
# Python: use ctypes to call libnuma
import ctypes
libnuma=ctypes.CDLL('libnuma.so.1')
# Allocate on specific node:
import mmap
size=1024*1024
mm=mmap.mmap(-1,size)
# libnuma.mbind(mm, size, 0, nodemask, 0, MPOL_BIND)
Memory allocated on node 0, accessed by CPU on node 0. Local access, low latency.

Prevention

Bind process to NUMA node. Use numactl --membind. Allocate memory close to executing CPU.

DodaTech Tools

Doda Browser's algorithm visualizer steps through DSA operations line by line. DodaZIP archives implementation patterns for team sharing. Durga Antivirus Pro detects memory corruption patterns in algorithm implementations.

FAQ

What is NUMA?

Non-Uniform Memory Access. Each CPU has local memory bank. Remote access slower.

Why it matters?

Remote NUMA access adds latency. Bind memory to same node as executing threads.

Tool?

numactl --hardware shows topology. numastat shows allocations per node.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro