while trying to prepare some diagrams to illustrate how the memory mapped
cache works I realized that we might not use the payload factor as
In sss_mmap_cache_init() we set a payload depending of the type of
cached data, e.g. for passwd data 4 * MC_SLOT_SIZE or for group data 3 *
MC_SLOT_SIZE. This value is used to calculate the data table size:
#define MC_DT_SIZE(elems, payload) ( (elems) * (payload) )
mc_ctx->dt_size = MC_DT_SIZE(n_elem, payload);
since this does not change the slot size there is now room for e.g
(n_elem * 4) slots for passwd data, which makes sense since we assume
that a typical passwd entry will occupy 4 slot and we want the cache to
be able to store n_elem passwd entries.
But the memory for the tree table is calculated only with n_elem
#define MC_FT_SIZE(elems) ( (elems) / 8 )
mc_ctx->ft_size = MC_FT_SIZE(n_elem);
This means that although we allocated memory for e.g. (4 * n_elem) slots
we can only handle n_elem slots because there are only n_elem bits in
the free table. As a result 3/4 of the allocate memory for the data is
unused and entries in the cache are overwritten earlier than needed.
Do you agree with this or did I miss something in the remaining part of
the code which makes sure the memory allocated for the data table can be
If not I would suggest to make the payload only a factor which then can
be used to allocate the memory for the data table and the free table.