Understanding the Space Used by ZFS -- (转)

Understanding the Space Used by ZFS

By Brian Leonard on Sep 28, 2010

Until recently, I‘ve been confused and frustrated by the zfs list output as I try to clear up space on my hard drive.

Take this example using a 1 GB zpool:

[email protected]:~# mkfile 1G /dev/dsk/disk1
[email protected]:~# zpool create tank disk1
[email protected]:~# zpool list tank
NAME   SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
tank  1016M    73K  1016M     0%  ONLINE  -

Now let‘s create some files and snapshots:

[email protected]:~# mkfile 100M /tank/file1
[email protected]:~# zfs snapshot [email protected]
[email protected]:~# mkfile 100M /tank/file2
[email protected]:~# zfs snapshot [email protected]
[email protected]:~# zfs list -t all -r tank
NAME         USED  AVAIL  REFER  MOUNTPOINT
tank         200M   784M   200M  /tank
[email protected]    17K      -   100M  -
[email protected]      0      -   200M  -

The output here looks as I‘d expect. I have used 200 MB of disk space, neither of which is used by the snapshots. snap1 refers to 100 MBs of data (file1) and snap2 refers to 200 MBs of data (file1 and file2).

Now let‘s delete file1 and look at our zfs list output again:

[email protected]:~# rm /tank/file1
[email protected]:~# zpool scrub tank
[email protected]:~# zfs list -t all -r tank
NAME         USED  AVAIL  REFER  MOUNTPOINT
tank         200M   784M   100M  /tank
[email protected]    17K      -   100M  -
[email protected]    17K      -   200M  -

Only 1 thing has changed - tank now only refers to 100 MB of data. file1 has been deleted and is only referenced by the snapshots. So why don‘t the snapshots reflect this in their USED column? You may think we should show 100 MB used by snap1, however, this would be misleading as deleting snap1 has no effect on the data used by the tank file system. Deleting snap1 would only free up 17K of disk space. We‘ll come back to this test case in a moment.

There is an option to get more detail on the space consumed by the snapshots. Although you can pretty easily deduct from the example above that the snapshots are using 100 MB, by using the zfs space option you can save yourself from doing the math:

[email protected]:~# zfs list -t all -o space -r tank
NAME        AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
tank         784M   200M      100M    100M              0       154K
[email protected]      -    17K         -       -              -          -
[email protected]      -    17K         -       -              -          -

Here we can clearly see that of the 200 MB used by our file system, 100 MB is used by snapshots (file1) and 100 MB is used by the dataset itself (file2). Of course, there are other factors that can affect the total amount used - see the zfs man page for details.

Now, if we were to delete snap1 (we know this is safe, because it‘s not using any space):

[email protected]:~# zfs destroy [email protected]
[email protected]:~# zfs list -t all -r tank
NAME         USED  AVAIL  REFER  MOUNTPOINT
tank         200M   784M   100M  /tank
[email protected]   100M      -   200M  -

We can see that snap2 now shows 100 MBs used. If I were to delete snap2, I would be deleting 100 MB of data (or reclaiming 100 MB of space):

Now let‘s look at a more realistic example - my home directory where I have Time Slider running:

[email protected]:~$ zfs list -t all -r -o space rpool/export/home
NAME                                                       AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD
rpool/export/home                                          25.4G  35.2G     17.9G   17.3G              0          0
rpool/export/[email protected]:monthly-2010-08-03-09:30       -   166M         -       -              -          -
rpool/export/[email protected]:30                  -  5.06M         -       -              -          -
rpool/export/[email protected]:56                  -  5.15M         -       -              -          -
rpool/export/[email protected]:12                  -  54.6M         -       -              -          -
rpool/export/[email protected]:monthly-2010-09-01-00:00       -  53.8M         -       -              -          -
rpool/export/[email protected]:weekly-2010-09-08-00:00        -  95.8M         -       -              -          -
rpool/export/[email protected]:04                  -  53.9M         -       -              -          -
rpool/export/[email protected]:weekly-2010-09-15-00:00        -  2.06G         -       -              -          -
rpool/export/[email protected]:weekly-2010-09-22-00:00        -  89.7M         -       -              -          -
rpool/export/[email protected]:frequent-2010-09-28-11:00      -  18.3M         -       -              -          -
rpool/export/[email protected]:frequent-2010-09-28-11:15      -   293K         -       -              -          -
rpool/export/[email protected]:frequent-2010-09-28-11:30      -   293K         -       -              -          -
rpool/export/[email protected]:frequent-2010-09-28-11:45      -  1.18M         -       -              -          -

