MainframeMaster

DFSORT Memory Usage

DFSORT uses central storage (memory) to hold records and perform the sort. The more memory it has, the more data it can process in memory before writing to sortwork datasets, which can reduce I/O and improve performance. This page explains how DFSORT uses memory, what limits it (SIZE/MOSIZE and REGION), what happens when data exceeds memory (spill to sortwork), and how to tune memory usage for large sorts or to reduce impact on other jobs.

Performance Optimization
Progress0 of 0 lessons

How the Sort Uses Memory

During a sort, DFSORT reads input records and builds sorted runs in memory. As long as the data fits in the allocated memory, it can complete the sort in memory (or with minimal spill). When the data exceeds that capacity, it writes sorted segments (runs) to sortwork datasets and then performs merge passes: reading from sortwork, merging runs, and writing back until one sorted run remains. So memory is the “first tier” of sort storage; sortwork is the second. More memory means fewer runs written to sortwork and often fewer merge passes, which reduces I/O and can significantly improve elapsed time for large sorts.

What Limits Memory Use

Two things limit how much memory DFSORT can use:

  • OPTION SIZE or MOSIZE — This is the maximum size of the memory objects DFSORT allocates for sort work. It can be specified as a percentage of “available” central storage (e.g. MOSIZE=50) or as a fixed value in MB. The product typically rounds down and may cap the value. So SIZE/MOSIZE is the “how much memory DFSORT is allowed to request” limit.
  • Step REGION (JCL) — The REGION parameter on the EXEC statement sets the maximum address space for the step. All of the step’s storage (program, buffers, DFSORT memory objects, etc.) must fit in this region. If REGION is 64M and you ask for SIZE=256M, DFSORT cannot get 256 MB; it is limited by the 64 MB region. So the effective memory limit is the minimum of what SIZE/MOSIZE allows and what REGION allows.

For large sorts, set both: SIZE/MOSIZE to the amount of memory you want DFSORT to use, and REGION to at least that amount (plus overhead for the program and buffers). Otherwise the sort may use less memory than you expect and rely more on sortwork.

Key Terms

Memory and related concepts
TermMeaning
Central storageMain memory (real storage) used by the address space; REGION limits it for the step.
Memory object (MO)Block of memory DFSORT uses for sort work; size limited by SIZE/MOSIZE.
Sortwork (SORTWK)DASD datasets that hold data when it does not fit in memory; I/O to sortwork can dominate elapsed time.
REGIONJCL EXEC parameter; maximum address space for the step; must be ≥ effective memory use.

When Data Exceeds Memory

When the volume of data to be sorted is larger than the allocated memory, DFSORT does not fail (as long as there is enough sortwork). It writes initial sorted runs to SORTWK datasets. The number and size of these runs depend on memory size and record size. Then it merges: reading multiple runs, merging them into a larger run, writing back. It repeats until one run remains, which is then written to SORTOUT. So sufficient sortwork space is essential when data exceeds memory. If sortwork is insufficient, you get ICE046A (sort capacity exceeded). Tuning memory (SIZE, REGION) reduces the amount of data that goes to sortwork and can reduce the number of merge passes; tuning sortwork (DYNALLOC, SORTWK count/size) ensures there is enough space when data does spill.

Tuning for More Memory

To let DFSORT use more memory: (1) Increase OPTION SIZE or MOSIZE (e.g. higher percentage or more MB). (2) Increase the step REGION in JCL so the step has enough address space (e.g. REGION=0M for system default, or REGION=512M for a specific value). (3) Ensure the system has enough central storage so that granting the region and the memory does not cause paging or impact other workloads. Balance: more memory can speed up the sort but uses more of the system’s resources.

Reducing Memory Use

If you want to limit how much memory DFSORT uses (e.g. to avoid impacting other jobs on the system), specify a smaller SIZE or MOSIZE. For example, use a lower percentage (e.g. MOSIZE=10) or a fixed value (e.g. SIZE=64 for 64 MB). The sort will then use more sortwork I/O and may run longer, but it will consume less central storage. Make sure you still have enough sortwork (SORTWK or DYNALLOC) and a realistic FILSZ so the sort can complete successfully.

Interaction with FILSZ and Sortwork

FILSZ tells DFSORT how much data to expect; it is used to plan sortwork allocation, not to limit memory. So you can have a large FILSZ (lots of data) and a large SIZE (lots of memory): DFSORT will use memory first and spill the rest to sortwork. Or a large FILSZ and a small SIZE: more will spill to sortwork. Sortwork (SORTWK or DYNALLOC) must be sufficient for whatever spills; FILSZ helps DFSORT request enough. So memory (SIZE, REGION) and sortwork (and FILSZ for planning) work together: memory reduces how much goes to sortwork; sortwork must be there when memory is full.

Explain It Like I'm Five

Imagine you’re sorting cards on a table. The table is like memory: the bigger the table, the more cards you can lay out and sort without putting any in boxes. When the table is full, you put sorted piles into boxes (sortwork). Later you take boxes back to the table and merge the piles. A bigger table means fewer boxes and less carrying. The “room” you’re in (REGION) has to be big enough for the table; if the room is tiny, you can’t have a big table no matter what. So: big table (SIZE) + big room (REGION) = less use of boxes (sortwork) and faster sorting.

Exercises

  1. Your job has REGION=64M and OPTION MOSIZE=80. The sort is slow and uses a lot of sortwork. What might you change and why?
  2. What is the difference between “memory” (central storage) and “sortwork” in DFSORT? When does data go to sortwork?
  3. You want to limit DFSORT’s impact on other jobs. How would you reduce its memory use while still allowing the sort to complete?

Quiz

Test Your Knowledge

1. What does DFSORT use central storage (memory) for?

  • Only for the input buffer
  • For sort work: holding records, building sorted runs, and merge buffers—when data exceeds memory it is written to sortwork datasets
  • Only for the output buffer
  • Only for control statements

2. What limits how much memory DFSORT can use?

  • Only the input file size
  • The OPTION SIZE/MOSIZE (product limit for sort objects) and the step REGION in JCL (address space limit)—whichever is smaller effectively caps memory use
  • Only SORTOUT
  • Only the number of SORTWK datasets

3. What happens when the sort data exceeds the allocated memory?

  • The sort fails immediately
  • DFSORT writes sorted runs to sortwork datasets and later merges from sortwork; more data than memory means more sortwork I/O and possibly more merge passes
  • Records are dropped
  • Output is truncated

4. Why might increasing REGION improve sort performance?

  • REGION does not affect performance
  • A larger region allows DFSORT to use more of the SIZE/MOSIZE you specified; with more memory, less data is written to sortwork and fewer merge passes may be needed
  • Only for MERGE
  • Only for COPY

5. What is a memory object in DFSORT context?

  • The input file
  • A block of central storage that DFSORT uses for sort work—holding records and merge buffers; SIZE/MOSIZE limits the total size of these objects
  • The SORTOUT dataset
  • The SORTWK dataset