Copy file without using cached memory

本文介绍如何在Linux系统中通过使用dd命令直接复制文件而不占用缓存内存的方法,解决因缓存占用过多导致MySQL启动时无法分配足够内存的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值