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>
12 #define CREATE_TRACE_POINTS
13 #include <trace/events/fscache.h>
15 EXPORT_TRACEPOINT_SYMBOL(fscache_access_cache
);
16 EXPORT_TRACEPOINT_SYMBOL(fscache_access_volume
);
17 EXPORT_TRACEPOINT_SYMBOL(fscache_access
);
19 struct workqueue_struct
*fscache_wq
;
20 EXPORT_SYMBOL(fscache_wq
);
23 * Mixing scores (in bits) for (7,20):
24 * Input delta: 1-bit 2-bit
25 * 1 round: 330.3 9201.6
26 * 2 rounds: 1246.4 25475.4
27 * 3 rounds: 1907.1 31295.1
28 * 4 rounds: 2042.3 31718.6
30 * (32*64) (32*31/2 * 64)
32 #define HASH_MIX(x, y, a) \
34 y ^= x, x = rol32(x, 7),\
35 x += y, y = rol32(y,20),\
38 static inline unsigned int fold_hash(unsigned long x
, unsigned long y
)
40 /* Use arch-optimized multiply if one exists */
41 return __hash_32(y
^ __hash_32(x
));
45 * Generate a hash. This is derived from full_name_hash(), but we want to be
46 * sure it is arch independent and that it doesn't change as bits of the
47 * computed hash value might appear on disk. The caller must guarantee that
48 * the source data is a multiple of four bytes in size.
50 unsigned int fscache_hash(unsigned int salt
, const void *data
, size_t len
)
52 const __le32
*p
= data
;
53 unsigned int a
, x
= 0, y
= salt
, n
= len
/ sizeof(__le32
);
56 a
= le32_to_cpu(*p
++);
59 return fold_hash(x
, y
);
63 * initialise the fs caching module
65 int __init
fscache_init(void)
69 fscache_wq
= alloc_workqueue("fscache", WQ_UNBOUND
| WQ_FREEZABLE
, 0);
73 ret
= fscache_proc_init();
77 fscache_cookie_jar
= kmem_cache_create("fscache_cookie_jar",
78 sizeof(struct fscache_cookie
),
80 if (!fscache_cookie_jar
) {
81 pr_notice("Failed to allocate a cookie jar\n");
83 goto error_cookie_jar
;
86 pr_notice("FS-Cache loaded\n");
90 fscache_proc_cleanup();
92 destroy_workqueue(fscache_wq
);
98 * clean up on module removal
100 void __exit
fscache_exit(void)
104 kmem_cache_destroy(fscache_cookie_jar
);
105 fscache_proc_cleanup();
106 timer_shutdown_sync(&fscache_cookie_lru_timer
);
107 destroy_workqueue(fscache_wq
);
108 pr_notice("FS-Cache unloaded\n");