Two measures to remedy the Linux system swap partition is too small

  

In order to break through the limitations of physical memory, the "virtual memory" technology is implemented in the operating system. It allows applications to manipulate more than the actual physical memory. Moreover, virtual memory can be used to isolate each process and become a security protection network for the process, so that each process is not interfered by other programs. If the swap space is not enough, what negative effect will it be? Simply put, if the system's physical memory is used up, the system will reflect the slow speed, but the operating system can still run; if the Swap space runs out, then An error will occur in the system. For example, the web server can generate multiple service processes or threads according to different requests. If the Swap space runs out, the service process cannot be started, and the swap space shortage error will occur, and the service process will be deadlocked in severe cases. It can be seen that the allocation of Swap space is very important. If the swap space is too small, it will cause an application error, not just a performance degradation.


Under Linux, this virtual memory is called swap. When installing the operating system, the installation wizard will prompt the user how many swap spaces need to be created. Usually, the appropriate size of swap is 1-2 times the physical memory. But for some applications, for the swap partition, such as JAVA or Oracle applications, they require the size of the swap partition to be more than twice the physical memory. At this point, the swap partition that was originally assigned to the system when it was installed is too small. So how to remedy it?


I have encountered similar problems before. There is a Linux server with a file server deployed. Later, for the deployment of ERP systems, an Oracle database system was deployed on this server. However, the Oracle database system has requirements for the swap space. If this requirement is not met, the Oracle operating system cannot be installed. I can't extend the swap space by reinstalling the Linux server, because the file server is still running. For this reason, I have to use other means to achieve this demand. In response to this situation, the Linux system proposed two remedies, namely creating a new swap space and creating a swap file. The author adjusts the swap space by creating a swap file. As shown in the figure above, I created a swap file in the home directory and enabled it to be automatically enabled as the system starts by launching the configuration file. After this configuration, the Oracle database system can be successfully installed.


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





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


If there is more free space in the hard disk of the Linux server, or the system administrator has added a new hard disk, you can use the fdisk hard disk formatting tool that comes with the Linux system. Create a new swap partition. The specific operation is as follows:


Step 1: Create a new partition. If the author has a 20G partition in the server hard disk that has not been used, you can use the fdisk disk formatting tool to create a new partition. The specific use of the fdisk command can refer to other relevant information, the author has not expanded here. When using this tool, if you want to set the partition to swap partition, you need to pay attention to set the space to the extended partition. Then set up a logical partition on the extended partition. In this case, it provides convenience for subsequent maintenance and management. For example, administrators can increase the swap space and so on.


Step 2: Set the partition's file system to the swap file system.


By default, the newly added partition of the system has a file format of ext3. In order 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 done in the fdisk command. If you want to change the partition format to swap, when the fdisk command is executed, when prompted hex code, the system administrator needs to enter the code of the swap file system. Usually the swap file system is coded 82. However, Europe continues its follow-up work. If not modified, the system will adopt 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 for the previous settings to take effect. However, the fdisk command only divides a swap partition, and the system still cannot use the partition because the partition has not been formatted and started. As with the Microsoft operating system, after partitioning a partition, the system administrator also needs to format the partition. To do this, the system administrator needs to format the swap partition that was just partitioned by the mkswap command. However, unlike the Microsoft operating system, after the partition is formatted, the new partition is not started by default. The first time it needs to be manually started by the system administrator. At this point, the system administrator needs to use the command swappon to start the swap partition.


Through the above three simple steps, you can add a swap partition to the hard disk space or the newly added hard disk to achieve the purpose of expanding the swap partition capacity. However, it should be noted here that when using the fdisk tool, the contents of the target space will be deleted. To do this, use this method only if there are no files stored in the target space or if the stored files are no longer needed. If there is no unused space in the system now; but there is extra space in the existing partition, you need to use another method, which is to adjust the swap space capacity by increasing the swap file.

Copyright © Windows knowledge All Rights Reserved