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

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

问题描述

在一个课堂项目中,我的老师告诉我们进行一些代码评估(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.

man hdparmman system

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

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