LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2006, 01:02 AM   #1
minhsangniit
LQ Newbie
 
Registered: Mar 2006
Posts: 7

Rep: Reputation: 0
Please Help Me! How to use more 2GB (>7GB) in a C program


I have an C program (GNU C) and i need it use more 2GB (7-8GB) of RAM, and i used malloc to allocate >2GB of RAM and i got crash (when running - not compiling)- "Segmentation fault". What does option of GNU C compiler support it?
 
Old 03-04-2006, 01:27 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Try looking at mmap.

But I'm not at all sure you're going to get 7GB of contiguous memory with *any* technique.

BTW: are you running a 64-bit OS?
 
Old 03-04-2006, 01:32 AM   #3
minhsangniit
LQ Newbie
 
Registered: Mar 2006
Posts: 7

Original Poster
Rep: Reputation: 0
I'm running a 64-bit OS (Debian Linux 2.6.8), DUAL XEON 3.6GHz, 8GB RAM

Last edited by minhsangniit; 03-04-2006 at 03:49 AM.
 
Old 03-04-2006, 03:38 AM   #4
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Are you asking gcc to compile a 64 bit binary ?

Do you really want to use 7 GB of RAM, which is normally not a requirement for user space programs, but instead want to use 7 GB of virtual memory, and have the system mapping it to RAM when available ?
 
Old 03-04-2006, 02:50 PM   #5
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
what do you get when you printf("%d\n", sizeof(size_t)) ?

(Since malloc() takes a size_t as its argument, it would be bad for you if it's 4 bytes..)

But it really does seem that you should be using mmap. I'm fairly certain I remember there being an mmap64 syscall, but I don't know if regular mmap calls that when you compile for 64bit or not.
 
Old 03-05-2006, 03:04 AM   #6
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Quote:
Originally Posted by aluser
what do you get when you printf("%d\n", sizeof(size_t)) ?

(Since malloc() takes a size_t as its argument, it would be bad for you if it's 4 bytes..)

But it really does seem that you should be using mmap. I'm fairly certain I remember there being an mmap64 syscall, but I don't know if regular mmap calls that when you compile for 64bit or not.
No, mmap64() only offers an off64_t: support for mapping any portion of a large file like you would do with mmap()

It's not easy to use portions of memory larger than SIZE_MAX, but the real limit is SSIZE_MAX. Both read() and write() say they accept size_t but they return ssize_t so there are implementations that don't support sizes between SSIZE_MAX and SIZE_MAX - 2, and in those that do, code such as "if (read(fd, buf, size) < 0)" will fail horribly because SSIZE_MAX + 1 becomes negative on a signed variable.

I think you'd have to code a library on top of mmap and I/O calls and you'd have to keep an array of addresses and their lengths associated to mmap() returned pointers. But first try to see if your OS supports many of these.
 
Old 03-05-2006, 01:19 PM   #7
Intimidator
Member
 
Registered: Mar 2005
Distribution: FC4
Posts: 83

Rep: Reputation: 15
why don't u try increasing the amount of swap.
swap space can be created on a separate partition or by creating a file on an existing partition and mounting it as swap

to create a 1 MB swap file:
Code:
 dd if=/dev/zero of=swapfile bs=1000000

 mkswap swapfile (This cmd makes the file suitable for swap)

 swapon swapfile (Turn on the swap usage)
Post your result

Last edited by Intimidator; 03-05-2006 at 02:12 PM.
 
Old 03-05-2006, 02:34 PM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by Intimidator
why don't u try increasing the amount of swap.
...
The OP has already 8 GB of RAM on his machine, there's likely no need to add swap for his test.
 
Old 03-05-2006, 08:23 PM   #9
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
One hacky way to get it to work is use mmap with 2gb segments and MAP_FIXED to line them up against eachother. As long as you start by finding an 8gb area of your address space that's free (shouldn't be hard with a 64bit space; use pmap if unsure), there's not much to pontificate about.
 
Old 03-06-2006, 08:06 PM   #10
minhsangniit
LQ Newbie
 
Registered: Mar 2006
Posts: 7

Original Poster
Rep: Reputation: 0
I think I can use "shared memory" to resolve my problem (because an application can get 2GB of RAM) and i will get the memory area's address to use in other application.
 
Old 03-06-2006, 08:32 PM   #11
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Please remember:

* "memory" is memory: someplace to hold data.

* "shared memory", on the other hand, is an IPC.

Shared memory is a form of "InterProcess Communication"

Shared memory is for "sharing" data (not just "having" data).

* So don't use shared memory unless you genuinely need to communicate data between different processes.

* And, if you do, don't use shared memory unless you *synchronize* access to that shared data (e.g. with SysV semaphores)

IMHO .. PSM
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Actual file capacity for DVD-R 4.7GB? jryoung Linux - General 1 02-04-2006 11:01 AM
FC3 ~ 7GB (was 3.2GB on initial setup value) johnnydangerous Fedora 3 02-09-2005 04:57 AM
How do I split a 6.7GB movie dvd into two RottenMutt Linux - Software 4 04-19-2004 01:07 AM
RedHat 9 on 2GB HD? UrbanDEV Red Hat 4 12-26-2003 05:47 AM
2GB > Limit optize Linux - General 1 03-18-2002 08:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration