1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 21:35:45 +02:00

462 Commits

Author SHA1 Message Date
Zygo Blaxell
7548d865a0 docs: event counter documentation
This may help users understand some of the things that happen inside
bees...or it may just be horribly long and confusing.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2019-01-07 22:48:16 -05:00
Zygo Blaxell
4021dd42ca task: queue and run exactly once per instance
Enable much simpler Task management:  each time a Task needs to be done
at least once in the future, simply invoke the run() method on the Task.
The Task will ensure that it only runs once, only appears in a queue
once, and will run again if a run request is made while the Task is
already running.

Make the queue policy a member of the Task rather than a method.  This
enables Tasks to reschedule themselves, possibly on the appropriate queue
if we have more than one of those some day.

This happens to make Tasks more similar to Linux kernel workers.
This similarity is coincidental, but not undesirable.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2019-01-07 22:48:15 -05:00
Zygo Blaxell
e1de933f93 docs: add some notes about interactions with balance
Prompted by discussion at https://github.com/Zygo/bees/issues/105

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2019-01-07 22:48:15 -05:00
Zygo Blaxell
f41fd73760 docs: add Gotcha for SIGTERM
This summarizes the discussion at:

	https://github.com/Zygo/bees/issues/100

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2019-01-06 01:54:57 -05:00
Zygo Blaxell
d583700962 docs: describe expected exceptions and impact of exception handling
Add some docs about the exceptions that are less easy to suppress
directly.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2019-01-06 01:54:57 -05:00
Zygo Blaxell
be2c55119e bees: make exceptions less prominent in log output
Introduce a mechanism to suppress exceptions which do not produce a
full stack trace for common known cases where a loop should be aborted.
Use this mechanism to suppress the infamous "FIXME" exception.

