LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-12-2010, 02:28 PM   #1
hda7
Member
 
Registered: May 2009
Distribution: Debian wheezy
Posts: 252

Rep: Reputation: 31
Low level memory management


Can someone help explain low level (like assembly level) memory management? Such as, how does a process acquire more memory, sharing memory among processes, etc. I don't want to know how to use malloc or other library functions, but more along the lines of how an example malloc implementation would acquire memory.
 
Old 08-13-2010, 08:11 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by hda7 View Post
more along the lines of how an example malloc implementation would acquire memory.
I looked at an implementation of malloc Yesterday before making the obvious suggestion that the way to find out how malloc is implemented is to look at the open source code.

I didn't post that suggestion, because malloc actually buries its acquisition of memory so deep in macros and conditionals that it is incomprehensible. That is a consequence of writing efficient portable code across multiple OS's where specific efficient methods would not be portable.

Malloc in Linux appears to ultimately used a mixture of sbrk and mmap for acquiring memory from the kernel.

mmap seems to be clearly documented and is a fairly effective method by itself for acquiring memory from the Linux kernel. Depending on your specific needs, understanding and using mmap may be enough.

sbrk is simple, efficient, and understandable in the cases where there is free virtual address space for contiguous growth of the process's original contiguous heap. I find the documentation confusing and even contradictory for the case where some loaded .so file or other mmaped region prevents contiguous expansion of the original heap. Does sbrk then simply fail or does it deliver noncontiguous memory, or what?

I was expecting someone who knew these answers to reply sooner. But as that hasn't happened, you have my partial answers:

Use mmap if that is good enough.

Research sbrk, to learn more than I learned, if mmap alone isn't enough for you.

Dig deeper than I did into the source code of malloc, if reading mmap and sbrk documentation isn't enough.

Last edited by johnsfine; 08-13-2010 at 08:15 AM.
 
Old 08-13-2010, 12:43 PM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,226

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
This came up on Stackoverflow:
http://stackoverflow.com/questions/1...-and-free-work
 
Old 08-15-2010, 06:28 PM   #4
hda7
Member
 
Registered: May 2009
Distribution: Debian wheezy
Posts: 252

Original Poster
Rep: Reputation: 31
Okay, it looks like I would use mmap with MAP_ANONYMOUS, right? That looks like it would be good enough for me. Thanks for the info.
 
  


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
mounting memory card -low level formatted by the camera- rob07mxa Linux - General 2 09-29-2008 10:43 AM
Low level programming? andrw123 Programming 15 09-20-2008 10:23 PM
low level copy an USB flash drive / memory stick mr.v. Linux - Software 1 02-26-2007 04:05 PM
low level format juanb Linux - General 1 02-08-2006 03:16 AM
Low level formatting.... Santorres Linux - General 1 02-02-2004 07:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:54 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