您尚未登录。

#1 2021-12-01 10:04:32

ifnk
会员
注册时间: 2021-01-25
帖子: 93

关于 zram 和 swapfile 的疑问

我电脑是16g内存 , 500g 的 ssd
之前 按照 archwiki 开的是 16g 的 swapfile

$ sudo dd if=/dev/nvme0n1p3 of=/swapfile bs=1G count=16

平时都不关机,然后开的ide 就放那边也不关(webstorm ,idea , rider ,pycharm ……) 所以内存和 swapfile 都占的快满了……

今早浏览网页的时候 鼠标 卡的很,然后 开 网页 tab 也 慢,free -h 发现 swap 和 内存 都占满了……

然后 就 关机 重启了 ,想着把 swapfile 拉大 拉到了50g

但是百度 了 都说 swapfile 给 你内存 的 1倍就行了 ,还有说 开了 swap 对硬盘 读写有影响 ,影响ssd寿命 ……

然后 又 百度 到了 一个叫 zram 的东西 ,但是这个资料比较少 ,我只在 wiki 上面 看到 了 这个

# modprobe zram
# echo lz4 > /sys/block/zram0/comp_algorithm
# echo 32G > /sys/block/zram0/disksize
# mkswap --label zram0 /dev/zram0
# swapon --priority 100 /dev/zram0

然后 按照 这个 弄 下来 以后  ,我按 free -h  发现我有 81g 的 交换空间了 哈哈

$ free -h
               total        used        free      shared  buff/cache   available
内存:       14Gi        13Gi       238Mi       166Mi       1.2Gi       939Mi
交换:       81Gi       6.0Gi        76Gi

我就多开了 好多 网页 来测试  ,发现一点也不卡 (也有可能是 我刚关机 ,内存 占用 后面 会慢慢 变大的)



我平时 的笔记本使用 场景 就是  拿 jetbrains 的 ide 写代码 ,开 node  跑前端项目 ,开chrome 查资料 或者 看视频 ,偶尔用 docker  ,不玩游戏 , 16g内存 不开 交换 不够用 

原来 我本来 想 换一 台 32g 的笔记本 ,现在我 突然 就不想换了 ,有 这个 交换内存 技术,那我岂不是 16g 也够用了?

但是这个 也是有副作用 的吧?

百度说 zram 是 消耗 cpu 来 压缩 内存  的技术  ,也就是说 会让 cpu 占用 高

然后 swap 又会 影响  ssd寿命

想问下 我 这么 搞 对 电脑  影响(副作用) 大么 ? 不大的话 我 就不换电脑了

还有  开 zram 和 swapfile 同时开 可以 么? 还是 只开 zram 就可以 了 ,zram 是不是越大越好?

我看 github 有个 zram-generator  https://github.com/systemd/zram-generat … or.conf.md  项目 是 配置 zram config 的 , 我是 按照  archwiki 配置 zram的 ,

这两种方式 有什么区别么?

离线

#2 2021-12-01 10:50:03

JerryXiao
会员
注册时间: 2019-02-22
帖子: 6
个人网站

Re: 关于 zram 和 swapfile 的疑问

你的物理内存16G zram你已经开了32G了,而且 priority 设置成了 100 ,我觉得你的swapfile应该很难被用到了。
同时开当然可以 但是 priority 高的zram会先用,除非你已经用掉了32G的zram swap,(lz4 压缩的 zram 一般期望的压缩比是 2:1 左右,就是说你的16G物理内存已经基本用完了),才会用到你的swapfile,但是如果真的到了那个时候,你的kernel肯定在疯狂回收内存,多半你这时候已经感觉系统"卡死"了。
所以如果你要用32G zram,swapfile就不是非常必要的了。而且zram自己有backing_dev可以把数据写入非易失性储存中(ssd),这个和zram的配合远好于priority调节的swapfile。

离线

#3 2021-12-01 10:52:04