Reduce the log level to at most NOTICE, and in some cases DEBUG.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2019-01-06 01:48:35 -05:00
Zygo Blaxell
4a1971bce5 process: SIGUNUSED is deprecated
SIGUNUSED is not defined in many environments (it seems to be defined
in only one I've tried so far).  Hide the reference with #ifdef.

Fixes: https://github.com/Zygo/bees/issues/94
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-12-13 18:03:35 -05:00
Zygo Blaxell
843f78c380 docs: bees can stop now
Remove the paragraph stating otherwise.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-12-10 19:56:08 -05:00
Zygo Blaxell
5f063dd752 docs: tested with GCC 6.3.0
Update the list of compiler versions tested.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-12-09 23:39:44 -05:00
Zygo Blaxell
7933ccb660 build: make libcrucible a static library
libcrucible at one time in the distant past had to be a shared library
to force global C++ object initialization; however, this is no longer
required.

Make libcrucible static to solve various rpath and soname versioning
issues, especially when distros try (unwisely) to package the library
separately.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-12-09 23:39:44 -05:00
Zygo Blaxell
f17cf084e6 hash: clean up comments, audit for bugs
We stopped supporting shared hash tables a long time ago.  Remove comments
describing the behavior of shared hash tables.

Add an event counter for pushing a hash to the front when it is already at
the front.

Audited the code for a bug related to bucket handling that impairs space
efficiency when the bucket size is greater than 1.  Didn't find one.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-12-09 23:39:44 -05:00
Zygo Blaxell
570b3f7de0 bees: handle SIGTERM and SIGINT, force immediate flush and exit
Capture SIGINT and SIGTERM and shut down, preserving current completed
crawl and hash table state.

  * Executing tasks are completed, queued tasks are paused.
  * Crawl state is saved.
  * The crawl master and crawl writeback threads are terminated.
  * The task queue is flushed.
  * Dirty hash table extents are flushed.
  * Hash prefetch and writeback threads are terminated.
  * Hash table is deallocated.
  * FD caches and tmpfiles are destroyed.
  * Assuming the above didn't crash or deadlock, bees exits.

The above order isn't the fastest, but it does roughly follow the
shared_ptr dependencies and avoids data races--especially those that
might lead to bees reporting an extent scanned when it was only queued
for future scanning that did not occur.

In case of a violation of expected shared_ptr dependency order,
exceptions in BeesContext child object accessor methods (i.e. roots(),
hash_table(), etc) prevent any further progress in threads that somehow
remain unexpectedly active.

Move some threads from main into BeesContext so they can be stopped
via BeesContext.  The main thread now runs a loop waiting for signals.

A slow FD leak was discovered in TempFile handling.  This has not been
fixed yet, but an implementation detail of the C++ runtime library makes
the leak so slow it may never be important enough to fix.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-12-09 23:39:44 -05:00
Zygo Blaxell
cbc6725f0f time: separate sleep time calculation from sleep_for method
We need to replace nanosleeps with condition variables so that we
can implement BeesContext::stop.  Export the time calculation from
sleep_for() into a new method called sleep_time().

If the thread executing RateLimiter::sleep_for() is interrupted, it will
no longer be able to restart, as the sleep_time() method is destructive.
This calls for further refactoring of sleep_time() into destructive
and non-destructive parts; however, there are currently no users of
sleep_for() which rely on being able to restart after being interrupted
by a signal.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-12-09 23:45:52 -05:00
Zygo Blaxell
0e42c75f5a process: ntoa function for signals
This enables signal numbers to be translated to names.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-12-09 23:45:52 -05:00
Zygo Blaxell
4e962172a7 task: add cancel method
Add a method to have TaskMaster discard any entries in its queue, terminate
all worker threads, and prevent any new Tasks from being queued.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-12-09 01:15:24 -05:00
Zygo Blaxell
389dd52cc1 tempfile: drop the fsync()
The deadlock seems to be fixed now (if there ever was one--there certainly
were deadlocks, but matching deadlocks to root causes is non-trivial
and a number of distinct deadlock cases have been fixed in recent years).

The benchmark data is inconclusive about whether it is better to fsync or
not to fsync.  A paranoia option might be useful here.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-12-09 01:00:36 -05:00
Zygo Blaxell
f4464c6896 roots: quick fix for task scheduling bug leading to loss of crawl_master
The crawl_master task had a simple atomic variable that was supposed
to prevent duplicate crawl_master tasks from ending up in the queue;
however, this had a race condition that could lead to m_task_running
being set with no crawl_master task running to clear it.  This would in
turn prevent crawl_thread from scheduling any further crawl_master tasks,
and bees would eventually stop doing any more work.

A proper fix is to modify the Task class and its friends such that
Task::run() guarantees that 1) at most one instance of a Task is ever
scheduled or running at any time, and 2) if a Task is scheduled while
an instance of the Task is running, the scheduling is deferred until
after the current instance completes.  This is part of a fairly large
planned change set, but it's not ready to push now.

So instead, unconditionally push a new crawl_master Task into the queue
on every poll, then silently and quickly exit if the queue is too full
or the supply of new extents is empty.  Drop the scheduling-related
members of BeesRoots as they will not be needed when the proper fix lands.

Fixes: 4f0bc78a "crawl: don't block a Task waiting for new transids"
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-25 23:46:55 -05:00
Zygo Blaxell
f051d96d51 docs: dash more useful than previously believed
It turns out both dash and bash support `command -v` so let's use that.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-25 23:21:52 -05:00
Zygo Blaxell
ba5fda1605 docs: use bash "type -p" because dash isn't useful
If /bin/sh is bash, the 'type' builtin produces a list of filenames
that match the arguments to $PATH.

If /bin/sh is dash, we get errors like:

	/bin/sh: 1: P:: not found

