Openbsd下mount_mfs —— 内存虚拟磁盘分区
-
- 锌 Zn
- 帖子: 493
- 注册时间: 2010-02-02 18:00
Openbsd下mount_mfs —— 内存虚拟磁盘分区
网上搜了一圈,没找到好的使用mount——mfs 的例子。
$ sudo mount_mfs -s 2097152 /dev/wd0b /tmp
mount_mfs: mmap: Cannot allocate memory
$ sudo mount_mfs -s 1048576 /dev/wd0b /tmp
mount_mfs: mmap: Cannot allocate memory
$ sudo mount_mfs -s 1048576 /dev/wd1b /tmp
mount_mfs: /dev/wd1b: Device not configured
$ sudo mount_mfs -s 100000 /dev/wd1b /tmp
mount_mfs: /dev/wd1b: Device not configured
# size offset fstype [fsize bsize cpg]
a: 516.7M 2048 4.2BSD 2048 16384 1 # /
b: 517.7M 1060290 swap 不知道是不是跟此有关。
c: 19540.8M 0 unused
d: 4102.5M 2120580 4.2BSD 2048 16384 1 # /usr
e: 3074.9M 10522575 4.2BSD 2048 16384 1 # /var
f: 1557.1M 16820055 4.2BSD 2048 16384 1 # /home
i: 9770.8M 20008960 unknown
$ sudo mount_mfs -s 2097152 /dev/wd0b /tmp
mount_mfs: mmap: Cannot allocate memory
$ sudo mount_mfs -s 1048576 /dev/wd0b /tmp
mount_mfs: mmap: Cannot allocate memory
$ sudo mount_mfs -s 1048576 /dev/wd1b /tmp
mount_mfs: /dev/wd1b: Device not configured
$ sudo mount_mfs -s 100000 /dev/wd1b /tmp
mount_mfs: /dev/wd1b: Device not configured
# size offset fstype [fsize bsize cpg]
a: 516.7M 2048 4.2BSD 2048 16384 1 # /
b: 517.7M 1060290 swap 不知道是不是跟此有关。
c: 19540.8M 0 unused
d: 4102.5M 2120580 4.2BSD 2048 16384 1 # /usr
e: 3074.9M 10522575 4.2BSD 2048 16384 1 # /var
f: 1557.1M 16820055 4.2BSD 2048 16384 1 # /home
i: 9770.8M 20008960 unknown
-
- 锌 Zn
- 帖子: 493
- 注册时间: 2010-02-02 18:00
按照你“野战军”式的作风不应该搞不定这个的,要充分发挥我军敢打敢拼的精神,;)wkx9dragon 写了:我的目标是想获得一个2g 的mfs,可是没成功,网上说的都是老新闻了,因为maxdiz unix限制为一g,也就是说每个进程最多可以分配1g 内存(32位),我查了我的openbsd amd64的源码,他可是限制为8g哦,所以说问题不是他。想把编译内核放在内存里,还是不行呀。netbsd 有 tmpfs 文件系统,大大提速我的编译时间,还干净。
我知道你是8G内存,即使开了X(抑或是gnome)也占用不了多少,估计还有个7.xG的剩余吧, 假设用其中的5G来做虚拟分区,我们将这个虚拟分区挂在到 /testmfs , 这样试试吧:
代码: 全选
# cd /
# mkdir testmfs
# mount -t mfs -o rw,nodev,nosuid,-s=10240000 /dev/sd0b /testmfs
没有做编译内核和用户岛的测试,你喜欢就请尝试一下,并请将结果反馈上来,看看速度到底快了多少?—— 实际上我关心的倒是系统是否还会使用磁盘缓存?,因为如果要使用磁盘缓存的话,在编译内核和用户岛时这样做的意义似乎也不太大了,但是如果系统不使用或我们可以禁用磁盘缓存,这样做还是很有意思的。—— 最起码的CVS时,可以提高磁盘寿命,此外如果内存足够大,甚至还可以当作web的专用目录(小系统,拷贝不费时间,还可以从安全性以及文件权限上做一些文章。)
-
- 锌 Zn
- 帖子: 493
- 注册时间: 2010-02-02 18:00
-
- 锌 Zn
- 帖子: 493
- 注册时间: 2010-02-02 18:00
-
- 锌 Zn
- 帖子: 493
- 注册时间: 2010-02-02 18:00
好了,搞定,我新分了一个交换分区(8g 呀),挂上了
mfs -s 838860 /dev/sd0b /home/wkx/temp/ <
mount_mfs: reduced number of fragments per cylinder group from 52424 to 52216 to enlarge last cylinder group
$ mount
/dev/wd0a on / type ffs (local)
/dev/wd0f on /home type ffs (local, nodev, nosuid, softdep)
/dev/wd0d on /usr type ffs (local, nodev, softdep)
/dev/wd0e on /var type ffs (local, nodev, nosuid, softdep)
mfs:20361 on /home/wkx/temp type mfs (asynchronous, local, size=838860 512-blocks)
具体性能怎样,试试看。
mfs -s 838860 /dev/sd0b /home/wkx/temp/ <
mount_mfs: reduced number of fragments per cylinder group from 52424 to 52216 to enlarge last cylinder group
$ mount
/dev/wd0a on / type ffs (local)
/dev/wd0f on /home type ffs (local, nodev, nosuid, softdep)
/dev/wd0d on /usr type ffs (local, nodev, softdep)
/dev/wd0e on /var type ffs (local, nodev, nosuid, softdep)
mfs:20361 on /home/wkx/temp type mfs (asynchronous, local, size=838860 512-blocks)
具体性能怎样,试试看。
-
- 锌 Zn
- 帖子: 493
- 注册时间: 2010-02-02 18:00
这也是我奇怪的地方,我当初的swap可能也就128M(最大充其量也就应该1G,不好意思,时间长了,记不得了),但是现在查看居然没有了。—— 难道是当初没有分配swap? 又感觉不太可能,系统会自动地将第二个disklabel分区设置为swap的。所以要么这里确实没有swap大小的限制,要么就是我已经将交换分区和/tmp的数据全抹了。:owkx9dragon 写了:好了,搞定,我新分了一个交换分区(8g 呀),挂上了
mfs -s 838860 /dev/sd0b /home/wkx/temp/ <
mount_mfs: reduced number of fragments per cylinder group from 52424 to 52216 to enlarge last cylinder group
$ mount
/dev/wd0a on / type ffs (local)
/dev/wd0f on /home type ffs (local, nodev, nosuid, softdep)
/dev/wd0d on /usr type ffs (local, nodev, softdep)
/dev/wd0e on /var type ffs (local, nodev, nosuid, softdep)
mfs:20361 on /home/wkx/temp type mfs (asynchronous, local, size=838860 512-blocks)
具体性能怎样,试试看。
昨天晚上用大文件(一个4.4G的ts文件)做了测试,而且也尝试了在虚拟磁盘上更新cvs源代码,都没有问题,编译内核的速度是快了不少,还没有来得及尝试编译用户岛——手册上说/usr/obj是强制性的,也没有尝试编译X,并且由于太晚了,没有时间认真测定,就等着你的测试结果了。:p
此外你原来说不行时的系统提示是什么?
-
- 锌 Zn
- 帖子: 493
- 注册时间: 2010-02-02 18:00
这是我的默认/etc/login.conf 一部分
#
# The default values
# To alter the default authentication types change the line:
# :tc=auth-defaults:\
# to be read something like: (enables passwd, "myauth", and activ)
# :auth=passwd,myauth,activ:\
# Any value changed in the daemon class should be reset in default
# class.
#
default:\
:path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin:\
:umask=022:\
:datasize-max=512M:\ 我怀疑是他的原因
:datasize-cur=512M:\ 我怀疑是他的原因
:maxproc-max=256:\
:maxproc-cur=128:\
:openfiles-cur=128:\
:stacksize-cur=4M:\
:localcipher=blowfish,6:\
:ypcipher=old:\
:tc=auth-defaults:\
:tc=auth-ftp-defaults:
我怀疑是他的原因
#
# The default values
# To alter the default authentication types change the line:
# :tc=auth-defaults:\
# to be read something like: (enables passwd, "myauth", and activ)
# :auth=passwd,myauth,activ:\
# Any value changed in the daemon class should be reset in default
# class.
#
default:\
:path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin:\
:umask=022:\
:datasize-max=512M:\ 我怀疑是他的原因
:datasize-cur=512M:\ 我怀疑是他的原因
:maxproc-max=256:\
:maxproc-cur=128:\
:openfiles-cur=128:\
:stacksize-cur=4M:\
:localcipher=blowfish,6:\
:ypcipher=old:\
:tc=auth-defaults:\
:tc=auth-ftp-defaults:
我怀疑是他的原因
This is mine. So I don't know where your problem is.
代码: 全选
# cat /etc/login.conf
# $OpenBSD: login.conf.in,v 1.2 2007/01/09 10:20:12 millert Exp $
#
# Sample login.conf file. See login.conf(5) for details.
#
#
# Standard authentication styles:
#
# krb5-or-pwd First try Kerberos V password, then local password file
# passwd Use only the local password file
# krb5 Use only the Kerberos V password
# chpass Do not authenticate, but change users password (change
# the YP password if the user has one, else change the
# local password)
# lchpass Do not login; change user's local password instead
# radius Use radius authentication
# skey Use S/Key authentication
# activ ActivCard X9.9 token authentication
# crypto CRYPTOCard X9.9 token authentication
# snk Digital Pathways SecureNet Key authentication
# token Generic X9.9 token authentication
#
# Default allowed authentication styles
auth-defaults:auth=passwd,skey:
# Default allowed authentication styles for authentication type ftp
auth-ftp-defaults:auth-ftp=passwd:
#
# The default values
# To alter the default authentication types change the line:
# :tc=auth-defaults:\
# to be read something like: (enables passwd, "myauth", and activ)
# :auth=passwd,myauth,activ:\
# Any value changed in the daemon class should be reset in default
# class.
#
default:\
:path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin:\
:umask=022:\
:datasize-max=512M:\
:datasize-cur=512M:\
:maxproc-max=256:\
:maxproc-cur=128:\
:openfiles-cur=128:\
:stacksize-cur=4M:\
:localcipher=blowfish,6:\
:ypcipher=old:\
:tc=auth-defaults:\
:tc=auth-ftp-defaults:
#
# Settings used by /etc/rc and root
# This must be set properly for daemons started as root by inetd as well.
# Be sure reset these values back to system defaults in the default class!
#
daemon:\
:ignorenologin:\
:datasize=infinity:\
:maxproc=infinity:\
:openfiles-cur=128:\
:stacksize-cur=8M:\
:localcipher=blowfish,8:\
:tc=default:
#
# Staff have fewer restrictions and can login even when nologins are set.
#
staff:\
:datasize-cur=512M:\
:datasize-max=infinity:\
:maxproc-max=512:\
:maxproc-cur=128:\
:ignorenologin:\
:requirehome@:\
:tc=default:
#
# Authpf accounts get a special motd and shell
#
authpf:\
:welcome=/etc/motd.authpf:\
:shell=/usr/sbin/authpf:\
:tc=default:
#
-
- 锌 Zn
- 帖子: 493
- 注册时间: 2010-02-02 18:00
搞定,这是我的login.conf, 看来问题是出在login.conf 上了。禁用表情在那里,我找找。
# $OpenBSD: login.conf.in,v 1.2 2007/01/09 10:20:12 millert Exp $
#
# Sample login.conf file. See login.conf(5) for details.
#
#
# Standard authentication styles:
#
# krb5-or-pwd First try Kerberos V password, then local password file
# passwd Use only the local password file
# krb5 Use only the Kerberos V password
# chpass Do not authenticate, but change users password (change
# the YP password if the user has one, else change the
# local password)
# lchpass Do not login; change user's local password instead
# radius Use radius authentication
# skey Use S/Key authentication
# activ ActivCard X9.9 token authentication
# crypto CRYPTOCard X9.9 token authentication
# snk Digital Pathways SecureNet Key authentication
# token Generic X9.9 token authentication
#
# Default allowed authentication styles
auth-defaults:auth=passwd,skey:
# Default allowed authentication styles for authentication type ftp
auth-ftp-defaults:auth-ftp=passwd:
#
# The default values
# To alter the default authentication types change the line:
# :tc=auth-defaults:\
# to be read something like: (enables passwd, "myauth", and activ)
# :auth=passwd,myauth,activ:\
# Any value changed in the daemon class should be reset in default
# class.
#
default:\
:path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin:\
:umask=022:\
:datasize-max=8G:\
:datasize-cur=8G:\
:maxproc-max=256:\
:maxproc-cur=128:\
:openfiles-cur=128:\
:stacksize-cur=4M:\
:localcipher=blowfish,6:\
:ypcipher=old:\
:tc=auth-defaults:\
:tc=auth-ftp-defaults:
#
# Settings used by /etc/rc and root
# This must be set properly for daemons started as root by inetd as well.
# Be sure reset these values back to system defaults in the default class!
#
daemon:\
:ignorenologin:\
:datasize=infinity:\
:maxproc=infinity:\
:openfiles-cur=128:\
:stacksize-cur=8M:\
:localcipher=blowfish,8:\
:tc=default:
#
# Staff have fewer restrictions and can login even when nologins are set.
#
staff:\
:datasize-cur=512M:\
:datasize-max=infinity:\
:maxproc-max=512:\
:maxproc-cur=128:\
:ignorenologin:\
:requirehome@:\
:tc=default:
#
# Authpf accounts get a special motd and shell
#
authpf:\
:welcome=/etc/motd.authpf:\
:shell=/usr/sbin/authpf:\
:tc=default:
命令:
mount_mfs -s 8388608 swap /test_temp/
结果:
$ df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/wd0a 507M 64.8M 416M 13% /
/dev/wd0f 1.5G 635M 820M 44% /home
/dev/wd0d 3.9G 2.4G 1.4G 64% /usr
/dev/wd0e 3.0G 27.2M 2.8G 1% /var
mfs:24784 3.9G 1.0K 3.7G 0% /test_temp
我看了一下,你的在stuff 中把 :datasize-max=infinity:\ 无限了,还得研究一下,区别在那里。对了,在4。7里无限是假的,我看了源代码,最大DATASIZ是8g。
# $OpenBSD: login.conf.in,v 1.2 2007/01/09 10:20:12 millert Exp $
#
# Sample login.conf file. See login.conf(5) for details.
#
#
# Standard authentication styles:
#
# krb5-or-pwd First try Kerberos V password, then local password file
# passwd Use only the local password file
# krb5 Use only the Kerberos V password
# chpass Do not authenticate, but change users password (change
# the YP password if the user has one, else change the
# local password)
# lchpass Do not login; change user's local password instead
# radius Use radius authentication
# skey Use S/Key authentication
# activ ActivCard X9.9 token authentication
# crypto CRYPTOCard X9.9 token authentication
# snk Digital Pathways SecureNet Key authentication
# token Generic X9.9 token authentication
#
# Default allowed authentication styles
auth-defaults:auth=passwd,skey:
# Default allowed authentication styles for authentication type ftp
auth-ftp-defaults:auth-ftp=passwd:
#
# The default values
# To alter the default authentication types change the line:
# :tc=auth-defaults:\
# to be read something like: (enables passwd, "myauth", and activ)
# :auth=passwd,myauth,activ:\
# Any value changed in the daemon class should be reset in default
# class.
#
default:\
:path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin:\
:umask=022:\
:datasize-max=8G:\
:datasize-cur=8G:\
:maxproc-max=256:\
:maxproc-cur=128:\
:openfiles-cur=128:\
:stacksize-cur=4M:\
:localcipher=blowfish,6:\
:ypcipher=old:\
:tc=auth-defaults:\
:tc=auth-ftp-defaults:
#
# Settings used by /etc/rc and root
# This must be set properly for daemons started as root by inetd as well.
# Be sure reset these values back to system defaults in the default class!
#
daemon:\
:ignorenologin:\
:datasize=infinity:\
:maxproc=infinity:\
:openfiles-cur=128:\
:stacksize-cur=8M:\
:localcipher=blowfish,8:\
:tc=default:
#
# Staff have fewer restrictions and can login even when nologins are set.
#
staff:\
:datasize-cur=512M:\
:datasize-max=infinity:\
:maxproc-max=512:\
:maxproc-cur=128:\
:ignorenologin:\
:requirehome@:\
:tc=default:
#
# Authpf accounts get a special motd and shell
#
authpf:\
:welcome=/etc/motd.authpf:\
:shell=/usr/sbin/authpf:\
:tc=default:
命令:
mount_mfs -s 8388608 swap /test_temp/
结果:
$ df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/wd0a 507M 64.8M 416M 13% /
/dev/wd0f 1.5G 635M 820M 44% /home
/dev/wd0d 3.9G 2.4G 1.4G 64% /usr
/dev/wd0e 3.0G 27.2M 2.8G 1% /var
mfs:24784 3.9G 1.0K 3.7G 0% /test_temp
我看了一下,你的在stuff 中把 :datasize-max=infinity:\ 无限了,还得研究一下,区别在那里。对了,在4。7里无限是假的,我看了源代码,最大DATASIZ是8g。
又发现了一个更保险的方法,实际上,我上面的做法有破坏disklabel分区表的“嫌疑”,如果你的内存你不够用时,系统会请求磁盘缓存,也就是交换分区,但是我们已经把交换分区挂在到了 /testmfs 目录上,所以说实际的交换分区已经不存在了,这样对一些必须依赖交换分区的程序来说可能会有麻烦。
现在用另一种方法,也就是利用空余的磁盘空间(我一般是根据FAQ上的建议,并未将OpenBSD的fdisk分区全部分配为disklabel分区,一般还留有几个G的空闲已备出现极端情况时使用,现在这好使用这些空闲空间)。这次我们也不需要将其全部使用,只添加一个128M的sd0m分区,这样可以以后挂载到/testmfs上,先运行命令:
这个命令是编辑disklabel分区表,我们在这里添加一个sd0m分区,大小设置为128M,因为是新添加的分区,所以这里需要先计算一下offset, 这个就不详述了,看过FAQ的自然明白怎样计算,分区的类型设置为swap,挂载的目录不用填写,这样方便今后手动设置挂载位置。详附件001-0.jpg, 然后运行挂载命令:
我试了试拷贝一个4.4G的ts文件到虚拟的分区,一切Ok,详细操作请看附件002-0.jpg, 看来这个方法也奏效,可以保留原有的交换分区,而且不用动login.conf文件和源代码。
问题 : 为什么128M的分区里可以挂载上5G的内存以及拷贝下4.4G的文件?
答案:哦?这个吗,要看源代码了,别问我。:D
如果需要永久使用这个分区,则需要修改fstab了。
现在用另一种方法,也就是利用空余的磁盘空间(我一般是根据FAQ上的建议,并未将OpenBSD的fdisk分区全部分配为disklabel分区,一般还留有几个G的空闲已备出现极端情况时使用,现在这好使用这些空闲空间)。这次我们也不需要将其全部使用,只添加一个128M的sd0m分区,这样可以以后挂载到/testmfs上,先运行命令:
代码: 全选
# disklabel -e sd0
代码: 全选
# cd /
# mkdir testmfs
# mount -t mfs -o rw,nodev,nosuid,-s=10240000 /dev/sd0m /testmfs
问题 : 为什么128M的分区里可以挂载上5G的内存以及拷贝下4.4G的文件?
答案:哦?这个吗,要看源代码了,别问我。:D
如果需要永久使用这个分区,则需要修改fstab了。
-
- 锌 Zn
- 帖子: 493
- 注册时间: 2010-02-02 18:00
I mean the system will change it for you, you don't need change those parameters manually.wkx9dragon 写了:"可以保留原有的交换分区,而且不用动login.conf文件和源代码"
你这个方法挺好的,有的软件必须要有交换分区,不然会出现奇奇怪怪的问题,但是你说不用修改login.conf好像是不对的,得看自己本机的设置,你的不用改是因为
daemon:\
:ignorenologin:\
:datasize=infinity:\
:maxproc=infinity:\
staff:\
:datasize-cur=512M:\
:datasize-max=infinity:\
不信你改为512m试试。
在线用户
正浏览此版面之用户: 没有注册用户 和 0 访客