Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

We have a system with 1 GB memory. Out of this, i would like to restrict only 512MB for linux and would like to access the rest 512MB directly from an application that runs on linux.

What is the suggested means to achieve this on 2.6.x?

regards, Prab

share|improve this question

migrated from Feb 19 '11 at 15:08

This question came from our site for professional and enthusiast programmers.

If you need to ask how, you don't want to try. – Ignacio Vazquez-Abrams Feb 19 '11 at 2:24
If I had to do this, I think I'd set up Xen with two domains, and a copy of Linux in each, with one copy dedicated to your "special" use. See: – Jerry Coffin Feb 19 '11 at 3:21

5 Answers 5

You are running linux - all the memory in your machine to be available to linux so that linux can give them to your program.

If the system has 512Mb available free it will give it to your program, if not then it can't.

There are extra methods you can use to ensure that the 512Mb is locked into ram (can't be swapped to disk) but i suspect this is beyond what you need to do.

share|improve this answer

Only thing I can think of is have your application malloc() the 512 megs when it first starts and then subdivide the memory manually within the program. And boy oh boy is that ugly.

share|improve this answer

I don't really understand the question; you'll have to explain your purpose more clearly.

Linux allocates its memory to applications, so if Linux has the memory, it will GIVE it to your app.

If you want to definitely have the memory, NOW, you should

  • allocate it (with for example, malloc, or mmap)
  • Touch all the pages (e.g. by writing something to each page)
  • mlock() it - to make sure it won't get swapped out. Or just don't have swap configured (NB: clean file-backed pages can still be discarded if swap is disabled).

If you really need all the pages your program uses to be in core, use mlockall.

share|improve this answer

Allocate a 512MB anonymous mapping with mmap() and MAP_POPULATE, then lock it with mlock().

share|improve this answer

Your application cannot talk to "DIMM 2, chip 3, 42nd byte". It needs the other parts of the system, including Linux, to assign a simple number(address) to every byte of memory. If you excluded 512 MB from Linux, it wouldn't even have an address. That means your application couldn't even talk about the memory, let alone use it.

There would be more problems; e.g. the hibernate function would not restore the memory when waking up. But that's all theoretical, since the memory wouldn't contain anything - without addresses, there's no way to write to memory.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.