You are not logged in.

#1 2013-01-05 01:35:37

leetow2003
Member
Registered: 2012-04-08
Posts: 25

How to allocate virtual memory in linux

I read a book,it said that in every process its stack
beginning address is the same in logical address.
Is it right?If it is right,then other beginning address
such as text and data? and I want to know how to allocate
virtual memory in linux?

Offline

#2 2013-01-05 02:36:41

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: How to allocate virtual memory in linux

Off-Topic: Your post looks like a poem to me. LOL... don't use too much 'return'.


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#3 2013-01-05 03:23:48

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 5,670

Re: How to allocate virtual memory in linux

Why would you want to do that? And what to?

The kernel allocates virtual memory as needed. You can affect how likely it is to use virtual memory. You can stop it using it altogether. But once you set the parameters, you let the kernel get on with it. Perhaps I don't understand the question?


How To Ask Questions The Smart Way | Help Vampires

Arch Linux | x86_64 | GPT | EFI boot | grub2 | systemd | LVM2 on LUKS
Lenovo x121e | Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz GenuineIntel | Intel Centrino Wireless-N 1000 | US keyboard with Euro | 320G 7200 RPM Seagate HDD

Offline

#4 2013-01-05 03:35:00

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 987

Re: How to allocate virtual memory in linux

Modern CPUs have a facility called memory management, which maps virtual addresses (the addresses that appear to your actual program) to physical addresses of the actual components. This can be done differently per-process, so each process's stack may well start at the same virtual address, though the actual data resides at different physical locations.

This process is done largely in hardware, partially by the OS. As an application programmer, you can't tell the kernel or the CPU where to place your data, and you shouldn't really bother with it. Unless you're specifically interested in virtual memory, in which case you should perhaps pick up a book on OS design and/or computer architecture.

http://en.wikipedia.org/wiki/Virtual_memory

Offline

#5 2013-01-05 04:40:35

boast
Member
Registered: 2010-09-28
Posts: 219

Re: How to allocate virtual memory in linux

Every process has the possibility to address 2^32 or 2^64 bits of virtual memory. The moment you request to read or to write to one of these memory address', it is converted to a physical memory location (based on the process ID) as it is sent to your L1 data cache. It will take a miss and ask your L2 for it, your L2 will take a miss and ask your L3 or your main memory for it, and that will take a miss and ask disk for it. The page of memory will be transferred to main memory, then from main memory down your cache levels. Then if there is room in your L1 cache, the cache line from the page which contains the memory location you want will be placed there, or an older cache line will be kicked out before the new one is placed.

So to just randomly allocate virtual memory that will not be used would mean to go in a loop and continue to kick things out of your cache in order to fit the next one, since all of it will not fit- unless you are only doing it for a small bit to prefetch it into some level of your cache.

So if you want to allocate virtual memory, which in turn becomes physical memory, just ask to read the memory address and it will be temporarily allocated (as well as those around it, based on spacial locality, because the cache line and the page of cache lines were also pulled in)

Last edited by boast (2013-01-05 04:42:54)


Asus M4A785TD-V ;; Phenom II X4 @ 3.9GHz ;; Ripjaws 12GB DDR3-1600 ;; 128GB Samsung 830 ;; MSI GTX460 v2 w/ blob ;; Arch Linux + KDE 4.x

Offline

#6 2013-02-07 04:41:16

Paruga
Member
From: Germany
Registered: 2013-02-07
Posts: 8
Website

Re: How to allocate virtual memory in linux

leetow2003 wrote:

I read a book,it said that in every process its stack
beginning address is the same in logical address.
Is it right?If it is right,then other beginning address
such as text and data? and I want to know how to allocate
virtual memory in linux?

Your not accidentally looking for malloc or new?


---sometimes the obvious isn't there!---

Offline

Board footer

Powered by FluxBB