Explained: CICS Storage Management

Codelooru cics storage

It starts as a performance problem. Response times climb. Tasks start queuing. Then a message appears on the operator console: DFHSM0133 CICS is under stress (short on storage above 16MB). New transactions are refused. The region grinds to a halt and has to be recycled.

Short on storage is one of the most disruptive CICS failures in production, and unlike most failures it builds gradually. A storage leak in one transaction, a DSA limit set too conservatively, a sudden spike in concurrent users: any of these can tip a region into SOS. Understanding how CICS manages memory inside its address space is what lets you prevent it, diagnose it when it happens, and tune the region to handle growth.

This post assumes you have read Architecture: CICS. It covers how the CICS address space is divided into Dynamic Storage Areas, how programs and tasks use that storage, what storage protection does, and how SOS develops and is resolved.


The CICS Address Space Layout

When a CICS region starts, z/OS allocates it a virtual address space. CICS divides this space into named regions called Dynamic Storage Areas (DSAs). Each DSA is a pre-allocated pool of contiguous virtual memory set aside for a specific purpose. Programs, tasks, and CICS internals all draw their storage from these pools.

The DSA layout reflects the history of z/OS addressing. Early mainframes could only address 16 MB of memory (24-bit addressing). Later hardware extended this to 2 GB (31-bit) and then to 16 EB (64-bit). CICS retains separate DSAs for each address range because some older programs and system facilities still require storage below the 16 MB line. In practice, modern workloads live almost entirely in the 31-bit and 64-bit DSAs.

The DSAs divide along two axes: address range (below 16 MB, above 16 MB, or 64-bit) and storage key (CICS-key or user-key). The storage key distinction is the mechanism that prevents application programs from corrupting CICS internals. A program executing in user key cannot write to CICS-key storage, because the hardware enforces it. A program bug that overwrites memory can only damage user-key storage, not CICS itself.

64-BIT STORAGE GCDSA CICS-key, 64-bit GUDSA User-key, 64-bit GSDSA Shared, 64-bit 31-BIT STORAGE (above 16 MB line) ECDSA CICS-key control blocks CICS internal storage EUDSA User-key task storage Working Storage, commareas ESDSA Shared storage GETMAIN SHARED ERDSA Read-only: reentrant programs load modules, tables 24-BIT STORAGE (below 16 MB line — legacy) CDSA CICS-key below line Legacy CICS storage UDSA User-key below line Legacy program storage SDSA Shared below line RDSA Read-only below line CICS-key: protected from user programs writing to it User-key: where application programs run and allocate storage Figure 1: CICS DSAs by address range and storage key. Modern workloads use 31-bit and 64-bit DSAs.

How Tasks Use Storage

Every CICS task uses storage in several distinct ways. Understanding each one is necessary to diagnose where storage is going when a region runs short.

Working Storage

When a CICS task runs a COBOL program, CICS allocates a private copy of the program's Working Storage section from the EUDSA (for 31-bit programs running user-key, which covers most modern applications). This allocation happens when the task first executes the program and is released automatically when the task ends or when the program returns from a LINK call.

Working Storage size is fixed at compile time by the COBOL program's DATA DIVISION. A program with a 10 KB Working Storage section causes CICS to allocate 10 KB from the EUDSA for every task that runs it simultaneously. If 500 tasks are running that program at the same time, 5 MB of EUDSA is consumed just for that program's Working Storage. Working Storage size is therefore a design concern, not just a coding convenience.

Task Control Area

Each task also has a Task Control Area (TCA): a CICS internal control block that holds the task's state, priority, transaction ID, terminal association, and pointers to its storage allocations. The TCA is allocated from the CICS-key DSA (ECDSA for 31-bit). Application programs cannot access it directly, but it consumes storage for every active task.

Explicit GETMAIN

A program can request additional storage at runtime using EXEC CICS GETMAIN. This is useful when the amount of storage needed is not known at compile time, such as when building a variable-length output buffer or accumulating records from a browse.

EXEC CICS GETMAIN
    SET(WS-STORAGE-PTR)
    FLENGTH(WS-REQUIRED-LENGTH)
    INITIMG(LOW-VALUES)
    RESP(WS-RESP)
END-EXEC

The SET option receives the address of the allocated storage block into a pointer field. FLENGTH specifies the number of bytes required (using FLENGTH rather than LENGTH requests 31-bit storage from the EUDSA). INITIMG pre-fills the storage with a specified byte value, useful for debugging.

