Linux學習筆記:記憶體交換空間的構建

來源:互聯網
上載者:User

記憶體交換空間的構建

我們知道CPU計算與資料的儲存都會使用到記憶體,使用記憶體可以大大減少從磁碟讀取的時間,但是當實體記憶體不足時,就需要暫時將用不到的程式和資料挪到記憶體交換空間(swap)

作法:

1.      建立分區(fdisk ,檔案)
2.      格式化為swap
3.      啟動
4.      查看

建立分區

舉例

[root@bogon ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
  (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          13      104391  83  Linux
/dev/sda2              14        1288    10241437+  83  Linux
/dev/sda3            1289        1925    5116702+  83  Linux
/dev/sda4            1926        2610    5502262+  5  Extended
/dev/sda5            1926        2052    1020096  82  Linux swap / Solaris
/dev/sda6            2053        2115      506016  83  Linux

Command (m for help): t
Partition number (1-6): 6
Hex code (type L to list codes): 82
Changed system type of partition 6 to 82 (Linux swap / Solaris)

Command (m for help): p

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          1          13      104391  83  Linux
/dev/sda2              14        1288    10241437+  83  Linux
/dev/sda3            1289        1925    5116702+  83  Linux
/dev/sda4            1926        2610    5502262+  5  Extended
/dev/sda5            1926        2052    1020096  82  Linux swap / Solaris
/dev/sda6            2053        2115      506016  82  Linux swap / Solaris

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 裝置或資源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
part[root@bogon ~]# partprobe

這裡需要在進行設定下system ID

格式化

文法:mkswap裝置名稱

舉例

[root@bogon ~]# mkswap /dev/sda6

Setting up swapspace version 1, size = 518156 kB

啟動|關閉
文法:swapon [-s]裝置名稱

swapoff裝置名稱

選項與參數:

-s:查看所有swap檔案系統

舉例1:啟動swap

[root@bogon ~]# swapon /dev/sda6

舉例2:查看所有swap

[root@bogon ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda5                              partition      1020088 0      -1
/dev/sda6                              partition      506008  0      -2

查看

文法:free

舉例

            total      used      free    shared    buffers    cached
Mem:      2074972    1380996    693976          0    106740    1000288
-/+ buffers/cache:    273968    1801004
Swap:      1526096          0    1526096

可以看到Swap空間增加1526096

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.