Memory limit for C program

Thread Tools Search this Thread
Operating Systems AIX Memory limit for C program
# 1  
Old 08-09-2011
Memory limit for C program

Greetings -

I'm porting a C application to an AIX (6.1) system, and have bumped into the limits AIX imposes on memory allocation, namely the default limit of 256MB for a process. I'm aware of the compilation flag that allows an application to gain access to up to 8 memory segments (each 256MB, for a total of 2GB) ... but that seems like an unnecessary restriction on a computer that offers more RAM than that.

A toy example I'm using is given here
int main(int argc, char *argv[]) {
  long long size = 2100000000;
  int *T = (int *)malloc (size);
  printf("alloc'd %ld : %d\n",size, T);

Compiling this without increasing segment count results in the malloc call returning a null pointer:
% /usr/vac/bin/xlc_r   -o hello hello.c
% ./hello 
alloc'd 2100000000 : 0

but adding the correct compile flag (for xlc) makes it work:
% /usr/vac/bin/xlc_r  -bmaxdata:0x80000000 -o hello hello.c
% ./hello 
alloc'd 2100000000 : 268486928

(note, malloc returns a null pointer even with this flag if I try to allocate 2200000000 bytes)

But I'm unable to figure out how to allow my program to use more memory than that. My impression is that in 64-bit mode, none of these memory restrictions should even be present, e.g.

The default value of maxdata (-bmaxdata:0 or not included in the load command) for 32-bit applications is 256 MB. The maximum allowed for 32-bit applications is 2 GB. For 64-bit applications, the maxdata default value is unlimited.
(link omitted because I'm too new to this group ... but google will find it for you)

Which suggests to me that the first compilation above should've worked. Am I in 64-bit mode? I believe so:

% export OBJECT_MODE=64    
% /usr/vac/bin/xlc_r  -c hello.c  && file hello.o
hello.o: 64-bit XCOFF executable or object module not stripped

that's not what I see if I explicitly go for a 32-bit compile:
% /usr/vac/bin/xlc_r -q32 -c hello.c  && file hello.o
hello.o: executable (RISC System/6000) or object module not stripped

So ... what incredibly naive thing am I doing wrong? Any guidance is greatly appreciated.

(side note: I'm using xlc because it's required for the project. gcc isn't a viable option)

Thanks in advance.
# 2  
Old 08-09-2011
-q64 :

It's not just about RAM, it is about VM, like mmap64()!
# 3  
Old 08-09-2011
Thanks for taking the time to reply. I failed to mention: I've compiled with -q64, resulting in no change to outcome.

I'll also observe that the manual you pointed me to says:
"Compiler mode is set according to the last-found instance of the -q32 or -q64
compiler options. If neither of these compiler options is set, the compiler mode
is set by the value of the OBJECT_MODE environment variable."

As mentioned in my original post, I set that with
export OBJECT_MODE=64

Is there something else I'm supposed to get from the manual?
# 4  
Old 08-10-2011
It may ignore you if your platform or the specified target platform is not 64 bit address capable. However, it says it would warn.

The pdf says '=' after -bmaxdata, not ':'.

Does -qmaxmem= apply?

Are 64 bit libs in use/in dynamic search path?

Cute: setting compiler optimization space too big may exhaust swap!

Did you know that if you create a nominally huge ufs file with seek and write, only 1 block is used? Then, mmap6() allows you to do sparse array in 64 bit space, where missing entries are nulls for free (use RAM but no disk).

(Some sleazy money grubbers leave out options unless you buy a more premium compiler, so try gcc/g++ 64 bit and see if it works when this does not!)

Good luck!
# 5  
Old 08-14-2011
please post the output of ulimit -a
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Cpu, memory - limit by user

Hi all ! I'm new in this site, so sorry if this question is into wrong place. How can I limit cpu/core and memory usage by user? System: RedHat Ent. Linux. 6.4 Tks, (4 Replies)
Discussion started by: Tiago
4 Replies

2. Programming

Size of memory used by a program

Hello, Here is a portion of my code: a=(int *) malloc(dim*dim*sizeof(int)); b=(int *) malloc(dim*dim*sizeof(int)); c=(int *) malloc(dim*dim*sizeof(int)); for(i=0;i<dim;i++) for(j=0;j<dim;j++) c= rand(); for(i=0;i<dim;i++) for(j=0;j<dim;j++) b=rand(); ... (6 Replies)
Discussion started by: chercheur111
6 Replies

3. Red Hat

PAE kernel memory limit

What is the limit of LowMem and HighMem in PAE enable kernel. (2 Replies)
Discussion started by: hiten.r.chauhan
2 Replies

4. Programming

Shared memory between two c program

i have to shared a variable between two different c programs with shared memory and i do these: int main() { int a=5,b=7; int buffer; int *point; int shmid; shmid=shmget(IPC_PRIVATE , sizeof(buffer),0666); point=(int *)shmat(shmid,NULL,0); point=a; ... (21 Replies)
Discussion started by: tafazzi87
21 Replies

5. Shell Programming and Scripting

Memory limit on php in .sh script

Hi, I have .sh script running php script with "php". When I run php script from web browser, it is running without errors. When I run it from .sh script, I am getting "memory exhausted". It seems to me that running php from .sh does not respect php.ini or have its own setting. So, how can I set... (0 Replies)
Discussion started by: LukasB
0 Replies

6. Shell Programming and Scripting

AWK Memory Limit ?

Is there an input file memory limit for awk? I have a 38Mb text file that I am trying to print out certatin lines and add a string to the end of that line. When I excute the script on the 38Mb file the string I am adding is put on a new line. If I do the same with a smaller file the... (3 Replies)
Discussion started by: cold_Que
3 Replies

7. Programming

Measuring memory used by a program?

I have a Java program. I want to measure the total memory used by the program, especially the peak memory. Is there a way to do it? I have tried utilities like time (which returns 0) and top (which is not very useful) as the program does not run for long. Can anyone suggest a way to do this?... (5 Replies)
Discussion started by: spathical
5 Replies

8. Ubuntu

Redhat 2.1 AS Memory Limit?

I have a customer with an HP DL380 G4 server running Redhat 2.1 AS that has 4GB memory installed. They want to upgrade in the server to the maximum of 12GB using (6) 2GB DIMMs. I can do this for them, but I read somewhere that Redhat 2.1 has an upper memory limit. Or you need a kernel patch to use... (2 Replies)
Discussion started by: Cbish68
2 Replies

9. UNIX for Dummies Questions & Answers

upper limit of accessible memory space for a single process in Unix/Linux

Hellp all, if there is 3G memory in my Unix server I want to know if all the 3G space can be used by ong sigle process. As i know, in Windows, one process can only access at most 1G memory despite there is probably more than 1G memory is equipped. (1 Reply)
Discussion started by: cy163
1 Replies

10. UNIX for Advanced & Expert Users

Program/ Memory Problems

I need some advise. I have an application server running several applications. When I try and start a particular application when the others are running I receive the following. This is appearing in the core file that is created. ... (1 Reply)
Discussion started by: dbrundrett
1 Replies
Login or Register to Ask a Question