Motr  M0
alloc.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-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 #ifndef __MOTR_BE_ALLOC_H__
25 #define __MOTR_BE_ALLOC_H__
26 
27 #include "lib/types.h" /* m0_bcount_t */
28 #include "lib/mutex.h"
29 
30 struct m0_be_op;
31 struct m0_be_seg;
32 struct m0_be_tx;
33 struct m0_be_tx_credit;
34 
42 enum {
48 };
49 
51  unsigned long bcs_nr;
53 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
54 
59 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
60 
61 enum {
64 };
65 
96  /* Maybe more zones in the future. */
98 } M0_XCA_ENUM;
99 
104  uint32_t bzs_type M0_XCA_FENUM(
107 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
108 
125  unsigned long bas_print_interval;
126  unsigned long bas_print_index;
127 } M0_XCA_RECORD M0_XCA_DOMAIN(be);
128 
130 
138  struct m0_be_seg *ba_seg;
146 };
147 
153 M0_INTERNAL int m0_be_allocator_init(struct m0_be_allocator *a,
154  struct m0_be_seg *seg);
155 
161 M0_INTERNAL void m0_be_allocator_fini(struct m0_be_allocator *a);
162 
169 M0_INTERNAL bool m0_be_allocator__invariant(struct m0_be_allocator *a);
170 
177 M0_INTERNAL int m0_be_allocator_create(struct m0_be_allocator *a,
178  struct m0_be_tx *tx,
179  uint32_t *zone_percent,
180  uint32_t zones_nr);
181 
188 M0_INTERNAL void m0_be_allocator_destroy(struct m0_be_allocator *a,
189  struct m0_be_tx *tx);
190 
203 };
204 
220 M0_INTERNAL void m0_be_allocator_credit(struct m0_be_allocator *a,
221  enum m0_be_allocator_op optype,
223  unsigned shift,
224  struct m0_be_tx_credit *accum);
225 
249 M0_INTERNAL void m0_be_alloc_aligned(struct m0_be_allocator *a,
250  struct m0_be_tx *tx,
251  struct m0_be_op *op,
252  void **ptr,
254  unsigned shift,
255  uint64_t zonemask);
256 
266 M0_INTERNAL void m0_be_alloc(struct m0_be_allocator *a,
267  struct m0_be_tx *tx,
268  struct m0_be_op *op,
269  void **ptr,
270  m0_bcount_t size);
271 
287 M0_INTERNAL void m0_be_free_aligned(struct m0_be_allocator *a,
288  struct m0_be_tx *tx,
289  struct m0_be_op *op,
290  void *ptr);
291 
297 M0_INTERNAL void m0_be_free(struct m0_be_allocator *a,
298  struct m0_be_tx *tx,
299  struct m0_be_op *op,
300  void *ptr);
307 M0_INTERNAL void m0_be_alloc_stats(struct m0_be_allocator *a,
308  struct m0_be_allocator_stats *out);
309 
310 M0_INTERNAL void m0_be_alloc_stats_credit(struct m0_be_allocator *a,
311  struct m0_be_tx_credit *accum);
312 M0_INTERNAL void m0_be_alloc_stats_capture(struct m0_be_allocator *a,
313  struct m0_be_tx *tx);
314 
315 
322 #define M0_BE_ALLOC_ARR(arr, nr, seg, tx, op) \
323  m0_be_alloc(m0_be_seg_allocator(seg), (tx), (op), \
324  (void **)&(arr), (nr) * sizeof((arr)[0]))
325 
332 #define M0_BE_ALLOC_PTR(ptr, seg, tx, op) \
333  M0_BE_ALLOC_ARR((ptr), 1, (seg), (tx), (op))
334 
335 #define M0_BE_ALLOC_ARR_SYNC(arr, nr, seg, tx) \
336  M0_BE_OP_SYNC(__op, \
337  M0_BE_ALLOC_ARR((arr), (nr), (seg), (tx), &__op))
338 
339 #define M0_BE_ALLOC_PTR_SYNC(ptr, seg, tx) \
340  M0_BE_OP_SYNC(__op, M0_BE_ALLOC_PTR((ptr), (seg), (tx), &__op))
341 
342 #define M0_BE_FREE_PTR(ptr, seg, tx, op) \
343  m0_be_free(m0_be_seg_allocator(seg), (tx), (op), (ptr))
344 
345 #define M0_BE_FREE_PTR_SYNC(ptr, seg, tx) \
346  M0_BE_OP_SYNC(__op, M0_BE_FREE_PTR((ptr), (seg), (tx), &__op))
347 
348 #define M0_BE_ALLOC_BUF(buf, seg, tx, op) \
349  m0_be_alloc(m0_be_seg_allocator(seg), (tx), (op), \
350  &(buf)->b_addr, (buf)->b_nob)
351 
352 #define M0_BE_ALLOC_BUF_SYNC(buf, seg, tx) \
353  M0_BE_OP_SYNC(__op, M0_BE_ALLOC_BUF((buf), (seg), (tx), &__op))
354 
355 #define M0_BE_ALLOC_CREDIT_PTR(ptr, seg, accum) \
356  m0_be_allocator_credit(m0_be_seg_allocator(seg), \
357  M0_BAO_ALLOC, sizeof *(ptr), 0, (accum))
358 
359 #define M0_BE_FREE_CREDIT_PTR(ptr, seg, accum) \
360  m0_be_allocator_credit(m0_be_seg_allocator(seg), \
361  M0_BAO_FREE, sizeof *(ptr), 0, (accum))
362 
363 #define M0_BE_ALLOC_CREDIT_ARR(arr, nr, seg, accum) \
364  m0_be_allocator_credit(m0_be_seg_allocator(seg), \
365  M0_BAO_ALLOC, (nr) * sizeof((arr)[0]), 0, (accum))
366 
367 #define M0_BE_FREE_CREDIT_ARR(arr, nr, seg, accum) \
368  m0_be_allocator_credit(m0_be_seg_allocator(seg), \
369  M0_BAO_FREE, (nr) * sizeof((arr)[0]), 0, (accum))
370 
371 #define M0_BE_ALLOC_CREDIT_BUF(buf, seg, accum) \
372  m0_be_allocator_credit(m0_be_seg_allocator(seg), \
373  M0_BAO_ALLOC, (buf)->b_nob, 0, (accum))
374 
375 
377 #endif /* __MOTR_BE_ALLOC_H__ */
378 /*
379  * Local variables:
380  * c-indentation-style: "K&R"
381  * c-basic-offset: 8
382  * tab-width: 8
383  * fill-column: 80
384  * scroll-step: 1
385  * End:
386  */
387 /*
388  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
389  */
static void ptr(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
Definition: dump.c:440
m0_bcount_t bzs_used
Definition: alloc.h:102
Allocator header.
struct m0_be_allocator_call_stats bas_stat0
Definition: alloc.h:123
m0_bcount_t bzs_total
Definition: alloc.h:101
m0_bcount_t bas_stat0_boundary
Definition: alloc.h:119
m0_bcount_t bas_space_total
Definition: alloc.h:116
M0_INTERNAL void m0_be_alloc_stats_capture(struct m0_be_allocator *a, struct m0_be_tx *tx)
Definition: alloc.c:1175
Allocator.
Definition: alloc.h:132
M0_INTERNAL void m0_be_alloc_stats(struct m0_be_allocator *a, struct m0_be_allocator_stats *out)
Definition: alloc.c:1159
Allocator statistics.
Definition: alloc.h:114
uint64_t m0_bcount_t
Definition: types.h:77
M0_INTERNAL void m0_be_alloc_aligned(struct m0_be_allocator *a, struct m0_be_tx *tx, struct m0_be_op *op, void **ptr, m0_bcount_t size, unsigned shift, uint64_t zonemask)
Definition: alloc.c:1020
m0_bcount_t bas_chunk_overhead
Definition: alloc.h:115
m0_bcount_t bas_space_used
Definition: alloc.h:117
op
Definition: libdemo.c:64
struct m0_be_allocator_call_stats bzs_stats
Definition: alloc.h:106
M0_INTERNAL void m0_be_alloc_stats_credit(struct m0_be_allocator *a, struct m0_be_tx_credit *accum)
Definition: alloc.c:1168
m0_bcount_t bas_free_chunks_nr
Definition: alloc.h:121
struct m0_be_allocator_call_stat bacs_free
Definition: alloc.h:58
enum m0_be_alloc_zone_type M0_XCA_ENUM
struct m0_be_allocator_call_stats bas_stat1
Definition: alloc.h:124
enum @25 M0_XCA_DOMAIN
unsigned long bcs_nr
Definition: alloc.h:51
struct m0_be_allocator_header * ba_h[M0_BAP_NR]
Definition: alloc.h:145
struct m0_be_allocator_call_stats bas_total
Definition: alloc.h:122
M0_INTERNAL void m0_be_alloc(struct m0_be_allocator *a, struct m0_be_tx *tx, struct m0_be_op *op, void **ptr, m0_bcount_t size)
Definition: alloc.c:1091
m0_bcount_t bas_chunks_nr
Definition: alloc.h:120
M0_INTERNAL bool m0_be_allocator__invariant(struct m0_be_allocator *a)
Definition: alloc.c:758
m0_be_allocator_op
Definition: alloc.h:196
struct m0_be_allocator_call_stat bacs_alloc_failure
Definition: alloc.h:57
uint32_t bzs_type M0_XCA_FENUM(m0_be_alloc_zone_type)
unsigned long bas_print_index
Definition: alloc.h:126
M0_INTERNAL void m0_be_allocator_destroy(struct m0_be_allocator *a, struct m0_be_tx *tx)
Definition: alloc.c:883
Definition: seg.h:66
m0_bcount_t bcs_size
Definition: alloc.h:52
m0_bcount_t bzs_free
Definition: alloc.h:103
struct m0_be_seg * ba_seg
Definition: alloc.h:138
M0_INTERNAL void m0_be_free(struct m0_be_allocator *a, struct m0_be_tx *tx, struct m0_be_op *op, void *ptr)
Definition: alloc.c:1151
struct m0_be_allocator_call_stat bacs_alloc_success
Definition: alloc.h:56
m0_bcount_t size
Definition: di.c:39
unsigned long bas_print_interval
Definition: alloc.h:125
M0_INTERNAL void m0_be_free_aligned(struct m0_be_allocator *a, struct m0_be_tx *tx, struct m0_be_op *op, void *ptr)
Definition: alloc.c:1101
static struct m0_be_seg * seg
Definition: btree.c:40
M0_INTERNAL int m0_be_allocator_create(struct m0_be_allocator *a, struct m0_be_tx *tx, uint32_t *zone_percent, uint32_t zones_nr)
Definition: alloc.c:821
M0_INTERNAL int m0_be_allocator_init(struct m0_be_allocator *a, struct m0_be_seg *seg)
Definition: alloc.c:719
#define out(...)
Definition: gen.c:41
M0_INTERNAL void m0_be_allocator_credit(struct m0_be_allocator *a, enum m0_be_allocator_op optype, m0_bcount_t size, unsigned shift, struct m0_be_tx_credit *accum)
Definition: alloc.c:900
Definition: op.h:74
Definition: mutex.h:47
m0_bcount_t bas_space_free
Definition: alloc.h:118
m0_be_alloc_zone_type
Definition: alloc.h:85
static struct m0_be_ut_backend be
Definition: service_ut.c:59
struct m0_mutex ba_lock
Definition: alloc.h:143
M0_INTERNAL void m0_be_allocator_fini(struct m0_be_allocator *a)
Definition: alloc.c:745
Definition: tx.h:280