---
title: "32位系统的最大内存"
author: "jedy"
date: "2007-06-04T00:15:00Z"
tags: []
slug: "32"
draft: false
lastmod: "2007-06-04T00:15:00Z"
id: 304683
url: "https://jedy.iteye.com/blog/304683"
---

mysql遇到内存不足的问题，但实际上内存并没有用完。所以做了一些调查，道听途说而已，可能结果并不是很准确。32位的linux只支持最大4G内存，而4G的内存一般情况下是分1G为系统空间，3G为用户空间，用户的程序只能在用户空间中分配内存，也可能用到系统空间，但不是自己分配的。因此一般单进程最大能分配3G内存。可以使用下面的程序测试一下：

```
#include <stdio.h>
#include <stdlib.h>
int main(){
  int MB = 0;
  while(malloc(1 << 20)) ++MB;
  printf("Allocated %d MB total.\n", MB);
}
```