• Stars
    star
    414
  • Rank 104,550 (Top 3 %)
  • Language
    D
  • License
    GNU General Publi...
  • Created about 4 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

sampling disk usage profiler for btrfs

btdu - sampling disk usage profiler for btrfs

Some btrfs features may make it difficult to estimate what disk space is being used for:

  • Subvolumes allow cheap copy-on-write snapshots of entire filesystem trees, with unmodified data being shared among snapshots
  • File and extent cloning allow creating cheap copies of files or parts thereof, with extents being stored only once
  • Compression transparently allows further reducing disk usage

For these reasons, classic disk usage analyzers such as ncdu cannot provide an accurate depiction of actual disk usage. (btrfs compression in particular is challenging to classic analyzers, and special tools must be used to query compressed usage.)

btdu is a sampling disk usage profiler for btrfs. It works according to the following algorithm:

  1. Pick a random point on the disk in use
  2. Find what is located at that point
  3. Add the path to the results
  4. Repeat the above steps indefinitely

Though it works by taking random samples, it is "eventually" accurate.

It differs from classic analyzers through the following properties:

  • btdu starts showing results instantly. Though wildly inaccurate at first, they become progressively more accurate the longer btdu is allowed to run.
  • btdu analyzes entire filesystems only. There is no way to analyze only a particular subdirectory or subvolume.
  • btdu counts extents used by multiple files only once. (The shortest path is used when placing the sample in the tree for visualization.)
  • By nature of its algorithm, btdu works correctly with compression and other btrfs filesystem features.
  • Because it queries raw filesystem metadata, btdu requires root privileges to run.

Use cases

  • Quickly summarize space usage

    btdu needs to collect only 100 samples to achieve a ~1% resolution, which means it can identify space hogs very quickly. This is useful if the disk is full, and some space must be freed urgently to restore normal operation.

  • Estimate snapshot size

    When an extent is in use by multiple files or snapshots, to decide where to place it in the browsable tree, btdu picks the path with the shortest length, or the lexicographically smaller path if the length is the same. An emergent effect of this property is that it can be used to estimate snapshot size, if your snapshots use a fixed-length lexicographically-ordered naming scheme (such as e.g. YYYY-MM-DD-HH-MM-SS): the size of snapshots displayed in btdu will thus indicate data that occurs in that snapshot or any later one, i.e. the amount of "new" data in that snapshot.

  • Estimate compressed data size

    If you use btrfs data compression (whether to save space, improve performance, or conserve flash writes), btdu can be used to estimate how much real disk space compressed data uses.

  • Estimate unreachable extent size

    A feature unique to btdu is the ability to estimate the amount of space used by unreachable parts of extents, i.e. data in extents containing older versions of file content which has since been overwritten. This btrfs "dark matter" can be an easily overlooked space hog, which can be eliminated by rewriting or defragmenting affected files.

  • Understand btrfs space usage

    btdu shows explanations for hierarchy objects and common errors, which can help understand how btrfs uses disk space. The --expert mode enables the collection and display of additional size metrics, providing more insight into the allocation of objects with non-trivial sharing. Logical and physical sampling modes can help understand RAID space usage, especially when using multiple profiles.

Installation

Packaging status

btdu can be installed in one of the following ways:

  • Via package manager, if it is packaged by your distribution (see on the right).
  • Download a static binary from the releases page or the latest CI run.
  • Clone this repository and build from source (see below).

Building

  1. Install a D compiler.
    Note that you will need a compiler supporting D v2.097 or newer - the compiler in your distribution's repositories might be too old.
  2. Install Dub, if it wasn't included with your D compiler.
  3. Install libncursesw5-dev, or your distribution's equivalent package.
  4. Run dub build -b release

Usage

Run btdu with root privileges as follows:

# btdu /path/to/filesystem/root

Note: The indicated path must be to the top-level subvolume (otherwise btdu will be unable to open other subvolumes for inode resolution). If in doubt, mount the filesystem to a new mountpoint with -o subvol=/,subvolid=5.

You can start browsing the results instantly; btdu will keep collecting samples to improve accuracy until it is stopped by quitting or pausing (which you can do by pressing p).

Run btdu --help for more usage information.

See CONCEPTS.md for information about some btdu / btrfs concepts, such as represented / exclusive / shared size.

Headless mode

With the --headless switch, btdu will run without the user interface. This is useful together with the --export option, which saves results to a file that can later be viewed in the UI using the --import option. For automated invocations, don't forget to specify a stop condition such as --max-time.

