当前位置: 首页 > news >正文

GNU/Linux - /proc/sys/vm/drop_caches

/proc/sys/vm/drop_caches 是 Linux 中的一个特殊文件,允许用户释放系统内存中的各种缓存。让我们深入了解一下这项功能的细节:
The /proc/sys/vm/drop_caches is a special file in Linux that allows users to free up various caches in the system's memory. Let's dive into the details of this feature:
    Overview
/proc/sys/vm/drop_caches 是 Linux 内核提供的一种机制,用于手动释放内存中的页面缓存、目录项缓存和 inodes。这在测试或需要快速释放内存的情况下非常有用。
/proc/sys/vm/drop_caches is a mechanism provided by the Linux kernel to manually free up pagecache, dentries, and inodes from memory. This can be useful for testing purposes or in situations where you need to free up memory quickly.
Functionality
drop_caches 参数允许用户指示内核释放不同类型的缓存:
The drop_caches parameter allows users to instruct the kernel to free different types of caches:
1. 页面缓存: 这是文件内容的缓存。
2. Dentries: 这是目录条目缓存。
3. Inodes: 这些是包含文件元数据的数据结构。
1. Pagecache: This is the cache for file contents.
2. Dentries: These are directory entry caches.
3. Inodes: These are data structures containing metadata about files.
Usage
要使用 drop_caches,需要在文件中写入一个特定值:
To use drop_caches, you write a specific value to the file:
1. Echo 1:仅释放页面缓存。
2. Echo 2:释放目录项缓存和 inodes。
3. Echo 3: 释放页面缓存、目录项缓存和 inodes。
1. Echo 1: Frees pagecache only.
2. Echo 2: Frees dentries and inodes.
3. Echo 3: Frees pagecache, dentries, and inodes.
例如,要释放所有缓存,可以使用
For example, to free all caches, you would use:
echo 3 > /proc/sys/vm/drop_caches
    Important Considerations  重要考虑因素
1. 非破坏性操作: 此操作为非破坏性操作,不会释放任何脏对象(已修改但尚未写入磁盘的对象)。
1. Non-destructive Operation: This operation is non-destructive and will not free any dirty objects (those that have been modified but not yet written to disk).
2. 丢弃前同步: 建议在删除缓存前运行 “同步”,以确保所有脏对象都写入磁盘。
2. Sync Before Dropping: It's recommended to run 'sync' before dropping caches to ensure all dirty objects are written to disk.
3. 性能影响: 使用 drop_caches 可能会导致性能问题,因为它会丢弃可能需要重新创建的缓存对象,从而可能导致大量的 I/O 和 CPU 占用。
3. Performance Impact: Using drop_caches can cause performance problems as it discards cached objects that may need to be recreated, potentially causing significant I/O and CPU usage.
4. 不适合常规使用: 由于可能影响性能,不建议在测试或调试环境之外使用 drop_caches。
4. Not for Regular Use: Due to potential performance impacts, using drop_caches is not recommended outside of testing or debugging environments.
5. 自动回收: 当系统其他地方需要内存时,内核会自动回收这些对象,因此通常不需要人工干预。
5. Automatic Reclamation: The kernel automatically reclaims these objects when memory is needed elsewhere in the system, so manual intervention is usually unnecessary.
6. 信息消息: 使用该文件时,您可能会在内核日志中看到信息消息。这些信息并不表示系统有任何问题。
6. Informational Messages: You may see informational messages in your kernel log when this file is used. These messages do not indicate any problem with your system.
    Behavior After Dropping Caches
删除缓存后
1. 作为正常运行的一部分,系统会立即重新开始缓存。
2. /proc/sys/vm/drop_caches 中的值会自动重置为 0。
After dropping caches:
1. The system immediately starts caching again as part of its normal operation.
2. The value in /proc/sys/vm/drop_caches automatically resets to 0.
    Use Cases
