diff options
author | Eric Nelson <eric@nelint.com> | 2016-03-28 10:05:44 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2016-04-01 17:18:27 -0400 |
commit | e40cf34a29f1b248643731a11fb1c6f0520d016c (patch) | |
tree | 2970c8fdbf0d35135f1d2eddd238372c20ac65f5 /cmd/blkcache.c | |
parent | e721e98125ebaad71bc7d19287ce54c337f59154 (diff) | |
download | u-boot-e40cf34a29f1b248643731a11fb1c6f0520d016c.tar.gz u-boot-e40cf34a29f1b248643731a11fb1c6f0520d016c.tar.bz2 u-boot-e40cf34a29f1b248643731a11fb1c6f0520d016c.zip |
drivers: block: add block device cache
Add a block device cache to speed up repeated reads of block devices by
various filesystems.
This small amount of cache can dramatically speed up filesystem
operations by skipping repeated reads of common areas of a block
device (typically directory structures).
This has shown to have some benefit on FAT filesystem operations of
loading a kernel and RAM disk, but more dramatic benefits on ext4
filesystems when the kernel and/or RAM disk are spread across
multiple extent header structures as described in commit fc0fc50.
The cache is implemented through a minimal list (block_cache) maintained
in most-recently-used order and count of the current number of entries
(cache_count). It uses a maximum block count setting to prevent copies
of large block reads and an upper bound on the number of cached areas.
The maximum number of entries in the cache defaults to 32 and the maximum
number of blocks per cache entry has a default of 2, which has shown to
produce the best results on testing of ext4 and FAT filesystems.
The 'blkcache' command (enabled through CONFIG_CMD_BLOCK_CACHE) allows
changing these values and can be used to tune for a particular filesystem
layout.
Signed-off-by: Eric Nelson <eric@nelint.com>
Diffstat (limited to 'cmd/blkcache.c')
-rw-r--r-- | cmd/blkcache.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/cmd/blkcache.c b/cmd/blkcache.c new file mode 100644 index 0000000000..9a619e2199 --- /dev/null +++ b/cmd/blkcache.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) Nelson Integration, LLC 2016 + * Author: Eric Nelson<eric@nelint.com> + * + * SPDX-License-Identifier: GPL-2.0+ + * + */ +#include <config.h> +#include <common.h> +#include <malloc.h> +#include <part.h> + +static int blkc_show(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct block_cache_stats stats; + blkcache_stats(&stats); + + printf(" hits: %u\n" + " misses: %u\n" + " entries: %u\n" + " max blocks/entry: %u\n" + " max cache entries: %u\n", + stats.hits, stats.misses, stats.entries, + stats.max_blocks_per_entry, stats.max_entries); + return 0; +} + +static int blkc_configure(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + unsigned blocks_per_entry, max_entries; + if (argc != 3) + return CMD_RET_USAGE; + + blocks_per_entry = simple_strtoul(argv[1], 0, 0); + max_entries = simple_strtoul(argv[2], 0, 0); + blkcache_configure(blocks_per_entry, max_entries); + printf("changed to max of %u entries of %u blocks each\n", + max_entries, blocks_per_entry); + return 0; +} + +static cmd_tbl_t cmd_blkc_sub[] = { + U_BOOT_CMD_MKENT(show, 0, 0, blkc_show, "", ""), + U_BOOT_CMD_MKENT(configure, 3, 0, blkc_configure, "", ""), +}; + +static __maybe_unused void blkc_reloc(void) +{ + static int relocated; + + if (!relocated) { + fixup_cmdtable(cmd_blkc_sub, ARRAY_SIZE(cmd_blkc_sub)); + relocated = 1; + }; +} + +static int do_blkcache(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + cmd_tbl_t *c; + +#ifdef CONFIG_NEEDS_MANUAL_RELOC + blkc_reloc(); +#endif + if (argc < 2) + return CMD_RET_USAGE; + + /* Strip off leading argument */ + argc--; + argv++; + + c = find_cmd_tbl(argv[0], &cmd_blkc_sub[0], ARRAY_SIZE(cmd_blkc_sub)); + + if (c) + return c->cmd(cmdtp, flag, argc, argv); + else + return CMD_RET_USAGE; + + return 0; +} + +U_BOOT_CMD( + blkcache, 4, 0, do_blkcache, + "block cache diagnostics and control", + "show - show and reset statistics\n" + "blkcache configure blocks entries\n" +); |