Example:

# btdu --headless --export=results.json --max-time=10m /path/to/filesystem/root
$ btdu --import results.json

Deleting

You can delete the selected file or directory from the filesystem by pressing d then โ‡ง ShiftY. This will recursively delete the file or directory shown as "Full path".

Deleting files during a btdu run (whether via btdu or externally) skews the results. When deleting files from btdu, it will make a best-effort attempt to adjust the results to match. Statistics such as exclusive size may be inaccurate. Re-run btdu to obtain fresh results.

Marking

You can mark or unmark items under the cursor by pressing the space bar.

Press โ‡ง ShiftM to view all marks, and โ‡ง ShiftD then โ‡ง ShiftY to delete all marked items.

Press * to invert marks on the current screen.

Marks are saved in exported .json files; a boolean field named "mark" will be present on marked nodes. Press โ‡ง ShiftO to save an export file during an interactive session.

License

btdu is available under the GNU GPL v2. (The license is inherited from btrfs-progs.)

See Also

  • btsdu, the Btrfs Snapshot Disk Usage Analyzer

More Repositories

1

aconfmgr

A configuration manager for Arch Linux
Shell
931
star
2

RABCDAsm

Robust ABC (ActionScript Bytecode) [Dis-]Assembler
D
411
star
3

DFeed

D news aggregator, newsgroup client, web newsreader and IRC bot
D
368
star
4

dhcptest

Cross-platform DHCP test client
D
315
star
5

trimcheck

SSD TRIM check tool for Windows
D
236
star
6

ae

An auxiliary general-purpose D library
D
168
star
7

DustMite

General-purpose data reduction tool
D
112
star
8

hax11

Hackbrary to Hook and Augment X11 protocol calls
C
98
star
9

term-keys

Lossless keyboard input for Emacs
Emacs Lisp
90
star
10

Digger

A tool to build D and bisect old D versions
D
56
star
11

AutoMouseLock

Multi-monitor gaming helper
C++
34
star
12

WormKit

W:A Extension Framework
Pascal
30
star
13

wp2git

Downloads and imports Wikipedia page histories to a git repository
D
27
star
14

DuolingoMoreKeys

JavaScript
24
star
15

SlimD

Bare-bones D on Win32
D
20
star
16

swfutilsex

Some classes that use or extend the Adobe Flex 4 SDK that may be useful for reverse engineering.
Java
20
star
17

dmdprof

DMD compilation time profiler
Python
19
star
18

DBuildStat

Tools to measure and visualize performance of building D programs
D
17
star
19

tree-sitter-d

JavaScript
17
star
20

Ditto

Fork of Ditto Clipboard Manager
C++
14
star
21

TrenD

D stats/benchmarks and historic results
JavaScript
13
star
22

MMTool-Extract-All

D
12
star
23

csfo4

Fallout 4 native mods
D
11
star
24

MyWormNET2

WormNET server written in D
D
11
star
25

dscripten-tools

Alternative build toolchain for Dscripten
D
11
star
26

LiteUnits

Lightweight Delphi units to replace heavy system units like SysUtils. I did not write these, I only maintain them for personal projects.
Pascal
11
star
27

dlint

D
10
star
28

thincow

Create a deduplicated, COW view of block devices as a FUSE filesystem
D
9
star
29

DMapTreeMap

Visualizes D map files in a treemap
D
9
star
30

EnvMan

FAR plugin for comfortable management of environment variables
Pascal
9
star
31

steamkeyactivator

Cross-platform Steam bulk key activator
D
9
star
32

dcaptcha

CAPTCHA for D programming websites
D
8
star
33

keygen.js

<keygen> polyfill for modern browsers
JavaScript
8
star
34

Diamond

D memory debugger and profiler
D
8
star
35

DDD