JerryXiao
会员
注册时间: 2019-02-22
帖子: 6
个人网站

Re: 关于 zram 和 swapfile 的疑问

另外archlinux的kernel默认开启zswap,详情请看zswap的wiki页面,所以你以为你在用zram,实际上很可能是在在用zswap,包括你的swapfile也不一定就是写到ssd上了,很可能是zswap压缩一下又放回内存了

离线

#4 2021-12-02 09:30:45

ifnk
会员
注册时间: 2021-01-25
帖子: 93

Re: 关于 zram 和 swapfile 的疑问

JerryXiao 说:

另外archlinux的kernel默认开启zswap,详情请看zswap的wiki页面,所以你以为你在用zram,实际上很可能是在在用zswap,包括你的swapfile也不一定就是写到ssd上了,很可能是zswap压缩一下又放回内存了


大佬,我昨天用了一天 zram ,没关机 ,今早  我的 webstorm 崩了 …… 然后 我又开开 ,过一会又崩了 …… 会不会是 zram 引起 的 ? 我现在 把 zram 禁用 了,只用 swapfile  ,看看 ide 会不会崩……

下面是 webstorm 的 崩溃 日志

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGILL (0x4) at pc=0x00007efc73d08005, pid=1266841, tid=1331668
#
# JRE version: OpenJDK Runtime Environment JBR-11.0.13.7-1751.19-jcef (11.0.13+7) (build 11.0.13+7-b1751.19)
# Java VM: OpenJDK 64-Bit Server VM JBR-11.0.13.7-1751.19-jcef (11.0.13+7-b1751.19, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# J 51749 c1 com.intellij.codeInsight.daemon.impl.Divider.divideInsideAndOutsideInOneRoot(Lcom/intellij/psi/PsiFile;JJLjava/util/List;Lit/unimi/dsi/fastutil/longs/LongList;Ljava/util/List;Lit/unimi/dsi/fastutil/longs/LongList;Ljava/util/List;Lit/unimi/dsi/fastutil/longs/LongList;Z)V (706 bytes) @ 0x00007efc73d08005 [0x00007efc73d02bc0+0x0000000000005445]
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h" (or dumping to /home/ifnk/core.1266841)
#
# If you would like to submit a bug report, please visit:
#   https://bugreport.java.com/bugreport/crash.jsp
#

---------------  S U M M A R Y ------------

Command Line: -Xms128m -Xmx750m -XX:ReservedCodeCacheSize=512m -XX:+IgnoreUnrecognizedVMOptions -XX:+UseG1GC -XX:SoftRefLRUPolicyMSPerMB=50 -XX:CICompilerCount=2 -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -ea -Dsun.io.useCanonCaches=false -Djdk.http.auth.tunneling.disabledSchemes="" -Djdk.attach.allowAttachSelf=true -Djdk.module.illegalAccess.silent=true -Dkotlinx.coroutines.debug=off -Dsun.tools.attach.tmp.only=true -Xmx1859m -XX:ErrorFile=/home/ifnk/java_error_in_webstorm_%p.log -XX:HeapDumpPath=/home/ifnk/java_error_in_webstorm_.hprof -Djb.vmOptionsFile=/home/ifnk/.config/JetBrains/WebStorm2021.3/webstorm64.vmoptions -Djava.system.class.loader=com.intellij.util.lang.PathClassLoader -Didea.vendor.name=JetBrains -Didea.paths.selector=WebStorm2021.3 -Didea.platform.prefix=WebStorm -Dsplash=true com.intellij.idea.Main

Host: AMD Ryzen 5 5500U with Radeon Graphics, 12 cores, 14G, Arch Linux
Time: Thu Dec  2 09:16:46 2021 CST elapsed time: 1627.024258 seconds (0d 0h 27m 7s)

---------------  T H R E A D  ---------------

