summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2017-07-25 16:51:34 -0400
committerDavid Sterba <dsterba@suse.com>2017-10-06 13:41:06 +0200
commita5ce5d2198226db6e4ed8f99c6f34ef74e8567bf (patch)
tree43a226d71cca6505b800c6d32f6dfe29e11c2a84 /utils.c
parentad39e6252b098f62a81912dd5c97b74076a80c74 (diff)
btrfs-progs: extent-cache: actually cache extent buffers
We have the infrastructure to cache extent buffers but we don't actually do the caching. As soon as the last reference is dropped, the buffer is dropped. This patch keeps the extent buffers around until the max cache size is reached (defaults to 25% of memory) and then it drops the last 10% of the LRU to free up cache space for reallocation. The cache size is configurable (for use by e.g. lowmem) when the cache is initialized. Signed-off-by: Jeff Mahoney <jeffm@suse.com> [ update codingstyle, switch total_memory to bytes ] Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 9d20cab0..524f463d 100644
--- a/utils.c
+++ b/utils.c
@@ -24,6 +24,7 @@
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/sysinfo.h>
#include <uuid/uuid.h>
#include <fcntl.h>
#include <unistd.h>
@@ -2688,3 +2689,15 @@ u8 rand_u8(void)
void btrfs_config_init(void)
{
}
+
+/* Returns total size of main memory in bytes, -1UL if error. */
+unsigned long total_memory(void)
+{
+ struct sysinfo si;
+
+ if (sysinfo(&si) < 0) {
+ error("can't determine memory size");
+ return -1UL;
+ }
+ return si.totalram * si.mem_unit; /* bytes */
+}