鍍金池/ 教程/ Linux/ 內存交換空間的構建
Linux 學習記錄--開機掛載錯誤
日志系統(tǒng)
數(shù)據(jù)流重定向
內存交換空間的構建
文件系統(tǒng)簡介
Linux 學習記錄--軟件安裝 RPM|SRPM|YUM
文件特殊權限
目錄配置 FHS
文件內容查閱
Boot Loader
文件壓縮
Linux 學習記錄--文件權限
Linux 命令縮寫
命令與文件的查詢
文件|目錄的默認權限與隱藏權限
shell script
服務
Linux 學習記錄--程序編譯與函數(shù)庫
正則表達式與其應用
關機相關指令
shell
vim 與 vi 常用命令
系統(tǒng)調用:進程控制
文件系統(tǒng)簡單操作
磁盤掛載與卸載
有名管道通訊
磁盤分區(qū),格式化與檢驗
工作管理與進程管理
匿名管道通訊
Linux 學習記錄--啟動流程
文件與目錄管理
管道命令
命名別名與歷史命令
文件備份|還原
shell變量
Linux 學習記錄--ACL 權限控制
內核|內核模塊編譯
文件管理相關系統(tǒng)編程

內存交換空間的構建

我們知道 CPU 計算與數(shù)據(jù)的存儲都會使用到內存,使用內存可以大大減少從磁盤讀取的時間,但是當物理內存不足時,就需要暫時將用不到的程序和數(shù)據(jù)挪到內存交換空間(swap)

作法:
1.創(chuàng)建分區(qū)(fdisk ,文件)
2.格式化為 swap
3.啟動
4.查看

創(chuàng)建分區(qū)

舉例

[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 設備名稱
選項與參數(shù):
-s:查看所有 swap 文件系統(tǒng)

舉例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