2013-09-25 76 views

回答

1

在Linux系統中,看到man ulimit

(修訂版)

它說:

使用ulimit內置用來設置 殼的資源使用限制和任何進程的催生它。如果省略新的限制值 ,則會打印資源限制的當前值。

的ulimit -a打印出與開關選項,其他開關,例如所有的電流值ulimit -n打印出否。最大值打開文件。

不幸的是,「最大內存大小」告訴「無限」,這意味着它不受系統管理員的限制。

您可以通過

cat /proc/meminfo 

導致像查看內存大小:

MemTotal:  4048744 kB 
MemFree:   465504 kB 
Buffers:   316192 kB 
Cached:   1306740 kB 
SwapCached:   508 kB 
Active:   1744884 kB 
(...) 

所以,如果的ulimit說 「無限」,該MemFree都是你的。幾乎。

不要忘記,的malloc()(和運營商,這就要求的malloc())是STDLIB功能,因此,如果調用malloc的(100) 10倍,there will be lot of "slack",遵循鏈接瞭解爲什麼。

+0

沒關係,我會更新 – ern0

+0

偉大的,你有更新的answere – Satpal

5

How much user address space and kernel address space for 4 GB of RAM?

一個進程的地址空間被分成兩個部分,

用戶空間:在標準的32位x86_64的體系結構中,最大可尋址存儲器是4GB,外面從0x00000000地址到0xbfffffff = (3GB)意味着代碼,數據段。當用戶進程在用戶或內核模式下執行時,可以對該區域進行尋址。

內核空間:類似地,從0xc00000000xffffffff = (1GB)地址是指爲內核的虛擬地址空間,並且當進程內核模式中執行只能尋址。

分割在x86上的這個特定地址空間由PAGE_OFFSET的值確定。參照Linux的3.11.1vpage_32_types.hpage_64_types.h,頁偏移定義如下,

#define __PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)

Kconfig限定的default 0xC0000000默認值也可用其他地址分離選項。

類似地,對於64位,

#define __PAGE_OFFSET _AC(0xffff880000000000, UL)

在64位架構上3G/1G由於巨大的地址空間,拆分不再有效。根據最新的Linux版本已經給出了上面的偏移量作爲抵消。

當我看到我的64位x86_64體系結構時,32位進程可以包含整個用戶地址空間的4GB,並且內核將保持地址範圍高於4GB。有趣的是,在現代的64位x86_64 CPU中,並非所有的地址線都被使能(或者地址總線不夠大),以便爲我們提供虛擬地址空間的2^64 = 16 exabytes。或許AMD64/x86體系結構已啓用48/42的低位,分別導致地址空間的2^48 = 256TB/2^42 = 4TB。現在,這大大提高了RAM的性能,同時也帶來了如何有效管理操作系統限制的問題。

0

在Linux中,有一種方法可以找出地址空間的限制。 使用rlimit結構。

struct rlimit { 
    rlim_t cur; //current limit 
    rlim_t max; //ceiling for cur. 
} 

rlim_tunsigned long類型。

,你可以有這樣的:

#include <stdio.h> 
#include <stdlib.h> 
#include <sys/resource.h> 

//Bytes To GigaBytes 
static inline unsigned long btogb(unsigned long bytes) { 
    return bytes/(1024 * 1024 * 1024); 
} 

//Bytes To ExaBytes 
static inline double btoeb(double bytes) { 
    return bytes/(1024.00 * 1024.00 * 1024.00 * 1024.00 * 1024.00 * 1024.00); 
} 

int main() { 

    printf("\n"); 

    struct rlimit rlim_addr_space; 
    rlim_t addr_space; 

    /* 
    * Here we call to getrlimit(), with RLIMIT_AS (Address Space) and 
    * a pointer to our instance of rlimit struct. 
    */ 
    int retval = getrlimit(RLIMIT_AS, &rlim_addr_space); 
    // Get limit returns 0 if succeded, let's check that. 
    if(!retval) { 
     addr_space = rlim_addr_space.rlim_cur; 
     fprintf(stdout, "Current address_space: %lu Bytes, or %lu GB, or %f EB\n", addr_space, btogb(addr_space), btoeb((double)addr_space)); 
    } else { 
     fptintf(stderr, "Coundn\'t get address space current limit."); 
     return 1: 
    } 

    return 0: 
} 

我跑這我的電腦上,並... prrrrrrrrrrrrrrrrr嘖!

輸出:Current address_space: 18446744073709551615 Bytes, or 17179869183 GB, or 16.000000 EB

我有16個艾字節的最大地址空間可以在我的Linux x86_64的。

這裏的getrlimit()'s definition 它也列出了可以傳給其他常量getrlimits(),並介紹了getrlimit()的妹妹setrlimit()。當rlimitmax成員變得非常重要時,你應該經常檢查你是否超過這個值,這樣核心就不會打你的臉,喝你的咖啡並偷走你的論文。

PD:請原諒我的一個擊鼓的遺憾藉口^ _^

相關問題