Current thread (0x00007efb9427a000):  JavaThread "JobScheduler FJ pool 8/11" daemon [_thread_in_Java, id=1331668, stack(0x00007efb5408e000,0x00007efb5418f000)]

Stack: [0x00007efb5408e000,0x00007efb5418f000],  sp=0x00007efb5418d030,  free space=1020k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
J 51749 c1 com.intellij.codeInsight.daemon.impl.Divider.divideInsideAndOutsideInOneRoot(Lcom/intellij/psi/PsiFile;JJLjava/util/List;Lit/unimi/dsi/fastutil/longs/LongList;Ljava/util/List;Lit/unimi/dsi/fastutil/longs/LongList;Ljava/util/List;Lit/unimi/dsi/fastutil/longs/LongList;Z)V (706 bytes) @ 0x00007efc73d08005 [0x00007efc73d02bc0+0x0000000000005445]
J 53225 c1 com.intellij.codeInsight.daemon.impl.Divider.divideInsideAndOutsideInOneRoot(Lcom/intellij/psi/PsiFile;JJLcom/intellij/util/Processor;)V (170 bytes) @ 0x00007efc7345b544 [0x00007efc7345ab60+0x00000000000009e4]
j  com.intellij.codeInsight.daemon.impl.LineMarkersPass.doCollectInformation(Lcom/intellij/openapi/progress/ProgressIndicator;)V+120
J 54735 c2 com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(Lcom/intellij/openapi/progress/ProgressIndicator;)V (39 bytes) @ 0x00007efc81e746f8 [0x00007efc81e743e0+0x0000000000000318]
J 52612 c2 com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$$Lambda$3391.run()V (8 bytes) @ 0x00007efc810fd630 [0x00007efc810fd420+0x0000000000000210]
J 46333 c2 com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(Ljava/lang/Runnable;)Z (68 bytes) @ 0x00007efc818d2688 [0x00007efc818d2540+0x0000000000000148]
J 52611 c2 com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$$Lambda$3388.run()V (8 bytes) @ 0x00007efc80de2ff0 [0x00007efc80de2ec0+0x0000000000000130]
J 57991 c2 com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(Lcom/intellij/openapi/progress/ProgressIndicator;Ljava/lang/Thread;Lcom/intellij/openapi/progress/ProgressIndicator;Lcom/intellij/openapi/util/ThrowableComputable;)Ljava/lang/Object; (607 bytes) @ 0x00007efc820fa4f0 [0x00007efc820fa2a0+0x0000000000000250]
J 52502 c2 com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$$Lambda$3386.run()V (8 bytes) @ 0x00007efc811b5a18 [0x00007efc811b5140+0x00000000000008d8]
J 55918 c2 com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec()Z (153 bytes) @ 0x00007efc813e7e70 [0x00007efc813e7c60+0x0000000000000210]
J 58375 c2 java.util.concurrent.ForkJoinTask.doExec()I java.base@11.0.13 (37 bytes) @ 0x00007efc8215580c [0x00007efc821557c0+0x000000000000004c]
J 31993 c2 java.util.concurrent.ForkJoinPool.scan(Ljava/util/concurrent/ForkJoinPool$WorkQueue;I)Z java.base@11.0.13 (209 bytes) @ 0x00007efc81091f28 [0x00007efc81091c80+0x00000000000002a8]
j  java.util.concurrent.ForkJoinPool.runWorker(Ljava/util/concurrent/ForkJoinPool$WorkQueue;)V+25 java.base@11.0.13
j  java.util.concurrent.ForkJoinWorkerThread.run()V+24 java.base@11.0.13
v  ~StubRoutines::call_stub
V  [libjvm.so+0x8766c3]  JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, Thread*)+0x313
V  [libjvm.so+0x874960]  JavaCalls::call_virtual(JavaValue*, Klass*, Symbol*, Symbol*, JavaCallArguments*, Thread*)+0x160
V  [libjvm.so+0x874a31]  JavaCalls::call_virtual(JavaValue*, Handle, Klass*, Symbol*, Symbol*, Thread*)+0x81
V  [libjvm.so+0x914f4c]  thread_entry(JavaThread*, Thread*)+0x6c
V  [libjvm.so+0xe05260]  JavaThread::thread_main_inner()+0xd0
V  [libjvm.so+0xe01369]  Thread::call_run()+0x149
V  [libjvm.so+0xbc580e]  thread_native_entry(Thread*)+0xee


