在Linux中禁用磁盘缓存 [英] Disabling disk cache in linux

查看:1719
本文介绍了在Linux中禁用磁盘缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一类项目我的老师叫我们做一些code评价(C语言),并这样做,我们需要在测试期间禁用磁盘缓存。

In a class project my teacher told us to make some code evaluations (C language) and to do so we need to disable the disk caching during the tests.

目前我使用的Ubuntu 12.04,我怎么能这样做呢?

Currently I'm using Ubuntu 12.04, how can I do this?

感谢。

推荐答案

您需要root权限才能做到这一点。您可以运行 hdparm的-W 0的/ dev / sda上命令禁用写入缓存,在那里你必须替换的/ dev / sda上为您的驱动器设备:

You need root access to do this. You can run hdparm -W 0 /dev/sda command to disable write caching, where you have to replace /dev/sda with device for your drive:

#include <stdlib.h>
...
system("hdparm -W 0 /dev/sda1");

您也可以选择禁用写入缓存到各个分区是这样的: hdparm的-W 0的/ dev / sda1的

You can also selectively disable write caching to individual partitions like this: hdparm -W 0 /dev/sda1.

要重新启用缓存再次只使用 -W 1 参数。

To reenable caching again just use the -W 1 argument.

男子hdparm的,的人系统

这篇关于在Linux中禁用磁盘缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