My snapshots are consuming almost 18 GBs of space. However, it would appear that I could only reclaim about 2.5 GBs of space by deleting all of my snapshots. In reality, 15.5 GBs of space is referenced by 2 or more snapshots.

I can get a better idea of which snapshots might reclaim the most space by removing the space option so I get the REFER field in the output:

[email protected]:~$ zfs list -t all -r rpool/export/home
NAME                                                        USED  AVAIL  REFER  MOUNTPOINT
rpool/export/home                                          35.2G  25.4G  17.3G  /export/home
rpool/export/[email protected]:monthly-2010-08-03-09:30    166M      -  15.5G  -
rpool/export/[email protected]:30              5.06M      -  28.5G  -
rpool/export/[email protected]:56              5.15M      -  28.5G  -
rpool/export/[email protected]:12              54.6M      -  15.5G  -
rpool/export/[email protected]:monthly-2010-09-01-00:00   53.8M      -  15.5G  -
rpool/export/[email protected]:weekly-2010-09-08-00:00    95.8M      -  15.5G  -
rpool/export/[email protected]:04              53.9M      -  17.4G  -
rpool/export/[email protected]:weekly-2010-09-15-00:00    2.06G      -  19.4G  -
rpool/export/[email protected]:weekly-2010-09-22-00:00    89.7M      -  15.5G  -
rpool/export/[email protected]:frequent-2010-09-28-11:15   293K      -  17.3G  -
rpool/export/[email protected]:frequent-2010-09-28-11:30   293K      -  17.3G  -
rpool/export/[email protected]:frequent-2010-09-28-11:45  1.18M      -  17.3G  -
rpool/export/[email protected]:hourly-2010-09-28-12:00        0      -  17.3G  -
rpool/export/[email protected]:frequent-2010-09-28-12:00      0      -  17.3G  -

In the above output, I can see that 2 snapshots, taken 26 seconds apart, are referring to 28.5 GBs of disk space. If I were to delete one of those snapshots and check the zfs list output again:

[email protected]:~$ pfexec zfs destroy rpool/export/[email protected]:30
[email protected]:~$ zfs list -t all -r rpool/export/home
NAME                                                        USED  AVAIL  REFER  MOUNTPOINT
rpool/export/home                                          35.2G  25.4G  17.3G  /export/home
rpool/export/[email protected]:monthly-2010-08-03-09:30    166M      -  15.5G  -
rpool/export/[email protected]:56              12.5G      -  28.5G  -
rpool/export/[email protected]:12              54.6M      -  15.5G  -
rpool/export/[email protected]:monthly-2010-09-01-00:00   53.8M      -  15.5G  -
rpool/export/[email protected]:weekly-2010-09-08-00:00    95.8M      -  15.5G  -
rpool/export/[email protected]:04              53.9M      -  17.4G  -
rpool/export/[email protected]:weekly-2010-09-15-00:00    2.06G      -  19.4G  -
rpool/export/[email protected]:weekly-2010-09-22-00:00    89.7M      -  15.5G  -
rpool/export/[email protected]:frequent-2010-09-28-11:15   293K      -  17.3G  -
rpool/export/[email protected]:frequent-2010-09-28-11:30   293K      -  17.3G  -
rpool/export/[email protected]:frequent-2010-09-28-11:45  1.18M      -  17.3G  -
rpool/export/[email protected]:frequent-2010-09-28-12:00   537K      -  17.3G  -

I can now clearly see that the remaining snapshot is using 12.5 GBs of space and deleting this snapshot would reclaim much needed space on my laptop:

[email protected]:~$ zpool list rpool
NAME    SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
rpool   149G   120G  28.5G    80%  ONLINE  -
[email protected]:~$ pfexec zfs destroy rpool/export/[email protected]:56
[email protected]:~$ zpool list rpool
NAME    SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
rpool   149G   108G  41.0G    72%  ONLINE  -

