License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-03-24 07:11:31 +08:00
|
|
|
/*
|
|
|
|
* bcache sysfs interfaces
|
|
|
|
*
|
|
|
|
* Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
|
|
|
|
* Copyright 2012 Google, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bcache.h"
|
|
|
|
#include "sysfs.h"
|
|
|
|
#include "btree.h"
|
|
|
|
#include "request.h"
|
2013-06-05 21:21:07 +08:00
|
|
|
#include "writeback.h"
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2013-04-27 06:39:55 +08:00
|
|
|
#include <linux/blkdev.h>
|
2013-03-24 07:11:31 +08:00
|
|
|
#include <linux/sort.h>
|
2017-02-01 23:36:40 +08:00
|
|
|
#include <linux/sched/clock.h>
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
static const char * const cache_replacement_policies[] = {
|
|
|
|
"lru",
|
|
|
|
"fifo",
|
|
|
|
"random",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-07-12 10:42:51 +08:00
|
|
|
static const char * const error_actions[] = {
|
|
|
|
"unregister",
|
|
|
|
"panic",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-03-24 07:11:31 +08:00
|
|
|
write_attribute(attach);
|
|
|
|
write_attribute(detach);
|
|
|
|
write_attribute(unregister);
|
|
|
|
write_attribute(stop);
|
|
|
|
write_attribute(clear_stats);
|
|
|
|
write_attribute(trigger_gc);
|
|
|
|
write_attribute(prune_cache);
|
|
|
|
write_attribute(flash_vol_create);
|
|
|
|
|
|
|
|
read_attribute(bucket_size);
|
|
|
|
read_attribute(block_size);
|
|
|
|
read_attribute(nbuckets);
|
|
|
|
read_attribute(tree_depth);
|
|
|
|
read_attribute(root_usage_percent);
|
|
|
|
read_attribute(priority_stats);
|
|
|
|
read_attribute(btree_cache_size);
|
|
|
|
read_attribute(btree_cache_max_chain);
|
|
|
|
read_attribute(cache_available_percent);
|
|
|
|
read_attribute(written);
|
|
|
|
read_attribute(btree_written);
|
|
|
|
read_attribute(metadata_written);
|
|
|
|
read_attribute(active_journal_entries);
|
|
|
|
|
|
|
|
sysfs_time_stats_attribute(btree_gc, sec, ms);
|
|
|
|
sysfs_time_stats_attribute(btree_split, sec, us);
|
|
|
|
sysfs_time_stats_attribute(btree_sort, ms, us);
|
|
|
|
sysfs_time_stats_attribute(btree_read, ms, us);
|
|
|
|
|
|
|
|
read_attribute(btree_nodes);
|
|
|
|
read_attribute(btree_used_percent);
|
|
|
|
read_attribute(average_key_size);
|
|
|
|
read_attribute(dirty_data);
|
|
|
|
read_attribute(bset_tree_stats);
|
|
|
|
|
|
|
|
read_attribute(state);
|
|
|
|
read_attribute(cache_read_races);
|
2018-02-08 03:41:39 +08:00
|
|
|
read_attribute(reclaim);
|
|
|
|
read_attribute(flush_write);
|
|
|
|
read_attribute(retry_flush_write);
|
2013-03-24 07:11:31 +08:00
|
|
|
read_attribute(writeback_keys_done);
|
|
|
|
read_attribute(writeback_keys_failed);
|
|
|
|
read_attribute(io_errors);
|
|
|
|
read_attribute(congested);
|
|
|
|
rw_attribute(congested_read_threshold_us);
|
|
|
|
rw_attribute(congested_write_threshold_us);
|
|
|
|
|
|
|
|
rw_attribute(sequential_cutoff);
|
|
|
|
rw_attribute(data_csum);
|
|
|
|
rw_attribute(cache_mode);
|
|
|
|
rw_attribute(writeback_metadata);
|
|
|
|
rw_attribute(writeback_running);
|
|
|
|
rw_attribute(writeback_percent);
|
|
|
|
rw_attribute(writeback_delay);
|
|
|
|
rw_attribute(writeback_rate);
|
|
|
|
|
|
|
|
rw_attribute(writeback_rate_update_seconds);
|
bcache: implement PI controller for writeback rate
bcache uses a control system to attempt to keep the amount of dirty data
in cache at a user-configured level, while not responding excessively to
transients and variations in write rate. Previously, the system was a
PD controller; but the output from it was integrated, turning the
Proportional term into an Integral term, and turning the Derivative term
into a crude Proportional term. Performance of the controller has been
uneven in production, and it has tended to respond slowly, oscillate,
and overshoot.
This patch set replaces the current control system with an explicit PI
controller and tuning that should be correct for most hardware. By
default, it attempts to write at a rate that would retire 1/40th of the
current excess blocks per second. An integral term in turn works to
remove steady state errors.
IMO, this yields benefits in simplicity (removing weighted average
filtering, etc) and system performance.
Another small change is a tunable parameter is introduced to allow the
user to specify a minimum rate at which dirty blocks are retired.
There is a slight difference from earlier versions of the patch in
integral handling to prevent excessive negative integral windup.
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 07:35:36 +08:00
|
|
|
rw_attribute(writeback_rate_i_term_inverse);
|
2013-03-24 07:11:31 +08:00
|
|
|
rw_attribute(writeback_rate_p_term_inverse);
|
bcache: implement PI controller for writeback rate
bcache uses a control system to attempt to keep the amount of dirty data
in cache at a user-configured level, while not responding excessively to
transients and variations in write rate. Previously, the system was a
PD controller; but the output from it was integrated, turning the
Proportional term into an Integral term, and turning the Derivative term
into a crude Proportional term. Performance of the controller has been
uneven in production, and it has tended to respond slowly, oscillate,
and overshoot.
This patch set replaces the current control system with an explicit PI
controller and tuning that should be correct for most hardware. By
default, it attempts to write at a rate that would retire 1/40th of the
current excess blocks per second. An integral term in turn works to
remove steady state errors.
IMO, this yields benefits in simplicity (removing weighted average
filtering, etc) and system performance.
Another small change is a tunable parameter is introduced to allow the
user to specify a minimum rate at which dirty blocks are retired.
There is a slight difference from earlier versions of the patch in
integral handling to prevent excessive negative integral windup.
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 07:35:36 +08:00
|
|
|
rw_attribute(writeback_rate_minimum);
|
2013-03-24 07:11:31 +08:00
|
|
|
read_attribute(writeback_rate_debug);
|
|
|
|
|
2013-06-05 21:24:39 +08:00
|
|
|
read_attribute(stripe_size);
|
|
|
|
read_attribute(partial_stripes_expensive);
|
|
|
|
|
2013-03-24 07:11:31 +08:00
|
|
|
rw_attribute(synchronous);
|
|
|
|
rw_attribute(journal_delay_ms);
|
|
|
|
rw_attribute(discard);
|
|
|
|
rw_attribute(running);
|
|
|
|
rw_attribute(label);
|
|
|
|
rw_attribute(readahead);
|
2013-07-12 10:42:51 +08:00
|
|
|
rw_attribute(errors);
|
2013-03-24 07:11:31 +08:00
|
|
|
rw_attribute(io_error_limit);
|
|
|
|
rw_attribute(io_error_halflife);
|
|
|
|
rw_attribute(verify);
|
2013-09-11 05:27:42 +08:00
|
|
|
rw_attribute(bypass_torture_test);
|
2013-03-24 07:11:31 +08:00
|
|
|
rw_attribute(key_merging_disabled);
|
|
|
|
rw_attribute(gc_always_rewrite);
|
2013-10-25 07:36:03 +08:00
|
|
|
rw_attribute(expensive_debug_checks);
|
2013-03-24 07:11:31 +08:00
|
|
|
rw_attribute(cache_replacement_policy);
|
|
|
|
rw_attribute(btree_shrinker_disabled);
|
|
|
|
rw_attribute(copy_gc_enabled);
|
|
|
|
rw_attribute(size);
|
|
|
|
|
|
|
|
SHOW(__bch_cached_dev)
|
|
|
|
{
|
|
|
|
struct cached_dev *dc = container_of(kobj, struct cached_dev,
|
|
|
|
disk.kobj);
|
|
|
|
const char *states[] = { "no cache", "clean", "dirty", "inconsistent" };
|
|
|
|
|
|
|
|
#define var(stat) (dc->stat)
|
|
|
|
|
|
|
|
if (attr == &sysfs_cache_mode)
|
2013-03-29 02:50:55 +08:00
|
|
|
return bch_snprint_string_list(buf, PAGE_SIZE,
|
|
|
|
bch_cache_modes + 1,
|
|
|
|
BDEV_CACHE_MODE(&dc->sb));
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
sysfs_printf(data_csum, "%i", dc->disk.data_csum);
|
|
|
|
var_printf(verify, "%i");
|
2013-09-11 05:27:42 +08:00
|
|
|
var_printf(bypass_torture_test, "%i");
|
2013-03-24 07:11:31 +08:00
|
|
|
var_printf(writeback_metadata, "%i");
|
|
|
|
var_printf(writeback_running, "%i");
|
|
|
|
var_print(writeback_delay);
|
|
|
|
var_print(writeback_percent);
|
2013-11-12 05:58:34 +08:00
|
|
|
sysfs_hprint(writeback_rate, dc->writeback_rate.rate << 9);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
var_print(writeback_rate_update_seconds);
|
bcache: implement PI controller for writeback rate
bcache uses a control system to attempt to keep the amount of dirty data
in cache at a user-configured level, while not responding excessively to
transients and variations in write rate. Previously, the system was a
PD controller; but the output from it was integrated, turning the
Proportional term into an Integral term, and turning the Derivative term
into a crude Proportional term. Performance of the controller has been
uneven in production, and it has tended to respond slowly, oscillate,
and overshoot.
This patch set replaces the current control system with an explicit PI
controller and tuning that should be correct for most hardware. By
default, it attempts to write at a rate that would retire 1/40th of the
current excess blocks per second. An integral term in turn works to
remove steady state errors.
IMO, this yields benefits in simplicity (removing weighted average
filtering, etc) and system performance.
Another small change is a tunable parameter is introduced to allow the
user to specify a minimum rate at which dirty blocks are retired.
There is a slight difference from earlier versions of the patch in
integral handling to prevent excessive negative integral windup.
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 07:35:36 +08:00
|
|
|
var_print(writeback_rate_i_term_inverse);
|
2013-03-24 07:11:31 +08:00
|
|
|
var_print(writeback_rate_p_term_inverse);
|
bcache: implement PI controller for writeback rate
bcache uses a control system to attempt to keep the amount of dirty data
in cache at a user-configured level, while not responding excessively to
transients and variations in write rate. Previously, the system was a
PD controller; but the output from it was integrated, turning the
Proportional term into an Integral term, and turning the Derivative term
into a crude Proportional term. Performance of the controller has been
uneven in production, and it has tended to respond slowly, oscillate,
and overshoot.
This patch set replaces the current control system with an explicit PI
controller and tuning that should be correct for most hardware. By
default, it attempts to write at a rate that would retire 1/40th of the
current excess blocks per second. An integral term in turn works to
remove steady state errors.
IMO, this yields benefits in simplicity (removing weighted average
filtering, etc) and system performance.
Another small change is a tunable parameter is introduced to allow the
user to specify a minimum rate at which dirty blocks are retired.
There is a slight difference from earlier versions of the patch in
integral handling to prevent excessive negative integral windup.
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 07:35:36 +08:00
|
|
|
var_print(writeback_rate_minimum);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
if (attr == &sysfs_writeback_rate_debug) {
|
2013-11-12 05:58:34 +08:00
|
|
|
char rate[20];
|
2013-03-24 07:11:31 +08:00
|
|
|
char dirty[20];
|
|
|
|
char target[20];
|
2013-11-12 05:58:34 +08:00
|
|
|
char proportional[20];
|
bcache: implement PI controller for writeback rate
bcache uses a control system to attempt to keep the amount of dirty data
in cache at a user-configured level, while not responding excessively to
transients and variations in write rate. Previously, the system was a
PD controller; but the output from it was integrated, turning the
Proportional term into an Integral term, and turning the Derivative term
into a crude Proportional term. Performance of the controller has been
uneven in production, and it has tended to respond slowly, oscillate,
and overshoot.
This patch set replaces the current control system with an explicit PI
controller and tuning that should be correct for most hardware. By
default, it attempts to write at a rate that would retire 1/40th of the
current excess blocks per second. An integral term in turn works to
remove steady state errors.
IMO, this yields benefits in simplicity (removing weighted average
filtering, etc) and system performance.
Another small change is a tunable parameter is introduced to allow the
user to specify a minimum rate at which dirty blocks are retired.
There is a slight difference from earlier versions of the patch in
integral handling to prevent excessive negative integral windup.
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 07:35:36 +08:00
|
|
|
char integral[20];
|
2013-11-12 05:58:34 +08:00
|
|
|
char change[20];
|
|
|
|
s64 next_io;
|
|
|
|
|
|
|
|
bch_hprint(rate, dc->writeback_rate.rate << 9);
|
|
|
|
bch_hprint(dirty, bcache_dev_sectors_dirty(&dc->disk) << 9);
|
2013-03-29 02:50:55 +08:00
|
|
|
bch_hprint(target, dc->writeback_rate_target << 9);
|
2013-11-12 05:58:34 +08:00
|
|
|
bch_hprint(proportional,dc->writeback_rate_proportional << 9);
|
bcache: implement PI controller for writeback rate
bcache uses a control system to attempt to keep the amount of dirty data
in cache at a user-configured level, while not responding excessively to
transients and variations in write rate. Previously, the system was a
PD controller; but the output from it was integrated, turning the
Proportional term into an Integral term, and turning the Derivative term
into a crude Proportional term. Performance of the controller has been
uneven in production, and it has tended to respond slowly, oscillate,
and overshoot.
This patch set replaces the current control system with an explicit PI
controller and tuning that should be correct for most hardware. By
default, it attempts to write at a rate that would retire 1/40th of the
current excess blocks per second. An integral term in turn works to
remove steady state errors.
IMO, this yields benefits in simplicity (removing weighted average
filtering, etc) and system performance.
Another small change is a tunable parameter is introduced to allow the
user to specify a minimum rate at which dirty blocks are retired.
There is a slight difference from earlier versions of the patch in
integral handling to prevent excessive negative integral windup.
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 07:35:36 +08:00
|
|
|
bch_hprint(integral, dc->writeback_rate_integral_scaled << 9);
|
2013-11-12 05:58:34 +08:00
|
|
|
bch_hprint(change, dc->writeback_rate_change << 9);
|
|
|
|
|
|
|
|
next_io = div64_s64(dc->writeback_rate.next - local_clock(),
|
|
|
|
NSEC_PER_MSEC);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
return sprintf(buf,
|
2013-11-12 05:58:34 +08:00
|
|
|
"rate:\t\t%s/sec\n"
|
2013-03-24 07:11:31 +08:00
|
|
|
"dirty:\t\t%s\n"
|
2013-11-12 05:58:34 +08:00
|
|
|
"target:\t\t%s\n"
|
|
|
|
"proportional:\t%s\n"
|
bcache: implement PI controller for writeback rate
bcache uses a control system to attempt to keep the amount of dirty data
in cache at a user-configured level, while not responding excessively to
transients and variations in write rate. Previously, the system was a
PD controller; but the output from it was integrated, turning the
Proportional term into an Integral term, and turning the Derivative term
into a crude Proportional term. Performance of the controller has been
uneven in production, and it has tended to respond slowly, oscillate,
and overshoot.
This patch set replaces the current control system with an explicit PI
controller and tuning that should be correct for most hardware. By
default, it attempts to write at a rate that would retire 1/40th of the
current excess blocks per second. An integral term in turn works to
remove steady state errors.
IMO, this yields benefits in simplicity (removing weighted average
filtering, etc) and system performance.
Another small change is a tunable parameter is introduced to allow the
user to specify a minimum rate at which dirty blocks are retired.
There is a slight difference from earlier versions of the patch in
integral handling to prevent excessive negative integral windup.
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 07:35:36 +08:00
|
|
|
"integral:\t%s\n"
|
2013-11-12 05:58:34 +08:00
|
|
|
"change:\t\t%s/sec\n"
|
|
|
|
"next io:\t%llims\n",
|
|
|
|
rate, dirty, target, proportional,
|
bcache: implement PI controller for writeback rate
bcache uses a control system to attempt to keep the amount of dirty data
in cache at a user-configured level, while not responding excessively to
transients and variations in write rate. Previously, the system was a
PD controller; but the output from it was integrated, turning the
Proportional term into an Integral term, and turning the Derivative term
into a crude Proportional term. Performance of the controller has been
uneven in production, and it has tended to respond slowly, oscillate,
and overshoot.
This patch set replaces the current control system with an explicit PI
controller and tuning that should be correct for most hardware. By
default, it attempts to write at a rate that would retire 1/40th of the
current excess blocks per second. An integral term in turn works to
remove steady state errors.
IMO, this yields benefits in simplicity (removing weighted average
filtering, etc) and system performance.
Another small change is a tunable parameter is introduced to allow the
user to specify a minimum rate at which dirty blocks are retired.
There is a slight difference from earlier versions of the patch in
integral handling to prevent excessive negative integral windup.
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 07:35:36 +08:00
|
|
|
integral, change, next_io);
|
2013-03-24 07:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sysfs_hprint(dirty_data,
|
2013-06-05 21:21:07 +08:00
|
|
|
bcache_dev_sectors_dirty(&dc->disk) << 9);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2013-08-17 17:13:15 +08:00
|
|
|
sysfs_hprint(stripe_size, dc->disk.stripe_size << 9);
|
2013-06-05 21:24:39 +08:00
|
|
|
var_printf(partial_stripes_expensive, "%u");
|
|
|
|
|
2013-03-24 07:11:31 +08:00
|
|
|
var_hprint(sequential_cutoff);
|
|
|
|
var_hprint(readahead);
|
|
|
|
|
|
|
|
sysfs_print(running, atomic_read(&dc->running));
|
|
|
|
sysfs_print(state, states[BDEV_STATE(&dc->sb)]);
|
|
|
|
|
|
|
|
if (attr == &sysfs_label) {
|
|
|
|
memcpy(buf, dc->sb.label, SB_LABEL_SIZE);
|
|
|
|
buf[SB_LABEL_SIZE + 1] = '\0';
|
|
|
|
strcat(buf, "\n");
|
|
|
|
return strlen(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef var
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SHOW_LOCKED(bch_cached_dev)
|
|
|
|
|
|
|
|
STORE(__cached_dev)
|
|
|
|
{
|
|
|
|
struct cached_dev *dc = container_of(kobj, struct cached_dev,
|
|
|
|
disk.kobj);
|
2018-02-08 03:41:45 +08:00
|
|
|
ssize_t v;
|
2013-03-24 07:11:31 +08:00
|
|
|
struct cache_set *c;
|
2013-06-09 06:54:48 +08:00
|
|
|
struct kobj_uevent_env *env;
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
#define d_strtoul(var) sysfs_strtoul(var, dc->var)
|
2013-11-12 05:58:34 +08:00
|
|
|
#define d_strtoul_nonzero(var) sysfs_strtoul_clamp(var, dc->var, 1, INT_MAX)
|
2013-03-24 07:11:31 +08:00
|
|
|
#define d_strtoi_h(var) sysfs_hatoi(var, dc->var)
|
|
|
|
|
|
|
|
sysfs_strtoul(data_csum, dc->disk.data_csum);
|
|
|
|
d_strtoul(verify);
|
2013-09-11 05:27:42 +08:00
|
|
|
d_strtoul(bypass_torture_test);
|
2013-03-24 07:11:31 +08:00
|
|
|
d_strtoul(writeback_metadata);
|
|
|
|
d_strtoul(writeback_running);
|
|
|
|
d_strtoul(writeback_delay);
|
2013-11-12 05:58:34 +08:00
|
|
|
|
2013-03-24 07:11:31 +08:00
|
|
|
sysfs_strtoul_clamp(writeback_percent, dc->writeback_percent, 0, 40);
|
|
|
|
|
2013-11-12 05:58:34 +08:00
|
|
|
sysfs_strtoul_clamp(writeback_rate,
|
|
|
|
dc->writeback_rate.rate, 1, INT_MAX);
|
|
|
|
|
2018-02-08 03:41:44 +08:00
|
|
|
sysfs_strtoul_clamp(writeback_rate_update_seconds,
|
|
|
|
dc->writeback_rate_update_seconds,
|
|
|
|
1, WRITEBACK_RATE_UPDATE_SECS_MAX);
|
bcache: implement PI controller for writeback rate
bcache uses a control system to attempt to keep the amount of dirty data
in cache at a user-configured level, while not responding excessively to
transients and variations in write rate. Previously, the system was a
PD controller; but the output from it was integrated, turning the
Proportional term into an Integral term, and turning the Derivative term
into a crude Proportional term. Performance of the controller has been
uneven in production, and it has tended to respond slowly, oscillate,
and overshoot.
This patch set replaces the current control system with an explicit PI
controller and tuning that should be correct for most hardware. By
default, it attempts to write at a rate that would retire 1/40th of the
current excess blocks per second. An integral term in turn works to
remove steady state errors.
IMO, this yields benefits in simplicity (removing weighted average
filtering, etc) and system performance.
Another small change is a tunable parameter is introduced to allow the
user to specify a minimum rate at which dirty blocks are retired.
There is a slight difference from earlier versions of the patch in
integral handling to prevent excessive negative integral windup.
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 07:35:36 +08:00
|
|
|
d_strtoul(writeback_rate_i_term_inverse);
|
2013-11-12 05:58:34 +08:00
|
|
|
d_strtoul_nonzero(writeback_rate_p_term_inverse);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
d_strtoi_h(sequential_cutoff);
|
|
|
|
d_strtoi_h(readahead);
|
|
|
|
|
|
|
|
if (attr == &sysfs_clear_stats)
|
|
|
|
bch_cache_accounting_clear(&dc->accounting);
|
|
|
|
|
|
|
|
if (attr == &sysfs_running &&
|
|
|
|
strtoul_or_return(buf))
|
|
|
|
bch_cached_dev_run(dc);
|
|
|
|
|
|
|
|
if (attr == &sysfs_cache_mode) {
|
2017-09-06 14:25:57 +08:00
|
|
|
v = bch_read_string_list(buf, bch_cache_modes + 1);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
if (v < 0)
|
|
|
|
return v;
|
|
|
|
|
|
|
|
if ((unsigned) v != BDEV_CACHE_MODE(&dc->sb)) {
|
|
|
|
SET_BDEV_CACHE_MODE(&dc->sb, v);
|
|
|
|
bch_write_bdev_super(dc, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == &sysfs_label) {
|
2013-09-24 14:17:28 +08:00
|
|
|
if (size > SB_LABEL_SIZE)
|
|
|
|
return -EINVAL;
|
|
|
|
memcpy(dc->sb.label, buf, size);
|
|
|
|
if (size < SB_LABEL_SIZE)
|
|
|
|
dc->sb.label[size] = '\0';
|
|
|
|
if (size && dc->sb.label[size - 1] == '\n')
|
|
|
|
dc->sb.label[size - 1] = '\0';
|
2013-03-24 07:11:31 +08:00
|
|
|
bch_write_bdev_super(dc, NULL);
|
|
|
|
if (dc->disk.c) {
|
|
|
|
memcpy(dc->disk.c->uuids[dc->disk.id].label,
|
|
|
|
buf, SB_LABEL_SIZE);
|
|
|
|
bch_uuid_write(dc->disk.c);
|
|
|
|
}
|
2013-06-09 06:54:48 +08:00
|
|
|
env = kzalloc(sizeof(struct kobj_uevent_env), GFP_KERNEL);
|
2013-07-05 14:05:46 +08:00
|
|
|
if (!env)
|
|
|
|
return -ENOMEM;
|
2013-06-09 06:54:48 +08:00
|
|
|
add_uevent_var(env, "DRIVER=bcache");
|
|
|
|
add_uevent_var(env, "CACHED_UUID=%pU", dc->sb.uuid),
|
|
|
|
add_uevent_var(env, "CACHED_LABEL=%s", buf);
|
|
|
|
kobject_uevent_env(
|
|
|
|
&disk_to_dev(dc->disk.disk)->kobj, KOBJ_CHANGE, env->envp);
|
|
|
|
kfree(env);
|
2013-03-24 07:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == &sysfs_attach) {
|
bcache: fix for data collapse after re-attaching an attached device
back-end device sdm has already attached a cache_set with ID
f67ebe1f-f8bc-4d73-bfe5-9dc88607f119, then try to attach with
another cache set, and it returns with an error:
[root]# cd /sys/block/sdm/bcache
[root]# echo 5ccd0a63-148e-48b8-afa2-aca9cbd6279f > attach
-bash: echo: write error: Invalid argument
After that, execute a command to modify the label of bcache
device:
[root]# echo data_disk1 > label
Then we reboot the system, when the system power on, the back-end
device can not attach to cache_set, a messages show in the log:
Feb 5 12:05:52 ceph152 kernel: [922385.508498] bcache:
bch_cached_dev_attach() couldn't find uuid for sdm in set
In sysfs_attach(), dc->sb.set_uuid was assigned to the value
which input through sysfs, no matter whether it is success
or not in bch_cached_dev_attach(). For example, If the back-end
device has already attached to an cache set, bch_cached_dev_attach()
would fail, but dc->sb.set_uuid was changed. Then modify the
label of bcache device, it will call bch_write_bdev_super(),
which would write the dc->sb.set_uuid to the super block, so we
record a wrong cache set ID in the super block, after the system
reboot, the cache set couldn't find the uuid of the back-end
device, so the bcache device couldn't exist and use any more.
In this patch, we don't assigned cache set ID to dc->sb.set_uuid
in sysfs_attach() directly, but input it into bch_cached_dev_attach(),
and assigned dc->sb.set_uuid to the cache set ID after the back-end
device attached to the cache set successful.
Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
Reviewed-by: Michael Lyle <mlyle@lyle.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-02-08 03:41:46 +08:00
|
|
|
uint8_t set_uuid[16];
|
|
|
|
|
|
|
|
if (bch_parse_uuid(buf, set_uuid) < 16)
|
2013-03-24 07:11:31 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2018-02-08 03:41:45 +08:00
|
|
|
v = -ENOENT;
|
2013-03-24 07:11:31 +08:00
|
|
|
list_for_each_entry(c, &bch_cache_sets, list) {
|
bcache: fix for data collapse after re-attaching an attached device
back-end device sdm has already attached a cache_set with ID
f67ebe1f-f8bc-4d73-bfe5-9dc88607f119, then try to attach with
another cache set, and it returns with an error:
[root]# cd /sys/block/sdm/bcache
[root]# echo 5ccd0a63-148e-48b8-afa2-aca9cbd6279f > attach
-bash: echo: write error: Invalid argument
After that, execute a command to modify the label of bcache
device:
[root]# echo data_disk1 > label
Then we reboot the system, when the system power on, the back-end
device can not attach to cache_set, a messages show in the log:
Feb 5 12:05:52 ceph152 kernel: [922385.508498] bcache:
bch_cached_dev_attach() couldn't find uuid for sdm in set
In sysfs_attach(), dc->sb.set_uuid was assigned to the value
which input through sysfs, no matter whether it is success
or not in bch_cached_dev_attach(). For example, If the back-end
device has already attached to an cache set, bch_cached_dev_attach()
would fail, but dc->sb.set_uuid was changed. Then modify the
label of bcache device, it will call bch_write_bdev_super(),
which would write the dc->sb.set_uuid to the super block, so we
record a wrong cache set ID in the super block, after the system
reboot, the cache set couldn't find the uuid of the back-end
device, so the bcache device couldn't exist and use any more.
In this patch, we don't assigned cache set ID to dc->sb.set_uuid
in sysfs_attach() directly, but input it into bch_cached_dev_attach(),
and assigned dc->sb.set_uuid to the cache set ID after the back-end
device attached to the cache set successful.
Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
Reviewed-by: Michael Lyle <mlyle@lyle.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-02-08 03:41:46 +08:00
|
|
|
v = bch_cached_dev_attach(dc, c, set_uuid);
|
2013-03-24 07:11:31 +08:00
|
|
|
if (!v)
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_err("Can't attach %s: cache set not found", buf);
|
2018-02-08 03:41:45 +08:00
|
|
|
return v;
|
2013-03-24 07:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == &sysfs_detach && dc->disk.c)
|
|
|
|
bch_cached_dev_detach(dc);
|
|
|
|
|
|
|
|
if (attr == &sysfs_stop)
|
|
|
|
bcache_device_stop(&dc->disk);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
STORE(bch_cached_dev)
|
|
|
|
{
|
|
|
|
struct cached_dev *dc = container_of(kobj, struct cached_dev,
|
|
|
|
disk.kobj);
|
|
|
|
|
|
|
|
mutex_lock(&bch_register_lock);
|
|
|
|
size = __cached_dev_store(kobj, attr, buf, size);
|
|
|
|
|
|
|
|
if (attr == &sysfs_writeback_running)
|
|
|
|
bch_writeback_queue(dc);
|
|
|
|
|
|
|
|
if (attr == &sysfs_writeback_percent)
|
|
|
|
schedule_delayed_work(&dc->writeback_rate_update,
|
|
|
|
dc->writeback_rate_update_seconds * HZ);
|
|
|
|
|
|
|
|
mutex_unlock(&bch_register_lock);
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct attribute *bch_cached_dev_files[] = {
|
|
|
|
&sysfs_attach,
|
|
|
|
&sysfs_detach,
|
|
|
|
&sysfs_stop,
|
|
|
|
#if 0
|
|
|
|
&sysfs_data_csum,
|
|
|
|
#endif
|
|
|
|
&sysfs_cache_mode,
|
|
|
|
&sysfs_writeback_metadata,
|
|
|
|
&sysfs_writeback_running,
|
|
|
|
&sysfs_writeback_delay,
|
|
|
|
&sysfs_writeback_percent,
|
|
|
|
&sysfs_writeback_rate,
|
|
|
|
&sysfs_writeback_rate_update_seconds,
|
bcache: implement PI controller for writeback rate
bcache uses a control system to attempt to keep the amount of dirty data
in cache at a user-configured level, while not responding excessively to
transients and variations in write rate. Previously, the system was a
PD controller; but the output from it was integrated, turning the
Proportional term into an Integral term, and turning the Derivative term
into a crude Proportional term. Performance of the controller has been
uneven in production, and it has tended to respond slowly, oscillate,
and overshoot.
This patch set replaces the current control system with an explicit PI
controller and tuning that should be correct for most hardware. By
default, it attempts to write at a rate that would retire 1/40th of the
current excess blocks per second. An integral term in turn works to
remove steady state errors.
IMO, this yields benefits in simplicity (removing weighted average
filtering, etc) and system performance.
Another small change is a tunable parameter is introduced to allow the
user to specify a minimum rate at which dirty blocks are retired.
There is a slight difference from earlier versions of the patch in
integral handling to prevent excessive negative integral windup.
Signed-off-by: Michael Lyle <mlyle@lyle.org>
Reviewed-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2017-10-14 07:35:36 +08:00
|
|
|
&sysfs_writeback_rate_i_term_inverse,
|
2013-03-24 07:11:31 +08:00
|
|
|
&sysfs_writeback_rate_p_term_inverse,
|
|
|
|
&sysfs_writeback_rate_debug,
|
|
|
|
&sysfs_dirty_data,
|
2013-06-05 21:24:39 +08:00
|
|
|
&sysfs_stripe_size,
|
|
|
|
&sysfs_partial_stripes_expensive,
|
2013-03-24 07:11:31 +08:00
|
|
|
&sysfs_sequential_cutoff,
|
|
|
|
&sysfs_clear_stats,
|
|
|
|
&sysfs_running,
|
|
|
|
&sysfs_state,
|
|
|
|
&sysfs_label,
|
|
|
|
&sysfs_readahead,
|
|
|
|
#ifdef CONFIG_BCACHE_DEBUG
|
|
|
|
&sysfs_verify,
|
2013-09-11 05:27:42 +08:00
|
|
|
&sysfs_bypass_torture_test,
|
2013-03-24 07:11:31 +08:00
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
KTYPE(bch_cached_dev);
|
|
|
|
|
|
|
|
SHOW(bch_flash_dev)
|
|
|
|
{
|
|
|
|
struct bcache_device *d = container_of(kobj, struct bcache_device,
|
|
|
|
kobj);
|
|
|
|
struct uuid_entry *u = &d->c->uuids[d->id];
|
|
|
|
|
|
|
|
sysfs_printf(data_csum, "%i", d->data_csum);
|
|
|
|
sysfs_hprint(size, u->sectors << 9);
|
|
|
|
|
|
|
|
if (attr == &sysfs_label) {
|
|
|
|
memcpy(buf, u->label, SB_LABEL_SIZE);
|
|
|
|
buf[SB_LABEL_SIZE + 1] = '\0';
|
|
|
|
strcat(buf, "\n");
|
|
|
|
return strlen(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
STORE(__bch_flash_dev)
|
|
|
|
{
|
|
|
|
struct bcache_device *d = container_of(kobj, struct bcache_device,
|
|
|
|
kobj);
|
|
|
|
struct uuid_entry *u = &d->c->uuids[d->id];
|
|
|
|
|
|
|
|
sysfs_strtoul(data_csum, d->data_csum);
|
|
|
|
|
|
|
|
if (attr == &sysfs_size) {
|
|
|
|
uint64_t v;
|
|
|
|
strtoi_h_or_return(buf, v);
|
|
|
|
|
|
|
|
u->sectors = v >> 9;
|
|
|
|
bch_uuid_write(d->c);
|
|
|
|
set_capacity(d->disk, u->sectors);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == &sysfs_label) {
|
|
|
|
memcpy(u->label, buf, SB_LABEL_SIZE);
|
|
|
|
bch_uuid_write(d->c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == &sysfs_unregister) {
|
2013-08-22 08:49:09 +08:00
|
|
|
set_bit(BCACHE_DEV_DETACHING, &d->flags);
|
2013-03-24 07:11:31 +08:00
|
|
|
bcache_device_stop(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
STORE_LOCKED(bch_flash_dev)
|
|
|
|
|
|
|
|
static struct attribute *bch_flash_dev_files[] = {
|
|
|
|
&sysfs_unregister,
|
|
|
|
#if 0
|
|
|
|
&sysfs_data_csum,
|
|
|
|
#endif
|
|
|
|
&sysfs_label,
|
|
|
|
&sysfs_size,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
KTYPE(bch_flash_dev);
|
|
|
|
|
2013-11-12 11:25:55 +08:00
|
|
|
struct bset_stats_op {
|
|
|
|
struct btree_op op;
|
|
|
|
size_t nodes;
|
|
|
|
struct bset_stats stats;
|
|
|
|
};
|
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
static int bch_btree_bset_stats(struct btree_op *b_op, struct btree *b)
|
2013-11-12 11:25:55 +08:00
|
|
|
{
|
|
|
|
struct bset_stats_op *op = container_of(b_op, struct bset_stats_op, op);
|
|
|
|
|
|
|
|
op->nodes++;
|
|
|
|
bch_btree_keys_stats(&b->keys, &op->stats);
|
|
|
|
|
|
|
|
return MAP_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2014-01-11 10:53:02 +08:00
|
|
|
static int bch_bset_print_stats(struct cache_set *c, char *buf)
|
2013-11-12 11:25:55 +08:00
|
|
|
{
|
|
|
|
struct bset_stats_op op;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
memset(&op, 0, sizeof(op));
|
|
|
|
bch_btree_op_init(&op.op, -1);
|
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
ret = bch_btree_map_nodes(&op.op, c, &ZERO_KEY, bch_btree_bset_stats);
|
2013-11-12 11:25:55 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return snprintf(buf, PAGE_SIZE,
|
|
|
|
"btree nodes: %zu\n"
|
|
|
|
"written sets: %zu\n"
|
|
|
|
"unwritten sets: %zu\n"
|
|
|
|
"written key bytes: %zu\n"
|
|
|
|
"unwritten key bytes: %zu\n"
|
|
|
|
"floats: %zu\n"
|
|
|
|
"failed: %zu\n",
|
|
|
|
op.nodes,
|
|
|
|
op.stats.sets_written, op.stats.sets_unwritten,
|
|
|
|
op.stats.bytes_written, op.stats.bytes_unwritten,
|
|
|
|
op.stats.floats, op.stats.failed);
|
|
|
|
}
|
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
static unsigned bch_root_usage(struct cache_set *c)
|
2013-03-24 07:11:31 +08:00
|
|
|
{
|
2014-03-18 14:13:56 +08:00
|
|
|
unsigned bytes = 0;
|
|
|
|
struct bkey *k;
|
|
|
|
struct btree *b;
|
|
|
|
struct btree_iter iter;
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
goto lock_root;
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
do {
|
|
|
|
rw_unlock(false, b);
|
2013-03-24 07:11:31 +08:00
|
|
|
lock_root:
|
2014-03-18 14:13:56 +08:00
|
|
|
b = c->root;
|
|
|
|
rw_lock(false, b, b->level);
|
|
|
|
} while (b != c->root);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
for_each_key_filter(&b->keys, k, &iter, bch_ptr_bad)
|
|
|
|
bytes += bkey_bytes(k);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
rw_unlock(false, b);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
return (bytes * 100) / btree_bytes(c);
|
|
|
|
}
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
static size_t bch_cache_size(struct cache_set *c)
|
|
|
|
{
|
|
|
|
size_t ret = 0;
|
|
|
|
struct btree *b;
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
mutex_lock(&c->bucket_lock);
|
|
|
|
list_for_each_entry(b, &c->btree_cache, list)
|
|
|
|
ret += 1 << (b->keys.page_order + PAGE_SHIFT);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
mutex_unlock(&c->bucket_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
static unsigned bch_cache_max_chain(struct cache_set *c)
|
|
|
|
{
|
|
|
|
unsigned ret = 0;
|
|
|
|
struct hlist_head *h;
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
mutex_lock(&c->bucket_lock);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
for (h = c->bucket_hash;
|
|
|
|
h < c->bucket_hash + (1 << BUCKET_HASH_BITS);
|
|
|
|
h++) {
|
|
|
|
unsigned i = 0;
|
|
|
|
struct hlist_node *p;
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
hlist_for_each(p, h)
|
|
|
|
i++;
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
ret = max(ret, i);
|
2013-03-24 07:11:31 +08:00
|
|
|
}
|
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
mutex_unlock(&c->bucket_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
static unsigned bch_btree_used(struct cache_set *c)
|
|
|
|
{
|
|
|
|
return div64_u64(c->gc_stats.key_bytes * 100,
|
|
|
|
(c->gc_stats.nodes ?: 1) * btree_bytes(c));
|
|
|
|
}
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
static unsigned bch_average_key_size(struct cache_set *c)
|
|
|
|
{
|
|
|
|
return c->gc_stats.nkeys
|
|
|
|
? div64_u64(c->gc_stats.data, c->gc_stats.nkeys)
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SHOW(__bch_cache_set)
|
|
|
|
{
|
2013-03-24 07:11:31 +08:00
|
|
|
struct cache_set *c = container_of(kobj, struct cache_set, kobj);
|
|
|
|
|
|
|
|
sysfs_print(synchronous, CACHE_SYNC(&c->sb));
|
|
|
|
sysfs_print(journal_delay_ms, c->journal_delay_ms);
|
|
|
|
sysfs_hprint(bucket_size, bucket_bytes(c));
|
|
|
|
sysfs_hprint(block_size, block_bytes(c));
|
|
|
|
sysfs_print(tree_depth, c->root->level);
|
2014-03-18 14:13:56 +08:00
|
|
|
sysfs_print(root_usage_percent, bch_root_usage(c));
|
2013-03-24 07:11:31 +08:00
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
sysfs_hprint(btree_cache_size, bch_cache_size(c));
|
|
|
|
sysfs_print(btree_cache_max_chain, bch_cache_max_chain(c));
|
2013-03-24 07:11:31 +08:00
|
|
|
sysfs_print(cache_available_percent, 100 - c->gc_stats.in_use);
|
|
|
|
|
|
|
|
sysfs_print_time_stats(&c->btree_gc_time, btree_gc, sec, ms);
|
|
|
|
sysfs_print_time_stats(&c->btree_split_time, btree_split, sec, us);
|
2013-09-11 13:53:34 +08:00
|
|
|
sysfs_print_time_stats(&c->sort.time, btree_sort, ms, us);
|
2013-03-24 07:11:31 +08:00
|
|
|
sysfs_print_time_stats(&c->btree_read_time, btree_read, ms, us);
|
|
|
|
|
2014-03-18 14:13:56 +08:00
|
|
|
sysfs_print(btree_used_percent, bch_btree_used(c));
|
2013-03-24 07:11:31 +08:00
|
|
|
sysfs_print(btree_nodes, c->gc_stats.nodes);
|
2014-03-18 14:13:56 +08:00
|
|
|
sysfs_hprint(average_key_size, bch_average_key_size(c));
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
sysfs_print(cache_read_races,
|
|
|
|
atomic_long_read(&c->cache_read_races));
|
|
|
|
|
2018-02-08 03:41:39 +08:00
|
|
|
sysfs_print(reclaim,
|
|
|
|
atomic_long_read(&c->reclaim));
|
|
|
|
|
|
|
|
sysfs_print(flush_write,
|
|
|
|
atomic_long_read(&c->flush_write));
|
|
|
|
|
|
|
|
sysfs_print(retry_flush_write,
|
|
|
|
atomic_long_read(&c->retry_flush_write));
|
|
|
|
|
2013-03-24 07:11:31 +08:00
|
|
|
sysfs_print(writeback_keys_done,
|
|
|
|
atomic_long_read(&c->writeback_keys_done));
|
|
|
|
sysfs_print(writeback_keys_failed,
|
|
|
|
atomic_long_read(&c->writeback_keys_failed));
|
|
|
|
|
2013-07-12 10:42:51 +08:00
|
|
|
if (attr == &sysfs_errors)
|
|
|
|
return bch_snprint_string_list(buf, PAGE_SIZE, error_actions,
|
|
|
|
c->on_error);
|
|
|
|
|
2013-03-24 07:11:31 +08:00
|
|
|
/* See count_io_errors for why 88 */
|
|
|
|
sysfs_print(io_error_halflife, c->error_decay * 88);
|
bcache: set error_limit correctly
Struct cache uses io_errors for two purposes,
- Error decay: when cache set error_decay is set, io_errors is used to
generate a small piece of delay when I/O error happens.
- I/O errors counter: in order to generate big enough value for error
decay, I/O errors counter value is stored by left shifting 20 bits (a.k.a
IO_ERROR_SHIFT).
In function bch_count_io_errors(), if I/O errors counter reaches cache set
error limit, bch_cache_set_error() will be called to retire the whold cache
set. But current code is problematic when checking the error limit, see the
following code piece from bch_count_io_errors(),
90 if (error) {
91 char buf[BDEVNAME_SIZE];
92 unsigned errors = atomic_add_return(1 << IO_ERROR_SHIFT,
93 &ca->io_errors);
94 errors >>= IO_ERROR_SHIFT;
95
96 if (errors < ca->set->error_limit)
97 pr_err("%s: IO error on %s, recovering",
98 bdevname(ca->bdev, buf), m);
99 else
100 bch_cache_set_error(ca->set,
101 "%s: too many IO errors %s",
102 bdevname(ca->bdev, buf), m);
103 }
At line 94, errors is right shifting IO_ERROR_SHIFT bits, now it is real
errors counter to compare at line 96. But ca->set->error_limit is initia-
lized with an amplified value in bch_cache_set_alloc(),
1545 c->error_limit = 8 << IO_ERROR_SHIFT;
It means by default, in bch_count_io_errors(), before 8<<20 errors happened
bch_cache_set_error() won't be called to retire the problematic cache
device. If the average request size is 64KB, it means bcache won't handle
failed device until 512GB data is requested. This is too large to be an I/O
threashold. So I believe the correct error limit should be much less.
This patch sets default cache set error limit to 8, then in
bch_count_io_errors() when errors counter reaches 8 (if it is default
value), function bch_cache_set_error() will be called to retire the whole
cache set. This patch also removes bits shifting when store or show
io_error_limit value via sysfs interface.
Nowadays most of SSDs handle internal flash failure automatically by LBA
address re-indirect mapping. If an I/O error can be observed by upper layer
code, it will be a notable error because that SSD can not re-indirect
map the problematic LBA address to an available flash block. This situation
indicates the whole SSD will be failed very soon. Therefore setting 8 as
the default io error limit value makes sense, it is enough for most of
cache devices.
Changelog:
v2: add reviewed-by from Hannes.
v1: initial version for review.
Signed-off-by: Coly Li <colyli@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tang Junhui <tang.junhui@zte.com.cn>
Reviewed-by: Michael Lyle <mlyle@lyle.org>
Cc: Junhui Tang <tang.junhui@zte.com.cn>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-02-08 03:41:42 +08:00
|
|
|
sysfs_print(io_error_limit, c->error_limit);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
sysfs_hprint(congested,
|
|
|
|
((uint64_t) bch_get_congested(c)) << 9);
|
|
|
|
sysfs_print(congested_read_threshold_us,
|
|
|
|
c->congested_read_threshold_us);
|
|
|
|
sysfs_print(congested_write_threshold_us,
|
|
|
|
c->congested_write_threshold_us);
|
|
|
|
|
|
|
|
sysfs_print(active_journal_entries, fifo_used(&c->journal.pin));
|
|
|
|
sysfs_printf(verify, "%i", c->verify);
|
|
|
|
sysfs_printf(key_merging_disabled, "%i", c->key_merging_disabled);
|
2013-10-25 07:36:03 +08:00
|
|
|
sysfs_printf(expensive_debug_checks,
|
|
|
|
"%i", c->expensive_debug_checks);
|
2013-03-24 07:11:31 +08:00
|
|
|
sysfs_printf(gc_always_rewrite, "%i", c->gc_always_rewrite);
|
|
|
|
sysfs_printf(btree_shrinker_disabled, "%i", c->shrinker_disabled);
|
|
|
|
sysfs_printf(copy_gc_enabled, "%i", c->copy_gc_enabled);
|
|
|
|
|
|
|
|
if (attr == &sysfs_bset_tree_stats)
|
|
|
|
return bch_bset_print_stats(c, buf);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SHOW_LOCKED(bch_cache_set)
|
|
|
|
|
|
|
|
STORE(__bch_cache_set)
|
|
|
|
{
|
|
|
|
struct cache_set *c = container_of(kobj, struct cache_set, kobj);
|
|
|
|
|
|
|
|
if (attr == &sysfs_unregister)
|
|
|
|
bch_cache_set_unregister(c);
|
|
|
|
|
|
|
|
if (attr == &sysfs_stop)
|
|
|
|
bch_cache_set_stop(c);
|
|
|
|
|
|
|
|
if (attr == &sysfs_synchronous) {
|
|
|
|
bool sync = strtoul_or_return(buf);
|
|
|
|
|
|
|
|
if (sync != CACHE_SYNC(&c->sb)) {
|
|
|
|
SET_CACHE_SYNC(&c->sb, sync);
|
|
|
|
bcache_write_super(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == &sysfs_flash_vol_create) {
|
|
|
|
int r;
|
|
|
|
uint64_t v;
|
|
|
|
strtoi_h_or_return(buf, v);
|
|
|
|
|
|
|
|
r = bch_flash_dev_create(c, v);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == &sysfs_clear_stats) {
|
|
|
|
atomic_long_set(&c->writeback_keys_done, 0);
|
|
|
|
atomic_long_set(&c->writeback_keys_failed, 0);
|
|
|
|
|
|
|
|
memset(&c->gc_stats, 0, sizeof(struct gc_stat));
|
|
|
|
bch_cache_accounting_clear(&c->accounting);
|
|
|
|
}
|
|
|
|
|
2017-09-06 14:25:55 +08:00
|
|
|
if (attr == &sysfs_trigger_gc) {
|
|
|
|
/*
|
|
|
|
* Garbage collection thread only works when sectors_to_gc < 0,
|
|
|
|
* when users write to sysfs entry trigger_gc, most of time
|
|
|
|
* they want to forcibly triger gargage collection. Here -1 is
|
|
|
|
* set to c->sectors_to_gc, to make gc_should_run() give a
|
|
|
|
* chance to permit gc thread to run. "give a chance" means
|
|
|
|
* before going into gc_should_run(), there is still chance
|
|
|
|
* that c->sectors_to_gc being set to other positive value. So
|
|
|
|
* writing sysfs entry trigger_gc won't always make sure gc
|
|
|
|
* thread takes effect.
|
|
|
|
*/
|
|
|
|
atomic_set(&c->sectors_to_gc, -1);
|
2013-10-25 08:19:26 +08:00
|
|
|
wake_up_gc(c);
|
2017-09-06 14:25:55 +08:00
|
|
|
}
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
if (attr == &sysfs_prune_cache) {
|
|
|
|
struct shrink_control sc;
|
|
|
|
sc.gfp_mask = GFP_KERNEL;
|
|
|
|
sc.nr_to_scan = strtoul_or_return(buf);
|
drivers: convert shrinkers to new count/scan API
Convert the driver shrinkers to the new API. Most changes are compile
tested only because I either don't have the hardware or it's staging
stuff.
FWIW, the md and android code is pretty good, but the rest of it makes me
want to claw my eyes out. The amount of broken code I just encountered is
mind boggling. I've added comments explaining what is broken, but I fear
that some of the code would be best dealt with by being dragged behind the
bike shed, burying in mud up to it's neck and then run over repeatedly
with a blunt lawn mower.
Special mention goes to the zcache/zcache2 drivers. They can't co-exist
in the build at the same time, they are under different menu options in
menuconfig, they only show up when you've got the right set of mm
subsystem options configured and so even compile testing is an exercise in
pulling teeth. And that doesn't even take into account the horrible,
broken code...
[glommer@openvz.org: fixes for i915, android lowmem, zcache, bcache]
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Glauber Costa <glommer@openvz.org>
Acked-by: Mel Gorman <mgorman@suse.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Carlos Maiolino <cmaiolino@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: David Rientjes <rientjes@google.com>
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Greg Thelen <gthelen@google.com>
Cc: J. Bruce Fields <bfields@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Kent Overstreet <koverstreet@google.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Steven Whitehouse <swhiteho@redhat.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2013-08-28 08:18:11 +08:00
|
|
|
c->shrink.scan_objects(&c->shrink, &sc);
|
2013-03-24 07:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sysfs_strtoul(congested_read_threshold_us,
|
|
|
|
c->congested_read_threshold_us);
|
|
|
|
sysfs_strtoul(congested_write_threshold_us,
|
|
|
|
c->congested_write_threshold_us);
|
|
|
|
|
2013-07-12 10:42:51 +08:00
|
|
|
if (attr == &sysfs_errors) {
|
|
|
|
ssize_t v = bch_read_string_list(buf, error_actions);
|
|
|
|
|
|
|
|
if (v < 0)
|
|
|
|
return v;
|
|
|
|
|
|
|
|
c->on_error = v;
|
|
|
|
}
|
|
|
|
|
2013-03-24 07:11:31 +08:00
|
|
|
if (attr == &sysfs_io_error_limit)
|
bcache: set error_limit correctly
Struct cache uses io_errors for two purposes,
- Error decay: when cache set error_decay is set, io_errors is used to
generate a small piece of delay when I/O error happens.
- I/O errors counter: in order to generate big enough value for error
decay, I/O errors counter value is stored by left shifting 20 bits (a.k.a
IO_ERROR_SHIFT).
In function bch_count_io_errors(), if I/O errors counter reaches cache set
error limit, bch_cache_set_error() will be called to retire the whold cache
set. But current code is problematic when checking the error limit, see the
following code piece from bch_count_io_errors(),
90 if (error) {
91 char buf[BDEVNAME_SIZE];
92 unsigned errors = atomic_add_return(1 << IO_ERROR_SHIFT,
93 &ca->io_errors);
94 errors >>= IO_ERROR_SHIFT;
95
96 if (errors < ca->set->error_limit)
97 pr_err("%s: IO error on %s, recovering",
98 bdevname(ca->bdev, buf), m);
99 else
100 bch_cache_set_error(ca->set,
101 "%s: too many IO errors %s",
102 bdevname(ca->bdev, buf), m);
103 }
At line 94, errors is right shifting IO_ERROR_SHIFT bits, now it is real
errors counter to compare at line 96. But ca->set->error_limit is initia-
lized with an amplified value in bch_cache_set_alloc(),
1545 c->error_limit = 8 << IO_ERROR_SHIFT;
It means by default, in bch_count_io_errors(), before 8<<20 errors happened
bch_cache_set_error() won't be called to retire the problematic cache
device. If the average request size is 64KB, it means bcache won't handle
failed device until 512GB data is requested. This is too large to be an I/O
threashold. So I believe the correct error limit should be much less.
This patch sets default cache set error limit to 8, then in
bch_count_io_errors() when errors counter reaches 8 (if it is default
value), function bch_cache_set_error() will be called to retire the whole
cache set. This patch also removes bits shifting when store or show
io_error_limit value via sysfs interface.
Nowadays most of SSDs handle internal flash failure automatically by LBA
address re-indirect mapping. If an I/O error can be observed by upper layer
code, it will be a notable error because that SSD can not re-indirect
map the problematic LBA address to an available flash block. This situation
indicates the whole SSD will be failed very soon. Therefore setting 8 as
the default io error limit value makes sense, it is enough for most of
cache devices.
Changelog:
v2: add reviewed-by from Hannes.
v1: initial version for review.
Signed-off-by: Coly Li <colyli@suse.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Tang Junhui <tang.junhui@zte.com.cn>
Reviewed-by: Michael Lyle <mlyle@lyle.org>
Cc: Junhui Tang <tang.junhui@zte.com.cn>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2018-02-08 03:41:42 +08:00
|
|
|
c->error_limit = strtoul_or_return(buf);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
/* See count_io_errors() for why 88 */
|
|
|
|
if (attr == &sysfs_io_error_halflife)
|
|
|
|
c->error_decay = strtoul_or_return(buf) / 88;
|
|
|
|
|
|
|
|
sysfs_strtoul(journal_delay_ms, c->journal_delay_ms);
|
|
|
|
sysfs_strtoul(verify, c->verify);
|
|
|
|
sysfs_strtoul(key_merging_disabled, c->key_merging_disabled);
|
2013-10-25 07:36:03 +08:00
|
|
|
sysfs_strtoul(expensive_debug_checks, c->expensive_debug_checks);
|
2013-03-24 07:11:31 +08:00
|
|
|
sysfs_strtoul(gc_always_rewrite, c->gc_always_rewrite);
|
|
|
|
sysfs_strtoul(btree_shrinker_disabled, c->shrinker_disabled);
|
|
|
|
sysfs_strtoul(copy_gc_enabled, c->copy_gc_enabled);
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
STORE_LOCKED(bch_cache_set)
|
|
|
|
|
|
|
|
SHOW(bch_cache_set_internal)
|
|
|
|
{
|
|
|
|
struct cache_set *c = container_of(kobj, struct cache_set, internal);
|
|
|
|
return bch_cache_set_show(&c->kobj, attr, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
STORE(bch_cache_set_internal)
|
|
|
|
{
|
|
|
|
struct cache_set *c = container_of(kobj, struct cache_set, internal);
|
|
|
|
return bch_cache_set_store(&c->kobj, attr, buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bch_cache_set_internal_release(struct kobject *k)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct attribute *bch_cache_set_files[] = {
|
|
|
|
&sysfs_unregister,
|
|
|
|
&sysfs_stop,
|
|
|
|
&sysfs_synchronous,
|
|
|
|
&sysfs_journal_delay_ms,
|
|
|
|
&sysfs_flash_vol_create,
|
|
|
|
|
|
|
|
&sysfs_bucket_size,
|
|
|
|
&sysfs_block_size,
|
|
|
|
&sysfs_tree_depth,
|
|
|
|
&sysfs_root_usage_percent,
|
|
|
|
&sysfs_btree_cache_size,
|
|
|
|
&sysfs_cache_available_percent,
|
|
|
|
|
|
|
|
&sysfs_average_key_size,
|
|
|
|
|
2013-07-12 10:42:51 +08:00
|
|
|
&sysfs_errors,
|
2013-03-24 07:11:31 +08:00
|
|
|
&sysfs_io_error_limit,
|
|
|
|
&sysfs_io_error_halflife,
|
|
|
|
&sysfs_congested,
|
|
|
|
&sysfs_congested_read_threshold_us,
|
|
|
|
&sysfs_congested_write_threshold_us,
|
|
|
|
&sysfs_clear_stats,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
KTYPE(bch_cache_set);
|
|
|
|
|
|
|
|
static struct attribute *bch_cache_set_internal_files[] = {
|
|
|
|
&sysfs_active_journal_entries,
|
|
|
|
|
|
|
|
sysfs_time_stats_attribute_list(btree_gc, sec, ms)
|
|
|
|
sysfs_time_stats_attribute_list(btree_split, sec, us)
|
|
|
|
sysfs_time_stats_attribute_list(btree_sort, ms, us)
|
|
|
|
sysfs_time_stats_attribute_list(btree_read, ms, us)
|
|
|
|
|
|
|
|
&sysfs_btree_nodes,
|
|
|
|
&sysfs_btree_used_percent,
|
|
|
|
&sysfs_btree_cache_max_chain,
|
|
|
|
|
|
|
|
&sysfs_bset_tree_stats,
|
|
|
|
&sysfs_cache_read_races,
|
2018-02-08 03:41:39 +08:00
|
|
|
&sysfs_reclaim,
|
|
|
|
&sysfs_flush_write,
|
|
|
|
&sysfs_retry_flush_write,
|
2013-03-24 07:11:31 +08:00
|
|
|
&sysfs_writeback_keys_done,
|
|
|
|
&sysfs_writeback_keys_failed,
|
|
|
|
|
|
|
|
&sysfs_trigger_gc,
|
|
|
|
&sysfs_prune_cache,
|
|
|
|
#ifdef CONFIG_BCACHE_DEBUG
|
|
|
|
&sysfs_verify,
|
|
|
|
&sysfs_key_merging_disabled,
|
2013-10-25 07:36:03 +08:00
|
|
|
&sysfs_expensive_debug_checks,
|
2013-03-24 07:11:31 +08:00
|
|
|
#endif
|
|
|
|
&sysfs_gc_always_rewrite,
|
|
|
|
&sysfs_btree_shrinker_disabled,
|
|
|
|
&sysfs_copy_gc_enabled,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
KTYPE(bch_cache_set_internal);
|
|
|
|
|
2017-10-14 07:35:28 +08:00
|
|
|
static int __bch_cache_cmp(const void *l, const void *r)
|
|
|
|
{
|
|
|
|
return *((uint16_t *)r) - *((uint16_t *)l);
|
|
|
|
}
|
|
|
|
|
2013-03-24 07:11:31 +08:00
|
|
|
SHOW(__bch_cache)
|
|
|
|
{
|
|
|
|
struct cache *ca = container_of(kobj, struct cache, kobj);
|
|
|
|
|
|
|
|
sysfs_hprint(bucket_size, bucket_bytes(ca));
|
|
|
|
sysfs_hprint(block_size, block_bytes(ca));
|
|
|
|
sysfs_print(nbuckets, ca->sb.nbuckets);
|
|
|
|
sysfs_print(discard, ca->discard);
|
|
|
|
sysfs_hprint(written, atomic_long_read(&ca->sectors_written) << 9);
|
|
|
|
sysfs_hprint(btree_written,
|
|
|
|
atomic_long_read(&ca->btree_sectors_written) << 9);
|
|
|
|
sysfs_hprint(metadata_written,
|
|
|
|
(atomic_long_read(&ca->meta_sectors_written) +
|
|
|
|
atomic_long_read(&ca->btree_sectors_written)) << 9);
|
|
|
|
|
|
|
|
sysfs_print(io_errors,
|
|
|
|
atomic_read(&ca->io_errors) >> IO_ERROR_SHIFT);
|
|
|
|
|
|
|
|
if (attr == &sysfs_cache_replacement_policy)
|
2013-03-29 02:50:55 +08:00
|
|
|
return bch_snprint_string_list(buf, PAGE_SIZE,
|
|
|
|
cache_replacement_policies,
|
|
|
|
CACHE_REPLACEMENT(&ca->sb));
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
if (attr == &sysfs_priority_stats) {
|
2014-02-26 09:34:21 +08:00
|
|
|
struct bucket *b;
|
|
|
|
size_t n = ca->sb.nbuckets, i;
|
|
|
|
size_t unused = 0, available = 0, dirty = 0, meta = 0;
|
2013-03-24 07:11:31 +08:00
|
|
|
uint64_t sum = 0;
|
2013-05-29 12:53:19 +08:00
|
|
|
/* Compute 31 quantiles */
|
|
|
|
uint16_t q[31], *p, *cached;
|
2013-03-24 07:11:31 +08:00
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
cached = p = vmalloc(ca->sb.nbuckets * sizeof(uint16_t));
|
|
|
|
if (!p)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
mutex_lock(&ca->set->bucket_lock);
|
2014-02-26 09:34:21 +08:00
|
|
|
for_each_bucket(b, ca) {
|
|
|
|
if (!GC_SECTORS_USED(b))
|
|
|
|
unused++;
|
|
|
|
if (GC_MARK(b) == GC_MARK_RECLAIMABLE)
|
|
|
|
available++;
|
|
|
|
if (GC_MARK(b) == GC_MARK_DIRTY)
|
|
|
|
dirty++;
|
|
|
|
if (GC_MARK(b) == GC_MARK_METADATA)
|
|
|
|
meta++;
|
|
|
|
}
|
|
|
|
|
2013-03-24 07:11:31 +08:00
|
|
|
for (i = ca->sb.first_bucket; i < n; i++)
|
|
|
|
p[i] = ca->buckets[i].prio;
|
|
|
|
mutex_unlock(&ca->set->bucket_lock);
|
|
|
|
|
2017-10-14 07:35:28 +08:00
|
|
|
sort(p, n, sizeof(uint16_t), __bch_cache_cmp, NULL);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
while (n &&
|
|
|
|
!cached[n - 1])
|
|
|
|
--n;
|
|
|
|
|
|
|
|
unused = ca->sb.nbuckets - n;
|
|
|
|
|
|
|
|
while (cached < p + n &&
|
|
|
|
*cached == BTREE_PRIO)
|
2014-02-26 09:34:21 +08:00
|
|
|
cached++, n--;
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
sum += INITIAL_PRIO - cached[i];
|
|
|
|
|
|
|
|
if (n)
|
|
|
|
do_div(sum, n);
|
|
|
|
|
2013-05-29 12:53:19 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(q); i++)
|
|
|
|
q[i] = INITIAL_PRIO - cached[n * (i + 1) /
|
|
|
|
(ARRAY_SIZE(q) + 1)];
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
vfree(p);
|
|
|
|
|
2013-05-29 12:53:19 +08:00
|
|
|
ret = scnprintf(buf, PAGE_SIZE,
|
|
|
|
"Unused: %zu%%\n"
|
2014-02-26 09:34:21 +08:00
|
|
|
"Clean: %zu%%\n"
|
|
|
|
"Dirty: %zu%%\n"
|
2013-05-29 12:53:19 +08:00
|
|
|
"Metadata: %zu%%\n"
|
|
|
|
"Average: %llu\n"
|
|
|
|
"Sectors per Q: %zu\n"
|
|
|
|
"Quantiles: [",
|
|
|
|
unused * 100 / (size_t) ca->sb.nbuckets,
|
2014-02-26 09:34:21 +08:00
|
|
|
available * 100 / (size_t) ca->sb.nbuckets,
|
|
|
|
dirty * 100 / (size_t) ca->sb.nbuckets,
|
|
|
|
meta * 100 / (size_t) ca->sb.nbuckets, sum,
|
2013-05-29 12:53:19 +08:00
|
|
|
n * ca->sb.bucket_size / (ARRAY_SIZE(q) + 1));
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(q); i++)
|
|
|
|
ret += scnprintf(buf + ret, PAGE_SIZE - ret,
|
|
|
|
"%u ", q[i]);
|
|
|
|
ret--;
|
|
|
|
|
|
|
|
ret += scnprintf(buf + ret, PAGE_SIZE - ret, "]\n");
|
|
|
|
|
2013-03-24 07:11:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
SHOW_LOCKED(bch_cache)
|
|
|
|
|
|
|
|
STORE(__bch_cache)
|
|
|
|
{
|
|
|
|
struct cache *ca = container_of(kobj, struct cache, kobj);
|
|
|
|
|
|
|
|
if (attr == &sysfs_discard) {
|
|
|
|
bool v = strtoul_or_return(buf);
|
|
|
|
|
|
|
|
if (blk_queue_discard(bdev_get_queue(ca->bdev)))
|
|
|
|
ca->discard = v;
|
|
|
|
|
|
|
|
if (v != CACHE_DISCARD(&ca->sb)) {
|
|
|
|
SET_CACHE_DISCARD(&ca->sb, v);
|
|
|
|
bcache_write_super(ca->set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == &sysfs_cache_replacement_policy) {
|
2013-03-29 02:50:55 +08:00
|
|
|
ssize_t v = bch_read_string_list(buf, cache_replacement_policies);
|
2013-03-24 07:11:31 +08:00
|
|
|
|
|
|
|
if (v < 0)
|
|
|
|
return v;
|
|
|
|
|
|
|
|
if ((unsigned) v != CACHE_REPLACEMENT(&ca->sb)) {
|
|
|
|
mutex_lock(&ca->set->bucket_lock);
|
|
|
|
SET_CACHE_REPLACEMENT(&ca->sb, v);
|
|
|
|
mutex_unlock(&ca->set->bucket_lock);
|
|
|
|
|
|
|
|
bcache_write_super(ca->set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr == &sysfs_clear_stats) {
|
|
|
|
atomic_long_set(&ca->sectors_written, 0);
|
|
|
|
atomic_long_set(&ca->btree_sectors_written, 0);
|
|
|
|
atomic_long_set(&ca->meta_sectors_written, 0);
|
|
|
|
atomic_set(&ca->io_count, 0);
|
|
|
|
atomic_set(&ca->io_errors, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
STORE_LOCKED(bch_cache)
|
|
|
|
|
|
|
|
static struct attribute *bch_cache_files[] = {
|
|
|
|
&sysfs_bucket_size,
|
|
|
|
&sysfs_block_size,
|
|
|
|
&sysfs_nbuckets,
|
|
|
|
&sysfs_priority_stats,
|
|
|
|
&sysfs_discard,
|
|
|
|
&sysfs_written,
|
|
|
|
&sysfs_btree_written,
|
|
|
|
&sysfs_metadata_written,
|
|
|
|
&sysfs_io_errors,
|
|
|
|
&sysfs_clear_stats,
|
|
|
|
&sysfs_cache_replacement_policy,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
KTYPE(bch_cache);
|