Hopefully having a build-dep on bash is not controversial.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-22 21:37:09 -05:00
Zygo Blaxell
6cf16c4849 docs: add instructions for Ubuntu 18.10
As described in https://github.com/Zygo/bees/issues/88

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-22 21:36:39 -05:00
Zygo Blaxell
5a80ce5cd6 README: reintroduce new btrfs-send-compatibility workaround
Now it appears in both the github.io and github.com feature lists.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-22 21:22:10 -05:00
Zygo Blaxell
012219bbfb docs: derive docs/index.md from README.md
The two files are identical except README.md links to docs/* while
index.md links to *.

A sed script can do that transformation, so use sed to do it.

This does modify a file in git, but this is necessary to make all
the Github views work consistently.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-22 21:21:29 -05:00
Zygo Blaxell
bf2a014607 roots: improve "RO root 6094" message
This sequence of log messages isn't clear:

	crawl_master: WORKAROUND: Avoiding RO subvol 6094
	crawl_master: WORKAROUND: RO root 6094

The first is from a cache miss, and appears wherever a root is opened
(dedupe or crawl).  The second is skipping an entire subvol scan, and
only happens in crawl_master.

Elaborate on the second message a little.

Also use the term "root" consistently when referring to subvol tree IDs.
btrfs refers to these objects by (at least) three distinct names:  tree,
subvol, and root.  Using three different words for the same thing is worse
than using a single wrong word consistently to refer to the same concept.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-22 21:10:15 -05:00
Zygo Blaxell
cdca2bcdcd main: single BeesContext instance per process
After weeks of testing I copied part of a change to main without copying
the rest of the change, leading to an immediate segfault on startup.

So here is the rest of the change:  limit the number of
BeesContexts per process to 1.  This change was discussed at
https://github.com/Zygo/bees/issues/54#issuecomment-360332529 but there
are more reasons to do it now:  the candidates to replace the current
hash table format are less forgiving of sharing hash tables, and it may
even become necessary to have more than one hash table per BeesContext
instance (e.g. to keep datasum and nodatasum data separate).

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-22 20:40:30 -05:00
Zygo Blaxell
e0c8df6809 docs: working with btrfs send is kind of a feature
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-21 23:19:37 -05:00
Zygo Blaxell
34b04f4255 bees: soft-limit computed thread counts to 8
https://github.com/Zygo/bees/issues/91 describes problems encountered
when running bees on systems with many CPU cores.

Limit the computed number of threads (using --thread-factor or the
default) to a maximum of 8 (i.e. the number of logical cores in a modern
laptop).  Users can override the limit by using --thread-count.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-21 21:49:16 -05:00
Zygo Blaxell
d9c788d30a docs: reorganize options, add workaround for btrfs send
options.md was a disorganized mess that markdown couldn't parse properly.

Break the options list down into sections by theme.  Add the new
'--workaround-btrfs-send' option to the new 'Workarounds' section.

Clean up the rest of the text and fix some inconsistencies.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-21 21:49:16 -05:00
Zygo Blaxell
23f3e4ec42 workarounds: add workaround for btrfs send
Introduce --workaround options which trade performance or effectiveness to
avoid triggering kernel bugs.

The first such option is --workaround-btrfs-send, which avoids making any
modification to read-only subvols to avoid btrfs send bugs.

Clean up usage message:  no tabs for formatting, split options into
sections by theme.

Make scan mode a non-static data member like all (most?) other options.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-21 21:49:16 -05:00
Kai Krakow
6c68e81da7
Makefile: Fix git usage for non-git source archive
We didn't take enough care to fix all invocations of git in this
scenario.

Fixes: 32d2739 ("Makefile: Specify version when building from tarball")
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-11-18 16:10:32 +01:00
Zygo Blaxell
e74122b512 resolver: don't log hash collision incidents
The log message is quite CPU-intensive to generate, and some data sets
have enough hash collisions to throw off benchmarks.

Keep the event counter but drop the log message.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-16 17:20:49 -05:00
Zygo Blaxell
0d5c018c3c fs: if search fails, return empty result set
Make sure the result set is empty before running the ioctl in case
something tries to consume the result without checking the error status.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-16 17:20:49 -05:00
Zygo Blaxell
a676928ed5 fs: remove thread_local storage
If we are not zero-filling containers then the overhead of allocating them
on each use is negligible.  The effect that the thread_local containers
were having on RAM usage was very non-negligible.

Use dynamic containers (members or stack objects) for better control
of object lifetimes and much lower peak RAM usage.  They're a tiny bit
faster, too.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-08 23:55:13 -05:00
Zygo Blaxell
e3247d3471 stats: streamline add_count
Perf was blaming BeesStats::add_count for >1% of instructions.

Trim the instruction count a little.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-08 23:31:50 -05:00
Zygo Blaxell
19859b0a0d docs: toxic extents and btrfs send
Update documentation of toxic extent / slow backref workaround.

Add notes about btrfs send kernel bugs and incremental send failures.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-08 21:31:02 -05:00
Kai Krakow
688d0dc014
crucible: Try repairing a build failure around swap macro
Gentoo-Bug: https://bugs.gentoo.org/670606
Fixes: https://github.com/Zygo/bees/issues/85
Suggested-by: Zygo Blaxell <bees@furryterror.org>
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-11-08 19:29:11 +01:00
Kai Krakow
c69a954d8f
Makefile: Bring back -O3 in a downstream-compatible way
This commit brings back -O3 but in an overridable way. This should make
downstream distributions happy enough to accept it.

While at the subject, let's apply the same fixup logic to LDFLAGS, too.

This commit also properly gets rid of the implicit rules which collided
too easily with the depends.mk.

Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-11-08 03:23:40 +01:00
Kai Krakow
f2dec480a6
Makefile: mkdir .depends only when needed
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-11-08 02:56:48 +01:00
Kai Krakow
d4535901a5
Makefile: Use the jobserver properly
Signed-off-by: Kai Krakow <kai@kaishome.de>
2018-11-08 02:52:04 +01:00
Zygo Blaxell
8cbd6fc67a fs: support LOGICAL_INO_V2
Automatically fall back to LOGICAL_INO if LOGICAL_INO_V2 fails and no
_V2 flags are used.

Add methods to set the flags argument with build portability to older
headers.

Use thread_local storage for the somewhat large buffers used by
LOGICAL_INO_V2 (and other users of BtrfsDataContainer like INO_PATHS).

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-05 21:12:36 -05:00
Zygo Blaxell
c2762740ef context: remove limit on the number of references to an extent
Better toxic extent detection means we can now handle extents with
many more references--easily hundreds of thousands.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-11-05 21:12:11 -05:00
rsjaffe
8bec9624da
systemd service replace deprecated parameters
Replace CPU shares and IO block weight by CPU weight and IO weight. Note that new parameters are roughly 1/100 of old one--I believe that's the right conversion. Also removed duplicate Nice parameter and alphabetized the parameters for ease of reading.
2018-11-05 12:35:17 -08:00
Zygo Blaxell
aa74a238b3 hash: remove preloaded toxic hash blacklist
Faster and more reliable toxic extent detection means we can now be much
less paranoid about creating toxic extents.

The paranoia has significant impact on dedupe hit rates because every
extent that contains even one toxic hash is abandoned.  The preloaded
toxic hashes were chosen because they occur more frequently than any
other block contents in typical filesystem data.  The combination of these
resulted in as much as 30% of duplicate extents being left untouched.

Remove the preloaded toxic extent blacklist, and rely on the new
kernel-CPU-usage-based workaround instead.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-10-31 23:03:01 -04:00
Zygo Blaxell
6e6b08ea0e scripts: put AL16M back to avoid breaking existing scripts
Leave AL16M defined in beesd to avoid breaking scripts based on
beesd.conf.sample which used this constant.

Use the absolute size in beesd.conf.sample to avoid any future problems.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-10-31 22:50:36 -04:00
Zygo Blaxell
542371684c context: better detection for toxic extents
We detect toxic extents by measuring how long the LOGICAL_INO ioctl takes
to run.  If it is above some threshold, we consider the extent toxic,
and blacklist it; otherwise, we process the extent normally.

The detector was using the execution time of the ioctl, which detects
toxic extents, but it also detects pauses of the bees process and
transaction commit latency due to load.  This leads to a significant
number of false positives.  The detection threshold was also very long,
burning a lot of kernel CPU before the detection was triggered.

Use the per-thread system CPU statistics to measure the kernel CPU usage
of the LOGICAL_INO call directly.  This is much more reliable because it
is not confounded by other threads, and it's faster because we can set
the time threshold two orders of magnitude lower.

Also remove the lock and mutex added in "context: serialize LOGICAL_INO
calls" because we theoretically no longer need it (but leave the code
there with #if 0 in case we do need it in practice).

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-10-31 21:12:16 -04:00
Zygo Blaxell
9a97699dd9 roots: reimplement transid_max_nocache using extent tree root
ROOT_TREE contains the ROOT_ITEM for EXTENT_TREE.  Every modification
(that we care about) to a btrfs must go through EXTENT_TREE, and must
modify the page in ROOT_TREE pointing to the root of EXTENT_TREE...
which makes that a very good source for the filesystem transid.

Remove the loop and the root lookups, and just look at one item for
max_transid.

Also note that every caller of transid_max_nocache() immediately
feeds the return value to m_transid_re.update(), so don't do that
inside transid_max_nocache().

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-10-31 00:09:49 -04:00
Zygo Blaxell
0e8b591232 Revert "roots: simplify BeesRoots::transid_max_nocache"
It turns out that we do need to scan all the subvols in order
to find transid_max.

Keep the bug fix though.

This reverts commit bf6ae80eeec6afcbee505d22af8e62f60dc1c9a6.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-10-30 23:29:05 -04:00
Zygo Blaxell
bf6ae80eee roots: simplify BeesRoots::transid_max_nocache
BeesRoots::transid_max_nocache calls btrfs_get_root_transid() which
retrieves the transid of the root of the given Fd.  Since the FS_TREE
(subvol 5) is the root of the subvol hierarchy, it will always have
the highest transid on the filesystem, and we do not need to look at
any others.

Also fix a bug where we pass BTRFS_FS_TREE_OBJECTID instead of the
file descriptor root_fd() to btrfs_get_root_transid().  If BEESHOME
is somewhere on the same btrfs filesystem, and there are no leaked FDs
at bees startup, then BTRFS_FS_TREE_OBJECTID (5) usually has the same
integer value as a valid file descriptor of some object on the filesystem
that has a regularly increasing transid value.  If Fd 5 happens to be a
file in BEESHOME then bees itself drives the transid increments.  This,
combined with the search of all subvol roots, hides the bug (unless Fd
5 gets closed somehow).

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-10-30 21:12:17 -04:00
Zygo Blaxell
1a51bb53bf context: cache result of home_fd()
BeesContext::home_fd() is supposed to open $BEESHOME once and cache
the Fd for later calls; however, instead it was reopening a new Fd each
time it was called, and _also_ holding that Fd in a BeesContext member.
Fds clean themselves up when they are forgotten, so it was not leaking
per se, but it certainly had more open Fds than it needed to.

Check to see if we have m_home_fd open, and return that if so.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-10-30 21:12:16 -04:00
Zygo Blaxell
35b21687bc bees: drop unused member m_uuid
There is a m_root_uuid which is used.  m_uuid is not, so drop it
and save a tiny amount of memory.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-10-30 21:12:16 -04:00
Zygo Blaxell
63ddbb9a4f context: serialize LOGICAL_INO calls
LOGICAL_INO can trip over the btrfs slow-backrefs bug, resulting in
some very long in-kernel runtimes.  If too many threads are executing
LOGICAL_INO then there may be no cores left on the system to run other
tasks.

Toxic extent detection is done by a very rudimentary algorithm which
can be confused by unrelated sources of latency within btrfs (especially
commit latency).  The algorithm can also be confused by other threads
executing the LOGICAL_INO ioctl.

These are two good reasons to prevent any two threads in a single bees
process instance from executing LOGICAL_INO at the same time, so let's
do that.

It is possible to limit the number of threads executing LOGICAL_INO with
the -c and -C options; however, this also limits the number of threads
which can perform any operation, while only LOGICAL_INO (*) has such a
profound effect on the rest of system operation.

Also make the status message clearer about exactly when LOGICAL_INO is
executed, as opposed to merely waiting to acquire a lock before executing
the ioctl.

(*) or maybe FILE_EXTENT_SAME.  The problem function that keeps showing
up in kernel stack traces is find_parent_nodes, which is called by both
the LOGICAL_INO and FILE_EXTENT_SAME ioctls.  We'll try this change
first and see if it prevents any recurrences of forced watchdog reboots;
if it does not, then we'll limit FILE_EXTENT_SAME the same way.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2018-10-30 21:12:16 -04:00