#includeビルド&ラン#define SIZE_1M (1024*1024) #define LIMIT 4096 int main(){ int *p; int i; for(i=0; i < LIMIT; i++){ p=malloc(SIZE_1M); if(p==NULL){ printf("NIL\n"); perror(""); return 1; } memset(p,i,SIZE_1M); printf("%d Mbyte\n",i); } }
$ sh4-linux-gnu-gcc malloc_test.c -static $ qemu-sh4 ./a.out ざっくりと略 1526 Mbyte 1527 Mbyte 1528 Mbyte 1529 Mbyte qemu: uncaught target signal 11 (Segmentation fault) - core dumped Segmentation faultなわけで およそ1.5Gで死ぬ。 大規模パッケージのリンク工程などで1.5Gではメモリが足りないことがある。qemuのドキュメントを見ると -R オプションで回避できるようだ。
$ qemu-sh4 -R 4G ./a.out (4Gをリザーブする) 4092 Mbyte 4093 Mbyte 4094 Mbyte 4095 Mbyteqemuのソースコードを見ると、事前に -R オプションで指定した reserved_va サイズだけ mmap()するようだ。
--- linux-user/main.c-orig 2011-08-04 11:45:43.000000000 +0000 +++ linux-user/main.c 2011-08-04 11:45:14.000000000 +0000 @@ -2941,40 +2941,44 @@ #endif } cpu_exec_init_all(0); /* NOTE: we need to init the CPU at this stage to get qemu_host_page_size */ env = cpu_init(cpu_model); if (!env) { fprintf(stderr, "Unable to find CPU definition\n"); exit(1); } #if defined(TARGET_I386) || defined(TARGET_SPARC) || defined(TARGET_PPC) cpu_reset(env); #endif thread_env = env; if (getenv("QEMU_STRACE")) { do_strace = 1; } + if (getenv("QEMU_4G")){ + reserved_va = 0xffffffff; + } + target_environ = envlist_to_environ(envlist, NULL); envlist_free(envlist);使ってみる
qemu-sh4 を使って動いている sh4 debian の chroot 内で $ export QEMU_4G=1 指定 $ ./a.out ざっくり略 4092 Mbyte 4093 Mbyte 4094 Mbyte 4095 Mbyte $ export -n QEMU_4G 解除ばっちり
boss3 core7:~# mkfs.ext3 /dev/sdb2 -v mke2fs 1.41.12 (17-May-2010) fs_types for mke2fs.conf resolution: 'ext3', 'default' Calling BLKDISCARD from 0 to 100002951168 failed. Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 6111232 inodes, 24414783 blocks 1220739 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 746 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872Calling BLKDISCARD が failed になるが、関係無いらしい。
SH4でmkfs.ext3すると実行開始されない
supercat:~# mkfs.ext3 /dev/mmcblk0p2 -v mke2fs 1.41.12 (17-May-2010) fs_types for mke2fs.conf resolution: 'ext3', 'default' Calling BLKDISCARD from 0 to 3500982272 failed. supercat:~#で終わってしまう
util-linuxを作りなおし、libblkid, libuuid1 を入れ直したら直った