Articles in this section

How do I identify Shared memory segments?

Context

Aerospike uses System V shared memory segments for several internal data structures, depending on namespace and storage configuration.
In some cases, it is useful to identify which shared memory segments belong to Aerospike and to estimate how much memory has been allocated.


 


Method

You can use the ipcs command to inspect shared memory segments.
List shared memory segments:

sudo ipcs -m


example output:

root@asd70-1:/# ipcs -m

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0xae001100 14         root       666        1073741824 1
0xad001000 15         root       666        402653184  1
0xad001001 16         root       666        402653184  1
0xad001002 17         root       666        402653184  1
0xad001003 18         root       666        402653184  1
0xad001004 19         root       666        402653184  1
0xad001005 20         root       666        402653184  1
0xad001006 21         root       666        402653184  1
0xad001007 22         root       666        402653184  1

Common Aerospike shared memory key prefixes include:

  • 0xae : primary index (PI)
  • 0xa2 : secondary index (SI)
  • 0xad : in-memory data segments



The following command can be used to filter for Aerospike Shared memory segments:

ipcs -m | sed "s/ .*$//" | egrep 0xa[de2]


To double check the creator and last-operation PIDs of the shared memory segments:

root@asd70-1:/# ipcs -mp

------ Shared Memory Creator/Last-op PIDs --------
shmid      owner      cpid       lpid
14         root       870        1424
15         root       870        1424
16         root       870        1424
17         root       870        1424
18         root       870        1424
19         root       870        1424
20         root       870        1424
21         root       870        1424
22         root       870        1424

Then compare with the running Aerospike process:

root@asd70-1:/# ps ax | grep asd
    1424 ?        Ssl    0:01 /usr/bin/asd

If Aerospike is actively using these segments, lpid will often match the running asd PID.
cpid may reflect an earlier Aerospike process that originally created the segment.



The following bash script can be used to compare resident memory with the total allocated Aerospike shared memory based on segment size:

 cat ./getshmem.sh 
#!/bin/bash

# --- Configuration ---
# Aerospike SHM Key Prefixes (excluding the initial '0x'):
# ae: Primary Index (PI)
# a2: Secondary Index (SI)
# ad: Data in Memory (D)
AEROSPIKE_KEY_PREFIXES="ae|a2|ad"

# Get the system memory page size in bytes
PAGE_SIZE_BYTES=$(getconf PAGE_SIZE 2>/dev/null)
if [[ -z "$PAGE_SIZE_BYTES" || "$PAGE_SIZE_BYTES" == 0 ]]; then
    # Fallback to 4096 bytes if getconf fails
    PAGE_SIZE_BYTES=4096
fi

# --- 1. Calculate Total ALLOCATED Size for Aerospike Segments (from ipcs -m) ---

TOTAL_ALLOCATED_BYTES=0

# Filter ipcs -m output for Aerospike keys and sum the "bytes" column (column 5)
AEROSPIKE_SEGMENTS=$(ipcs -m 2>/dev/null | grep -E "^0x($AEROSPIKE_KEY_PREFIXES)")

if [ -n "$AEROSPIKE_SEGMENTS" ]; then
    TOTAL_ALLOCATED_BYTES=$(echo "$AEROSPIKE_SEGMENTS" | awk '{sum += $5} END {print sum}')
fi

TOTAL_ALLOCATED_MB=$(awk "BEGIN { printf \"%.2f\", $TOTAL_ALLOCATED_BYTES / 1024 / 1024 }")

# --- 2. Calculate Total RESIDENT Size System-Wide (from ipcs -u) ---

PAGES_RESIDENT=0

# Get the "pages resident" line from ipcs -u
PAGES_RESIDENT_LINE=$(ipcs -u 2>/dev/null | grep "pages resident")

if [ -n "$PAGES_RESIDENT_LINE" ]; then
    # FIX: Extract the number of resident pages, which is the LAST word ($NF).
    PAGES_RESIDENT=$(echo "$PAGES_RESIDENT_LINE" | awk '{print $NF}')
fi

# Calculate total resident bytes
TOTAL_RESIDENT_BYTES=$(awk "BEGIN { print $PAGES_RESIDENT * $PAGE_SIZE_BYTES }")
TOTAL_RESIDENT_MB=$(awk "BEGIN { printf \"%.2f\", $TOTAL_RESIDENT_BYTES / 1024 / 1024 }")

# --- 3. Report ---

echo "--- Aerospike Shared Memory Summary (System-Wide) ---"
echo "System Page Size: $(awk "BEGIN { print $PAGE_SIZE_BYTES / 1024 }") KB"
echo "--------------------------------------------------------"
echo "Aerospike Segments Found: $(echo "$AEROSPIKE_SEGMENTS" | wc -l) (0x$AEROSPIKE_KEY_PREFIXES)"
echo ""
echo "TOTAL ALLOCATED (MB): $TOTAL_ALLOCATED_MB MB"
echo "SYSTEM RESIDENT (MB): $TOTAL_RESIDENT_MB MB"
echo "--------------------------------------------------------"
echo "Note: The 'SYSTEM RESIDENT' value is for ALL shared memory segments on the system,"
echo "not just Aerospike, but provides an upper bound and confirmation of resident pages."




 


Notes

Aerospike does not auto-release shared memory segments.
The memory Arenas will stay allocated and will not get released by Aerospike until a cold start.
Any storage engine memory segments will not be released on a cold start.

You will see differing cpids (Creator Pid's) for a coldstart.

root@asd70-1:/# ipcs -mp

------ Shared Memory Creator/Last-op PIDs --------
shmid      owner      cpid       lpid
15         root       870        1732
16         root       870        1732
17         root       870        1732
18         root       870        1732
19         root       870        1732
20         root       870        1732
21         root       870        1732
22         root       870        1732
27         root       1732       1732

root@asd70-1:/# ps ax | grep asd
   1732 ?        Ssl    0:01 /usr/bin/asd --cold-start


Storage engine memory should use by default stripes of 8 shared memory segments, unless files/devices are specified for file backed storage, at which point you will get a stripe count matching the number of devices/files you have specified.
 


Applies To Earliest Version

Pre 4.9

Applies To Latest Version

Current Version
Was this article helpful?
0 out of 0 found this helpful