return res;
}
- virtual void commit_start() = 0;
- virtual void commit_finish() = 0;
-
virtual void dump() = 0;
virtual void init_add_free(uint64_t offset, uint64_t length) = 0;
* Bitmap based in-memory allocator.
* Author: Ramesh Chander, Ramesh.Chander@sandisk.com
*
- * TBD list:
- * 1. Make commiting and un commiting lists concurrent.
*/
#include "BitAllocator.h"
BitMapAllocator::BitMapAllocator(int64_t device_size, int64_t block_size)
- : m_num_uncommitted(0),
- m_num_committing(0)
{
assert(ISP2(block_size));
if (!ISP2(block_size)) {
void BitMapAllocator::dump()
{
std::lock_guard<std::mutex> l(m_lock);
-
- dout(0) << __func__ << " instance " << (uint64_t) this
- << " Allocator Status dump : " << dendl;
-
+ dout(0) << __func__ << " instance " << this << dendl;
m_bit_alloc->dump();
- dout(0) << __func__ << " instance " << (uint64_t) this
- << " committing: " << m_committing.num_intervals() << " extents"
- << dendl;
-
- for (auto p = m_committing.begin();
- p != m_committing.end(); ++p) {
- dout(0) << __func__ << " instance " << (uint64_t) this
- << " 0x" << std::hex << p.get_start()
- << "~" << p.get_len() << std::dec
- << dendl;
- }
- dout(0) << __func__ << " instance " << (uint64_t) this
- << " uncommitted: " << m_uncommitted.num_intervals() << " extents"
- << dendl;
-
- for (auto p = m_uncommitted.begin();
- p != m_uncommitted.end(); ++p) {
- dout(0) << __func__ << " 0x" << std::hex << p.get_start()
- << "~" << p.get_len() << std::dec
- << dendl;
- }
}
void BitMapAllocator::init_add_free(uint64_t offset, uint64_t length)
m_bit_alloc->shutdown();
}
-void BitMapAllocator::commit_start()
-{
- std::lock_guard<std::mutex> l(m_lock);
-
- dout(10) << __func__ << " instance " << (uint64_t) this
- << " releasing " << m_num_uncommitted
- << " in extents " << m_uncommitted.num_intervals()
- << dendl;
- assert(m_committing.empty());
- m_committing.swap(m_uncommitted);
- m_num_committing = m_num_uncommitted;
- m_num_uncommitted = 0;
-}
-
-void BitMapAllocator::commit_finish()
-{
- std::lock_guard<std::mutex> l(m_lock);
- dout(10) << __func__ << " instance " << (uint64_t) this
- << " released " << m_num_committing
- << " in extents " << m_committing.num_intervals()
- << dendl;
- for (auto p = m_committing.begin();
- p != m_committing.end();
- ++p) {
- insert_free(p.get_start(), p.get_len());
- }
- m_committing.clear();
- m_num_committing = 0;
-}
class BitMapAllocator : public Allocator {
std::mutex m_lock;
- int64_t m_num_uncommitted;
- int64_t m_num_committing;
int64_t m_block_size;
int64_t m_num_reserved;
- btree_interval_set<uint64_t> m_uncommitted; ///< released but not yet usable
- btree_interval_set<uint64_t> m_committing; ///< released but not yet usable
BitAllocator *m_bit_alloc; // Bit allocator instance
void insert_free(uint64_t offset, uint64_t len);
int release(
uint64_t offset, uint64_t length);
- void commit_start();
- void commit_finish();
-
uint64_t get_free();
void dump() override;
StupidAllocator::StupidAllocator()
: num_free(0),
- num_uncommitted(0),
- num_committing(0),
num_reserved(0),
free(10),
last_alloc(0)
<< p.get_len() << std::dec << dendl;
}
}
- dout(0) << __func__ << " committing: "
- << committing.num_intervals() << " extents" << dendl;
- for (auto p = committing.begin();
- p != committing.end();
- ++p) {
- dout(0) << __func__ << " 0x" << std::hex << p.get_start() << "~"
- << p.get_len() << std::dec << dendl;
- }
- dout(0) << __func__ << " uncommitted: "
- << uncommitted.num_intervals() << " extents" << dendl;
- for (auto p = uncommitted.begin();
- p != uncommitted.end();
- ++p) {
- dout(0) << __func__ << " 0x" << std::hex << p.get_start() << "~"
- << p.get_len() << std::dec << dendl;
- }
}
void StupidAllocator::init_add_free(uint64_t offset, uint64_t length)
dout(1) << __func__ << dendl;
}
-void StupidAllocator::commit_start()
-{
- std::lock_guard<std::mutex> l(lock);
- dout(10) << __func__ << " releasing " << num_uncommitted
- << " in extents " << uncommitted.num_intervals() << dendl;
- assert(committing.empty());
- committing.swap(uncommitted);
- num_committing = num_uncommitted;
- num_uncommitted = 0;
-}
-
-void StupidAllocator::commit_finish()
-{
- std::lock_guard<std::mutex> l(lock);
- dout(10) << __func__ << " released " << num_committing
- << " in extents " << committing.num_intervals() << dendl;
- for (auto p = committing.begin();
- p != committing.end();
- ++p) {
- _insert_free(p.get_start(), p.get_len());
- }
- committing.clear();
- num_free += num_committing;
- num_committing = 0;
-}
std::mutex lock;
int64_t num_free; ///< total bytes in freelist
- int64_t num_uncommitted;
- int64_t num_committing;
int64_t num_reserved; ///< reserved bytes
std::vector<btree_interval_set<uint64_t> > free; ///< leading-edge copy
- btree_interval_set<uint64_t> uncommitted; ///< released but not yet usable
- btree_interval_set<uint64_t> committing; ///< released but not yet usable
uint64_t last_alloc;
int release(
uint64_t offset, uint64_t length);
- void commit_start();
- void commit_finish();
-
uint64_t get_free();
void dump() override;