虽然不建议经常使用,但 drop_caches 在特定情况下还是很有用的:
1. 测试: 需要使用低缓存进行基准测试或性能测试时。
2. 调试: 隔离与缓存相关的问题。
3. 内存管理: 在极少数情况下,需要快速释放内存,但应谨慎处理。
While not recommended for regular use, drop_caches can be useful in specific scenarios:
1. Testing: When you need to start with a "cold" cache for benchmarking or performance testing.
2. Debugging: To isolate issues related to caching.
3. Memory Management: In rare cases where you need to quickly free up memory, though this should be approached with caution.
    Alternative Approaches
对于大多数系统来说,最好让内核自动管理缓存。如果内存一直不足,可以考虑:
1. 为系统添加更多内存。
2. 调整其他内存管理参数。
3. 优化系统上运行的应用程序。
For most systems, it's better to let the kernel manage caches automatically. If you're consistently running low on memory, consider:
1. Adding more RAM to the system.
2. Adjusting other memory management parameters.
3. Optimizing the applications running on the system.
总之,虽然 /proc/sys/vm/drop_caches 提供了在 Linux 中手动释放各种缓存的方法,但应谨慎使用,并主要用于测试或调试目的。对于正常的系统操作,最好还是依靠内核内置的内存管理功能。
In conclusion, while /proc/sys/vm/drop_caches provides a way to manually free up various caches in Linux, it should be used judiciously and primarily for testing or debugging purposes. For normal system operation, it's generally best to rely on the kernel's built-in memory management capabilities.
资料来源:
[1] Setting /proc/sys/vm/drop_caches to clear cache, https://unix.stackexchange.com/questions/17936/setting-proc-sys-vm-drop-caches-to-clear-cache
[2] Drop_Caches - linux-mm.org Wiki, Drop_Caches - linux-mm.org Wiki
[3] Freeing page cache using echo 3 > /proc/sys/vm/drop_caches ..., https://askubuntu.com/questions/609226/freeing-page-cache-using-echo-3-proc-sys-vm-drop-caches-doesnt-work
[4] Why does drop_caches increase "available" memory - Server Fault, https://serverfault.com/questions/1099933/why-does-drop-caches-increase-available-memory

相关文章:

GNU/Linux - /proc/sys/vm/drop_caches

/proc/sys/vm/drop_caches 是 Linux 中的一个特殊文件,允许用户释放系统内存中的各种缓存。让我们深入了解一下这项功能的细节: The /proc/sys/vm/drop_caches is a special file in Linux that allows users to free up various caches in the systems …...

ubuntu 22.04 如何调整进程启动后能打开的文件数限制

在 Ubuntu 22.04 中,可以通过修改系统配置来调整进程启动后能够打开的文件数软限制。软限制是指操作系统允许单个进程打开的文件描述符的最大数量。以下是调整该限制的方法: 1. 查看当前限制 首先,你可以通过 ulimit 命令查看当前的软限制和…...

linux基础-完结(详讲补充)

