Linux Shared Memory的查看与设置

2023-05-16

 

1. Linux Check Memory Usage

 

 

2. How to Check Shared Memory on Linux

 

3. Shared Memory Configuration

 

 

 

共享内存就是进程之间可以共享的一段内存,通过一个唯一的KEY值绑定
shmget()创建或获取
shmat()连接
shmdt()断连

共享内存的访问涉及同步措施,通常与信号灯一起使用
用ipcs -m命令可以查看系统中已有的共享内存段

/proc/sys/kernel/shm开头的几个文件是共享内存的参数


共享内存的访问涉及同步措施,通常与信号灯一起使用
用ipcs -m命令可以查看系统中已有的共享内存段

ipcs -m 看Shared Memory 共享内存

ipcs -q 看Message Queues 消息队列
ipcs -s 看Semaphore Arrays 信号量

 

使用命令:ipcs -al

------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 4091826
max total shared memory (pages) = 2097152
min seg size (bytes) = 1

1. Linux Check Memory Usage

by VIVEK GITE on APRIL 6, 2006 · 36 COMMENTS

How do I check used and free RAM memory usage under Linux operating systems using command line and GUI tools?

Linux comes with different set of commands to check memory usage. The free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The vmstat command reports information about processes, memory, paging, block IO, traps, and cpu activity. Finally, you can use the top command which provides a dynamic real-time view of a running system. It can display system summary information as well as a list of tasks currently being managed by the Linux kernel.

free command

Display free memory size in MB:

$ free -mOutput:


             total       used       free     shared    buffers     cached
Mem:           750        625        125          0         35        335
-/+ buffers/cache:        254        496
Swap:          956          0        956  

Displays a line containing the totals memory in MB:
$ free -t -m
Output:


       total       used       free     shared    buffers     cached
Mem:           750        625        125          0         35        335
-/+ buffers/cache:        253        496
Swap:          956          0        956
Total:        1707        625       1082  

vmstat command

Type vmstat command at shell prompt:

$ vmstat
Output:


procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
1  0      0 131620  35432 341496    0    0    42    82  737  1364 15  3 81  1  

top command

Type top command at the shell prompt:
$ top
Sample outputs:

Fig.01: top command displaying used memory

Fig.01: top command displaying used memory


To exit from top command type q key. Read man page of free, vmstat, top command for more information.

 

GNOME Desktop: GUI Tool

The Gnome System Monitor application enables you to display basic system information and monitor system processes, usage of system resources, and file systems. You can also use System Monitor to modify the behavior of your system. You can start System Monitor by visiting System menu > Choose Administration > System Monitor option. Or type the following command at the shell prompt:


 
gnome-system-monitor
   

Sample outputs:

Fig.02: Linux See Memory Usage With GUI System Monitor Tool

Fig.02: Linux See Memory Usage With GUI System Monitor Tool

 

----------------------------------------------------------------------------------------

2. How to Check Shared Memory on Linux

By Garrett Genet, eHow Contributor
updated: August 11, 2010

Shared memory is responsible for the smooth operation of your system; it acts as a space that multiple programs can access at once. This enables those programs to communicate in sync, while avoiding file redundancy. Shared memory can exist in the system's physical RAM or the swap file (which is virtual memory). In Linux operating systems, check the details of shared memory by typing in a few simple commands.

Difficulty: Moderately Easy

Instructions

  1. 1

    Power on your system and log in.

  2. 2

    Open a "Terminal" window.

  3. 3

    Type in "cat /proc/sys/kernel/shmall" and press "Enter." You'll see the total amount of shared memory available displayed in bytes. The max size of a shared memory segment is displayed with "cat /proc/sys/kernel/shmmax", and the total number of segments in the system is displayed with "cat /proc/sys/kernel/shmmni".

 



Read more: How to Check Shared Memory on Linux | eHow.com http://www.ehow.com/how_6849046_check-shared-memory-linux.html#ixzz19eUg5rtL

 

-------------------------------------------------------------------------------------------

3. Shared Memory Configuration

