william

Keep Calm and Markdown.

Linux 内存调优的两个重要参数

今天在看这篇介绍 Linux 性能调优 的博客(Linux Performance: Almost Always Add Swap Space),其中涉及到如何调整内核内存的调整机制。主要的参数有

  • swappiness: This control is used to define how aggressively the kernel will swap memory pages. Higher values will increase aggressiveness; lower values decrease the amount of swap. (default = 60, recommended values between 1 and 60) Remove your swap for 0 value, but it is usually not recommended in most cases.
  • vfs_cache_pressure: Controls the kernel’s tendency to reclaim the memory, which is used for caching of directory and inode objects. (default = 100, recommend value 50 to 200)

kitty 终端模拟器

安装 1 2 3 4 5 6 ## magick-cli sudo apt-get install imagemagick sudo apt-get install luajit sudo apt-get install luarocks luarocks install magick tmux.conf 1 2 3 4 5 ##----------------------------------------------------------------------------- ## HACK: for kitty set -gq allow-passthrough on set -g visual-activity off ##-----------------------------------------------------------------------------

nvim dap 映射 r 快捷键

最近在研究如何使用 nvim-dap 进行 debugging。在 gdb,我们可以很方便的使用单个按键就可以触发一些行为,如

  • r: run
  • c: continue
  • s: step-in

那么,我的想法也是在 nvim-dap 实现这样快捷键 r 来模拟 run 的行为。现在的问题是:由于在 normal mode,单个按键 r 代表 replace one character

因此,我们需要在 nvimbuffers 去识别是否启动了 nvim-dap

  • 如果存在 dap-repl,则映射 r
  • 如果找不到,则回退到 replace 的功能。

在 c 代码文件插入 shell 命令

今天看到一个帖子:Just realized you can put shell script inside c source files,想到以前有个朋友也是这么使用 c,觉得挺神奇的。

这个是在 c 源代码文件,使用 macro 宏定义一组 shell 命令,然后再退出 shell,这样就不会在继续执行真正的 c 代码了。这样做的好处是可以使用一个命令 sh main.c 即可快速运行可执行文件,对于一些简单部署的任务比较方便。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#if 0
cc -o /tmp/app main.c
/tmp/app
exit # required, otherwise sh will try to interpret the C code below
#endif

#include <stdio.h>

int main(void)
{
    printf("quick script\n");
    return 0;
}
1
2
3
sh main.c

quick script

tmux: error while loading shared libraries: libevent_core 2.1.so.6

tmux 报错

1
tmux: error while loading shared libraries: libevent_core-2.1.so.7

使用 ldd 查看是可以找到动态库

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
ldd ~/local/bin/tmux
        linux-vdso.so.1 (0x00007ffe043f8000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007fa85ce0c000)
        libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007fa85cbe2000)
        libevent_core-2.1.so.6 => /home/lfang/local/lib/libevent_core-2.1.so.6 (0x00007fa85c9ac000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fa85c6aa000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fa85c493000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fa85c0e7000)
        libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007fa85bc84000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa85ba66000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa85d00f000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fa85b862000)
        libz.so.1 => /home/lfang/opt/lib/libz.so.1 (0x00007fa85d20c000)
0%