Two measures to solve the problem of too small swap partition in Linux

Source: Internet
Author: User
Tags hex code
Article Title: two solutions to solve the problem of too small swap partition in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

In order to break through the limitation of physical memory, the "Virtual Memory" technology is implemented in the operating system. It allows applications to manipulate space larger than the actual physical memory. Moreover, the virtual memory can be used to isolate every process and become a process security protection network, so that every process is not disturbed by other programs. What will happen if swap space is insufficient? Simply put, if the system's physical memory is used up, the system will reflect that the speed will be slow, but the operating system can still run; if the Swap space is used up, the system will have an error. For example, a Web server can generate multiple service processes or threads based on the number of requests. If Swap space is used up, the service process cannot be started, and the swap space is insufficient, in severe cases, the service process may be deadlocked. It can be seen that Swap space allocation is very important. If swap space is too small, it will cause application errors, not just performance degradation.

In Linux, this virtual memory is called swap. When installing the operating system, the installation wizard prompts you how much swap space you need to create. Generally, swap is 1-2 times the physical memory size. However, some applications are hungry for swap partitions, such as JAVA or Oracle applications. They require that the size of swap partitions be more than twice the physical memory. At this time, the swap partition allocated to the system is too small. So how can we fix it?

I have encountered similar problems before. There is a Linux server where the file server is deployed. Later, an Oracle database system will be deployed on the server to deploy the ERP system. However, the Oracle database system requires swap space. If this requirement is not met, the Oracle operating system cannot be installed. However, I cannot extend the swap space by reinstalling the Linux server because the file server is still running. For this reason, I have to use other methods to achieve this demand. To solve this problem, the Linux system provides two remedial measures: creating a swap space and creating a swap file. The author creates a swap file to adjust the swap space. As shown in, I created a swap file in the home directory and enabled it automatically as the system starts. After this configuration, the Oracle database system can be successfully installed.

The specific implementation of these two adjustment methods is as follows.



Measure 1: Create a new swap space and increase the swap capacity.

If there is more spare capacity in the hard disk of the Linux server, or the system administrator adds a new hard disk, you can use the fdisk hard disk formatting tool that comes with the Linux system, create a swap partition. The specific operations are as follows:

Step 1: Create a New partition. For example, if I still have a 20 GB partition on the server hard disk, I can use the fdisk disk formatting tool to create a new partition. For details about how to use the fdisk command, refer to other related materials. I will not go over it here. When using this tool, if you want to set the partition as a swap partition, you must set the space to an extended partition. Then, set a logical partition on the extended partition. In this case, it provides convenience for subsequent maintenance and management. For example, the administrator can gradually increase the swap space.

Step 2: Set the partition File System to the swap file system.

By default, the file format of the newly added partition is ext3. To make this partition a swap partition, you need to change the file format of this partition to the swap file system. This task is also completed in the fdisk command. If you want to change the partition format to swap, the system administrator needs to enter the swap file system code when hex code is prompted during fdisk command execution. Generally, the swap file system code is 82. However, ou will continue his subsequent work. If this parameter is not modified, the system uses the ext3 file system format by default.

Step 3: Format and start the swap partition format. After the fdisk command is executed, you must restart the computer to make the settings take effect. However, the fdisk command only divides a swap partition, and the system still cannot use this partition because the partition has not been formatted and started. Like Microsoft, after dividing a partition, the system administrator needs to format the partition. To this end, the system administrator needs to use the mkswap command to format the swap partition. However, unlike the Microsoft operating system, after the partition is formatted, the new partition is not started by default. For the first time, you need to manually start it through the system administrator. In this case, the system administrator needs to use the swapon command to start the swap partition.

With the preceding three steps, you can add a swap partition to the disk space or the newly added hard disk to expand the swap partition capacity. Note that when using the fdisk tool, all content in the target space will be deleted. This method is used only when the target space does not store files or the stored files are no longer needed. If there is no unused space in the system, but there is excess space in the existing partitions, you need to use another method, that is, the swap space capacity is adjusted by adding swap files.

[1] [2] Next page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.