Storage obtained by GETMAIN without the SHARED option is automatically released when the task ends. Storage obtained with the SHARED option persists beyond task end and must be explicitly freed with EXEC CICS FREEMAIN by any task that has the address. Forgetting to FREEMAIN shared storage is the most common cause of slow-building storage leaks in CICS regions.

Program Storage

Load modules themselves occupy storage in the RDSA or ERDSA (read-only DSAs). When a program is first invoked, CICS loads it into the read-only DSA and keeps it there for subsequent tasks to share. Programs can be defined as RESIDENT in the CSD (kept permanently in memory) or RELOAD (a fresh copy is loaded on each LINK). Most production programs are non-resident and are compressed out of the DSA under memory pressure. The next invocation triggers a fresh load.


Storage Key and Storage Protection

The z/OS hardware enforces storage protection using storage keys. Each 4 KB page of virtual memory has a key value (0 to 15). A program executing with key K can write to any page with key K or key 0. It cannot write to pages with a different key.

CICS uses two keys. CICS-key storage (key 7 by default) holds CICS control blocks, internal queues, and the structures that CICS itself manages. User-key storage (key 8) holds application Working Storage, commareas, and GETMAIN allocations for user programs. A user-key program running with key 8 cannot write to key 7 storage. If it tries, the hardware raises a protection exception (S0C4 abend).

Storage protection is enabled in the CICS SIT (System Initialization Table) with the parameter STGPROT=YES. With storage protection off, user programs can overwrite CICS internals, making bugs catastrophic and hard to diagnose. With it on, a misbehaving program's damage is contained: it can corrupt its own Working Storage but not CICS itself.

Each transaction is defined with a TASKDATAKEY setting in the CSD: TASKDATAKEY(USER) runs the task's Working Storage in user-key storage (the safe default for all application transactions) and TASKDATAKEY(CICS) runs it in CICS-key storage (reserved for CICS system tasks and certain vendor products). Nearly all application transactions should use TASKDATAKEY(USER).

Transaction Isolation

Storage protection prevents user programs from damaging CICS. Transaction isolation, enabled with TRANISO=YES in the SIT, goes further: it prevents user programs from accessing the Working Storage of other user tasks. With transaction isolation active, task A's Working Storage is protected from task B's programs, even though both are user-key. This matters in CICS because all tasks share the same address space: without isolation, a runaway task could theoretically walk through memory and read or corrupt another task's data.

CICS-KEY STORAGE (key 7) CICS internal control blocks Task Control Areas, dispatcher tables CICS queues and chains File control, program manager state ECDSA / CDSA Protected by hardware storage key USER-KEY STORAGE (key 8) Task A Working Storage TASKDATAKEY(USER), EUDSA Task B Working Storage TASKDATAKEY(USER), EUDSA GETMAIN allocations Commareas, dynamic buffers Write blocked by hardware TRANISO=YES also isolates A from B Figure 2: Storage key protection. User-key programs cannot write to CICS-key storage. TRANISO isolates tasks from each other.

DSA Limits and Tuning

Each DSA has a configured size limit. The key parameters in the CICS SIT are:

  • DSALIM: the total limit for all DSAs below the 16 MB line, combined. Governs CDSA + UDSA + SDSA + RDSA.
  • EDSALIM: the total limit for all extended DSAs above the 16 MB line, combined. Governs ECDSA + EUDSA + ESDSA + ERDSA. This is the most important limit for modern workloads.
  • GCDSA, GUDSA, GSDSA: individual limits for the 64-bit DSAs.

CICS divides the total DSA limit between individual DSAs dynamically, using an internal algorithm that tries to satisfy GETMAIN requests. You set the total ceiling; CICS manages the distribution within it. The only exception is the 64-bit DSAs, which have individually configured limits.

Setting EDSALIM too low is the most common cause of SOS in modern regions. The right value depends on the region's workload: the number of concurrent tasks, the Working Storage size of the programs they run, and the size of any explicit GETMAIN allocations. Monitoring peak DSA usage with the CICS statistics transaction (CEST) and the CICS monitoring facility gives the data needed to tune the limits accurately.

CICS maintains a storage cushion within each DSA: a reserved block of memory (64 KB for standard DSAs, 128 KB for extended DSAs) that is held back from normal allocation. When the DSA reaches its limit, CICS enters SOS. It begins refusing new GETMAIN requests and suspending new task dispatches. It then attempts to recover by waiting for in-flight tasks to complete and release their storage. If the cushion is sufficient, the region recovers without operator intervention. If not, it may require an emergency CICS restart.


Storage Violations

