Skip to content

Commit

Permalink
lib: make htable buffersize a template parameter
Browse files Browse the repository at this point in the history
Previously you could name the number of pages you wanted htable to
allocate per BigBuf when calling the constructor. This can now be
selected as small/medium/large as a template parameter. As before the
default is large to provide best performance, but also produce maximum
overhead.
  • Loading branch information
arogge committed Feb 24, 2022
1 parent a27e023 commit 4e68f7d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
5 changes: 2 additions & 3 deletions core/src/dird/ndmp_fhdb_mem.cc
Expand Up @@ -111,7 +111,7 @@ struct ooo_metadata {
};
typedef struct ooo_metadata OOO_MD;

using MetadataTable = htable<uint64_t, OOO_MD>;
using MetadataTable = htable<uint64_t, OOO_MD, htableBufferSize::small>;

struct fhdb_state_mem {
N_TREE_ROOT* fhdb_root;
Expand Down Expand Up @@ -438,8 +438,7 @@ static inline void add_out_of_order_metadata(NIS* nis,
item_size = sizeof(OOO_MD);
nr_items = (nr_pages * B_PAGE_SIZE) / item_size;

meta_data
= new MetadataTable(md_entry, &md_entry->link, nr_items, nr_pages);
meta_data = new MetadataTable(md_entry, &md_entry->link, nr_items);
((struct fhdb_state_mem*)nis->fhdb_state)->out_of_order_metadata
= meta_data;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/findlib/find.h
Expand Up @@ -186,7 +186,7 @@ struct CurLink {
char name[1]; /**< The name */
};

using LinkHash = htable<htable_binary_key, CurLink>;
using LinkHash = htable<htable_binary_key, CurLink, htableBufferSize::medium>;


/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/findlib/hardlink.cc
Expand Up @@ -63,7 +63,7 @@ CurLink* new_hardlink(JobControlRecord* jcr,
uint8_t* new_key;

if (!ff_pkt->linkhash) {
ff_pkt->linkhash = new LinkHash(hl, &hl->link, 10000, 480);
ff_pkt->linkhash = new LinkHash(hl, &hl->link, 10000);
}

len = strlen(fname) + 1;
Expand Down
23 changes: 21 additions & 2 deletions core/src/lib/htable.h
Expand Up @@ -127,13 +127,32 @@ struct htable_binary_key {
uint32_t len;
};

template <typename Key, typename T> class htable {
enum class htableBufferSize
{
small,
medium,
large
};

template <typename Key,
typename T,
enum htableBufferSize BufferSize = htableBufferSize::large>
class htable {
std::unique_ptr<htableImpl> pimpl;

public:
htable() { pimpl = std::make_unique<htableImpl>(); }
htable(T* item, hlink* link, int tsize = 31, int nr_pages = 0)
htable(T* item, hlink* link, int tsize = 31)
{
int nr_pages = 0;
if constexpr (BufferSize == htableBufferSize::large) {
nr_pages = 0;
} else if constexpr (BufferSize == htableBufferSize::medium) {
nr_pages = 512;
} else if constexpr (BufferSize == htableBufferSize::small) {
nr_pages = 1;
}

pimpl = std::make_unique<htableImpl>(item, link, tsize, nr_pages);
}
T* lookup(Key key)
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/tree.cc
Expand Up @@ -92,7 +92,7 @@ TREE_ROOT* new_tree(int count)
root->type = TN_ROOT;
root->fname = "";
HL_ENTRY* entry = NULL;
new (&root->hardlinks) HardlinkTable(entry, &entry->link, 0, 1);
new (&root->hardlinks) HardlinkTable(entry, &entry->link);
return root;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/lib/tree.h
Expand Up @@ -108,7 +108,7 @@ struct s_hl_entry {
};
typedef struct s_hl_entry HL_ENTRY;

using HardlinkTable = htable<uint64_t, HL_ENTRY>;
using HardlinkTable = htable<uint64_t, HL_ENTRY, htableBufferSize::small>;

struct s_tree_root {
s_tree_root()
Expand Down

0 comments on commit 4e68f7d

Please sign in to comment.