16MB allocation on iSeries is not quite 16MB.  There is some header info OS
uses (1 page = 4KB, IIRC) in the allocated space.  So your allocation needs
to account (read reduce) for the header (16MB - 4KB).  

That said, here is a V5R1 APAR that may relate to the original poster's

It sounds to me though, that the original poster really needs to look at the
teraspace compile options.  With it, you can allocate up to 4GB blocks (on

If interested, read "Chapter 17. Using Teraspace" in the manual "WebSphere
Development Studio ILE C/C++ Programmer's Guide", for version 5 releases.

Also, "WebSphereR Development Studio ILE C/C++ Compiler Reference" for
version 5 releases, has some very detailed info on teraspace usage.



-----Original Message-----
From: c400-l-bounces@xxxxxxxxxxxx [mailto:c400-l-bounces@xxxxxxxxxxxx] On
Behalf Of Mike Mills
Sent: Thursday, July 01, 2004 3:01 PM
To: 'C programming iSeries / AS400'
Subject: RE: [C400-L] RE: Porting C Linux to ILE C: Performance problem

Just following up my other message with some code you can use to measure
memory access performance.  It takes one required parameter - the amount of
memory to manipulate, and one optional parameter - a flag indicating whether
to print out the 'touch rate' for every megabyte (by default this is 'on';
specify '0' as the second parm to turn it off.)

Anyway, the program measures three things:

1. How long it takes to perform the malloc().
2. The 'touch rate' per million bytes (optional; on by default).
3. The total time it takes to touch all allocated bytes.

The program uses 'gettimeofday()' in order to get microsecond resolution.

Summarizing the results I get on my V5R2 machine, for 24,000,000 bytes:

malloc() time:  27,392 microseconds
Typical time to touch 1 million bytes BELOW 16MB:  around 225,000
Typical time to touch 1 million bytes ABOVE 16MB:  around 3 seconds +
300,000 microseconds

By the way, this affects Java applications as well (try to use byte[] arrays

Following is the code.  Note that you have to specify the 'teraspace'
options on the C compiler in order to allocate >16MB of contiguous memory.


#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

void computeTimeDiff(struct timeval *start, struct timeval *finish,
                     struct timeval *difference)
    difference->tv_sec = finish->tv_sec - start->tv_sec;
    difference->tv_usec = finish->tv_usec - start->tv_usec;

    while(difference->tv_usec < 0)
        difference->tv_usec += 1000000L;

int main(int argc, char *argv[])
    int mem = 0, i = 0, showRate = 1;
    char *p = NULL;
    struct timeval beforeMalloc, afterMalloc, beforeLoop, afterLoop;
    struct timeval mallocDiff, loopDiff;
    struct timeval mbStart, mbCurrent, mbDiff;

    if(argc < 2)
        printf("Usage: %s <memory size>\n", argv[0]);
    if(argc > 2)   /* Check 'showRate' flag */
        if((argv[2][0] == 'n') || (argv[2][0] == 'N') ||
           (argv[2][0] == '0'))
            showRate = 0;

    mem = atoi(argv[1]);
    if(mem < 1)
        printf("%s: must specify memory size > 0\n", argv[0]);

    gettimeofday(&beforeMalloc, NULL);
    p = malloc(mem);
    gettimeofday(&afterMalloc, NULL);

    computeTimeDiff(&beforeMalloc, &afterMalloc, &mallocDiff);
    printf("Attempt to malloc '%d' bytes took: %ld sec and %ld us\n",
           mem, mallocDiff.tv_sec, mallocDiff.tv_usec);

    if(p == NULL)
        printf("%s: failed to malloc '%d' byts of memory\n", argv[0], mem);

    gettimeofday(&beforeLoop, NULL);
    gettimeofday(&mbStart, NULL);
    for(i = 0; i < mem; i++)
        if(showRate && (i >= 1000000) && ((i % 1000000) == 0))
            gettimeofday(&mbCurrent, NULL);
            computeTimeDiff(&mbStart, &mbCurrent, &mbDiff);
            printf("Current offset: %d, rate: %ld s and %ld us\n",
                   i, mbDiff.tv_sec, mbDiff.tv_usec);
            gettimeofday(&mbStart, NULL);
        p[i] = 'x';
    gettimeofday(&afterLoop, NULL);

    computeTimeDiff(&beforeLoop, &afterLoop, &loopDiff);
    printf("Touching '%d' bytes took: %ld sec and %ld us\n",
           mem, loopDiff.tv_sec, loopDiff.tv_usec);



/*** END PROGRAM ***/

Mike Mills
ConsulTech Information Systems, Inc.

This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].