]>
git.proxmox.com Git - ceph.git/blob - ceph/src/msg/xio/XioPool.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2014 CohortFS, LLC
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
24 #include "include/atomic.h"
25 #include "common/likely.h"
28 static inline int xpool_alloc(struct xio_mempool
*pool
, uint64_t size
,
29 struct xio_reg_mem
* mp
);
30 static inline void xpool_free(uint64_t size
, struct xio_reg_mem
* mp
);
37 struct xio_mempool
*handle
;
40 static bool trace_mempool
;
41 static bool trace_msgcnt
;
42 static const int MB
= 8;
45 struct xio_reg_mem mp
[1];
46 struct xio_piece
*next
;
51 explicit XioPool(struct xio_mempool
*_handle
) :
52 handle(_handle
), first(0)
60 if (unlikely(trace_mempool
)) {
61 memset(p
->payload
, 0xcf, p
->s
); // guard bytes
63 xpool_free(sizeof(struct xio_piece
)+(p
->s
)-MB
, p
->mp
);
66 void *alloc(size_t _s
)
69 struct xio_reg_mem mp
[1];
71 int e
= xpool_alloc(handle
, (sizeof(struct xio_piece
)-MB
) + _s
, mp
);
75 x
= reinterpret_cast<struct xio_piece
*>(mp
->addr
);
98 atomic_t ctr_set
[NUM_SLABS
];
100 atomic_t msg_cnt
; // send msgs
101 atomic_t hook_cnt
; // recv msgs
104 XioPoolStats() : msg_cnt(0), hook_cnt(0) {
105 for (int ix
= 0; ix
< NUM_SLABS
; ++ix
) {
110 void dump(const char* tag
, uint64_t serial
);
112 void inc(uint64_t size
) {
114 (ctr_set
[SLAB_64
]).inc();
118 (ctr_set
[SLAB_256
]).inc();
122 (ctr_set
[SLAB_1024
]).inc();
126 (ctr_set
[SLAB_PAGE
]).inc();
129 (ctr_set
[SLAB_MAX
]).inc();
132 void dec(uint64_t size
) {
134 (ctr_set
[SLAB_64
]).dec();
138 (ctr_set
[SLAB_256
]).dec();
142 (ctr_set
[SLAB_1024
]).dec();
146 (ctr_set
[SLAB_PAGE
]).dec();
149 (ctr_set
[SLAB_MAX
]).dec();
152 void inc_overflow() { ctr_set
[SLAB_OVERFLOW
].inc(); }
153 void dec_overflow() { ctr_set
[SLAB_OVERFLOW
].dec(); }
156 if (unlikely(XioPool::trace_msgcnt
)) {
162 if (unlikely(XioPool::trace_msgcnt
)) {
168 if (unlikely(XioPool::trace_msgcnt
)) {
174 if (unlikely(XioPool::trace_msgcnt
)) {
180 extern XioPoolStats xp_stats
;
182 static inline int xpool_alloc(struct xio_mempool
*pool
, uint64_t size
,
183 struct xio_reg_mem
* mp
)
185 // try to allocate from the xio pool
186 int r
= xio_mempool_alloc(pool
, size
, mp
);
188 if (unlikely(XioPool::trace_mempool
))
192 // fall back to malloc on errors
193 mp
->addr
= malloc(size
);
196 if (unlikely(XioPool::trace_mempool
))
197 xp_stats
.inc_overflow();
201 static inline void xpool_free(uint64_t size
, struct xio_reg_mem
* mp
)
204 if (unlikely(XioPool::trace_mempool
))
206 xio_mempool_free(mp
);
207 } else { // from malloc
208 if (unlikely(XioPool::trace_mempool
))
209 xp_stats
.dec_overflow();
214 #define xpool_inc_msgcnt() \
215 do { xp_stats.inc_msgcnt(); } while (0)
217 #define xpool_dec_msgcnt() \
218 do { xp_stats.dec_msgcnt(); } while (0)
220 #define xpool_inc_hookcnt() \
221 do { xp_stats.inc_hookcnt(); } while (0)
223 #define xpool_dec_hookcnt() \
224 do { xp_stats.dec_hookcnt(); } while (0)
226 #endif /* XIO_POOL_H */