McIDAS-X 200x uses shared memory for a variety of tasks including frame allocation. By default, the shared memory facility is activated and should have sufficient maximum segment size on HP, IBM and SGI systems. However, this is not true for Sun systems running Solaris 2.x or Digital systems running True64. On Linux systems, the amount of available shared memory appears is equivalent to the combination of physical RAM and swap.

The system administrator should complete the steps below the first time McIDAS-X 200x is installed on Sun Solaris or Digital True64 workstations or if they desire to increase shared memory defaults on HP, IBM, or SGI systems.

Sun Solaris 2.X
SGI IRIX 6.x
HP HP-UX 10, 11
IBM AIX
Compaq Tru64 UNIX
RedHat Linux
FreeBSD 4.[789]
MacOS-X 7.4.0

 

Sun Solaris 2.x

The system administrator must complete the steps below the first time McIDAS-X is installed on a Sun workstation running Solaris 2. x .

  1.  
    • Type: /usr/sbin/sysdef | grep SHMMAX

      
      
      536870912 max shared memory segment size (SHMMAX)  
  2. 1. Force the kernel to activate the shared memory system at boot time by adding the line below to the appropriate location in the file 
    /etc/system .

    
    
    forceload: sys/shmsys  

    2. Check the maximum size of a shared memory segment using the command below. The value is indicated in bytes; the example lists a 512 MB maximum shared memory segment.

    If your value is less than 512 MB, go to step 3. If your value is 512 MB or greater, go to step 4.

    3. Set the shared memory size to 512 MB by adding the line below to the appropriate location in the file /etc/system .

    
    
    set shmsys:shminfo_shmmax = 536870912  

    4. Reboot the system so the forceload entry and 512 MB maximum shared memory size take effect.

SGI IRIX 6.x

On Irix, SHMMAX defaults to 512 MB (0x20000000 bytes), so tuning this parameter is unlikely to be needed. SHMMAX is found in /var/sysgen/mtune/shm.

HP HP-UX 10, 11

On HP-UX 10 and 11, the maximum value for SHMMAX is 1024 MB (0x40000000; the default value for 64 MB (0x04000000). SHMMAX is found in /etc/conf/master.d/core-hpux.

The procedure for changing the parameter is similar, if not identical, to the one described for HP-UX 9.

One way to check the current value of SHMMAX is to enter the following command:

Type: grep SHMMAX /etc/master

If the grep does not print anything, you are using the default value of 64 MB. If the grep prints something, the output might look like this:


 shmmax          SHMMAX              0X20000000   

The value is bytes, so here the maximum segment size has been set to 512 MB.

IBM AIX 4.x

The shmget(2) man page says that the maximum shared-memory segment size is 256 MB (0x10000000); this limit does not appear to be tunable.

Compaq Tru64 UNIX

The easiest way to increase shared-memory allocation on True64 is to use the GUI called dxkerneltuner, but one can also use the sysconfigdb command-line interface.

Running dxkerneltuner and increasing the shared-memory size to 64 MB will result in the following entry in the file /etc/sysconfigtab:


 ipc:
       shm-max=67108864
  

The following are the out-of-the-box defaults for the ipc subsystem for OSF/1 Version 4.0. They may be helpful for True64:


% sysconfig -q ipc
ipc:
msg-max = 8192
msg-mnb = 16384
msg-mni = 64
msg-tql = 40
shm-max = 4194304
shm-min = 1
shm-mni = 128
shm-seg = 32
sem-mni = 16
sem-msl = 25
sem-opm = 10
sem-ume = 10
sem-vmx = 32767
sem-aem = 16384
num-of-sems = 60
max-kernel-ports = 22487
port-hash-max-num = 1124350
port-reserved-max-num = 22487
set-max-num = 1029
ssm-threshold = 8388608
ssm-enable-core-dump = 1
  

 

 

RedHat Linux

There appears to be two ways of (re)defining the amount of shared memory in your system (tips thanks to Dave Glowacki of SSEC):

  • add this line to your /etc/rc.d/rc.local file:

    echo shared_memory_size > /proc/sys/kernel/shmmax

    (where shared_memory_size is the amount of shared memory you want to declare in bytes) and reboot.

    Note: since this will be the last thing run before your system comes up, your McIDAS session won't get a larger shared memory segment if it's started during the boot process).

     

  • a more permanent solution would be to change the value of SHMMAX in /usr/src/linux/include/asm/shmparam.h and rebuild your kernel

