oliver_peng 发表于 2013-1-28 19:28:01

Copy file without using cached memory

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:08InnoDB: 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
页: [1]
查看完整版本: Copy file without using cached memory