search
HomeOperation and MaintenanceLinux Operation and MaintenanceIntroduce two methods to create memory swap space swap

First, let’s introduce the role of swap. Generally, when we install the Linux operating system, the system will create a swap partition by default. Let's take a look at the usage of the swap partition on the server

# free -h
              total        used        free      shared  buff/cache   available
Mem:           992M        630M         68M        264K        293M        198M
Swap:          1.0G         96M        927M

The swap partition size of the server is 1G. This swap partition is created by the system by default. We will increase the capacity of the swap partition on this basis later. .

The swap partition is called the swap partition. As a special hard disk space, it plays the role of memory. When the system memory is not enough, the system will store some of the data in the memory that will not be used temporarily into the swap partition. The advantage of using swap partitions is that hard drives are much cheaper than memory, so this is a very cost-effective way to increase system memory. However, if swap is used frequently, it will greatly affect the running speed of the system. Therefore, the best strategy for using swap partitions is to "prepare for use".

Next, let’s take a look at how to create a swap partition.

Build a swap partition through physical partition

First you need to partition itIntroduce two methods to create memory swap space swap

Next, format it

mkswap /dev/sda5

Then open the new swap partition

Introduce two methods to create memory swap space swapAt this point, the construction of the swap partition is completed. Unlike ordinary partitions, there is no need to mount the swap partition when building it. Just use the command swapon partition name.

Build a swap partition through files

The above method is suitable for unused remaining space on the disk. But if all the disk space is partitioned, how to create a swap partition? We can build a swap partition by making a large file. Although the disk space has been completely allocated, this method can be used as long as there is remaining space in any of the partitions.

Let’s create a large file

Introduce two methods to create memory swap space swap

Next format it

Introduce two methods to create memory swap space swap

Finally turn on swap Partition

Introduce two methods to create memory swap space swap

Today I will introduce two methods to build a swap partition. Generally, the size of the swap partition is recommended to be within 2G. Remember that the role of the swap partition is when the memory is not enough. Use the hard disk space as memory temporarily.

The above is the detailed content of Introduce two methods to create memory swap space swap. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
什么是linux的swap空间什么是linux的swap空间Jul 18, 2023 am 11:58 AM

linux的swap空间是Linux操作系统中用作内存扩展的特殊硬盘空间,其作用是提供额外的虚拟内存以确保系统的正常运行,正确配置和管理swap空间可以帮助保持系统的稳定性和性能,定期监控Swap空间的使用情况,并根据实际情况调整swap空间的大小是系统管理员的责任。

Redis关闭SWAP有什么用Redis关闭SWAP有什么用May 27, 2023 am 10:30 AM

关闭SWAPSWAP是内存交换技术。将内存按页,复制到预先设定的磁盘空间上。内存是快速的,昂贵的。而磁盘是低速的,廉价的。通常使用SWAP越多,系统性能越低。Redis是内存数据库,使用SWAP会导致性能快速下降。建议留有足够内存,并关闭SWAP。

增加swap交换分区的步骤和方法 - Linux系统指南增加swap交换分区的步骤和方法 - Linux系统指南Jan 03, 2024 pm 07:10 PM

linux系统中想要增加swap交换分区,该怎么增加呢?下面我们就来看看详细的教程。1、首先点击dock栏上的“启动器”,找到“深度终端”并运行。2、然后给root用户设置密码,因为安装过程的是管理员用户,并没有设置root密码。sudopasswdroot3、设置完成后,执行su命令切换到root用户4、执行如下命令,在根目录生成swap文件,count设定块数,bs设定块大小,生成4G的swap。ddif=/dev/zeroof=/swapfilecou

Linux Swap空间利用率过高怎么解决Linux Swap空间利用率过高怎么解决May 27, 2023 pm 12:37 PM

什么是swap?swapspace是磁盘上的一块区域,可以是一个分区,也可以是一个文件,或者是他们的组合。简单点说,当系统物理内存吃紧时,Linux会将内存中不常访问的数据保存到swap上,这样系统就有更多的物理内存为各个进程服务,而当系统需要访问swap上存储的内容时,再将swap上的数据加载到内存中,这就是我们常说的swapout和swapin。为什么需要swap?要回答这个问题,就需要回答swap给我们带来了哪些好处。对于一些大型的应用程序(如LibreOffice、videoeditor

Linux云服务器如何设置swap虚拟内存Linux云服务器如何设置swap虚拟内存May 15, 2023 pm 11:52 PM

swap交换内存主要是指当物理内存不够用时,系统会启用硬盘的一部分空间来充当服务器内存,而默认情况下swap内存会有一些设置标准,它与物理内存的大小也是有关系的。查看内存空间:free-h创建swap分区文件:ddif=/dev/zeroof=/data/swapbs=1Mcount=4096代码解释:bs为块的大小,count为块的数量,已知bs=1M,count=4096,1M*1024=4G的swap分区虚拟内存,/data/swap是swap文件创建的路径,以上参数可根据自己需求修改。m

deepin没有swap分区怎么办 deepin没有swap分区解决方法deepin没有swap分区怎么办 deepin没有swap分区解决方法Feb 29, 2024 am 10:10 AM

在deepin使用过程中,有的用户发现自己的系统缺少了swap分区不知道怎么办,其实大部分情况下我们没有swap分区也没有关系,如果一定需要的话,也可以手动创建并挂载一个swap分区来解决。deepin没有swap分区怎么办:一、安装时1、如果我们在安装系统分区时没有swap,如图所示。2、这时候可以先退出安装程序,然后在文件系统项下选择swap,再安装即可。二、找不到swap1、如果我们安装时建立了swap分区,但是使用时找不到了,可能是分辨率的问题。2、这时候我们可以尝试进入grub界面,在

Linux云服务器如何设置swapLinux云服务器如何设置swapMay 18, 2023 pm 11:55 PM

第一步:确认swap的状态使用下面的命令查看内存情况:free-m如果结果显示swap为0,说明swap不存在,需要创建swap。totalusedfreesharedbufferscachedMem:1840161422615361340-/+buffers/cache:2381602Swap:000或者也可以用这个命令来查看。如果没有输出任何结果,说明swap不存在。swapon-s第二步:创建swap我们用下面的命令来创建一个大小为2GB的swap文件。ddif=/dev/zeroof=/

Linux调整Swap空间大小的扩容分区技巧Linux调整Swap空间大小的扩容分区技巧Feb 29, 2024 am 11:43 AM

查看当前Swap文件位置以及大小要查看当前正在使用的swap文件或分区的位置,您可以使用swapon命令。执行以下命令:sudoswapon--show这将显示所有活动的swap空间,包括其类型(例如文件或分区)、大小、使用情况和位置。如果您只对文件路径或分区路径感兴趣,您可以通过/proc/swaps文件查看相同的信息:cat/proc/swaps这将列出系统上所有的swap空间,包括它们的位置。设置一个新的Swap空间在Manjaro(基于Arch的Linux发行版)上,您可以使用多种方法设

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.