And that should be enough to keep Time Slider humming along smoothly and prevent the warning dialog from appearing (lucky you if you haven‘t seen that yet).

https://blogs.oracle.com/observatory/entry/understanding_the_space_used_by

Understanding the Space Used by ZFS -- (转)

时间: 2024-08-28 20:24:29

Understanding the Space Used by ZFS -- (转)的相关文章

操作系统的运行流程了解+定时器和串口例程了解

http://blog.sina.com.cn/s/blog_1556e73ba0102w62k.htmlhttp://blog.sina.com.cn/s/blog_1556e73ba0102w62j.htmlhttp://blog.sina.com.cn/s/blog_1556e73ba0102w62i.htmlhttp://blog.sina.com.cn/s/blog_1556e73ba0102w62f.htmlhttp://blog.sina.com.cn/s/blog_1556e73

开发环境搭建及常见问题解决方法

http://blog.sina.com.cn/s/blog_1556e73ba0102w62k.htmlhttp://blog.sina.com.cn/s/blog_1556e73ba0102w62j.htmlhttp://blog.sina.com.cn/s/blog_1556e73ba0102w62i.htmlhttp://blog.sina.com.cn/s/blog_1556e73ba0102w62f.htmlhttp://blog.sina.com.cn/s/blog_1556e73

基础拾遗类型语法基础和内存管理基础

http://www.zfs.cn/home.php?mod=space&uid=674359 http://www.zfs.cn/home.php?mod=space&uid=674360 http://www.zfs.cn/home.php?mod=space&uid=674361 http://www.zfs.cn/home.php?mod=space&uid=674363 http://www.zfs.cn/home.php?mod=space&uid=67

前端也要学点数据结构神奇的树状数组的三大应用

http://www.zfs.cn/home.php?mod=space&uid=674359 http://www.zfs.cn/home.php?mod=space&uid=674360 http://www.zfs.cn/home.php?mod=space&uid=674361 http://www.zfs.cn/home.php?mod=space&uid=674363 http://www.zfs.cn/home.php?mod=space&uid=67

无论工作还是学习C语言的朋友都看看吧!

http://www.zfs.cn/home.php?mod=space&uid=674359 http://www.zfs.cn/home.php?mod=space&uid=674360 http://www.zfs.cn/home.php?mod=space&uid=674361 http://www.zfs.cn/home.php?mod=space&uid=674363 http://www.zfs.cn/home.php?mod=space&uid=67

模拟百度登录并到指定网站评论回帖

http://www.zfs.cn/home.php?mod=space&uid=674782&do=profile&from=spacehttp://www.zfs.cn/home.php?mod=space&uid=674783&do=profile&from=spacehttp://www.zfs.cn/home.php?mod=space&uid=674784&do=profile&from=spacehttp://www.z

群蚁算法理论与实践全攻略旅行商等路径优化问题的新方法

http://www.zfs.cn/home.php?mod=space&uid=674782&do=profile&from=spacehttp://www.zfs.cn/home.php?mod=space&uid=674783&do=profile&from=spacehttp://www.zfs.cn/home.php?mod=space&uid=674784&do=profile&from=spacehttp://www.z

中什么情况会导致索引查找变成索引扫描

http://www.zfs.cn/home.php?mod=space&uid=674782&do=profile&from=spacehttp://www.zfs.cn/home.php?mod=space&uid=674783&do=profile&from=spacehttp://www.zfs.cn/home.php?mod=space&uid=674784&do=profile&from=spacehttp://www.z

Python爬虫|深入请求(四)常见的反爬机制以及应对方法

作者:David Qian 链接:https://zhuanlan.zhihu.com/p/21558661 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 大家好!我是厦门大学王亚南经济研究院的大一学生,今天将由我来为大家介绍一下常见的反爬机制以及应对方法. 注:非商业转载注明作者即可,商业转载请联系作者授权并支付稿费.本人已授权"维权骑士"网站(http://rightknights.com)对我在知乎发布文章的版权侵权行为进行追究与维权. ---