Skip to content

Commit

Permalink
nginx: Share necessary heap allocated pools
Browse files Browse the repository at this point in the history
These changes are sufficient to get the RTMP streaming module to service
an input stream and convert to HLS.
  • Loading branch information
rinon committed Oct 17, 2023
1 parent 468a77d commit 37d68cc
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion external/nginx-rtmp-module/ngx_rtmp_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ ngx_rtmp_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_value(conf->busy, prev->busy, 0);

if (prev->pool == NULL) {
prev->pool = ngx_create_pool(4096, &cf->cycle->new_log);
prev->pool = ngx_create_shared_pool(4096, &cf->cycle->new_log);
if (prev->pool == NULL) {
return NGX_CONF_ERROR;
}
Expand Down
2 changes: 1 addition & 1 deletion external/nginx-rtmp-module/ngx_rtmp_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ ngx_rtmp_set_chunk_size(ngx_rtmp_session_t *s, ngx_uint_t size)

s->in_old_pool = s->in_pool;
s->in_chunk_size = size;
s->in_pool = ngx_create_pool(4096, s->connection->log);
s->in_pool = ngx_create_shared_pool(4096, s->connection->log);

/* copy existing chunk data */
if (s->in_old_pool) {
Expand Down
2 changes: 1 addition & 1 deletion external/nginx/src/core/nginx.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ main(int argc, char *const *argv)
init_cycle.log = log;
ngx_cycle = &init_cycle;

init_cycle.pool = ngx_create_pool(1024, log);
init_cycle.pool = ngx_create_shared_pool(1024, log);
if (init_cycle.pool == NULL) {
return 1;
}
Expand Down
7 changes: 7 additions & 0 deletions external/nginx/src/core/ngx_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <ngx_config.h>
#include <ngx_core.h>

#include <ia2.h>

typedef void * ngx_buf_tag_t;

Expand Down Expand Up @@ -121,6 +122,7 @@ typedef struct {

#define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR

IA2_BEGIN_NO_WRAP

#define ngx_buf_in_memory(b) ((b)->temporary || (b)->memory || (b)->mmap)
#define ngx_buf_in_memory_only(b) (ngx_buf_in_memory(b) && !(b)->in_file)
Expand Down Expand Up @@ -152,7 +154,10 @@ ngx_chain_t *ngx_alloc_chain_link(ngx_pool_t *pool);


ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in);
IA2_END_NO_WRAP
/* ngx_chain_writer is used as a callback, so must be wrapped */
ngx_int_t ngx_chain_writer(void *ctx, ngx_chain_t *in);
IA2_BEGIN_NO_WRAP

ngx_int_t ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain,
ngx_chain_t *in);
Expand All @@ -164,4 +169,6 @@ off_t ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit);

ngx_chain_t *ngx_chain_update_sent(ngx_chain_t *in, off_t sent);

IA2_END_NO_WRAP

#endif /* _NGX_BUF_H_INCLUDED_ */
6 changes: 6 additions & 0 deletions external/nginx/src/core/ngx_palloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <ngx_config.h>
#include <ngx_core.h>

#include <ia2.h>

/*
* NGX_MAX_ALLOC_FROM_POOL should be (ngx_pagesize - 1), i.e. 4095 on x86.
Expand Down Expand Up @@ -72,6 +73,7 @@ typedef struct {
ngx_log_t *log;
} ngx_pool_cleanup_file_t;

IA2_BEGIN_NO_WRAP

ngx_pool_t *ngx_create_pool(size_t size, ngx_log_t *log);
ngx_pool_t *ngx_create_shared_pool(size_t size, ngx_log_t *log);
Expand All @@ -87,6 +89,10 @@ ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p);

ngx_pool_cleanup_t *ngx_pool_cleanup_add(ngx_pool_t *p, size_t size);
void ngx_pool_run_cleanup_file(ngx_pool_t *p, ngx_fd_t fd);

IA2_END_NO_WRAP

/* cleanup callback is wrapped */
void ngx_pool_cleanup_file(void *data);
void ngx_pool_delete_file(void *data);

Expand Down
6 changes: 3 additions & 3 deletions external/nginx/src/event/ngx_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,14 +734,14 @@ ngx_event_process_init(ngx_cycle_t *cycle)
#endif

cycle->connections =
ngx_alloc(sizeof(ngx_connection_t) * cycle->connection_n, cycle->log);
ngx_shared_alloc(sizeof(ngx_connection_t) * cycle->connection_n, cycle->log);
if (cycle->connections == NULL) {
return NGX_ERROR;
}

c = cycle->connections;

cycle->read_events = ngx_alloc(sizeof(ngx_event_t) * cycle->connection_n,
cycle->read_events = ngx_shared_alloc(sizeof(ngx_event_t) * cycle->connection_n,
cycle->log);
if (cycle->read_events == NULL) {
return NGX_ERROR;
Expand All @@ -753,7 +753,7 @@ ngx_event_process_init(ngx_cycle_t *cycle)
rev[i].instance = 1;
}

cycle->write_events = ngx_alloc(sizeof(ngx_event_t) * cycle->connection_n,
cycle->write_events = ngx_shared_alloc(sizeof(ngx_event_t) * cycle->connection_n,
cycle->log);
if (cycle->write_events == NULL) {
return NGX_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion external/nginx/src/event/ngx_event_accept.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ ngx_event_accept(ngx_event_t *ev)
(void) ngx_atomic_fetch_add(ngx_stat_active, 1);
#endif

c->pool = ngx_create_pool(ls->pool_size, ev->log);
c->pool = ngx_create_shared_pool(ls->pool_size, ev->log);
if (c->pool == NULL) {
ngx_close_accepted_connection(c);
return;
Expand Down
2 changes: 1 addition & 1 deletion external/nginx/src/event/ngx_event_posted.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

ngx_queue_t ngx_posted_accept_events;
ngx_queue_t ngx_posted_next_events;
ngx_queue_t ngx_posted_events;
ngx_queue_t ngx_posted_events IA2_SHARED_DATA;


void
Expand Down
4 changes: 2 additions & 2 deletions external/nginx/src/os/unix/ngx_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <ia2_allocator.h>


ngx_uint_t ngx_pagesize;
ngx_uint_t ngx_pagesize_shift;
ngx_uint_t ngx_pagesize IA2_SHARED_DATA;
ngx_uint_t ngx_pagesize_shift IA2_SHARED_DATA;
ngx_uint_t ngx_cacheline_size IA2_SHARED_DATA;


Expand Down

0 comments on commit 37d68cc

Please sign in to comment.