1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* General filesystem local caching manager
4 * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #define FSCACHE_DEBUG_LEVEL CACHE
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #define CREATE_TRACE_POINTS
14 MODULE_DESCRIPTION("FS Cache Manager");
15 MODULE_AUTHOR("Red Hat, Inc.");
16 MODULE_LICENSE("GPL");
18 unsigned fscache_debug;
19 module_param_named(debug, fscache_debug, uint,
21 MODULE_PARM_DESC(fscache_debug,
22 "FS-Cache debugging mask");
24 EXPORT_TRACEPOINT_SYMBOL(fscache_access_cache);
25 EXPORT_TRACEPOINT_SYMBOL(fscache_access_volume);
26 EXPORT_TRACEPOINT_SYMBOL(fscache_access);
28 struct workqueue_struct *fscache_wq;
29 EXPORT_SYMBOL(fscache_wq);
32 * Mixing scores (in bits) for (7,20):
33 * Input delta: 1-bit 2-bit
34 * 1 round: 330.3 9201.6
35 * 2 rounds: 1246.4 25475.4
36 * 3 rounds: 1907.1 31295.1
37 * 4 rounds: 2042.3 31718.6
39 * (32*64) (32*31/2 * 64)
41 #define HASH_MIX(x, y, a) \
43 y ^= x, x = rol32(x, 7),\
44 x += y, y = rol32(y,20),\
47 static inline unsigned int fold_hash(unsigned long x, unsigned long y)
49 /* Use arch-optimized multiply if one exists */
50 return __hash_32(y ^ __hash_32(x));
54 * Generate a hash. This is derived from full_name_hash(), but we want to be
55 * sure it is arch independent and that it doesn't change as bits of the
56 * computed hash value might appear on disk. The caller must guarantee that
57 * the source data is a multiple of four bytes in size.
59 unsigned int fscache_hash(unsigned int salt, const void *data, size_t len)
61 const __le32 *p = data;
62 unsigned int a, x = 0, y = salt, n = len / sizeof(__le32);
65 a = le32_to_cpu(*p++);
68 return fold_hash(x, y);
72 * initialise the fs caching module
74 static int __init fscache_init(void)
78 fscache_wq = alloc_workqueue("fscache", WQ_UNBOUND | WQ_FREEZABLE, 0);
82 ret = fscache_proc_init();
86 fscache_cookie_jar = kmem_cache_create("fscache_cookie_jar",
87 sizeof(struct fscache_cookie),
89 if (!fscache_cookie_jar) {
90 pr_notice("Failed to allocate a cookie jar\n");
92 goto error_cookie_jar;
95 pr_notice("Loaded\n");
99 fscache_proc_cleanup();
101 destroy_workqueue(fscache_wq);
106 fs_initcall(fscache_init);
109 * clean up on module removal
111 static void __exit fscache_exit(void)
115 kmem_cache_destroy(fscache_cookie_jar);
116 fscache_proc_cleanup();
117 destroy_workqueue(fscache_wq);
118 pr_notice("Unloaded\n");
121 module_exit(fscache_exit);