FreeBSD 4.[789]

Shared memory parameters are only read when the system goes from single user to multi user mode.

Add setting of shared memory max to /etc/sysctl.conf


# $FreeBSD: src/etc/sysctl.conf,v 1.1.2.3 2002/04/15 00:44:13 dougb Exp $
#
#  This file is read when going to multi-user and its contents piped thru
#  ``sysctl'' to adjust kernel values.  ``man 5 sysctl.conf'' for details.
#
kern.ipc.shmmax=536870912
  

and then reboot.

 

MacOS-X 7.4.0 (Panther)

In the Panther release of MacOS-X, shared memory is set in the file /etc/rc. The default settings will look something like:


# System tuning
sysctl -w kern.maxvnodes=$(echo $(sysctl -n hw.physmem) '33554432 / 512 * 1024 +p'|dc)
sysctl -w kern.sysv.shmmax=4194304
sysctl -w kern.sysv.shmmin=1
sysctl -w kern.sysv.shmmni=32
sysctl -w kern.sysv.shmseg=8
sysctl -w kern.sysv.shmall=1024
  

 

We recommend changing this to:


# System tuning
sysctl -w kern.maxvnodes=$(echo $(sysctl -n hw.physmem) '33554432 / 512 * 1024 +p'|dc)
sysctl -w kern.sysv.shmmax=536870912
sysctl -w kern.sysv.shmmin=1
sysctl -w kern.sysv.shmmni=4096
sysctl -w kern.sysv.shmseg=4096
sysctl -w kern.sysv.shmall=131072
  

 

