|簡體中文

比思論壇

 找回密碼
 按這成為會員
搜索



查看: 646|回復: 4
打印 上一主題 下一主題

Linux 增加虚拟内存

[複製鏈接]

25

主題

0

好友

292

積分

小學生

Rank: 2

  • TA的每日心情
    開心
    2023-8-10 12:40
  • 簽到天數: 131 天

    [LV.7]常住居民III

    推廣值
    0
    貢獻值
    0
    金錢
    623
    威望
    292
    主題
    25
    樓主
    發表於 2013-12-19 00:40:54

    1:创建文件:dd if=/dev/zero  of=/data/swapfile bs=1024 count=65536
    2:激活和使用:mkswap /data/swapfile
                  free

                  swapon /data/swapfile

                  free

    3:移除:swapoff /data/swapfile
    ----------------------------------------------------------
    上述操作开启重启之后交换空间会变得不可用,需要在/etc/fstab中增加自动挂载设置
    /data/swapfile  none  swap sw 0  0

    示例:
    系统运行过程中一直报错如下
    Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000d92f0000, 264314880, 0) failed; error='无法分配内存' (errno=12)
    #
    # There is insufficient memory for the Java Runtime Environment to continue.
    # Native memory allocation (malloc) failed to allocate 264314880 bytes for committing reserved memory.
    # An error report file with more information is saved as:
    # /usr/local/Tomcat_Trans/bin/hs_err_pid10365.log

    程序异常中止,查看内存,发现内存配置是一样的(系统迁移),但是竟然报内存不足,free看一下,发现在新系统上没有增加虚拟内存,增加一个2GB的虚拟内存再观察看下,具体如下:

    [root@pacteralinux ~]# dd if=/dev/zero  of=/root/swapfile  bs=1024 count=2048000^C
    [root@pacteralinux ~]# df
    Filesystem          1K-blocks      Used Available Use% Mounted on
    /dev/sda1            29954008  21352544  7079852  76% /
    tmpfs                  794380        0    794380  0% /dev/shm
    /dev/sdb1            72246600  4014596  64562092  6% /mnt/resource
    /dev/sdc1            379509584    199164 360032424  1% /mnt/resource/mysqldataper
    /dev/sdc2            136543368    192128 129415180  1% /mnt/resource/sdc3mnt
    [root@pacteralinux ~]# df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda1              29G  21G  6.8G  76% /
    tmpfs                776M    0  776M  0% /dev/shm
    /dev/sdb1              69G  3.9G  62G  6% /mnt/resource
    /dev/sdc1            362G  195M  344G  1% /mnt/resource/mysqldataper
    /dev/sdc2            131G  188M  124G  1% /mnt/resource/sdc3mnt
    [root@pacteralinux ~]# touch /mnt/resource/sdc3mnt/swapfile
    [root@pacteralinux ~]# dd id=/dev/zero of=/mnt/resource/sdc3mnt/swapfile bs=1024 count=2048000
    dd: unrecognized operand `id=/dev/zero'
    Try `dd --help' for more information.
    [root@pacteralinux ~]# dd if=/dev/zero of=/mnt/resource/sdc3mnt/swapfile bs=1024 count=2048000
    2048000+0 records in
    2048000+0 records out
    2097152000 bytes (2.1 GB) copied, 134.705 s, 15.6 MB/s
    [root@pacteralinux ~]# cd /mnt/resource/sdc3mnt/
    [root@pacteralinux sdc3mnt]# ll -h
    total 2.0G
    drwx------. 2 root root  16K Dec  2 14:20 lost+found
    -rw-r--r--. 1 root root 2.0G Dec  7 23:19 swapfile
    [root@pacteralinux sdc3mnt]# mkswap swapfile
    mkswap: swapfile: warning: don't erase bootbits sectors
            on whole disk. Use -f to force.
    Setting up swapspace version 1, size = 2047996 KiB
    no label, UUID=7e85b4b9-5473-4fad-afbe-5b989890e81b
    [root@pacteralinux sdc3mnt]# free -m
                total      used      free    shared    buffers    cached
    Mem:          1551      1452        99          0          4        635
    -/+ buffers/cache:        812        739
    Swap:            0          0          0
    [root@pacteralinux sdc3mnt]# swapon swapfile
    [root@pacteralinux sdc3mnt]# free -m
                total      used      free    shared    buffers    cached
    Mem:          1551      1453        97          0          4        635
    -/+ buffers/cache:        813        737
    Swap:        1999          0      1999
    [root@pacteralinux sdc3mnt]#


    無效樓層,該帖已經被刪除
    無效樓層,該帖已經被刪除
    無效樓層,該帖已經被刪除

    0

    主題

    1

    好友

    1270

    積分

    高中生

    Rank: 4

  • TA的每日心情
    奮斗
    昨天 23:45
  • 簽到天數: 431 天

    [LV.9]以壇為家II

    推廣值
    0
    貢獻值
    0
    金錢
    23
    威望
    1270
    主題
    0
    5#
    發表於 2014-1-30 15:27:45
    学习学习。。
    重要聲明:本論壇是以即時上載留言的方式運作,比思論壇對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,讀者及用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,讀者及用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本論壇受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者及用戶發現有留言出現問題,請聯絡我們比思論壇有權刪除任何留言及拒絕任何人士上載留言 (刪除前或不會作事先警告及通知 ),同時亦有不刪除留言的權利,如有任何爭議,管理員擁有最終的詮釋權。用戶切勿撰寫粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。

    手機版| 廣告聯繫

    GMT+8, 2024-5-31 02:16 , Processed in 0.049368 second(s), 26 queries , Gzip On.

    Powered by Discuz! X2.5

    © 2001-2012 Comsenz Inc.

    回頂部