资讯专栏INFORMATION COLUMN

About tmpfs, /dev/shm and Oracle

array_huang / 1566人阅读

摘要:结论通过以上的讨论,结合对设置时性能的考虑,要求是从物理内存中取一定的比例进行设置。如果设置的过大,也就是允许大于物理内存,这样就可能出现单单的就让服务器产生的的结果。建议设置物理内存,至少必须大于的说法是不合适的。

引子

做下面这个总结的起源,是因为在一篇文章中看到了下面内容:

修改tmpfs
vi /etc/fstab
tmpfs                   /dev/shm                tmpfs   size=65000M     0 0 

tmpfs 建议设置>=物理内存,至少必须大于Memory

在自己当时的印象中,linux中的/dev/shm是将内存作为文件系统使用的一个虚拟的文件系统,就对“tmpfs 建议设置>=物理内存”这点产生了疑问。于是就在网络查找资料。

About tmpfs

tmpfs is a common name for a temporary file storage facility on many Unix-like operating systems. It is intended to appear as a mounted file system, but stored in volatile memory instead of a persistent storage device. A similar construction is a RAM disk, which appears as a virtual disk drive and hosts a disk file system.

Everything stored in tmpfs is temporary in the sense that no files will be created on the hard drive; however, swap space is used as backing store in case of low memory situations. On reboot, everything in tmpfs will be lost.

Many Unix distributions enable and use tmpfs by default for the /tmp branch of the file system or for shared memory. This can be observed with df as in this example:

Filesystem            Size  Used Avail Use% Mounted on
tmpfs                 256M  688K  256M   1%  /tmp

On some Linux distributions (e.g. Debian, Ubuntu), /tmp is a normal directory, but /dev/shm uses tmpfs.
来自:wikipedia

上面这段内容的意思是,tmpfs是Unix-like系统中的临时文件存储机制,实现形式是将内存中的一部分作为挂载的文件系统使用。tmpfs可以使用的大小为“物理内存+SWAP”,在物理内存不足时,在内存不足时,tmpfs可以使用swap的空间。但在操作系统重启时,tmpfs中的内容会丢失。

About /dev/shm

/dev/shm/是linux下一个非常有用的目录,因为这个目录不在硬盘上,而是在内存里。因此在linux下,就不需要大费周折去建ramdisk,直接使用/dev/shm/就可达到很好的优化效果。 /dev /shm/需要注意的一个是容量问题,在linux下,它默认最大为内存的一半大小,使用df -h命令可以看到。但它并不会真正的占用这块内存,如果/dev/shm/下没有任何文件,它占用的内存实际上就是0字节;如果它最大为1G,里头放有 100M文件,那剩余的900M仍然可为其它应用程序所使用,但它所占用的100M内存,是绝不会被系统回收重新划分的,否则谁还敢往里头存文件呢?

默认系统就会加载/dev/shm ,它就是所谓的tmpfs,有人说跟ramdisk(虚拟磁盘),但不一样。象虚拟磁盘一样,tmpfs 可以使用您的 RAM,但它也可以使用您的交换分区来存储。而且传统的虚拟磁盘是个块设备,并需要一个 mkfs 之类的命令才能真正地使用它,tmpfs 是一个文件系统,而不是块设备;您只是安装它,它就可以使用了。

tmpfs有以下优势:

动态文件系统的大小。

tmpfs 的另一个主要的好处是它闪电般的速度。因为典型的 tmpfs 文件系统会完全驻留在 RAM 中,读写几乎可以是瞬间的。

tmpfs 数据在重新启动之后不会保留,因为虚拟内存本质上就是易失的。所以有必要做一些脚本做诸如加载,绑定的操作。
来自xifenfei的博客

Oracle and /dev/shm

Oracle数据库中,有两个地方会和/dev/shm产生交集。一个是增强32bit系统上内存使用的extended buffer cache feature,另一个是Oracle 11g引入的AMM(
Automatic Memory Management)特性。

extended buffer cache feature

extended buffer cache feature特性由oracle初始化参数文件中的USE_INDIRECT_DATA_BUFFERS参数控制,这个参数的设置可以使Oracle在32bit平台上使用更多内存。而使用更多的内存,在linux平台就是通过/dev/shm来获得的。

To use the extended buffer cache feature, create an in-memory file system on the /dev/shm mount point equal in size or larger than the amount of memory that you intend to use for the database buffer cache. For example, to create an 8 GB file system on the /dev/shm mount point:

Run the following command as the root user:

# mount -t tmpfs shmfs -o size=8g /dev/shm

To ensure that the in-memory file system is mounted when the system restarts, add an entry in the /etc/fstab file similar to the following:

shmfs /dev/shm tmpfs size=8g 0 0

When Oracle Database starts with the extended buffer cache feature enabled, it creates a file in the /dev/shm directory that corresponds to the Oracle buffer cache.

注:这里要求/dev/shm的设置的至少和buffer cache的目标值一样大。

AMM

启用AMM时,oracle使用的内存是通过/dev/shm这个接口来分配的,oracle实例启动之后,会发现在/dev/shm中创建了很多ora打头的文件,这些文件其实就是AMM使用的内存。