siginfo: si_signo: 4 (SIGILL), si_code: 2 (ILL_ILLOPN), si_addr: 0x00007efc73d08005

Register to memory mapping:

RAX=0x0000000095353468 is an oop: com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
{0x0000000095353468} - klass: 'com/intellij/psi/impl/source/tree/PsiWhiteSpaceImpl'
RBX=0x00000000b41d2d30 is an oop: [Ljava.lang.Object;
{0x00000000b41d2d30} - klass: 'java/lang/Object'[]
- length: 10
RCX=0x0 is NULL
RDX=0x00000000b41d2d10 is pointing into object: [Ljava.lang.Object;
{0x00000000b41d2ce0} - klass: 'java/lang/Object'[]
- length: 10
RSP=0x00007efb5418d030 is pointing into the stack for thread: 0x00007efb9427a000
RBP=0x00007efb5418d428 is pointing into the stack for thread: 0x00007efb9427a000
RSI=0x0000000000000212 is an unknown value
RDI=0x00000000b41d2d18 is an oop: com.intellij.util.containers.Stack
{0x00000000b41d2d18} - klass: 'com/intellij/util/containers/Stack'
R8 =0x0000000000000030 is an unknown value
R9 =0x0000000000000001 is an unknown value
R10=0x0000000095353468 is an oop: com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl
{0x0000000095353468} - klass: 'com/intellij/psi/impl/source/tree/PsiWhiteSpaceImpl'
R11=0x00000000000006b8 is an unknown value
R12=0x0 is NULL
R13=0x00000000901de8b8 is an oop: java.lang.ThreadLocal
{0x00000000901de8b8} - klass: 'java/lang/ThreadLocal'
R14=0x000000000000002d is an unknown value
R15=0x00007efb9427a000 is a thread


Registers:
RAX=0x0000000095353468, RBX=0x00000000b41d2d30, RCX=0x0000000000000000, RDX=0x00000000b41d2d10
RSP=0x00007efb5418d030, RBP=0x00007efb5418d428, RSI=0x0000000000000212, RDI=0x00000000b41d2d18
R8 =0x0000000000000030, R9 =0x0000000000000001, R10=0x0000000095353468, R11=0x00000000000006b8
R12=0x0000000000000000, R13=0x00000000901de8b8, R14=0x000000000000002d, R15=0x00007efb9427a000
RIP=0x00007efc73d08005, EFLAGS=0x0000000000010213, CSGSFS=0x002b000000000033, ERR=0x0000000000000000
  TRAPNO=0x0000000000000006

Top of Stack: (sp=0x00007efb5418d030)
0x00007efb5418d030:   000000000000db05 00007efc80f406c4
0x00007efb5418d040:   0000000095682e50 0000000094789e30
0x00007efb5418d050:   000000009127e7e8 0000000094789e30
0x00007efb5418d060:   0000000300000002 00000000b41d2b10

Instructions: (pc=0x00007efc73d08005)
0x00007efc73d07f05:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07f15:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07f25:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07f35:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07f45:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07f55:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07f65:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07f75:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07f85:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07f95:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07fa5:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07fb5:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07fc5:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07fd5:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07fe5:   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d07ff5:   00 00 00 00 00 00 00 00 00 00 00 00 c2 26 00 c2
0x00007efc73d08005:   27 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x00007efc73d08015:   00 01 00 c2 28 00 01 80 e5 01 e6 02 00 ea 02 03
0x00007efc73d08025:   03 d8 01 00 00 19 00 c2 21 00 00 00 00 01 00 00
0x00007efc73d08035:   c4 22 00 c2 1d 00 c2 1e 00 c2 1f 00 c2 47 00 c2
0x00007efc73d08045:   48 00 c2 49 00 c1 4a 00 c1 23 00 e1 23 00 c2 25
0x00007efc73d08055:   00 c2 26 00 c2 27 00 c2 28 00 c2 29 00 c2 2c 00
0x00007efc73d08065:   c1 2a 00 00 00 00 00 00 00 00 00 01 90 fa 02 00
0x00007efc73d08075:   00 ff 03 04 0a ac 00 00 19 00 c2 21 00 00 00 00
0x00007efc73d08085:   01 00 00 c4 22 00 c2 1d 00 c2 1e 00 c2 1f 00 c2
0x00007efc73d08095:   47 00 c2 48 00 c2 49 00 c1 4a 00 c1 23 00 e1 23
0x00007efc73d080a5:   00 c2 25 00 c2 26 00 c2 27 00 c2 28 00 c2 29 00
0x00007efc73d080b5:   c2 2c 00 c1 2a 00 c2 25 00 c1 2d 00 e1 2a 00 00
0x00007efc73d080c5:   00 01 b1 cd 04 00 00 19 00 c2 21 00 00 00 00 01
0x00007efc73d080d5:   00 00 c4 22 00 c2 1d 00 c2 1e 00 c2 1f 00 c2 47
0x00007efc73d080e5:   00 c2 48 00 c2 49 00 c1 4a 00 c1 23 00 e1 23 00
0x00007efc73d080f5:   c2 25 00 c2 26 00 c2 27 00 c2 28 00 c2 29 00 c2


Stack slot to memory mapping:
stack at sp + 0 slots: 0x000000000000db05 is an unknown value
stack at sp + 1 slots: 0x00007efc80f406c4 is at entry_point+100 in (nmethod*)0x00007efc80f40490
stack at sp + 2 slots: 0x0000000095682e50 is an oop: java.util.HashMap$Node
{0x0000000095682e50} - klass: 'java/util/HashMap$Node'
stack at sp + 3 slots: 0x0000000094789e30 is an oop: com.intellij.openapi.vfs.newvfs.impl.VirtualFileImpl
{0x0000000094789e30} - klass: 'com/intellij/openapi/vfs/newvfs/impl/VirtualFileImpl'
stack at sp + 4 slots: 0x000000009127e7e8 is an oop: com.intellij.openapi.project.impl.ProjectExImpl
{0x000000009127e7e8} - klass: 'com/intellij/openapi/project/impl/ProjectExImpl'
stack at sp + 5 slots: 0x0000000094789e30 is an oop: com.intellij.openapi.vfs.newvfs.impl.VirtualFileImpl
{0x0000000094789e30} - klass: 'com/intellij/openapi/vfs/newvfs/impl/VirtualFileImpl'
stack at sp + 6 slots: 0x0000000300000002 is an unknown value
stack at sp + 7 slots: 0x00000000b41d2b10 is an oop: [Lcom.intellij.openapi.roots.GeneratedSourcesFilter;
{0x00000000b41d2b10} - klass: 'com/intellij/openapi/roots/GeneratedSourcesFilter'[]
- length: 3





com.intellij.diagnostic.JBRCrash

离线

#5 2021-12-02 10:32:18

SamLukeYes
会员
所在地: Canton, China
注册时间: 2020-07-19
帖子: 320
个人网站

Re: 关于 zram 和 swapfile 的疑问

zram 不宜和 zswap 同时使用,但 Arch 的内核是默认开启 zswap 的,如果要使用 zram 的话应该加上内核参数 zswap.enabled=0

离线

页脚