linux 内存中的cached过大
两台机器主要用来跑nginx和php,内存分别为8G和4G,一段时间以后free命令的输出结果中的cached数值都会越来越大,如图
自己搜了几圈以后得知,cached主要负责缓存文件使用, 日志文件过大造成cached区内存增大把内存占用完 .
Free中的buffer和cache:(它们都是占用内存):
buffer : 作为buffer cache的内存,是块设备的读写缓冲区
cache: 作为page cache的内存, 文件系统的cache
如果 cache 的值很大,说明cache住的文件数很多。
但是仍有两个疑问:
1.用来跑php的这个两个机器的内存使用情况(cached占用)跟php执行请求的数量有些什么关系?比如这两个站,是不是访问数量越大,cached的值就一定越大?
2.执行sync命令,将cached写入磁盘后,对之后的访问有没有什么影响?
本人菜鸟,请大神指点。。。
回复内容:
两台机器主要用来跑nginx和php,内存分别为8G和4G,一段时间以后free命令的输出结果中的cached数值都会越来越大,如图
自己搜了几圈以后得知,cached主要负责缓存文件使用, 日志文件过大造成cached区内存增大把内存占用完 .
Free中的buffer和cache:(它们都是占用内存):
buffer : 作为buffer cache的内存,是块设备的读写缓冲区
cache: 作为page cache的内存, 文件系统的cache
如果 cache 的值很大,说明cache住的文件数很多。
但是仍有两个疑问:
1.用来跑php的这个两个机器的内存使用情况(cached占用)跟php执行请求的数量有些什么关系?比如这两个站,是不是访问数量越大,cached的值就一定越大?
2.执行sync命令,将cached写入磁盘后,对之后的访问有没有什么影响?
本人菜鸟,请大神指点。。。
哪里有过大?cached 和 buffers 占据 available 部分中的绝大部分是正常的。你说你的内存,free 着就是什么用处都没有,但你以为那些部分就不需要通电、刷新吗?
cached 通常属于 available 部分(该数据 3.14 内核之后提供,procps-ng 较新版本也显示),也就是可用内存。什么时候程序需要了,什么时候拿去用。暂时不需要?那我从磁盘那个慢到死的家伙里好不容易读出来的数据先留着,指不定用户还要用到呢。
有兴趣可以 echo 3 到那什么文件/proc/sys/vm/drop_caches
清空一下这些部分,然后 ls /usr/lib 试试。然后立即再执行一次,是不是有缓存之后就快多了?
至于 sync 命令。它和 cached 有关,但是不是你所想的那个功能。它的功能是,把脏页写回磁盘,也就是把修改过的数据还没写到磁盘的数据写到磁盘上。因为内核会延迟提交,每次提交多积累一些数据,以提高效率、降低延迟。没有使用的必要,只会让系统卡一下而已。****加粗文字加粗文字
cached占用多也没有关系啊,必要时系统会自动回收文件缓存,然后再分配的。缓存需要写入磁盘的话,文件系统自己会完成的,一般没必要sync吧
可以看一下PHP配置文件中memory_limit=xxx。也许能帮到楼主!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.