Oracle文档中对/dev/shm的说明如下:
/dev/shm mount point should be equal in size or larger than the value of SGA_MAX_SIZE, if set, or should be set to be at least MEMORY_TARGET or MEMORY_MAX_TARGET, whichever is larger. For example, with MEMORY_MAX_TARGET=4GB only set, to create a 4GB system on the /dev/shm mount point:

Run the following command as the root user:

# mount -t tmpfs shmfs -o size=4g /dev/shm

Ensure that the in-memory file system is mounted when the system restarts, add an entry in the /etc/fstab file similar to the following:

 # shmfs /dev/shm tmpfs size=4g 0

来自oracle文档

注:这里要求/dev/shm的设置的至少和max(memory_target,memory_max_target)一样大。如果/dev/shm设置小于max(memory_target,memory_max_target),在启动oracle实例时,会出现‘ORA-00845: MEMORY_TARGET not supported on this system’错误,同时在alert日志中会出现如下提示:

Starting ORACLE instance (normal)
WARNING: You are trying to use the MEMORY_TARGET feature. This feature requires the /dev/shm file system to be mounted for at least 2147483648 bytes. /dev/shm is either not mounted or is mounted with available space less than this size. Please fix this so that MEMORY_TARGET can work as expected. Current available is 1054498816 and used is 0 bytes. Ensure that the mount point is /dev/shm for this directory.
memory_target needs larger /dev/shm

Oracle两种使用/dev/shm的方式,实际上是/dev/shm这个虚拟的文件系统,作为分配和使用内存的接口。

结论

通过以上的讨论,结合对Oracle设置时性能的考虑,要求/dev/shm是从物理内存中取一定的比例进行设置。如果设置的过大,也就是允许memory_target大于物理内存,这样就可能出现单单oracle的sga+pga就让服务器产生的swap的结果。而且本身我们分配sga和pga的时候,就是按照从物理内存中取一定的比例出来。

所以/dev/shm的设置,以满足memory_target的设置为目标即可。“tmpfs 建议设置>=物理内存,至少必须大于Memory”的说法是不合适的。

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/35000.html

相关文章

  • About tmpfs, /dev/shm and Oracle

    摘要:结论通过以上的讨论,结合对设置时性能的考虑,要求是从物理内存中取一定的比例进行设置。如果设置的过大,也就是允许大于物理内存,这样就可能出现单单的就让服务器产生的的结果。建议设置物理内存,至少必须大于的说法是不合适的。 引子 做下面这个总结的起源,是因为在一篇文章中看到了下面内容: 修改tmpfs vi /etc/fstab tmpfs /dev/...

    cppowboy 评论0 收藏0
  • Ubuntu x86_64安装oracle 11gR2 XE

    摘要:注意是提供的精简版,拥有正式版的所有功能,对内存要求也不高。很遗憾的是,官方只提供了安装包适用于,,,并没有提供包。本文提供如何安装的步骤。 Oracle 11gR2 XE(注意XE)是Oracle提供的精简版Oracle,拥有正式版的所有功能,对内存要求也不高。很遗憾的是,官方只提供了rpm安装包(适用于CentOS,Redhat,Fedora),并没有提供deb包。本文提供如何安装...

    blastz 评论0 收藏0
  • Ubuntu x86_64安装oracle 11gR2 XE

    摘要:注意是提供的精简版,拥有正式版的所有功能,对内存要求也不高。很遗憾的是,官方只提供了安装包适用于,,,并没有提供包。本文提供如何安装的步骤。 Oracle 11gR2 XE(注意XE)是Oracle提供的精简版Oracle,拥有正式版的所有功能,对内存要求也不高。很遗憾的是,官方只提供了rpm安装包(适用于CentOS,Redhat,Fedora),并没有提供deb包。本文提供如何安装...

    wushuiyong 评论0 收藏0
  • Ubuntu x86_64安装oracle 11gR2 XE

    摘要:注意是提供的精简版,拥有正式版的所有功能,对内存要求也不高。很遗憾的是,官方只提供了安装包适用于,,,并没有提供包。本文提供如何安装的步骤。 Oracle 11gR2 XE(注意XE)是Oracle提供的精简版Oracle,拥有正式版的所有功能,对内存要求也不高。很遗憾的是,官方只提供了rpm安装包(适用于CentOS,Redhat,Fedora),并没有提供deb包。本文提供如何安装...

    lovXin 评论0 收藏0
  • 挂载、卸载、free查看内存情况、创建交换分区、回环设备、dd命令、自动挂载、fuser

    摘要:挂载卸载分区格式化创建了文件系统后就可以挂载了挂载将新的文件系统关联至当前根文件系统卸载将某文件系统与当前根文件系统的关联关系移除挂载使用方法设备挂载点设备可以是设备文件如可以是卷标如或者是如挂载点指定挂载的目录,该目录的要求是没有被其他进 挂载、卸载 分区、格式化创建了文件系统后就可以挂载了 挂载:将新的文件系统关联至当前根文件系统 卸载:将某文件系统与当前根文件系统的关联关系移除...

    keithyau 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<