A storage violation occurs when a program writes to a memory address it does not own. In CICS, the most common causes are: overrunning an array, using a pointer that was not initialized, writing beyond the end of a commarea, or miscalculating the length of a GETMAIN area.

CICS detects storage violations using storage check zones (SCZs): small guard areas placed immediately before and after every allocated storage block. When a block is freed (or when the task ends), CICS checks whether the guard areas are intact. If they have been overwritten, CICS raises an ASRA or AICA abend and logs a storage violation message.

The delayed detection is an important property: the violation may have occurred some time before it is detected. A program that overruns a buffer by one byte may corrupt an SCZ that is not checked until a later task's FREEMAIN. The CICS dump at the point of detection contains the overwritten guard area, but finding which program did the overwriting requires trace analysis. The CICS internal trace, with storage manager (SM) tracing enabled, records every GETMAIN and FREEMAIN and the address and program that issued each one. This trace is the primary diagnostic tool for storage violation root cause analysis.

Storage protection (STGPROT=YES) converts many storage violations into immediate hardware protection exceptions (S0C4 abends) rather than delayed SCZ failures. The program that caused the violation abends at the exact instruction that performed the illegal write, making the root cause far easier to find. This is one of the strongest reasons to run with STGPROT=YES in all environments including development.


How SOS Develops and Is Resolved

Short on storage (SOS) develops in three ways.

The first is a storage leak: a program issues EXEC CICS GETMAIN SHARED and never issues the corresponding FREEMAIN. Each transaction execution leaks a fixed amount. Over hours or days, the leaked storage accumulates until the DSA is exhausted. The fix is finding the program responsible (using storage manager trace and DSA statistics) and adding the missing FREEMAIN.

The second is a workload spike: a sudden increase in concurrent transactions causes total Working Storage demand to exceed the DSA limit. Each individual transaction is well-behaved; there are simply too many of them at once. The short-term fix is to increase EDSALIM. The longer-term fix may be to add capacity (more AORs in the CICSPlex) or to reduce Working Storage sizes in the heaviest programs.

The third is DSA fragmentation: enough total free storage exists in the DSA but it is not in contiguous blocks large enough to satisfy a GETMAIN request. CICS allocates storage in fixed-size pages and GETMAIN requests must be satisfied from a single contiguous extent. A region with many small allocations interspersed with free gaps may report free storage while being unable to fulfill a large GETMAIN. Fragmentation resolves as tasks complete and storage is consolidated, but a severely fragmented region may need to be recycled during a quiet period.

When SOS occurs, CICS issues message DFHSM0131 (below 16 MB) or DFHSM0133 (above 16 MB). It suspends new GETMAIN requests that cannot be satisfied and queues them until storage is freed. Tasks waiting for storage appear in the CICS dispatcher as SUSPEND. If the condition does not resolve, CICS may purge lower-priority tasks to free their storage and relieve the pressure.


Monitoring Storage

Proactive storage monitoring prevents SOS from reaching production users. The key tools are:

  • CICS statistics (CEST transaction or statistics datasets): report peak DSA utilization, high-water marks per DSA, number of SOS conditions, and times CICS was forced into the storage cushion. Reviewing these after each business day shows whether limits are approaching.
  • CICS monitoring facility (CMF): provides per-transaction storage consumption, including GETMAIN counts and peak storage in use. Useful for identifying which transactions are the largest consumers.
  • CEMT INQ TASK: shows all active tasks and their current storage usage. During an SOS condition, this identifies which tasks are holding the most storage and whether any are suspended waiting for storage to free.
  • CEMT INQ SYSTEM: displays current DSA utilization, storage protection status, and transaction isolation status. A quick check during a suspected SOS event.

Summary

CICS manages memory inside its address space through a set of named Dynamic Storage Areas, each carved out for a specific purpose and address range. The EUDSA and ECDSA above the 16 MB line carry the bulk of modern workloads. Storage keys enforced by the hardware protect CICS internals from user programs. Transaction isolation extends that protection between tasks.

Working Storage is the largest per-task consumer of DSA space. Its size is fixed at compile time, so every concurrent task running a program draws that program's Working Storage from the EUDSA. Explicit GETMAIN allocations with the SHARED option persist beyond task end and require explicit FREEMAIN; forgetting this is the most common route to a storage leak.

SOS is always preceded by a measurable trend in DSA utilization. Monitoring peak usage, high-water marks, and per-transaction storage consumption gives the warning needed to tune limits before a production region runs out. When SOS does occur, the CICS dump and storage manager trace provide the forensic detail to find the cause and fix it permanently.

Part of the Mainframe Decoded series — IBM Z and z/OS, clearly explained for engineers.



×