日期:2014-05-16  浏览次数:20600 次

LINUX 64位下运行32位程序加载和读取大数据段共享内存

LINUX 64位下运行32位程序加载和读取大数据段共享内存

1. 查看当前机器共享内存
1073741824 = 1024 * 1024 * 1024
[root@six shm]# ipcs

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status     
0x00000000 0          gdm        600        393216     2          dest        
0x00000000 32769      gdm        600        393216     2          dest        
0x00000000 65538      gdm        600        393216     2          dest        

------ Semaphore Arrays --------
key        semid      owner      perms      nsems    
0x00000000 0          root       600        1        
0x00000000 32769      root       600        1        
0x00000000 65538      apache     600        1        
0x00000000 98307      apache     600        1        
0x00000000 131076     apache     600        1        

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages

共享内存无我们加载的数据,正常。

2 修改需要被加载的文件,指定文件任意位置(1G)修改为随机指定的内容
[root@six shm]# ./modifyfile bigdatafile.dat 1073741824 ABCD1234567890END
read content=ABCD1234567890END,17

3 把大文件bigdatafile.dat(1.11G)加载到共享内存,一个进程一次加载两个,共加载3次
[root@six shm]# ./fileload mykey1 mykey2 bigdatafile.dat
Usage: mykey1 KeyFile
 e.g. srcfile:bigdatafile.dat
Key generated by ftok:  0x64030017
shaddr:0xb0109000,length:1198011173
Usage: mykey2 KeyFile
 e.g. srcfile:bigdatafile.dat
Key generated by ftok:  0x64030018
shaddr:0x68a85000,length:1198011173
[root@six shm]# ./fileload mykey3 mykey4 bigdatafile.dat   
Usage: mykey3 KeyFile
 e.g. srcfile:bigdatafile.dat
Key generated by ftok:  0x6403000d
shaddr:0xb0134000,length:1198011173
Usage: mykey4 KeyFile
 e.g. srcfile:bigdatafile.dat
Key generated by ftok:  0x6403000e
shaddr:0x68ab0000,length:1198011173
[root@six shm]# ./fileload mykey5 mykey6 bigdatafile.dat   
Usage: mykey5 KeyFile
 e.g. srcfile:bigdatafile.dat
Key generated by ftok:  0x6403001b
shaddr:0xb014b000,length:1198011173
Usage: mykey6 KeyFile
 e.g. srcfile:bigdatafile.dat
K