How Much Storage Is Left in Your Main Storage Pools?

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Learn an easy and efficient way to determine the amount of unallocated main storage.

 

There's no doubt that knowing the amount of unallocated storage in the main storage pools is important to system operators. But how to do that?

The Work with System Status (WRKSYSSTS) command and the Work with Shared Storage Pools (WRKSHRPOOL) command allow operators to manage main storage pools, but neither of them reports the information we're looking for.

At V5R4, as an improvement to Collection Services, a new field called the Unallocated Pool Space (POUNAL) was added to the performance data file QAPMPOOLB generated by the Create Performance Data (CRTPFRDTA) command. The POUNAL field is set to the value of the amount of pool storage (in KB) available to be used for new transfers into a main storage pool without displacing any virtual data already in the pool. However, the performance data collected by Collection Services is collected at sampling intervals; therefore, you cannot get real-time data out of it.

The Set Object Access (SETOBJACC) command brings an object into a main storage pool or purges it from all main storage pools. After a SETOBJACC command completes, it sends a completion message to the call message queue of the current job; this message reports the amount of unused storage remaining in the target main storage pool (in KB) before it brings an object to the pool. So it's a workable way to bring an object into a main storage pool and then retrieve the value of unallocated pool storage of the pool. Yes, it's an easy and workable approach, but not efficient enough!

Note: Using the SETOBJACC approach can be an interesting exercise. For your convenience, in Appendix A below, I list an example CL program that retrieves the amount of unallocated pool storage following the SETOBJACC approach.

An easy, yet efficient, method of gathering main storage information (especially the amount of unallocated pool storage) is via the Materialize Resource Management Data (MATRMD) MI instruction with option hex 2D (Materialize main storage pool information). Option hex 2D was added to the MATRMD instruction as of V5R4 as an improvement to option hex 09, and a major enhancement expanded the size of the returned pool data from 4-byte binaries to 8-byte binaries. The prototype of MATRMD and the materialization template for option hex 2D are defined in mih-stgrsc.rpgle (see below). The materialization template for option hex 2D consists of a base portion (defined by data structure matrmd_tmpl2d_t) followed by an array of up to 64 entries of individual main storage pool information (defined by data structure msp_info2_t). The main storage pool information entries in the array are in the same order that they appear in the WRKSYSSTS display.

     /* Selection option for MATRMD */

     d matrmd_option_t...

     d                 ds                  qualified

     d       val                       1a

     d                               7a

     /* Materialization template for MATRMD   */

     d matrmd_tmpl_t   ds                 qualified

     d       bytes_in                 10i 0

     d       bytes_out                 10i 0

     d       time_of_day...

     d                               20u 0

     * Resource management data

     /**

     * @BIF _MATRMD (Materialize Resource   Management Data (MATRMD))

     */

     d matrmd         pr                  extproc('_MATRMD')

     d       receiver                         likeds(matrmd_tmpl_t)

     d       opt                               likeds(matrmd_option_t)

     /**

     * Materialization template for MATRMD   with option hex 2D --

     * Materialize main storage pool   information.

     *

     * @remark Option "Main Storage   Pool Information (Hex 2D)" is the

     * preferred method of materializing   main storage pool

     * information because some of the   fields for this option may

     * overflow without any indication of   error.

     */

     d matrmd_tmpl2d_t...

     d                 ds                 qualified

     d                                       based(dummy_ptr)

     d       bytes_in                 10i 0

     d       bytes_out               10i 0

     d       time_of_day...

     d                               20u 0

     *

     * Machine minimum transfer size is the   smallest number of bytes

     * that may be transferred as a block to   or from main storage. A

     * typical value of this field is 4K.

     *

     d       machine_minimum_transfer_size...

     d                               10u 0

     d       maximum_number_of_pools...

     d                               10u 0

     d       current_number_of_pools...

     d                              10u 0

     d                               4a

     *

     * Main storage size is the amount of   main storage, in units

     * equal to the machine minimum transfer   size, which may be

     * apportioned among main storage pools.

     *

     d     main_storage_size...

     d                               20u 0

     d       pool_1_minimum_size...

     d                               20u 0

     *

     * Array of individual main storage pool   information DS of type

     * msp_info2_t (repeated once for each   pool, up to the current

     * number of pools)

     *

     /* Main storage pool information (for   option hex 2D). */

     d msp_info2_t     ds                 qualified

     d       pool_size...

     d                               20u 0

     d      pool_maintenance...

     d                               20u 0

     d       thread_interruptions_database...

     d                               20u 0

     d       thread_interruptions_nondatabase...

     d                               20u 0

     d       data_transferred_to_pool_database...

     d                               20u 0

     d       data_transferred_to_pool_nondatabase...

     d                               20u 0

     * Unallocated pool storage

     d       unal                     20u 0

     * Alias of @var unal

     d       amount_of_pool_not_assigned_to_virtual_addresses...

     d                               20u 0   overlay(unal)

     d                               8a