linux基础-完结 一、Linux目录介绍 二、基础命令详细讲解 1. ls(列出目录内容) 2. cd(更改目录) 3. clear(清除终端屏幕) 4. pwd(显示你当前所在的目录) 5. vim(文本编辑器) 6. touch(创…...

LoRA:大型语言模型(LLMs)的低秩适应;低秩调整、矩阵的低秩与高秩

目录 LoRA:大型语言模型(LLMs)的低秩适应 一、LoRA的基本原理 二、LoRA的举例说明 三、LoRA的优势 低秩调整、矩阵的低秩与高秩 一、低秩调整(LoRA) 二、矩阵的低秩 三、矩阵的高秩 LoRA:大型语言模型(LLMs)的低秩适应 LoRA(Low-Rank Adaptation of LLMs),…...

游戏引擎学习第四天

视频参考:https://www.bilibili.com/video/BV1aDmqYnEnc/ BitBlt 是 Windows GDI(图形设备接口)中的一个函数,用于在设备上下文(device context, DC)之间复制位图数据。BitBlt 的主要用途是将一个图像区域从一个地方复…...

GIT GUI和 GIT bash区别

Git GUI 和 Git Bash 都是与 Git 版本控制工具相关的用户界面,但它们有不同的功能和用途。下面详细说明它们的区别及各自的作用: Git GUI 作用: Git GUI 是一个图形用户界面(GUI)工具,用于执行 Git 操作。…...

丹摩征文活动|Faster-Rcnn-训练与测试详细教程

本文 丹摩智算平台官方网站的介绍Faster-Rcnn-训练与测试提前准备进行Faster-rcnn 的环境配置数据集的介绍 丹摩智算平台官方网站的介绍 丹摩智算平台(DAMODEL)是专为人工智能(AI)开发者打造的高性能计算服务平台,旨在…...

星期-时间范围选择器 滑动选择时间 最小粒度 vue3

星期-时间范围选择器 功能介绍属性说明事件说明实现代码使用范例 根据业务需要,实现了一个可选择时间范围的周视图。用户可以通过鼠标拖动来选择时间段,并且可以通过快速选择组件来快速选择特定的时间范围。 功能介绍 时间范围选择:用户可以…...

一条SQL查询语句的执行流程(MySQL)

第一步:连接器(负责跟客户端建立连接、获取权限、维持和管理连接) 第二步:查询缓存 之前执行过的查询,MySQL以"Key - Value"的形式存在内存(key为SQL,value为结果集)&…...

linux基础——详细篇

免责声明 学习视频来自B 站up主泷羽sec,如涉及侵权马上删除文章。 笔记的只是方便各位师傅学习知识,以下代码、网站只涉及学习内容,其他的都与本人无关,切莫逾越法律红线,否则后果自负。 linux 基础命令重现 cd(切…...

大数据学习10之Hive高级

1.Hive高级 将大的文件按照某一列属性进行GROUP BY 就是分区,只是默认开窗存储; 分区是按行,如一百行数据,按十位上的数字分区,则有十个分区,每个分区里有十行; 分桶是根据某个字段哈希对桶数取…...

MongoDB笔记01-概念与安装

文章目录 前言一、MongoDB相关概念1.1 业务应用场景具体的应用场景什么时候选择MongoDB 1.2 MongoDB简介1.3 体系结构1.4 数据模型1.5 MongoDB的特点 二、本地单机部署2.1 Windows系统中的安装启动第一步:下载安装包第二步:解压安装启动1.命令行参数方式…...

ollama + fastGPT + m3e 本地部署指南

[TOC](ollama fastgptm3e本地部署) 开启WSL 因为这里使用的win部署,所以要安装wsl,如果是linux系统就没那么麻烦 控制面板->程序->程序和功能 更新wsl wsl --set-default-version 2wsl --update --web-download安装ubuntu wsl --install -d Ubuntudoc…...

【设计模式系列】享元模式(十五)

目录 一、什么是享元模式 二、享元模式的角色 三、享元模式的典型应用场景 四、享元模式在ThreadPoolExecutor中的应用 1. 享元对象(Flyweight)- 工作线程(Worker) 2. 享元工厂(Flyweight Factory)- …...

2024大兴区火锅美食节即将开幕——品味多元火锅,点燃冬季消费热潮

为响应“中国国际精品消费月”活动,由大兴区商务局主办、大兴区餐饮行业协会承办的2024大兴区火锅美食节将于11月15日正式启动,为期一个半月的美食盛宴将在大兴区掀起一场冬日的火锅热潮。此次火锅节作为北京市“食在京城、沸腾火锅”火锅美食节的重要组…...

可视化建模与UML《类图实验报告》

史铁生: 余华和莫言扛着我上火车, 推着走打雪仗, 还带我偷西瓜, 被人发现后他们拔腿就跑, 却忘了我还在西瓜地里。 一、实验目的: 1、熟悉类图的构件事物。 2、熟悉类之间的泛化、依赖、聚合和组合关系…...

VS2022项目配置笔记

文章目录 $(ProjectDir)与 $(SolutionDir) 宏附加包含目录VC目录和C/C的区别 $(ProjectDir)与 $(SolutionDir) 宏 假设有一个解决方案 MySolution,其中包含两个项目 ProjectA 和 ProjectB,目录结构如下: C:\Projects\…...

springboot029基于springboot的网上购物商城系统

🍅点赞收藏关注 → 添加文档最下方联系方式领取本源代码、数据库🍅 本人在Java毕业设计领域有多年的经验,陆续会更新更多优质的Java实战项目希望你能有所收获,少走一些弯路。🍅关注我不迷路🍅 项目视频 基于…...

网站访问在TCP/IP四层模型中的流程

访问一个网站的过程可以通过 TCP/IP 网络模型来描述。TCP/IP 模型通常被分为四层:应用层、传输层、网络层和链路层。以下是从这些层级的角度描述你访问一个网站时所发生的过程: 1. 应用层 (Application Layer) 当你在浏览器中输入一个 URL(…...

C++笔记---包装器

1. 什么是包装器 C中的包装器是一种设计模式,用于将一个复杂或底层的接口进行封装,以便提供一个更简洁、易用的接口。包装器可以包装任何类型的可调用实体,如函数,成员函数,函数指针,仿函数对象&#xff0…...

调用支付宝接口响应40004 SYSTEM_ERROR问题排查

在对接支付宝API的时候,遇到了一些问题,记录一下排查过程。 Body:{"datadigital_fincloud_generalsaas_face_certify_initialize_response":{"msg":"Business Failed","code":"40004","sub_msg…...

docker详细操作--未完待续

docker介绍 docker官网: Docker:加速容器应用程序开发 harbor官网:Harbor - Harbor 中文 使用docker加速器: Docker镜像极速下载服务 - 毫秒镜像 是什么 Docker 是一种开源的容器化平台,用于将应用程序及其依赖项(如库、运行时环…...

学习STC51单片机32(芯片为STC89C52RCRC)OLED显示屏2

每日一言 今天的每一份坚持,都是在为未来积攒底气。 案例:OLED显示一个A 这边观察到一个点,怎么雪花了就是都是乱七八糟的占满了屏幕。。 解释 : 如果代码里信号切换太快(比如 SDA 刚变,SCL 立刻变&#…...

在Ubuntu24上采用Wine打开SourceInsight

1. 安装wine sudo apt install wine 2. 安装32位库支持,SourceInsight是32位程序 sudo dpkg --add-architecture i386 sudo apt update sudo apt install wine32:i386 3. 验证安装 wine --version 4. 安装必要的字体和库(解决显示问题) sudo apt install fonts-wqy…...

Yolov8 目标检测蒸馏学习记录

yolov8系列模型蒸馏基本流程,代码下载:这里本人提交了一个demo:djdll/Yolov8_Distillation: Yolov8轻量化_蒸馏代码实现 在轻量化模型设计中,**知识蒸馏(Knowledge Distillation)**被广泛应用,作为提升模型…...

git: early EOF

macOS报错: Initialized empty Git repository in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/.git/ remote: Enumerating objects: 2691797, done. remote: Counting objects: 100% (1760/1760), done. remote: Compressing objects: 100% (636/636…...

消息队列系统设计与实践全解析

文章目录 🚀 消息队列系统设计与实践全解析🔍 一、消息队列选型1.1 业务场景匹配矩阵1.2 吞吐量/延迟/可靠性权衡💡 权衡决策框架 1.3 运维复杂度评估🔧 运维成本降低策略 🏗️ 二、典型架构设计2.1 分布式事务最终一致…...

Neko虚拟浏览器远程协作方案:Docker+内网穿透技术部署实践

前言:本文将向开发者介绍一款创新性协作工具——Neko虚拟浏览器。在数字化协作场景中,跨地域的团队常需面对实时共享屏幕、协同编辑文档等需求。通过本指南,你将掌握在Ubuntu系统中使用容器化技术部署该工具的具体方案,并结合内网…...

高效的后台管理系统——可进行二次开发

随着互联网技术的迅猛发展,企业的数字化管理变得愈加重要。后台管理系统作为数据存储与业务管理的核心,成为了现代企业不可或缺的一部分。今天我们要介绍的是一款名为 若依后台管理框架 的系统,它不仅支持跨平台应用,还能提供丰富…...

react菜单,动态绑定点击事件,菜单分离出去单独的js文件,Ant框架

1、菜单文件treeTop.js // 顶部菜单 import { AppstoreOutlined, SettingOutlined } from ant-design/icons; // 定义菜单项数据 const treeTop [{label: Docker管理,key: 1,icon: <AppstoreOutlined />,url:"/docker/index"},{label: 权限管理,key: 2,icon:…...