Jinoh Kang (@iamahuman) commented about server/mapping.c:
- session_mapping = mapping;
- session.object_capacity = (mapping->size - offsetof(session_shm_t, objects[0])) / sizeof(session_obj_t);
- session.shared = tmp;
- return &mapping->obj;
+}
+static int grow_session_mapping(void) +{
- struct session new_session;
- unsigned int capacity;
- mem_size_t size;
- int unix_fd, i;
- struct fd *fd;
- capacity = session.object_capacity * 3 / 2;
To avoid unnecesary growth, I suggest that you keep track of number of allocated (`!invalid && !destroyed`) objects and use it to calculate capacity.
Otherwise, we end up unnecessarily extending size when e.g., 50% of the mapping is actually unused (invalid).