Fields directly related with our goal are the following:

  • matrmd_tmpl2d_t.machine_minimum_transfer_sizeMachine minimum transfer size is defined to be the smallest number of bytes that may be transferred as a block to and from main storage. Here it is used as the unit of storage size fields such as pool size and unallocated pool storage in the materialization template. The typical value of this field is 4KB.
  • matrmd_tmpl2d_t.current_number_of_poolsThis is the number of main storage pools currently being utilized.
  • msp_info2_t.pool_sizeThis is the size of the storage assigned to a main storage pool in units of machine minimum transfer size (zero if the main storage pool isn't currently being utilized).
  • msp_info2_t.unalThis is the unallocated pool storage in a main storage pool in units of the machine minimum transfer size. To calculate a pool's unallocated pool storage in KB, use the formula: unused_in_KB = msp_info2_t.unal * matrmd_tmpl2d_t.machine_minimum_transfer_size / 1024.

The following is an RPG example, t181.rpgle. It reports the amount of unallocated pool storage (in KB) in each main storage pool:

     /**

     * @file t181.rpgle

     *

     * Test of MATRMD -- Retrieve amount of   unallocated pool storage.

     */

     h dftactgrp(*no)

     /copy mih-stgrsc

     d @tmpl           s               *

     d tmpl           ds                 likeds(matrmd_tmpl2d_t)

     d                                       based(@tmpl)

     d @mspe           s              *

     d mspe           ds                 likeds(msp_info2_t)

     d                                       based(@mspe)

     d opt             ds                 likeds(matrmd_option_t)

     d len             s             10u 0

     d num            s             10u 0

     d unal           s             20u 0

     /free

           opt = *allx'00';

           opt.val = x'2D';

           // Get length of necessary buffer

           @tmpl =   %alloc(%size(matrmd_tmpl2d_t));

           tmpl.bytes_in =   %size(matrmd_tmpl2d_t);

           matrmd(tmpl : opt);

           len = tmpl.bytes_out;

           // Allocate buffer for   materialization template

           @tmpl = %realloc(@tmpl : len);

           tmpl.bytes_in = len;

           // Actually materialize main   storage pool info

           matrmd(tmpl : opt);

           // Report amount of unallocated   pool storage in each MSP

           @mspe = @tmpl +   %size(matrmd_tmpl2d_t);

           num = 1;

           dow num <=   tmpl.current_number_of_pools

              and

               mspe.pool_size > 0; //   Ignore empty pools

               // Amount of unallocated pool   storage in 1KB units

               unal = mspe.unal

                     *   tmpl.machine_minimum_transfer_size

                     / 1024;

               dsply num '' unal;

               // Offset to next msp_info2_t   structure

               num += 1;

               @mspe += %size(msp_info2_t);

           enddo;

           dealloc @tmpl;

           *inlr = *on;

     /end-free

Appendix A: CL Example of Retrieving the Amount of Unallocated Pool Storage via SETOBJACC

After a SETOBJACC command completes successfully, it sends a completion message to the call message queue of the current job. The message ID is CPC1140 for a file object (*FILE) and CPC1141 for a program object (*PGM), respectively. Either of these two CPC messages reports the amount of unused storage remaining in the target main storage pool (in KB) before an object is brought to the pool via the sixth message data field (of type BIN(4)). The offset of the sixth message data field from the beginning of the message data of either message is 41.

The following ILE CL example, unalloc.clle, retrieves the amount of unallocated storage in a specific main storage pool through the following steps:

  1. 1.Bring whatever program (UNALLOC itself in this example) to the target main storage pool via the SETOBJACC command.
  2. 2.Receive the CPC1141 message sent by the previous SETOBJACC command and save the value of the sixth message data field (amount of unallocated pool storage).
  3. 3.Report the amount of unallocated pool storage of the target main storage pool.
  4. 4.Purge itself out of the main storage via a SETOBJACC POOL(*PURGE) command.

UNALLOC

             PGM       PARM(&SBSNAM &POOLID)

             DCL       VAR(&SBSNAM) TYPE(*CHAR) LEN(10)

             DCL       VAR(&POOLID) TYPE(*INT) LEN(2)

             DCL       VAR(&MSGDTA) TYPE(*CHAR) LEN(256)

             DCL       VAR(&UNUSED) TYPE(*INT)   STG(*DEFINED) LEN(4) +

                         DEFVAR(&MSGDTA   42)

             DCL       VAR(&MSG) TYPE(*CHAR) LEN(80) +

                         VALUE('Unallocated   storage in target main +

                          storage pool in KB: ')

             DCL       VAR(&ZND) TYPE(*CHAR)   STG(*DEFINED) LEN(11) +

                         DEFVAR(&MSG 61)

             DCL       VAR(&ZNDATTR) TYPE(*CHAR) LEN(7)   +

                           VALUE(X'02000B00000000')

             DCL       VAR(&BIN4ATTR) TYPE(*CHAR) LEN(7)   +

                         VALUE(X'0A000400000000')

             IF         COND(&POOLID *EQ 0)   THEN(SETOBJACC +

                         OBJ(UNALLOC)   OBJTYPE(*PGM) POOL(&SBSNAM))

             ELSE       CMD(SETOBJACC OBJ(UNALLOC)   OBJTYPE(*PGM) +

                         POOL(&SBSNAM   &POOLID))

             RCVMSG     PGMQ(*SAME) MSGQ(*PGMQ) MSGTYPE(*COMP) +

                         MSGDTA(&MSGDTA)

             CALLPRC   PRC('_LBCPYNV') PARM((&ZND)   (&ZNDATTR) +

                         (&UNUSED)   (&BIN4ATTR))

             SNDPGMMSG MSG(&MSG)

             SETOBJACC OBJ(UNALLOC) OBJTYPE(*PGM) POOL(*PURGE)

             ENDPGM

The Copy Numeric Value (CPYNV) MI instruction is used in this example to convert the BIN(4) &UNUSED variable to zoned decimal.

To retrieve the amount of unallocated pool storage of a private pool (e.g., a private pool created in a subsystem called OCT with subsystem-related pool ID 2), call UNALLOC as shown:

4 > X UNALLOC (OCT X'0002')                                                

     Unallocated storage in target main   storage pool in KB:     00000007140

     Object UNALLOC purged from main   storage.                              

To retrieve the amount of unallocated pool storage of the *BASE pool, call UNALLOC like the following:

4 > X UNALLOC (*BASE X'0000')                                              

     Unallocated storage in target main   storage pool in KB:     00000481364

     Object UNALLOC purged from main   storage.                              

Junlei Li

Junlei Li is a programmer from Tianjin, China, with 10 years of experience in software design and programming. Junlei Li began programming under i5/OS (formerly known as AS/400, iSeries) in late 2005. He is familiar with most programming languages available on i5/OS—from special-purpose languages such as OPM/ILE RPG to CL to general-purpose languages such as C, C++, Java; from strong-typed languages to script languages such as QShell and REXX. One of his favorite programming languages on i5/OS is machine interface (MI) instructions, through which one can discover some of the internal behaviors of i5/OS and some of the highlights of i5/OS in terms of operating system design.

 

Junlei Li's Web site is http://i5toolkit.sourceforge.net/, where his open-source project i5/OS Programmer's Toolkit (https://sourceforge.net/projects/i5toolkit/) is documented.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: