首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >好斗的交换

问好斗的交换
EN

Ask Ubuntu用户
提问于 2015-01-03 03:52:58
回答 2查看 1.7K关注 0票数 1

我想用激进的交换行为配置Ubuntu14.04。我使用的是Linux内核3.14。我使用以下命令修改了swappiness。

代码语言:javascript
复制
echo 100 > /proc/sys/vm/swappiness

然而,在主机耗尽空闲内存之前,操作系统似乎不会交换页面。如何使操作系统主动地将未访问的页面交换到交换设备?

EN

回答 2

Ask Ubuntu用户

发布于 2015-01-04 00:21:14

用公羊做别的事。分配内存或磁盘IO试图分配缓存的进程会将空闲页推送到交换区以腾出空间。swappiness变量只会使系统更倾向于将应用程序推送出去,而倾向于将ram用于文件系统缓存。

票数 3
EN

Ask Ubuntu用户

发布于 2015-01-04 00:10:18

你为什么要这么做?

不管怎么说,如果这是你想要的,那就是你会得到的:

代码语言:javascript
复制
#include <stdio.h>
#include <sys/sysinfo.h>

fGetMyRAM()
{
    FILE* fStream = popen( "head -n1 /proc/meminfo", "r" );
    std::ostringstream output;
    int iBuffer = 128;

    while( !feof( fStream ) && !ferror( fStream ))
    {
        char cBuffer[iBuffer];
        int iBytesRead = fread( cBuffer, 1, iBuffer, fStream );
        output.write( cBuffer, iBytesRead );
    }
    std::string sResult = output.str();

    std::string sLabel, sRAM;
    std::istringstream iss(sResult);
    iss >> sLabel;
    iss >> sRAM;

    return std::stoi( sRAM );
}

int main()
{
  int iMyRAM = fGetMyRAM();
  int *pMemoryHog;

  while (true)
  {
    //as malloc alocates largest contiguous memory, keep slicing down.
    iMyRam = iMyRam/2;

    printf("%d\n", iMyRam);

    pMemoryHog = (int *) malloc ((iMyRam)*sizeof(void *));

    if (pMemoryHog == 0)
    {
      printf("Yeah! NO MORE MEMORY!\n");
      return 1;
    } // end if out of memory
    strcpy(pMemoryHog, "42");
  } // end while true
  free(pMemoryHog);
  return 0;
} // end main
票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/568273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档