Understanding how to allocate and manage space for datasets in JCL
When creating new datasets in JCL, you must specify how much disk space should be allocated. The SPACE parameter on the DD statement is used to define the amount of space to be allocated to a dataset. Proper space allocation is crucial for efficient use of storage resources and to ensure that your datasets have enough room to store all required data.
This tutorial covers the SPACE parameter in detail, including allocation units, primary and secondary allocation, directory blocks for partitioned datasets, and additional options that control how space is allocated and managed.
The SPACE parameter is required when creating a new dataset (DISP=NEW) and specifies how much disk space should be allocated. It has several subparameters that control different aspects of space allocation.
Basic Syntax:
12//ddname DD DSN=dataset.name,DISP=(NEW,CATLG,DELETE), // SPACE=(allocation-unit,(primary,secondary,directory))
The key components of the SPACE parameter are:
The first subparameter of the SPACE parameter specifies the unit of measurement for space allocation. There are three main types of allocation units:
Allocates space in terms of disk tracks. A track is a physical unit of storage on a disk device. The size of a track depends on the device type, but it's typically around 56KB for common disk types.
12//DDTRK DD DSN=USER.TRACKS.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(10,5))
This example allocates 10 tracks initially, with 5 additional tracks available as secondary allocation.
Allocates space in terms of disk cylinders. A cylinder consists of a set of tracks (typically 15) and is a larger unit of allocation. Using cylinders can improve performance for larger datasets.
12//DDCYL DD DSN=USER.CYLS.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(CYL,(2,1))
This example allocates 2 cylinders initially, with 1 additional cylinder available as secondary allocation.
Instead of using TRK or CYL, you can specify the average block size (in bytes). The system will calculate the appropriate number of tracks or cylinders to allocate based on the block size and quantity.
12//DDBLK DD DSN=USER.BLOCKS.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(800,(100,50))
This example specifies that the average block size is 800 bytes, and requests space for 100 such blocks initially, with space for 50 additional blocks available as secondary allocation.
Best Practice:
For most general-purpose datasets, TRK is a good choice for allocation. For larger datasets, CYL often provides better performance. Using block size can provide more precise control but requires more calculation and understanding of the device characteristics.
The SPACE parameter includes specifications for both primary and secondary allocation.
Primary allocation is the initial amount of space allocated when the dataset is created. This space is reserved in a contiguous manner if possible. You should allocate enough primary space to handle the expected data volume under normal conditions.
Secondary allocation specifies how much additional space to allocate if the dataset fills up. When the primary allocation is filled, the system will allocate secondary space in the amount specified. This can happen multiple times as needed, up to a system-defined limit (typically 16 extents, though modern systems often allow more).
Example:
1234//DD1 DD DSN=USER.PS.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(50,20)) //DD2 DD DSN=USER.SMALL.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(CYL,(1,1))
In the first example, 50 tracks are allocated initially, with 20 additional tracks allocated each time the dataset needs to expand. In the second example, 1 cylinder is allocated initially, with 1 additional cylinder allocated if needed.
Important:
Secondary allocations are not guaranteed to be contiguous with the primary allocation or with each other. Each secondary allocation creates a new "extent" of the dataset, which can impact performance if there are many extents.
To calculate the appropriate space allocation, consider:
A common approach is to allocate enough primary space for the immediate needs with a reasonable safety margin, and then specify a secondary allocation of about 20-30% of the primary allocation.
When creating a Partitioned Data Set (PDS), you must specify the number of directory blocks to allocate. Directory blocks store the information about the members of the PDS, including their names and locations.
Syntax for PDS:
12//PDSDEMO DD DSN=USER.PDS.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(10,5,5))
In this example, 5 directory blocks are allocated (the third value in the SPACE parameter). Each directory block can hold approximately 5-6 member entries, depending on the length of the member names and other factors.
Calculation Tip:
As a rule of thumb, allocate one directory block for every 5-6 members you expect to have in the PDS. For example, if you expect to have 30 members, allocate at least 6 directory blocks.
Warning:
Once a PDS is created, the number of directory blocks cannot be changed without recreating the dataset. If you run out of directory blocks, you won't be able to add more members to the PDS even if there is plenty of data space available.
The SPACE parameter has several additional options that can be used to control how space is allocated and managed.
The RLSE option instructs the system to release any unused space when the dataset is closed. This can help optimize disk usage by returning unused space to the system.
12//DDRLSE DD DSN=USER.RELEASE.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(100,50),RLSE)
In this example, if the dataset uses less than the allocated 100 tracks, the unused space will be released when the dataset is closed.
The CONTIG option requests that the primary allocation be in contiguous tracks or cylinders. If contiguous space is not available, the allocation will fail.
12//DDCONT DD DSN=USER.CONTIG.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(CYL,(5,2),,,CONTIG)
Note the use of commas to skip optional parameters between the allocation values and CONTIG.
When using average block length for allocation, the ROUND option rounds the space allocation up to a complete cylinder. This can improve performance for certain types of applications.
12//DDRND DD DSN=USER.ROUND.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(800,(1000,500),,,ROUND)
The ALX option requests that up to five separate contiguous areas (extents) be allocated for the primary allocation of the dataset. This is useful when a large contiguous area isn't available.
12//DDALX DD DSN=USER.ALX.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(CYL,(10,5),,,ALX)
The MXIG option requests allocation of the largest contiguous area of available space. The amount requested is treated as a minimum rather than an exact amount.
12//DDMXIG DD DSN=USER.MXIG.DATA,DISP=(NEW,CATLG,DELETE), // SPACE=(TRK,(50,10),,,MXIG)
Calculating the appropriate space allocation requires understanding the data characteristics and usage patterns. Here are some approaches to help determine the right space allocation:
For sequential datasets, calculate the space needed based on:
Example Calculation:
For a dataset with:
Total data size = 80 × 10,000 = 800,000 bytes
Number of blocks = ⌈800,000 ÷ 800⌉ = 1,000 blocks
Space required = ⌈1,000 × 800 ÷ 56,000⌉ = 15 tracks
With a safety margin and growth consideration, you might allocate:SPACE=(TRK,(20,10))
For a PDS, you need to consider both the data space and directory space:
Example PDS Calculation:
For a PDS with:
Using the same calculation as above for data space, with a safety margin:SPACE=(TRK,(10,5,5))
1. Which of the following is NOT a valid allocation unit in the SPACE parameter?
Answer: BLOCK (The valid options are TRK, CYL, or a numeric value for block size)
2. In the SPACE parameter SPACE=(TRK,(100,50,10)), what does the "10" represent?
Answer: The number of directory blocks (for a PDS)
3. What happens if a PDS runs out of directory blocks but still has data space available?
Answer: You cannot add more members even if data space is available
4. Which SPACE option releases unused space when the dataset is closed?
Answer: RLSE
5. Write a JCL statement to allocate a new PDS with 5 cylinders of primary space, 1 cylinder of secondary space, and 10 directory blocks. The dataset should be cataloged if successful or deleted if the job fails.
Answer://NEWPDS DD DSN=USER.NEW.PDS,DISP=(NEW,CATLG,DELETE),
// SPACE=(CYL,(5,1,10))