Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Memory Free up Failing on Solaris 8 - Off-topic

RE: Memory Free up Failing on Solaris 8 - Off-topic

From: Denny Koovakattu <groups_at_koovakattu.com>
Date: Tue, 04 Feb 2003 11:23:40 -0800
Message-ID: <F001.005439DB.20030204112340@fatcity.com>

  Anjo response is correct. Try running truss against your executable. You will see that brk is called for allocating memory. The way I understand it is, brk/sbrk is the system call which allocates/deallocates memory and malloc is the user mode library which internally calls brk/sbrk. I don't think "free" actually releases the memory back to the OS, but may reuse the memory for another request. Run the attached program and check the output. After you free the memory, the next malloc allocates the same memory which has been freed.

Output of truss <snipped> on your program


fstat(3, 0xFFBEEFAC)                            = 0
mmap(0x00000000, 8192, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xFF310000 mmap(0x00000000, 16384, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xFF300000
close(3)                                        = 0
munmap(0xFF310000, 8192)                        = 0
ioctl(1, TCGETA, 0xFFBEEBA4)                    = 0
allocating [20480] bytes
write(1, " a l l o c a t i n g   [".., 25)      = 25
brk(0x00020ED0)                                 = 0
brk(0x00026ED0)                                 = 0
ioctl(0, TCGETA, 0xFFBEF7CC)                    = 0

read(0, "\n", 1024)                             = 1
Freeing [1]
write(1, " F r e e i n g   [ 1 ]\n", 12)        = 12
read(0, 0xFF2BF634, 1024)       (sleeping...)

read(0, "\n", 1024)                             = 1
allocating [30720] bytes
write(1, " a l l o c a t i n g   [".., 25)      = 25
brk(0x00026ED0)                                 = 0
brk(0x00028ED0)                                 = 0
read(0, 0xFF2BF634, 1024)       (sleeping...)

read(0, "\n", 1024)                             = 1
Freeing [2]
write(1, " F r e e i n g   [ 2 ]\n", 12)        = 12
read(0, 0xFF2BF634, 1024)       (sleeping...)

read(0, "\n", 1024)                             = 1
allocating [40960] bytes
write(1, " a l l o c a t i n g   [".., 25)      = 25
brk(0x00028ED0)                                 = 0
brk(0x0002CED0)                                 = 0
read(0, 0xFF2BF634, 1024)       (sleeping...)

read(0, "\n", 1024)                             = 1
Freeing [3]
write(1, " F r e e i n g   [ 3 ]\n", 12)        = 12
read(0, 0xFF2BF634, 1024)       (sleeping...)



#include <stdio.h>

#include <malloc.h>
#include <string.h>
main()
{
  char *loc1;
  char *loc2;

  printf("Allocating [%d] bytes\n", 10*1024);   loc1 = (char *) malloc(10*1024);
  printf("Address : %x\n",loc1);
  printf("Allocating [%d] bytes\n", 10*1024);   loc2 = (char *) malloc(10*1024);
  printf("Address : %x\n",loc2);
  free(loc1);
  free(loc2);

  printf("Allocating [%d] bytes\n", 10*1024);   loc1 = (char *) malloc(10*1024);
  printf("Address : %x\n",loc1);
  printf("Allocating [%d] bytes\n", 10*1024);   loc2 = (char *) malloc(10*1024);
  printf("Address : %x\n",loc2);
  free(loc1);
  free(loc2);

  printf("Allocating [%d] bytes\n", 10*1024);   loc1 = (char *) malloc(10*1024);
  printf("Address : %x\n",loc2);
  free(loc1);
}

Regards,
Denny

Quoting VIVEK_SHARMA <VIVEK_SHARMA_at_infosys.com>:

> Hi
>
> brk, sbrk functions are used for DATA segments and we have problem with
> HEAP. Malloc allocates space onto heap and not in DATA segment.
>
> Seemingly the man page imply that it should not be used in conjunction
> with malloc, calloc ,
> that we are using.
>
> Pasting from man pages :-
> "USAGE
> The behavior of brk() and sbrk() is unspecified if an appli-
> cation also uses any other memory functions (such as
> malloc(3C), mmap(2), free(3C))."
>
>
> Qs. Is any alternative function which can be used OR am i missing
> something ?
>
> Thanks
>
>
> -----Original Message-----
> Sent: Monday, February 03, 2003 1:19 PM
> To: Multiple recipients of list ORACLE-L
>
>
> hmm,
>
> free() doesn't do sbrk() with a negative to reduce the process space. So
> yes
> the space stays allocated.
>
> Anjo.
>
> ----- Original Message -----
> To: "Multiple recipients of list ORACLE-L" <ORACLE-L_at_fatcity.com>
> Sent: Monday, February 03, 2003 7:58 AM
>
>
> > Hi
> >
> > SITUATION - On a production APP Server having about 4000 Concurrent
> application processes ,
> > the memory allocated does NOT seem to be getting freed even though
> the
> application program is issuing the respective call to Free the memory
> .
> >
> > Qs Any /etc/system parameters , OS patches which should help ?
> >
> > Qs Is our approach of using the pmap command Correct ?
> > else what Command to find the "Private" memory taken up by a process
> would
> be advisable ?
> >
> > Qs How to find the Total Amount of Swap Consumed ?
> > [ We probably do NOT know how to interpret the vmstat output Correctly
> ,
> > top/swap -s commands show an output Differing greatly from df -k
> output
> for /tmp filesystem ]
> >
> > Qs Any Body has encountered such as situation before ?
> >
> >
> > Configuration -
> > Solaris 2.8
> > Patch - Generic 108528-16 patch
> > Machine SF15K
> > CPUs = 36
> > RAM = 96 GB
> >
> >
> > We created a Small Sample C program which allocates & FREEs memory
> but
> found that even after
> > FREEing , the memory does NOT show as Freed in the pmap output . Is
> the
> following approach correct ?
> >
> > DETAILS :-
> >
> > @@@@@@@@@@@@@@@@@ SAMPLE C PROGRAM
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> > #include <stdio.h>
> > main()
> > {
> > char *abc = NULL ;
> > int i = 0 ;
> > for (i = 1; i < 10; i++){
> > printf("allocating [%d] bytes\n", 10*1024*(i+1));
> > abc = (char *)malloc(10*1024*(i+1));
> > memset(abc, '\0', 10*1024*(i+1));
> > getchar();
> >
> > free(abc);
> > printf("Freeing [%d]\n", i);
> > getchar();
> > }
> > exit() ;
> > }
> >
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> >
> >
> > RUN Output :-
> >
> > STEP 1 - allocating [20480] bytes
> >
> > pmap -x <PID of Above program process>
> >
> > Address Kbytes Resident Shared Private Permissions Mapped
> File
> > 00010000 8 8 8 - read/exec a.out
> > 00020000 8 8 - 8 read/write/exec a.out
> > 00022000 24 24 - 24 read/write/exec [ heap
> ]
> > FF280000 688 688 688 - read/exec libc.so.1
> > FF33C000 32 32 - 32 read/write/exec libc.so.1
> > FF370000 16 16 16 - read/exec
> libc_psr.so.1
> > FF390000 8 8 8 - read/exec
> libdl.so.1
> > FF3A0000 8 8 - 8 read/write/exec [ anon
> ]
> > FF3B0000 152 152 152 - read/exec ld.so.1
> > FF3E6000 8 8 - 8 read/write/exec ld.so.1
> > FFBEC000 16 16 - 16 read/write/exec [ stack
> ]
> > -------- ------ ------ ------ ------
> > total Kb 968 968 872 96
> >
> > THE "Private" memory allocated by the [ heap ] is 24 K
> >
> > STEP 2 - Freeing the memory allocated in the above Step
> >
> > Freeing [1]
> >
> > pmap -x <PID of Above program process>
> >
> > Address Kbytes Resident Shared Private Permissions Mapped
> File
> > 00022000 24 24 - 24 read/write/exec [ heap
> ]
> >
> > RESULT - THE "Private" memory allocated previously does NOT get Freed
> &
> > [ heap ] continues to be 24 K
> >
> > STEP 3 -
> > allocating [30720] bytes
> >
> > pmap -x <PID of Above Program process>
> >
> > Address Kbytes Resident Shared Private Permissions Mapped
> File
> > 00022000 32 32 - 32 read/write/exec [ heap
> ]
> >
> > STEP 4 - Freeing the memory allocated in the above Step
> > Freeing [2]
> >
> > pmap -x <PID of Above program process>
> >
> > Address Kbytes Resident Shared Private Permissions Mapped
> File
> > 00022000 32 32 - 32 read/write/exec [ heap
> ]
> >
> > RESULT - THE "Private" memory allocated previously in Step 3 does NOT
> get
> Freed &
> > [ heap ] continues to be 32 K
> >
> > Thanks
> >
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
> --
> Author: VIVEK_SHARMA
> INET: VIVEK_SHARMA_at_infosys.com
>
> Fat City Network Services -- 858-538-5051 http://www.fatcity.com
> San Diego, California -- Mailing list and web hosting services
> ---------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).
>
>

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Denny Koovakattu
  INET: groups_at_koovakattu.com

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Tue Feb 04 2003 - 13:23:40 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US