How to expand Linux swap memory

How to expand Linux swap memory

Swap memory mainly means that when the physical memory is insufficient, the system will enable a part of the hard disk space to act as the server memory. By default, there are some setting standards for swap memory, which is also related to the size of physical memory. The specific standards are as follows:

RAM size Swap size Total size after activating Swap 256MB 256MB 512MB
512MB 512MB 1GB
1GB 1GB 2GB
3GB 2GB 5GB
4GB 2GB 6GB
6GB 2GB 8GB
8GB 3GB 11GB
12GB 3GB 15GB
16GB 4GB 20GB
32GB 6GB 38GB
64GB 8GB 72GB
128GB 11GB 139GB

Check the memory space

free -h 

Increase swap space through swap partition files

1. Create a swap partition file

dd if=/dev/zero of=/data2/swapfile bs=1M count=1024

Where bs is the size of each block, count is the number of blocks; bs*count is the size of the swap file: here 1M*1024=1G. You can adjust it as needed. In addition, swapfile is the path of the swap file, which can be modified as needed.

2. Format the swap partition file

mkswap swapfile

The path here should correspond to the previous path.

3. Enable swap partition file

swapon swapfile

4. Add startup

Modify the /etc/fstab file and add or modify this line:

swapfile swap swap defaults 0 0

Note that the paths still need to correspond and must be full paths. The last two are zeros, not capital Os.

This option is optional. If you do not modify the startup configuration, the swap space will be reset after the reboot and the previous configuration will be lost.

When using a Java program, we need to set its maximum heap memory, which is a kind of protection for the system.

This is the end of this article about expanding the capacity of linux ~ swap memory. For more relevant content about expanding the capacity of linux ~ swap memory, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Checking with Valgrind under Linux (to prevent memory leaks)
  • Detailed explanation of how to run jmeter under Linux system and optimize local memory
  • Python3 monitors the CPU, hard disk, memory usage and the opening status of each port of Windows and Linux systems. Detailed code examples
  • How the Linux kernel breaks into the process address space and modifies the process memory
  • How to Monitor Linux Memory Usage Using Bash Script
  • Linux system to view CPU, machine model, memory and other information
  • Methods for optimizing Oracle database with large memory pages in Linux
  • Detailed explanation of Linux kernel memory management architecture
  • Use C program to output memory usage information of a process under Linux system
  • Solve the problem of memory exhaustion caused by too many php-fpm processes under Linux
  • Python monitors Linux memory and writes to MongoDB (recommended)
  • Detailed explanation of Linux memory descriptor mm_struct example
  • Detailed explanation of Linux shared memory implementation mechanism
  • How to Check Memory Usage in Linux

<<:  JavaScript DOMContentLoaded event case study

>>:  React homepage slow loading problem performance optimization case detailed explanation

Recommend

Install Docker for Windows on Windows 10 Home Edition

0. Background Hardware: Xiaomi Notebook Air 13/In...

Quickly solve the problem of slow and stuck opening of input[type=file]

Why is it that when the input tag type is file an...

Example of using CSS filter to write mouse over effect

Use CSS filter to write mouse over effect <div...

Differences between MySQL MyISAM and InnoDB

the difference: 1. InnoDB supports transactions, ...

JavaScript canvas to achieve scratch lottery example

This article shares the specific code of JavaScri...

Implementation of CSS loading effect Pac-Man

emmm the name is just a random guess 2333 Preface...

Solve the installation problem of mysql8.0.19 winx64 version

MySQL is an open source, small relational databas...

MySQL chooses the right storage engine

When it comes to databases, one of the most frequ...

Summary of 11 common mistakes made by MySQL call novices

Preface You may often receive warning emails from...

Uncommon but useful tags in Xhtml

Xhtml has many tags that are not commonly used but...

How to add Vite support to old Vue projects

1. Introduction I have taken over a project of th...

Let’s take a look at JavaScript precompilation (summary)

JS running trilogy js running code is divided int...

MySQL 5.7.23 installation and configuration graphic tutorial

This article records the detailed installation pr...

How to use JavaScript to get the most repeated characters in a string

Table of contents topic analyze Objects of use So...

Analysis of the principle of Rabbitmq heartbea heartbeat detection mechanism

Preface When using RabbitMQ, if there is no traff...