六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 34|回复: 0

Copy file without using cached memory

[复制链接]

升级  16%

18

主题

18

主题

18

主题

秀才

Rank: 2

积分
74
 楼主| 发表于 2013-1-28 19:28:01 | 显示全部楼层 |阅读模式
By default, Linux always cache the file which you just copied. But sometimes you don't want Linux to keep file pages in memory, for example when you copy a big disk image file and never use it again.

To copy file without using cache memory, you can use dd command and here is the sample:

dd iflag=direct,nonblock if=b_1_GB_file bs=64k oflag=direct,nonblock of=b_1_GB_file.backup

In fact, dd command create a pipe between file b_1_GB_file and b_1_GB_file.backup and dump all data from file b_1_GB_file to b_1_GB_file.backup.

Recently I have a problem is that MySQL can't start after I backup the big InnoDB database file to another directory. Here is the error message:

090603 16:10:08  InnoDB: Error: cannot allocate 2147500032 bytes of
InnoDB: memory with malloc! Total allocated memory
InnoDB: by InnoDB 23965696 bytes. Operating system errno: 12
InnoDB: Check if you should increase the swap file or
InnoDB: ulimits of your operating system.
InnoDB: On FreeBSD check you have compiled the OS with
InnoDB: a big enough maximum process size.
InnoDB: Note that in most 32-bit computers the process
InnoDB: memory space is limited to 2 GB or 4 GB.
InnoDB: We keep retrying the allocation for 60 seconds...
InnoDB: Fatal error: cannot allocate the memory for the buffer pool

Here is the memory status:

free -m
             total       used       free     shared    buffers     cached
Mem:          3287       3140        146          0          4       3013
-/+ buffers/cache:        122       3165
Swap:         4094          0       4094

So at that time, Linux is using 3G memory for cache and reject MySQL's request for allocating 2G memory. Of course, this is a bug. To work around this, you can run following command to release cached memory manually:

sync; echo 3 > /proc/sys/vm/drop_caches
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表