1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
From 95fd35da4e8485179ba71b9909f28d06f1c93a9b Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Wed, 28 May 2014 16:48:04 +0200
Subject: [PATCH 13/14] libdiskfs: remove the statistics code from the name
cache
The current name cache lookup operation completes in O(n) time. This
means that making the cache too large would decrease the performance.
Therefore it was required to tune the size, hence the need for
statistics.
We will use a data structure with worst case constant lookup times in
the future, removing the need to fine tune the cache size.
* libdiskfs/name-cache.c: Remove the statistics code from the name
cache.
---
libdiskfs/name-cache.c | 66 +-------------------------------------------------
1 file changed, 1 insertion(+), 65 deletions(-)
diff --git a/libdiskfs/name-cache.c b/libdiskfs/name-cache.c
index a212a6d..25b5d0d 100644
--- a/libdiskfs/name-cache.c
+++ b/libdiskfs/name-cache.c
@@ -45,29 +45,12 @@ struct lookup_cache
/* Strlen of NAME. If this is zero, it's an unused entry. */
size_t name_len;
-
- /* XXX */
- int stati;
};
/* The contents of the cache in no particular order */
static struct cacheq lookup_cache = { sizeof (struct lookup_cache) };
static pthread_spinlock_t cache_lock = PTHREAD_SPINLOCK_INITIALIZER;
-
-/* Buffer to hold statistics */
-static struct stats
-{
- long pos_hits;
- long neg_hits;
- long miss;
- long fetch_errors;
-} statistics;
-
-#define PARTIAL_THRESH 100
-#define NPARTIALS MAXCACHE / PARTIAL_THRESH
-struct stats partial_stats [NPARTIALS];
-
/* If there's an entry for NAME, of length NAME_LEN, in directory DIR in the
cache, return its entry, otherwise 0. CACHE_LOCK must be held. */
@@ -85,10 +68,7 @@ find_cache (struct node *dir, const char *name, size_t name_len)
if (c->name_len == name_len
&& c->dir_cache_id == dir->cache_id
&& c->name[0] == name[0] && strcmp (c->name, name) == 0)
- {
- c->stati = i / 100;
- return c;
- }
+ return c;
return 0;
}
@@ -152,46 +132,6 @@ diskfs_purge_lookup_cache (struct node *dp, struct node *np)
pthread_spin_unlock (&cache_lock);
}
-/* Register a negative hit for an entry in the Nth stat class */
-void
-register_neg_hit (int n)
-{
- int i;
-
- statistics.neg_hits++;
-
- for (i = 0; i < n; i++)
- partial_stats[i].miss++;
- for (; i < NPARTIALS; i++)
- partial_stats[i].neg_hits++;
-}
-
-/* Register a positive hit for an entry in the Nth stat class */
-void
-register_pos_hit (int n)
-{
- int i;
-
- statistics.pos_hits++;
-
- for (i = 0; i < n; i++)
- partial_stats[i].miss++;
- for (; i < NPARTIALS; i++)
- partial_stats[i].pos_hits++;
-}
-
-/* Register a miss */
-void
-register_miss ()
-{
- int i;
-
- statistics.miss++;
- for (i = 0; i < NPARTIALS; i++)
- partial_stats[i].miss++;
-}
-
-
/* Scan the cache looking for NAME inside DIR. If we don't know
anything entry at all, then return 0. If the entry is confirmed to
@@ -214,14 +154,12 @@ diskfs_check_lookup_cache (struct node *dir, const char *name)
if (id == 0)
/* A negative cache entry. */
{
- register_neg_hit (c->stati);
pthread_spin_unlock (&cache_lock);
return (struct node *)-1;
}
else if (id == dir->cache_id)
/* The cached node is the same as DIR. */
{
- register_pos_hit (c->stati);
pthread_spin_unlock (&cache_lock);
diskfs_nref (dir);
return dir;
@@ -232,7 +170,6 @@ diskfs_check_lookup_cache (struct node *dir, const char *name)
struct node *np;
error_t err;
- register_pos_hit (c->stati);
pthread_spin_unlock (&cache_lock);
if (name[0] == '.' && name[1] == '.' && name[2] == '\0')
@@ -259,7 +196,6 @@ diskfs_check_lookup_cache (struct node *dir, const char *name)
}
}
- register_miss ();
pthread_spin_unlock (&cache_lock);
return 0;
--
2.0.0.rc2
|