一种减轻 mirrors rsync 副作用的思路

80 views
Skip to first unread message

Justin Wong

unread,
May 3, 2016, 12:17:12 PM5/3/16
to tuna-g...@googlegroups.com, ustc...@googlegroups.com
以前在 ustc 邮件列表看到过 mirrors 磁盘缓存几乎无效的问题,其中一个主要原因是 rsync 一遍就扫一遍磁盘,cache 全废了。

今天看到一个叫 nocache 的工具 https://github.com/Feh/nocache 可以禁止某个进程使用
cache,进而发现除了 nocache 还有一些方案可以考虑。

一个是最暴力的方式是直接使用 cgroup 限制 rsync 的内存。我测了一下,效果拔群

```
cgcreate -g memory:cptest
cgset -r memory.limit_in_bytes=20M cptest # 创建个 cgroup 并限制内存使用为 20MB
dd if=/dev/zero of=test bs=1M count=2048 # 创建个2G的文件
echo 3 > /proc/sys/vm/drop_caches # 把已有的 cache drop 掉,这时
free -m 应该看见 cache 的量很小了

cgexec -g memory:cptest cp test test 1 # 在 cgroup 中复制一遍 test
/nocache/cachestats ./test1 # 用 nocache
提供的工具看一下 cache 情况,几乎没有被任何 cache
> pages in cache: 1175/524288 (0.2%) [filesize=2097152.0K, pagesize=4K]

# 然后直接跑 cp,再用 cachestats 看一下
cp test test1
nocache/cachestats ./test1
> pages in cache: 524288/524288 (100.0%) [filesize=2097152.0K, pagesize=4K]
# 全被 cache 住了
```

还有就是 http://insights.oetiker.ch/linux/fadvise.html 这个地方提供了一个 rsync 的
patch,使用 fadvice 让 rsync 尽量不使用 cache。

感觉解决了一个老大难问题啊。

--
Justin Wong

Sheng Yang

unread,
May 3, 2016, 12:29:20 PM5/3/16
to tuna-g...@googlegroups.com, ustc...@googlegroups.com

听起来这个思路很像database里第二遍使用才进cache的想法,因为一次扫描cache就全没了。


Justin Wong <i...@bigeagle.me>于2016年5月3日周二 12:17写道:
--

---
You received this message because you are subscribed to the Google Groups "TUNA 主邮件列表" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tuna-general...@googlegroups.com.
To post to this group, send email to tuna-g...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ray Song

unread,
May 3, 2016, 12:58:23 PM5/3/16
to Justin Wong, tuna-g...@googlegroups.com, ustc...@googlegroups.com
似乎是因为 memory.limit_in_bytes 限制物理内存
在应用程序申请的内存和 buffer cache 总和超过限制的情况下,会把超出的弄到 swap
buffer cache就直接丢弃了?
>--
>来自USTC LUG
>请使用gmail订阅,不要灌水。
>更多信息more info:http://groups.google.com/group/ustc_lug?hl=en?hl=en
>---
>You received this message because you are subscribed to the Google Groups "USTC_LUG" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to ustc_lug+u...@googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

--
Ray
http://maskray.me

Justin Wong

unread,
May 3, 2016, 10:10:32 PM5/3/16
to Ray Song, tuna-g...@googlegroups.com, ustc...@googlegroups.com
应该是这个逻辑,其实可以把limit_in_bytes放宽松一些,rsync 本身占不了多少内存,但是对cache的消耗非常大。

--
Justin Wong

1391509153

unread,
May 6, 2016, 4:41:41 AM5/6/16
to tuna-general, Ray Song, tuna-general, ustc_lug
tuna各位技术大牛们,我是自动化一名小硕,平时较少用linux。今天在组里服务器跑程序时inodes满了,于是Google了一下,按照这个博客的操作http://blog.gdsyzx.edu.cn/sense/?p=2329,现在服务器上好像什么都没有了,求问这种情况我的数据还有救吗?具体怎么恢复你?
 
Best Regards,
Chen
 

发件人:Justin Wong <i...@bigeagle.me>
发送时间:2016-05-04 10:10
主题:[tuna-general] Re: [USTC-LUG] 一种减轻 mirrors rsync 副作用的思路
收件人:"Ray Song"<i...@maskray.me>
抄送:"tuna-general"<tuna-g...@googlegroups.com>,"ustc_lug"<ustc...@googlegroups.com>
 
--  
 
---  
You received this message because you are subscribed to the Google Groups "TUNA 主邮件列表" group. 
To unsubscribe from this group and stop receiving emails from it, send an email to tuna-general...@googlegroups.com
To post to this group, send email to tuna-g...@googlegroups.com

Justin Wong

unread,
May 6, 2016, 5:06:55 AM5/6/16
to tuna-g...@googlegroups.com
直接拔电,不要正常关机,不要动那块盘,找个台式机装上数据恢复软件恢复,能用只读就用只读,然后祈祷吧,八成找不回来。
 
你找的那篇 blog 和你实际的问题可能是不一样的,「遍历目录并删除」这么危险的操作,以后不要别人说什么就运行什么……
 
--
Justin Wong
 
On Fri, May 6, 2016, at 16:41, 1391509153 wrote:
tuna各位技术大牛们,我是自动化一名小硕,平时较少用linux。今天在组里服务器跑程序时inodes满了,于是Google了一下,按照这个博客的操作http://blog.gdsyzx.edu.cn/sense/?p=2329,现在服务器上好像什么都没有了,求问这种情况我的数据还有救吗?具体怎么恢复你?
 
 
 
Best Regards,
Chen

 

Justin Wong

unread,
May 6, 2016, 5:23:13 AM5/6/16
to tuna-g...@googlegroups.com
 
试试这个工具,注意,原先那个盘至少要 unmount,千万不要做任何额外操作。

Wang Shanker

unread,
May 6, 2016, 6:01:38 AM5/6/16
to tuna-g...@googlegroups.com, Ray Song
这个博客只是删掉了 /usr/src 啊,似乎没啥问题


本邮件具有数字签名,敬请核对。
王邈
清华大学计算机科学与技术系
电话:+86 130-5186-7712
通信地址:北京市海淀区清华大学紫荆公寓2号楼307A 100084

Please verify the digital signature attached with the e-mail.
Miao Wang
Department of Computer Science and Technology, Tsinghua University
Tel.: +86 130-5186-7712
Add.: Room 307A, No.2 Zijing Building, Tsinghua University, Peking. P.R.C. 100084

Justin Wong

unread,
May 6, 2016, 6:06:29 AM5/6/16
to tuna-g...@googlegroups.com
楼主可能把这个方法 apply 到他的个人数据所在目录了
 
--
Justin Wong
 

Email had 1 attachment:

  • smime.p7s
      6k (application/pkcs7-signature)
 

Aron Xu

unread,
May 6, 2016, 8:02:57 AM5/6/16
to tuna-g...@googlegroups.com, Ray Song, ustc_lug
testdisk 里面的 photorec 吧,但用什么软件都很难说找回多少。
--
Regards,
Aron Xu
Reply all
Reply to author
Forward
0 new messages