Results 1 to 8 of 8
Hi
Im a newbie to Linux. I wanted to know how to explicitly manage memory for applications running on linux. For example, i want to create an application (using C) ...
- 03-30-2010 #1Just Joined!
- Join Date
- Mar 2010
- Posts
- 3
Explicit Memory Management
Hi
Im a newbie to Linux. I wanted to know how to explicitly manage memory for applications running on linux. For example, i want to create an application (using C) that has two separate physical address ranges associated with it. How do i assign explicitly those address ranges (the ranges are user defined) to the program?
pavan
- 03-30-2010 #2
I don't think you can do this outside of kernel, I could be wrong though
it doesn't make sense that you could, given that some other application could take up those addresses without you knowing that it did, and then there would be a lot of problems
- 03-30-2010 #3Just Joined!
- Join Date
- Mar 2010
- Posts
- 3
Hi
Thanks for the reply.I just want to partition the memory space in such a way that a set of applications A and set of applications B use different physical addresses (the addresses being under the programmer's control).Do you know of any such memory management support?
- 03-30-2010 #4
The system that you are describing is the default in basically all modern operating systems, called virtual memory. Applications are given separate address spaces. These are not controlled by the programmer, but this is because only the operating system has direct access to the physical memory.
So on Linux, you cannot manually assign ranges to different programs. Every program has an independent address range that lives in some unknown, ever-changing area of physical memory (and it can and does change at any time because of swapping).
If you want two processes to be able to share memory, there is a facility for this, however. You can employ shared memory and mmap to accomplish this:
What are you trying to accomplish by doing this? I can literally think of not a single reason why processes would need to share memory addresses except as a form of IPC, which can be done in many different ways.Code:man shm_overview man mmap
DISTRO=Arch
Registered Linux User #388732
- 03-30-2010 #5Just Joined!
- Join Date
- Mar 2010
- Posts
- 3
Hi
All i want to do is to specify the physical memory addresses a program can use. Is there a way to do this? For example, i want the physical memory addresses from X to Y to be used for program code.
- 03-30-2010 #6
Okay, this can be done, but it is by a very obscure technique.
This is done at compile-time, by interfacing with the linker. You can use linker scripts to determine what the output executable looks like. A brief guide can be found at:
Untitled Document
By using linker scripts, you can specify at what address the text segment should be loaded into.
So although this is possible, it's very complicated, and basically nobody does it. But you theoretically can.
Do be aware, however, that the address specified by the linker script is still a virtual memory address. Not a physical memory address. You cannot interface with the physical memory directly at all.DISTRO=Arch
Registered Linux User #388732
- 03-31-2010 #7
Sounds like homework. But anyway...
You normally would not do this except for boot loaders and some kernel modules. For normal use, there is nothing to be gained by attempting to load and run code at a specific physical address. There are some ways to achieve this (I think), but such methods require root privilege on the machine. So what are you trying to accomplish? There is nothing useful in userland to execute code at an arbitrary location, except in malware.
- 04-01-2010 #8Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,970
This is done automatically for you with Linux. All applications have their own virtual memory space, and the operating system automatically maps that virtual memory to the physical memory it is using at that time. This allows the system to utilize physical memory much more efficiently. In other words, this is NOT something to be concerned wtih. If you are writing an application in the C programming language, just malloc/free memory as you need and let the OS deal with what is where. It can relocate things as required, but your application will be non the wiser because as far as it is concerned, its memory (4GB on i386 systems, 4GBx4GB on x86_64 systems, or up to whatever your ulimit is set to) is a flat, contiguous space.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
