6

in one of our application's module, calloc() is failing and returning NULL. The amount of memory that it is trying to allocate is of structure which is of 9292 bytes. The operating system is AIX 7.1 and running VIOS 2.2.1.3.

The machine has 2+GB ram and does not seems to have an issue with lack of memory. The same application module is running fine on one of the other boxes, which has same configurations as the problematic box.Following is a snippet of memory from both the boxes and they are same !

WORKING BOX:

RLIMIT_AS      (infinite) (infinite)
RLIMIT_CORE    1073741312 (infinite)
RLIMIT_CPU     (infinite) (infinite)
RLIMIT_DATA     134217728 (infinite)
RLIMIT_FSIZE   (infinite) (infinite)
RLIMIT_NOFILE        2000 (infinite)
RLIMIT_RSS       33554432 (infinite)
RLIMIT_STACK     33554432 2147483646 

PROBLEMATIC BOX:

RLIMIT_AS      (infinite) (infinite)
RLIMIT_CORE    1073741312 (infinite)
RLIMIT_CPU     (infinite) (infinite)
RLIMIT_DATA     134217728 (infinite)
RLIMIT_FSIZE   (infinite) (infinite)
RLIMIT_NOFILE        2000 (infinite)
RLIMIT_RSS       33554432 (infinite)
RLIMIT_STACK     33554432 2147483646 

I'm clueless as can't really figure out why calloc() is failing even for 9292 bytes on this box.

Thanks

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
kuldeep
  • 817
  • 10
  • 27
  • Maybe memory fragmentation? There is no free block big enough to fit your allocation? When the allocation fails, have you checked e.g. `errno` to see what it says? – Some programmer dude Nov 06 '12 at 06:11
  • Yes I was thinking the same, but is there a way to proof or concretely know it ?? the error number ENOMEM ! Truss output shows this error ! a snippet from truss on the process shows this lseek(3, 0, 1) = 4318 lseek(3, 0, 1) = 4318 lseek(3, 0, 1) = 4318 lseek(3, 242, 0) = 242 kread(3, "\t M i n o r V e r s i o".., 4096) = 4096 lseek(3, 0, 1) = 4338 lseek(3, 222, 0) = 222 __libc_sbrk(0x00000000) Err#12 ENOMEM __libc_sbrk(0x00000000) Err#12 ENOMEM __libc_sbrk(0x00000000) Err#12 ENOMEM __libc_sbrk(0x00000000) Err#12 ENOMEM __libc_sbrk(0x00000000) Err#12 ENOMEM – kuldeep Nov 06 '12 at 06:12
  • Show us the code, including the call to `calloc` and the code that checks its result. – Keith Thompson Nov 06 '12 at 07:44
  • 1
    Did you check the `available` memory? The limits do not tell you anything about the actual memory allocation. Are the same processes with the same memory consumption running on both of your boxes? – Andreas Fester Nov 06 '12 at 07:56
  • ifp_handle_t * newhandle; newhandle = calloc(sizeof(ifp_handle_t),1); if (newhandle == NULL) { free(sIniPath); return IFP_ALLOC_RC; } //this case it is returning IFP_ALLOC_RC from here ! Also i want to know how to check the available memory ??? Yes the same processes with same memory consumption running on both of the boxes. This process dies as soon as it tries to read a configuraiton file, the calloc is a part of that code. The same process runs fine on other box – kuldeep Nov 06 '12 at 09:13

1 Answers1

1

Try calloc(1, sizeof(ifp_handle_t)); instead of calloc(sizeof(ifp_handle_t), 1); I maybe wrong but it seems you inverted the parameters.

Waterfrag
  • 517
  • 4
  • 20
  • Shouldn't make a difference unless your machine is padding single bytes... but you are right, it's `calloc( nmemb, size )`. – DevSolar Nov 06 '12 at 15:55
  • mmm .. i don't think so that this is making a difference, because i have tried with malloc too and that too fails. Moreover, the same code is working for a long time, it was only when customer created a new partition and upgraded AIX 6.1 VIOS partition to 2.2.1.3. I am suspecting a low page space, or may be some late/early allocation related thing, which may be specific to AIX. – kuldeep Nov 07 '12 at 06:43