#define segment_manager_foreach_segment_w_lock(VAR, SM, BODY) \
do { \
clib_rwlock_reader_lock (&(SM)->segments_rwlock); \
- pool_foreach((VAR), ((SM)->segments), (BODY)); \
+ pool_foreach((VAR), ((SM)->segments)) (BODY); \
clib_rwlock_reader_unlock (&(SM)->segments_rwlock); \
} while (0)
}
}
else
- seg_name = format (0, "%s%c", "process-private", 0);
+ {
+ app_worker_t *app_wrk = app_worker_get (sm->app_wrk_index);
+ application_t *app = application_get (app_wrk->app_index);
+ seg_name = format (0, "%v segment%c", app->name, 0);
+ }
fs->ssvm.ssvm_size = segment_size;
fs->ssvm.name = seg_name;
- fs->ssvm.requested_va = baseva;
+ /* clib_mem_vm_map_shared consumes first page before requested_va */
+ fs->ssvm.requested_va = baseva + page_size;
- if ((rv = ssvm_master_init (&fs->ssvm, props->segment_type)))
+ if ((rv = ssvm_server_init (&fs->ssvm, props->segment_type)))
{
clib_warning ("svm_master_init ('%v', %u) failed", seg_name,
segment_size);
if (ssvm_type (&fs->ssvm) != SSVM_SEGMENT_PRIVATE)
{
- clib_valloc_free (&smm->va_allocator, fs->ssvm.requested_va);
+ /* clib_mem_vm_map_shared consumes first page before requested_va */
+ clib_valloc_free (&smm->va_allocator,
+ fs->ssvm.requested_va - clib_mem_get_page_size ());
if (!segment_manager_app_detached (sm))
{
* Removes segment after acquiring writer lock
*/
static inline void
-segment_manager_lock_and_del_segment (segment_manager_t * sm, u32 fs_index)
+sm_lock_and_del_segment_inline (segment_manager_t * sm, u32 fs_index)
{
fifo_segment_t *fs;
u8 is_prealloc;
clib_rwlock_writer_unlock (&sm->segments_rwlock);
}
+void
+segment_manager_lock_and_del_segment (segment_manager_t * sm, u32 fs_index)
+{
+ sm_lock_and_del_segment_inline (sm, fs_index);
+}
+
/**
* Reads a segment from the segment manager's pool without lock
*/
return sm;
}
-/**
- * Initializes segment manager based on options provided.
- * Returns error if ssvm segment(s) allocation fails.
- */
int
segment_manager_init (segment_manager_t * sm)
{
segment_manager_props_t *props;
- uword first_seg_size;
- fifo_segment_t *fs;
- int fs_index, i;
props = segment_manager_properties_get (sm);
- first_seg_size = clib_max (props->segment_size,
- sm_main.default_segment_size);
sm->max_fifo_size = props->max_fifo_size ?
props->max_fifo_size : sm_main.default_max_fifo_size;
segment_manager_set_watermarks (sm,
props->high_watermark,
props->low_watermark);
+ return 0;
+}
+
+/**
+ * Initializes segment manager based on options provided.
+ * Returns error if ssvm segment(s) allocation fails.
+ */
+int
+segment_manager_init_first (segment_manager_t * sm)
+{
+ segment_manager_props_t *props;
+ uword first_seg_size;
+ fifo_segment_t *fs;
+ int fs_index, i;
+
+ segment_manager_init (sm);
+ props = segment_manager_properties_get (sm);
+ first_seg_size = clib_max (props->segment_size,
+ sm_main.default_segment_size);
if (props->prealloc_fifos)
{
clib_rwlock_writer_lock (&sm->segments_rwlock);
/* *INDENT-OFF* */
- pool_foreach (fifo_segment, sm->segments, ({
+ pool_foreach (fifo_segment, sm->segments) {
segment_manager_del_segment (sm, fifo_segment);
- }));
+ }
/* *INDENT-ON* */
clib_rwlock_writer_unlock (&sm->segments_rwlock);
segment_manager_segment_reader_lock (sm);
/* *INDENT-OFF* */
- pool_foreach (cur, sm->segments, ({
+ pool_foreach (cur, sm->segments) {
free_bytes = fifo_segment_available_bytes (cur);
if (free_bytes > max_free_bytes)
{
max_free_bytes = free_bytes;
fs = cur;
}
- }));
+ }
/* *INDENT-ON* */
if (fs)
}
else
{
- clib_warning ("Can't add new seg and no space to allocate fifos!");
+ SESSION_DBG ("Can't add new seg and no space to allocate fifos!");
return SESSION_E_SEG_NO_SPACE;
}
}
/* Remove segment if it holds no fifos or first but not protected */
if (segment_index != 0 || !sm->first_is_protected)
- segment_manager_lock_and_del_segment (sm, segment_index);
+ sm_lock_and_del_segment_inline (sm, segment_index);
/* Remove segment manager if no sessions and detached from app */
if (segment_manager_app_detached (sm)
"HighWater", "LowWater", "FifoTuning");
/* *INDENT-OFF* */
- pool_foreach (sm, smm->segment_managers, ({
+ pool_foreach (sm, smm->segment_managers) {
app_wrk = app_worker_get_if_valid (sm->app_wrk_index);
app = app_wrk ? application_get (app_wrk->app_index) : 0;
custom_logic = (app && (app->cb_fns.fifo_tuning_callback)) ? 1 : 0;
format_memory_size, max_fifo_size,
sm->high_watermark, sm->low_watermark,
custom_logic ? "custom" : "none");
- }));
+ }
/* *INDENT-ON* */
+ vlib_cli_output (vm, "\n");
}
if (show_segments)
{
vlib_cli_output (vm, "%U", format_fifo_segment, 0, verbose);
/* *INDENT-OFF* */
- pool_foreach (sm, smm->segment_managers, ({
+ pool_foreach (sm, smm->segment_managers) {
segment_manager_foreach_segment_w_lock (seg, sm, ({
vlib_cli_output (vm, "%U", format_fifo_segment, seg, verbose);
}));
- }));
+ }
/* *INDENT-ON* */
}
clib_rwlock_reader_lock (&sm->segments_rwlock);
/* *INDENT-OFF* */
- pool_foreach (fs, sm->segments, ({
+ pool_foreach (fs, sm->segments) {
for (slice_index = 0; slice_index < fs->n_slices; slice_index++)
{
f = fifo_segment_get_slice_fifo_list (fs, slice_index);
str = format (0, "%U", format_session, session, verbose);
if (verbose)
- s = format (s, "%-40s%-20s%-15u%-10u", str, app_name,
+ s = format (s, "%-40v%-20v%-15u%-10u", str, app_name,
app_wrk->api_client_index, app_wrk->connects_seg_manager);
else
- s = format (s, "%-40s%-20s", str, app_name);
+ s = format (s, "%-40v%-20v", str, app_name);
vlib_cli_output (vm, "%v", s);
vec_reset_length (s);
}
vec_free (s);
}
- }));
+ }
/* *INDENT-ON* */
clib_rwlock_reader_unlock (&sm->segments_rwlock);