After making these changes, the system will need to be rebooted for the changes to take effect.

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Linux Shared Memory的查看与设置 的相关文章

  • 如何在 Vim 中突出显示 Bash 脚本?

    我的 Vim 编辑器自动突出显示 PHP 文件 vim file php HTML 文件 vim file html 等等 但是当我输入 vim file在里面写一个Bash脚本 它不会突出显示它 我如何告诉 Vim 将其突出显示为 Bas
  • Apache 端口转发 80 到 8080 并访问 Apache (80) 中托管的应用程序,即 phpMyadmin 和 Tomcat (8080)

    我想访问托管在 tomcat 服务器 8080 中的应用程序 myapp 当前可以通过以下方式访问http example com 8080 myapp http example com 8080 myapp in http example
  • 如何获取与 shell 中的文件名模式匹配的所有文件的总文件大小?

    我正在尝试仅使用 shell 来计算与文件名模式匹配的所有文件 在目录树中 的总大小 以字节为单位 这是我到目前为止所拥有的 find name undo exec stat c s awk 总计 1 END 打印总计 有没有更简单的方法来
  • Vagrant 遇到问题 - “404 - 未找到”

    我正在尝试使用 Vagrant 制作一个 LAMP 盒子 有人告诉我它使用起来非常简单 我对网络和虚拟机完全陌生 对 Linux Ubuntu 的经验也很少 我目前已尝试按照官方文档页面上的教程进行操作 http docs vagrantu
  • Python列表内存存储[重复]

    这个问题在这里已经有答案了 据我了解 Python 列表本质上是 C 数组 它们分配特定的顺序内存块 但是 这些内存块实际上存储列表中的数据还是它们只是指向内存中存储实际数据的另一个位置 它可能取决于列表中存储的对象的大小吗 因为您可以轻松
  • 在ubuntu中打开spyder

    我想在ubuntu中打开spyder Python IDE 通常我会在 shell 中编写 spyder 它会打开spyder IDE 现在 当我在shell中编写spyder时 它只是换行 什么也没有发生 类似于按 enter 我如何找回
  • 更新Linux中的包含路径

    我的 my path to file 文件夹中有几个头文件 我知道如何将这些文件包含在新的 C 程序中 但每次我都需要在包含它之前输入头文件的完整路径 我可以在linux中设置一些路径变量 以便它自动查找头文件吗 您可以创建一个 makef
  • Ruby:在 Ubuntu 上安装 rmagick

    我正在尝试在 Ubuntu 10 04 上安装 RMagick 看起来here https stackoverflow com questions 1482823 is there an easy way to install rmagic
  • 为什么此 NASM 代码会打印我的环境变量?

    本学期我刚刚完成计算机体系结构课程 除其他外 我们一直在涉足 MIPS 汇编并在 MARS 模拟器中运行它 今天 出于好奇 我开始在我的 Ubuntu 机器上摆弄 NASM 基本上只是将教程中的内容拼凑起来 并感受一下 NASM 与 MIP
  • “git add”返回“致命:外部存储库”错误

    我刚刚进入 git 的奇妙世界 我必须提交我对程序所做的一系列更改 位于名为的目录中 var www myapp 我创建了一个新目录 home mylogin gitclone 从这个目录中 我做了一个git clone针对公共回购 我能够
  • 在 x86 汇编语言中获取文件大小的简单方法

    假设我已经在汇编中打开了一个文件 并且在寄存器 eax 中有该文件的文件句柄 我将如何获取文件的大小 以便为其分配足够的缓冲区空间 我在这里研究了另一个讨论 建议使用sys fstat 28 系统调用来获取文件统计信息但无法实现它 My a
  • LINUX:如何锁定内存中进程的页面

    我有一个 LINUX 服务器 运行一个具有大量内存占用的进程 某种数据库引擎 该进程分配的内存太大 需要将其中一部分换出 换出 我想做的是将所有其他进程 或正在运行的进程的子集 的内存页面锁定在内存中 以便只有数据库进程的页面被换出 例如
  • 如何在线程创建和退出时调用函数?

    include
  • Linux 使用 boost asio 拒绝套接字绑定权限

    我在绑定套接字时遇到问题 并且以用户身份运行程序时权限被拒绝 这行代码会产生错误 acceptor new boost asio ip tcp acceptor io boost asio ip tcp endpoint boost asi
  • 如何解决内存碎片

    我们偶尔会遇到这样的问题 长时间运行的服务器进程 在 Windows Server 2003 上运行 由于内存分配失败而引发异常 我们怀疑这些分配由于内存碎片而失败 因此 我们一直在寻找一些可能对我们有帮助的替代内存分配机制 我希望有人能告
  • 如何才能将 TCP 连接返回到同一端口?

    机器是 RHEL 5 3 内核 2 6 18 有时我在 netstat 中注意到我的应用程序有连接 建立了 TCP 连接本地地址 and 国外地址是一样的 其他人也报告了同样的问题 症状与链接中描述的相同 客户端连接到本地运行的服务器的端口
  • grep 排除文件的数组参数

    我想从我的文件中排除一些文件grep命令 为此我使用参数 exclude excluded file ext 为了更容易阅读 我想使用包含排除文件的 bash 数组 EXCLUDED FILES excluded file ext 然后将
  • free 和 malloc 在 C 中如何工作?

    我试图弄清楚如果我尝试 从中间 释放指针会发生什么 例如 看下面的代码 char ptr char malloc 10 sizeof char for char i 0 i lt 10 i ptr i i 10 ptr ptr ptr pt
  • 有没有一种快速方法可以从 Jar/war 中删除文件,而无需提取 jar 并重新创建它?

    所以我需要从 jar war 文件中删除一个文件 我希望有类似 jar d myjar jar file I donot need txt 的内容 但现在我能看到从 Linux 命令行执行此操作的唯一方法 不使用 WinRAR Winzip
  • 指针和内存范围

    我已经用 C 语言编程有一段时间了 但对 C 语言还是很陌生 有时我对 C 处理内存的方式感到困惑 考虑以下有效的 C 代码片段 const char string void where is this pointer variable l

随机推荐