Motr  M0
cache.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_STOB_CACHE_H__
26 #define __MOTR_STOB_CACHE_H__
27 
28 #include "lib/mutex.h" /* m0_mutex */
29 #include "lib/tlist.h" /* m0_tl */
30 #include "lib/types.h" /* uint64_t */
31 #include "fid/fid.h" /* m0_fid */
32 
41 struct m0_stob;
42 struct m0_stob_cache;
43 
45  struct m0_stob *stob);
49 struct m0_stob_cache {
50  struct m0_mutex sc_lock;
51  struct m0_tl sc_busy;
52  struct m0_tl sc_idle;
53  uint64_t sc_idle_size;
54  uint64_t sc_idle_used;
56 
57  uint64_t sc_busy_hits;
58  uint64_t sc_idle_hits;
59  uint64_t sc_misses;
60  uint64_t sc_evictions;
61 };
62 
69 M0_INTERNAL int m0_stob_cache_init(struct m0_stob_cache *cache,
70  uint64_t idle_size,
71  m0_stob_cache_eviction_cb_t eviction_cb);
72 M0_INTERNAL void m0_stob_cache_fini(struct m0_stob_cache *cache);
73 
80 M0_INTERNAL bool m0_stob_cache__invariant(const struct m0_stob_cache *cache);
81 
89 M0_INTERNAL void m0_stob_cache_add(struct m0_stob_cache *cache,
90  struct m0_stob *stob);
91 
98 M0_INTERNAL void m0_stob_cache_idle(struct m0_stob_cache *cache,
99  struct m0_stob *stob);
100 
108 M0_INTERNAL struct m0_stob *m0_stob_cache_lookup(struct m0_stob_cache *cache,
109  const struct m0_fid *stob_fid);
110 
117 M0_INTERNAL void m0_stob_cache_purge(struct m0_stob_cache *cache, int nr);
118 
119 M0_INTERNAL void m0_stob_cache_lock(struct m0_stob_cache *cache);
120 M0_INTERNAL void m0_stob_cache_unlock(struct m0_stob_cache *cache);
121 M0_INTERNAL bool m0_stob_cache_is_locked(const struct m0_stob_cache *cache);
122 M0_INTERNAL bool m0_stob_cache_is_not_locked(const struct m0_stob_cache *cache);
123 
124 M0_INTERNAL void m0_stob_cache__print(struct m0_stob_cache *cache);
125 
126 
127 #endif /* __MOTR_STOB_CACHE_H__ */
128 
129 /*
130  * Local variables:
131  * c-indentation-style: "K&R"
132  * c-basic-offset: 8
133  * tab-width: 8
134  * fill-column: 80
135  * scroll-step: 1
136  * End:
137  */
Definition: beck.c:235
static size_t nr
Definition: dump.c:1505
M0_INTERNAL void m0_stob_cache_unlock(struct m0_stob_cache *cache)
Definition: cache.c:190
uint64_t sc_idle_used
Definition: cache.h:54
uint64_t sc_idle_size
Definition: cache.h:53
struct m0_tl sc_busy
Definition: cache.h:51
M0_INTERNAL void m0_stob_cache_lock(struct m0_stob_cache *cache)
Definition: cache.c:185
uint64_t sc_evictions
Definition: cache.h:60
m0_stob_cache_eviction_cb_t sc_eviction_cb
Definition: cache.h:55
M0_INTERNAL void m0_stob_cache_purge(struct m0_stob_cache *cache, int nr)
Definition: cache.c:165
uint64_t sc_busy_hits
Definition: cache.h:57
struct m0_mutex sc_lock
Definition: cache.h:50
M0_INTERNAL struct m0_stob * m0_stob_cache_lookup(struct m0_stob_cache *cache, const struct m0_fid *stob_fid)
Definition: cache.c:137
M0_INTERNAL void m0_stob_cache_idle(struct m0_stob_cache *cache, struct m0_stob *stob)
Definition: cache.c:129
Definition: stob.h:163
static struct m0_stob * stob
Definition: storage.c:39
uint64_t sc_misses
Definition: cache.h:59
Definition: tlist.h:251
M0_INTERNAL int m0_stob_cache_init(struct m0_stob_cache *cache, uint64_t idle_size, m0_stob_cache_eviction_cb_t eviction_cb)
Definition: cache.c:42
M0_INTERNAL bool m0_stob_cache__invariant(const struct m0_stob_cache *cache)
Definition: cache.c:81
M0_INTERNAL bool m0_stob_cache_is_locked(const struct m0_stob_cache *cache)
Definition: cache.c:195
M0_INTERNAL void m0_stob_cache_fini(struct m0_stob_cache *cache)
Definition: cache.c:61
uint64_t sc_idle_hits
Definition: cache.h:58
Definition: fid.h:38
M0_INTERNAL bool m0_stob_cache_is_not_locked(const struct m0_stob_cache *cache)
Definition: cache.c:200
struct m0_tl sc_idle
Definition: cache.h:52
void(* m0_stob_cache_eviction_cb_t)(struct m0_stob_cache *cache, struct m0_stob *stob)
Definition: cache.h:44
M0_INTERNAL void m0_stob_cache__print(struct m0_stob_cache *cache)
Definition: cache.c:205
Definition: mutex.h:47
M0_INTERNAL void m0_stob_cache_add(struct m0_stob_cache *cache, struct m0_stob *stob)
Definition: cache.c:120