Generic External-Memory Delayed-Duplicate-Detection Search Engine for Implicit Graphs. Based on Kwirk DDD solver ( http://github.com/CyberShadow/kwirk ).
C++
7
star
36

D-dot-git

Git repository generator for all D components
D
7
star
37

graphstudio

Fork of MONOGRAM GraphStudio
C++
7
star
38

misc

Miscellaneous (non-script) utilities to complement my dotfiles
D
7
star
39

FiddlerAutoCapture

Fiddler extension to automatically save all content hierarchically
C#
7
star
40

DAppenderResearch

Benchmarks and experiments in writing appenders in D
D
6
star
41

turbotuber

relentless external youtube-dl downloader for YouTube
D
6
star
42

cacheset64

64-bit CacheSet
C++
6
star
43

squelch

D
6
star
44

dbt-mode

Emacs Lisp
5
star
45

rtf2any

D
5
star
46

putty-terminfo

Attempt at a better terminfo for PuTTY
5
star
47

steamguides

Steam Guide Uploader
D
5
star
48

MyWormNET

Personal WormNET server software
PHP
5
star
49

data.d

D wrapper for raw data located in unmanaged memory.
D
5
star
50

SimpleIndent

C++
5
star
51

term-title

Emacs Lisp
5
star
52

ProcMonTools

Process Monitor stuff
D
5
star
53

ripfs

Simple deduplicating userspace filesystem for recordings of Internet radio stations.
D
5
star
54

ProSnooper

ProSnooper is an application that lets you connect to WormNET, chat on the channels, join and host games.
Pascal
5
star
55

KeyboardEmperor

Kernel-mode hack to speed up USB keyboards [I have no idea what I'm doing]
C
5
star
56

DBugTests

Curated D issue test case database
D
4
star
57

FAR

Obsolete, see https://github.com/CyberShadow/farmanager
C++
4
star
58

UniUpload

CyberShadow's file uploader
Pascal
4
star
59

TextNavigate

Obsolete. See:
C++
4
star
60

DDD-Kwirk

Kwirk module for generic DDD solver ( http://github.com/CyberShadow/DDD )
C++
4
star
61

xmacro

Fork of the xmacro program with some essential fixes
C
4
star
62

GHDaemon

Caching GitHub API proxy for Digger
D
4
star
63

ForumAntiSpam

Client-side forum spam filter
D
4
star
64

localcmdhistory

C++
4
star
65

colorout

Colorize your compilerโ€™s output
D
3
star
66

cyberzshadow

My zsh theme
Shell
3
star
67

d-btrfs

D
3
star
68

win32

Shell
3
star
69

TimeTracker

Minimalistic time-tracking program for Windows
D
3
star
70

json2colorer

Utility to convert DMD .json output to Colorer wordlists
D
3
star
71

cirun

[WORK IN PROGRESS] Stand-alone CI test runner
D
3
star
72

ColorCalc

Command-line calculator for hex RGB colors.
D
3
star
73

image-quality

Quantifying generation loss using machine learning
Python
3
star
74

kwirk

Kwirk C++ solver. Obsolete, this project was split up into a generic DDD engine ( http://github.com/CyberShadow/DDD ) and the Kwirk module for it ( http://github.com/CyberShadow/DDD-Kwirk ).
C++
3
star
75

DDraw

Deprecated project, merged into ae:
D
2
star
76

monocre

D
2
star
77

DomainManager

D
2
star
78

pas2d

Simplistic text processor for doing part of grungework of Pascal->D conversion.
D
2
star
79

DvorakLayouts

Dvorak keyboard layouts
Shell
2
star
80

ShellUtils

Some stuff that goes into /usr/local/bin on my machines
Shell
2
star
81

Drain

D
2
star
82

metahumble

HumbleBundle Metalink generator
Python
2
star
83

multishellcheck

Lint multi-file scripts with ShellCheck
Shell
2
star
84

reduce

General-purpose data reduction tool
D
2
star
85

Team15

D1/Phobos library with various (mostly network) code
D
2
star
86

photosensitivity

Makefile
2
star
87

rwm

Remote Window Manager - list and manipulate windows remotely
D
2
star
88

SteamKeyAdder

Easily add bundle/retail keys to your Steam account
D
2
star
89

function_factory

D
2
star
90

ColorerVCLog

Combine Visual C++ build logs with colorer HTML output
D
2
star
91

DAutoTest

My D autotester (currently for just the documentation)
D
2
star
92

git-splice

Programs to splice histories of git repositories
D
2
star
93

ddoc2ghmd

Extremely simple filter to convert DMD Ddoc output to github Markdown
D
2
star
94

CpuUsageMon

D
2
star
95

AutoFix

D
2
star
96

PuttySessionsToSSH

Convert PuTTY sessions to OpenSSH config
D
2
star
97

SeatD

SeatD SVN mirror
D
2
star
98

dbot-server

D
1
star
99

dbot-client

D
1
star
100

dchmgen

D CHM generator
D
1
star