Bí Quyết Tối Ưu Hóa Bộ Nhớ Swap trong Linux

Tiếng Việt

Trong hệ điều hành Linux, bộ nhớ swap là một vùng lưu trữ trên ổ cứng được sử dụng để lưu trữ các trang bộ nhớ vật lý không còn được sử dụng. Khi bộ nhớ vật lý của hệ thống bị đầy, hệ thống sẽ sử dụng bộ nhớ swap để lưu trữ các trang bộ nhớ đó.

Việc tối ưu hóa bộ nhớ swap có thể giúp cải thiện hiệu suất của hệ thống Linux. Dưới đây là một số bí quyết tối ưu hóa bộ nhớ swap:

Chọn kích thước swap phù hợp

Kích thước bộ nhớ swap nên bằng ít nhất hai lần kích thước bộ nhớ vật lý. Ví dụ, nếu hệ thống của bạn có 4 GB bộ nhớ vật lý, thì kích thước bộ nhớ swap nên là ít nhất 8 GB.

Sử dụng swapfile thay vì swap partition

Swapfile là một tệp được lưu trữ trên ổ cứng. Swap partition là một phân vùng riêng biệt trên ổ cứng được sử dụng cho bộ nhớ swap. Swapfile có thể được tạo và xóa dễ dàng hơn so với swap partition.

Thay đổi thông số swappiness

Thông số swappiness là một giá trị từ 0 đến 100 xác định mức độ ưu tiên của hệ thống đối với việc sử dụng bộ nhớ swap. Giá trị càng cao thì hệ thống càng có khả năng sử dụng bộ nhớ swap. Giá trị mặc định của swappiness là 60.

Để thay đổi thông số swappiness, bạn có thể sử dụng lệnh sau:

sudo sysctl -w vm.swappiness=30

Sử dụng zram

zram là một công nghệ nén bộ nhớ được sử dụng để giảm kích thước của bộ nhớ swap. zram có thể giúp cải thiện hiệu suất của hệ thống bằng cách giảm số lượng truy cập vào ổ cứng.

Để sử dụng zram, bạn cần cài đặt gói zram-config. Sau đó, bạn có thể tạo một zram bằng lệnh sau:

sudo zramctl create NAME

Thay thế NAME bằng tên của zram bạn muốn tạo.

Để kích hoạt zram, bạn có thể sử dụng lệnh sau:

sudo swapon NAME

Thay thế NAME bằng tên của zram bạn muốn kích hoạt.

English

In the Linux operating system, swap memory is a region of storage on the hard drive that is used to store pages of physical memory that are no longer in use. When the physical memory of the system is full, the system will use swap memory to store those pages of memory.

Optimizing swap memory can help improve the performance of a Linux system. Here are some tips for optimizing swap memory:

Choose the right swap size

The size of the swap should be at least twice the size of the physical memory. For example, if your system has 4 GB of physical memory, then the size of the swap should be at least 8 GB.

Use a swapfile instead of a swap partition

A swapfile is a file that is stored on the hard drive. A swap partition is a separate partition on the hard drive that is used for swap memory. Swapfiles are easier to create and delete than swap partitions.

Change the swappiness parameter

The swappiness parameter is a value from 0 to 100 that determines the priority of the system for using swap memory. A higher value means that the system is more likely to use swap memory. The default value of swappiness is 60.

To change the swappiness parameter, you can use the following command:

sudo sysctl -w vm.swappiness=30

Use zram

zram is a memory compression technology that is used to reduce the size of the swap memory. zram can help improve the performance of the system by reducing the number of hard drive accesses.

To use zram, you need to install the zram-config package. Once installed, you can create a zram with the following command:

sudo zramctl create NAME

Replace NAME with the name of the zram you want to create.

To enable zram, you can use the following command:

sudo swapon NAME

Replace NAME with the name of the zram you want to enable.

Bí Quyết Tối Ưu Hóa Bộ Nhớ Swap trong Linux: Hướng Dẫn Chi Tiết và Tốt Nhất cho Hiệu Suất Máy Tính Của Bạn

Leave a Reply

All in one