[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference vaxaxp::alphanotes

Title:Alpha Support Conference
Notice:This is a new Alphanotes, please read note 2.2
Moderator:VAXAXP::BERNARDO
Created:Thu Jan 02 1997
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:128
Total number of notes:617

119.0. "cache questions" by BARNA::DSMAIL () Thu May 29 1997 05:45

  Hello, a customer has the following problem. Could you bring any ideas?

    Thanks in advance for your cooperation.

    Cristobal (IB004::PONCE)

    **********************************************************************
Problem description:

It seems that when we try to allocate memory blocks the 
system stores the size of these blocks. Any time you 
allocate blocks of a size that have been previously 
allocated (and freed) the pointer points to the memory 
zone that seems to be cached. But when you allocate a 
block size different from the sizes "cached" the system 
creates a new "cache" zone in a higher position.

Our problem is that we need to allocate, recursively, 
many blocks of different sizes, which means that 
thepointer returned grows until the page file quota is 
over.
----------------
#include <stdlib.h>
#include <stdio.h>
main()
{
   char *buffer;
   int n;
   void *status;

   while(1){
      printf("Blocks to allocate:");
      scanf("%d",&n);
      status= calloc(n, sizeof (char));
      printf("\ncalloc status: %d 		         
                                 (%x)\n",status,status);
      free(status);
      printf("\nfree status: %d\n",status);
   }
}
--------------
OUTPUT

Blocks to allocate:200
calloc status: 243512 (3b738) // Pointer dec (hex)
free status: 243512

Blocks to allocate:200
calloc status: 243512 (3b738)
free status: 243512

Blocks to allocate:200
calloc status: 243512 (3b738)
free status: 243512

Blocks to allocate:201
calloc status: 243720 (3b808)
free status: 243720

Blocks to allocate:205
calloc status: 243720 (3b808)
free status: 243720

Blocks to allocate:205
calloc status: 243720 (3b808)
free status: 243720

Blocks to allocate:203
calloc status: 243720 (3b808)
free status: 243720

Blocks to allocate:200
calloc status: 243512 (3b738)
free status: 243512

Blocks to allocate:5000
calloc status: 243944 (3b8e8)
free status: 243944

Blocks to allocate:50002
calloc status: 344072 (54008)
free status: 344072

Blocks to allocate:400
calloc status: 249064 (3cce8)
free status: 249064

Blocks to allocate:200
calloc status: 243512 (3b738)
free status: 243512



RFC-822-headers:
Received: from mail.vbo.dec.com (mail.vbo.dec.com)
 by vbemdf.vbe.dec.com (PMDF V5.0-7 #16475)
 id <[email protected]> for
 [email protected]; Wed, 28 May 1997 16:33:05 +0200
Received: from server21.digital.fr (server21.digital.fr [193.56.15.21])
 by mail.vbo.dec.com (8.7.3/8.7) with ESMTP id QAA00203 for
 <[email protected]>; Wed, 28 May 1997 16:33:02 +0200 (MET DST)
Received: from oasis (oasis.uab.es [158.109.25.11])
 by server21.digital.fr (8.7.5/8.7) with SMTP id QAA07609 for
 <[email protected]>; Wed, 28 May 1997 16:38:58 +0200 (MET DST)
X-VMS-To: SMTP%"[email protected]"
T.RTitleUserPersonal
Name
DateLines
119.1Generic C Memory Management Is Simple-MindedXDELTA::HOFFMANSteve, OpenVMS EngineeringThu May 29 1997 10:3950
   Use the RTL LIB$GET_VM services directly, or create your own memory
   manager layered on top of the C memory management routines. 

   In any event, I would strongly recommend centralizing all memory
   management calls into a single module, as this design will allow
   the easy implementation of memory management debugging in larger
   applications, when (not "if") this becomes necessary.  As part of
   this centralized design, you could choose to allocate fixed-size
   blocks of various sizes -- you could "round up" the allocated
   sizes, and force the C RTL (or your own explicit calls to the RTL
   LIB$ VM routines) to maintain a specific number of "lookaside lists".

   Various folks have posted similar suggestions in the DEC C conference,
   around centralizing the memory management, as well as schemes around
   adding an extra quadword at the front and at the back of the allocated
   storage, to allow the insertion of patterns that allow the detection
   of memory management corruptions.  (I've made several suggestions over
   there...)

   Direct use of the LIB$ VM routines allows one to designate the
   VM zone(s) used, and to designate the allocation sizes, and to
   implement the above debugging, and to access the memory statistics,
   and to implement "temporary memory" VM zones that can be quickly
   and entirely flushed via a single call.  There are other advantages.

   The C language has specific memory management behaviour expected, and
   this behaviour is fairly simple-minded -- among other behaviour, the
   last deallocation has traditionally tends to be cached pending a
   reallocation.  (There used to be the potential for a virtual memory
   leak because of this behaviour, but I believe this particular "leak"
   has been removed.)  

   The RTL folks will know if the LIB$ VM routines used by C have been
   extended to maintain seperate lookaside lists for the various sizes
   of allocations -- based on your comments, it would appear that the
   LIB$ VM routines or the C routines could benefit from the addition
   of a form of the "round up" scheme, should the routines find a large
   number of different size packets are required by the application.
  
   The OpenVMS version -- which is what the DEC C RTL shareable and
   the LIB shareable are both tied to -- would be of interest.

	--

   I'm curious as to why this question is here, I would have expected
   this in TURRIS::DECC (as it's a DEC C question), CLT::RTL (for the
   RTL VM routines "underneath" DEC C, or VAXAXP::VMSNOTES (for generic
   OpenVMS questions).  (VAXAXP::ALPHANOTES is the generic-Alpha and
   porting-to-Alpha conference.)
119.2calloc() should suffice; need more infoWIBBIN::NOYCEPulling weeds, pickin&#039; stonesThu May 29 1997 11:2122
> Our problem is that we need to allocate, recursively, 
> many blocks of different sizes, which means that 
> thepointer returned grows until the page file quota is 
> over.

It would be helpful to see an example program that demonstrates
this problem.  The memory-allocation routines do remember the
block sizes you have used, but if you exceed your PAGFILQUO they
are supposed to coalesce the available free space to find a
block big enough for your allocation request.

What is your PAGFILQUO?  How much memory do you think is in use
when the program fails?  Does the application work on some other
platform?  (Are you sure it remembers to free every block it
allocates?)

Since you mention page file quota, I assume this is VMS.  And
since you posted your note here, I assume it's on Alpha.  What
version of OpenVMS Alpha are you using?

While Steve's suggestions in .1 have some merit,.you shouldn't
have to go to that trouble to make the application work.
119.3check patchesDBGAVC::HIDERPaul Hider, DTN 381-2251Thu May 29 1997 15:5915
     
    The LIBRTL routines behind the DEC C RTL routines
    do use a lookaside list for smaller allocations.
    
    Larger allocations are managed more as a heap.  There were
    a number of complaints of fragmentation of this heap and
    patches were issued for VAX and Alpha to make the merging
    of free'd memory more aggressive.
    
    If you have not installed any LIBRTL patches already, then
    you may want to see if this helps.
    
    (Note: if you installed the 10K patches this was included).
    
    _Paul