Thread: max memory

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    351

    max memory

    Hi All,

    What's the default maximum amount of memory that a process can use on a linux system?

    Does it depend on the user?

    Where can it be changed?

    What happens if this maximum is exceeded? I assume malloc will fail?

    Thanks for your help,

    rotis23

  2. #2
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    -- depends your settings. one of them allows use of approx 96% and 4% is left for os / what it needs at runtime ( or something like that ). this is quite safe, linux wont never crash while allocating memory. kernel kills process if it tries allocate more than there's available. (available physical memory + available swap).
    Last edited by tjohnsson; 05-17-2004 at 06:56 AM.

  3. #3
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    I have crashed linux allocating too much memory before, albeit when I was root with a bad kernel module I wrote when a loop never exited
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  4. #4
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    Quote Originally Posted by chrismiceli
    I have crashed linux allocating too much memory before, albeit when I was root with a bad kernel module I wrote when a loop never exited
    Bless for that !!!

  5. #5
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    Nice one chrismiceli!!!!!!!!!!

    So the kernel will `kill -9' (SIGKILL) the process rather than return an error to a memory allocation function (e.g. malloc)?

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    If you are using malloc then it should return NULL and as long as you do your error checking correctly you'll be ok.
    What can cause the fault (which I've done) is when you have too deep of recursion and you fill the stack up, try to get more, and then the kernal smacks you for trying to use memory it hasn't said you can use.

    Edit: Oh the max amount of memory used on a per user base and/or a per group base can be done. Same with CPU %. I just don't know where

  7. #7
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    Looks like it's /etc/security/limits.conf - on a redhat system anyway.

  8. #8
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70
    Quote Originally Posted by rotis23
    Nice one chrismiceli!!!!!!!!!!

    So the kernel will `kill -9' (SIGKILL) the process rather than return an error to a memory allocation function (e.g. malloc)?
    I got message 'killed' to the terminal and 'dmesg' shows more information why kernel has done so.
    and was checking malloc against NULL but it did't change kernel behaviour...
    Last edited by tjohnsson; 05-17-2004 at 11:13 PM.

  9. #9
    SleepWalker tjohnsson's Avatar
    Join Date
    Apr 2004
    Posts
    70

    Red face

    Quote Originally Posted by Thantos
    If you are using malloc then it should return NULL and as long as you do your error checking correctly you'll be ok.
    What can cause the fault (which I've done) is when you have too deep of recursion and you fill the stack up, try to get more, and then the kernal smacks you for trying to use memory it hasn't said you can use.

    Edit: Oh the max amount of memory used on a per user base and/or a per group base can be done. Same with CPU %. I just don't know where
    it's safety feature when kernel kills running process if there's no more available memory
    echo 1 to /proc/sys/...somedir.../...somedir.../overcommit_memory to get malloc return NULL and error handling is leaved to running process.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  2. Ranged numbers
    By Desolation in forum Game Programming
    Replies: 8
    Last Post: 07-25-2006, 10:02 PM
  3. Novice Pointers/Class Question
    By C++Gamer in forum C++ Programming
    Replies: 8
    Last Post: 06-28-2006, 05:36 PM
  4. Memory Leak Help
    By (TNT) in forum Windows Programming
    Replies: 3
    Last Post: 06-19-2006, 11:22 AM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM