Browse code

- new script config vars: mlock_pages, shm_force_alloc, real_time, rt_prio, rt_policy, rt_timer1_prio, rt_timer1_policy, rt_timer2_prio, rt_timer2_policy (for more info see NEWS)

Andrei Pelinescu-Onciul authored on 07/06/2007 21:44:00
Showing 6 changed files
... ...
@@ -71,10 +71,36 @@ modules:
71 71
                         - t_set_retr(t1, t2) - changes the retransmissions
72 72
                            intervals on the fly, on a per transaction basis.
73 73
 core:
74
+             - support for locking ser's pages in memory, pre-mapping
75
+               all the shared memory on startup (fill it with 0)
76
+             - real time options
77
+             - devel: new PROC_INIT rank, init_child(PROC_INIT) called first
74 78
              - futex support on linux (better behaviour when waiting on 
75 79
                long held locks, almost no performance impact otherwise)
76 80
 
77 81
 new config variables:
82
+  mlock_pages = yes |no (default no) - locks all ser pages into memory making 
83
+    it unswappable (in general one doesn't want his sip proxy swapped out :-))
84
+  shm_force_alloc = yes | no (default no) - tries to pre-fault all the 
85
+    shared memory, before starting. When on start time will increase, but
86
+    combined with mlock_pages will guarantee ser will get all its memory from
87
+    the beginning (no more kswapd slow downs)
88
+  real_time = <int> (flags) (default off). - sets real time priority
89
+     for all the ser processes, or the timers. 
90
+     Possible values:   0  - off
91
+                        1  - the "fast" timer
92
+                        2  - the "slow" timer
93
+                        4  - all processes, except the timers
94
+     Example: real_time= 7 => everything switched to real time priority.
95
+  rt_prio = <int> (default 0) - real time priority used for everything except
96
+     the timers, if real_time is enabled
97
+  rt_policy= <0..3> (default 0)- real time scheduling policy, 0 = SCHED_OTHER,
98
+     1= SCHED_RR and 2=SCHED_FIFO
99
+  rt_timer1_prio=<int> (default 0) - like rt_prio but for the "fast" timer
100
+     process (if real_time & 1)
101
+  rt_timer1_policy=<0..3> (default 0) - like rt_policy but for the "fast" timer
102
+  rt_timer2_prio=<int> (default 0) - like rt_prio but for the "slow" timer
103
+  rt_timer2_policy=<0..3> (default 0) - like rt_policy but for the "slow" timer
78 104
   tcp_source_ipv4 = IPv4 address
79 105
   tcp_source_ipv6 = IPv6 address
80 106
     Set the given source IP for all outbound TCP connections.
... ...
@@ -64,6 +64,9 @@
64 64
  *              options (andrei)
65 65
  *  2006-10-13  added STUN_ALLOW_STUN, STUN_ALLOW_FP, STUN_REFRESH_INTERVAL
66 66
  *              (vlada)
67
+ *  2007-06-07  added SHM_FORCE_ALLOC, MLOCK_PAGES, REAL_TIME, RT_PRIO,
68
+ *              RT_POLICY, RT_TIMER1_PRIO, RT_TIMER1_POLICY, RT_TIMER2_PRIO,
69
+ *              RT_TIMER2_POLICY (andrei)
67 70
  */
68 71
 
69 72
 
... ...
@@ -290,6 +293,15 @@ ADVERTISED_ADDRESS	"advertised_address"
290 290
 ADVERTISED_PORT		"advertised_port"
291 291
 DISABLE_CORE		"disable_core_dump"
292 292
 OPEN_FD_LIMIT		"open_files_limit"
293
+SHM_FORCE_ALLOC		"shm_force_alloc"
294
+MLOCK_PAGES			"mlock_pages"
295
+REAL_TIME			"real_time"
296
+RT_PRIO				"rt_prio"
297
+RT_POLICY			"rt_policy"
298
+RT_TIMER1_PRIO		"rt_timer1_prio"|"rt_fast_timer_prio"|"rt_ftimer_prio"
299
+RT_TIMER1_POLICY	"rt_timer1_policy"|"rt_ftimer_policy"
300
+RT_TIMER2_PRIO		"rt_timer2_prio"|"rt_stimer_prio"
301
+RT_TIMER2_POLICY	"rt_timer2_policy"|"rt_stimer_policy"
293 302
 MCAST_LOOPBACK		"mcast_loopback"
294 303
 MCAST_TTL		"mcast_ttl"
295 304
 TOS			"tos"
... ...
@@ -535,6 +547,24 @@ EAT_ABLE	[\ \t\b\r]
535 535
 									return DISABLE_CORE; }
536 536
 <INITIAL>{OPEN_FD_LIMIT}		{	count(); yylval.strval=yytext;
537 537
 									return OPEN_FD_LIMIT; }
538
+<INITIAL>{SHM_FORCE_ALLOC}		{	count(); yylval.strval=yytext;
539
+									return SHM_FORCE_ALLOC; }
540
+<INITIAL>{MLOCK_PAGES}		{	count(); yylval.strval=yytext;
541
+									return MLOCK_PAGES; }
542
+<INITIAL>{REAL_TIME}		{	count(); yylval.strval=yytext;
543
+									return REAL_TIME; }
544
+<INITIAL>{RT_PRIO}		{	count(); yylval.strval=yytext;
545
+									return RT_PRIO; }
546
+<INITIAL>{RT_POLICY}		{	count(); yylval.strval=yytext;
547
+									return RT_POLICY; }
548
+<INITIAL>{RT_TIMER1_PRIO}		{	count(); yylval.strval=yytext;
549
+									return RT_TIMER1_PRIO; }
550
+<INITIAL>{RT_TIMER1_POLICY}		{	count(); yylval.strval=yytext;
551
+									return RT_TIMER1_POLICY; }
552
+<INITIAL>{RT_TIMER2_PRIO}		{	count(); yylval.strval=yytext;
553
+									return RT_TIMER2_PRIO; }
554
+<INITIAL>{RT_TIMER2_POLICY}		{	count(); yylval.strval=yytext;
555
+									return RT_TIMER2_POLICY; }
538 556
 <INITIAL>{MCAST_LOOPBACK}		{	count(); yylval.strval=yytext;
539 557
 									return MCAST_LOOPBACK; }
540 558
 <INITIAL>{MCAST_TTL}		{	count(); yylval.strval=yytext;
... ...
@@ -78,6 +78,9 @@
78 78
  *              (vlada)
79 79
  * 2007-02-09  separated command needed for tls-in-core and for tls in general
80 80
  *              (andrei)
81
+ *  2007-06-07  added SHM_FORCE_ALLOC, MLOCK_PAGES, REAL_TIME, RT_PRIO,
82
+ *              RT_POLICY, RT_TIMER1_PRIO, RT_TIMER1_POLICY, RT_TIMER2_PRIO,
83
+ *              RT_TIMER2_POLICY (andrei)
81 84
  */
82 85
 
83 86
 %{
... ...
@@ -328,6 +331,15 @@ static struct socket_id* mk_listen_id(char*, int, int);
328 328
 %token ADVERTISED_PORT
329 329
 %token DISABLE_CORE
330 330
 %token OPEN_FD_LIMIT
331
+%token SHM_FORCE_ALLOC
332
+%token MLOCK_PAGES
333
+%token REAL_TIME
334
+%token RT_PRIO
335
+%token RT_POLICY
336
+%token RT_TIMER1_PRIO
337
+%token RT_TIMER1_POLICY
338
+%token RT_TIMER2_PRIO
339
+%token RT_TIMER2_POLICY
331 340
 %token MCAST_LOOPBACK
332 341
 %token MCAST_TTL
333 342
 %token TOS
... ...
@@ -897,6 +909,24 @@ assign_stm:
897 897
 	| DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
898 898
 	| OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
899 899
 	| OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
900
+	| SHM_FORCE_ALLOC EQUAL NUMBER { shm_force_alloc=$3; }
901
+	| SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
902
+	| MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
903
+	| MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
904
+	| REAL_TIME EQUAL NUMBER { real_time=$3; }
905
+	| REAL_TIME EQUAL error { yyerror("boolean value expected"); }
906
+	| RT_PRIO EQUAL NUMBER { rt_prio=$3; }
907
+	| RT_PRIO EQUAL error { yyerror("boolean value expected"); }
908
+	| RT_POLICY EQUAL NUMBER { rt_policy=$3; }
909
+	| RT_POLICY EQUAL error { yyerror("boolean value expected"); }
910
+	| RT_TIMER1_PRIO EQUAL NUMBER { rt_timer1_prio=$3; }
911
+	| RT_TIMER1_PRIO EQUAL error { yyerror("boolean value expected"); }
912
+	| RT_TIMER1_POLICY EQUAL NUMBER { rt_timer1_policy=$3; }
913
+	| RT_TIMER1_POLICY EQUAL error { yyerror("boolean value expected"); }
914
+	| RT_TIMER2_PRIO EQUAL NUMBER { rt_timer2_prio=$3; }
915
+	| RT_TIMER2_PRIO EQUAL error { yyerror("boolean value expected"); }
916
+	| RT_TIMER2_POLICY EQUAL NUMBER { rt_timer2_policy=$3; }
917
+	| RT_TIMER2_POLICY EQUAL error { yyerror("boolean value expected"); }
900 918
 	| MCAST_LOOPBACK EQUAL NUMBER {
901 919
 		#ifdef USE_MCAST
902 920
 			mcast_loopback=$3;
... ...
@@ -289,11 +289,11 @@ static void core_shmmem(rpc_t* rpc, void* c)
289 289
 	shm_info(&mi);
290 290
 	rpc->add(c, "{", &handle);
291 291
 	rpc->struct_add(handle, "ddddd",
292
-		"total", mi.total_size,
293
-		"free", mi.free,
294
-		"used", mi.real_used,
295
-		"max_used", mi.max_used,
296
-		"fragments", mi.total_frags
292
+		"total", (unsigned int)mi.total_size,
293
+		"free", (unsigned int)mi.free,
294
+		"used", (unsigned int)mi.real_used,
295
+		"max_used", (unsigned int)mi.max_used,
296
+		"fragments", (unsigned int)mi.total_frags
297 297
 	);
298 298
 }
299 299
 
... ...
@@ -32,6 +32,8 @@
32 32
  *  2004-03-04  moved setuid/setgid in do_suid() (andrei)
33 33
  *  2004-03-25  added increase_open_fds & set_core_dump (andrei)
34 34
  *  2004-05-03  applied pgid patch from janakj
35
+ *  2007-06-07  added mlock_pages (no swap) support (andrei)
36
+  *             added set_rt_prio() (andrei)
35 37
  */
36 38
 
37 39
 
... ...
@@ -56,6 +58,15 @@
56 56
 #include <sys/resource.h> /* setrlimit */
57 57
 #include <unistd.h>
58 58
 
59
+#ifdef HAVE_SCHED_SETSCHEDULER
60
+#include <sched.h>
61
+#endif
62
+
63
+#ifdef _POSIX_MEMLOCK
64
+#define HAVE_MLOCKALL
65
+#include <sys/mman.h>
66
+#endif
67
+
59 68
 #include "daemonize.h"
60 69
 #include "globals.h"
61 70
 #include "dprint.h"
... ...
@@ -337,3 +348,75 @@ done:
337 337
 error:
338 338
 	return -1;
339 339
 }
340
+
341
+
342
+
343
+/* lock pages in memory (make the process not swapable) */
344
+int mem_lock_pages()
345
+{
346
+#ifdef HAVE_MLOCKALL
347
+	if (mlockall(MCL_CURRENT|MCL_FUTURE) !=0){
348
+		LOG(L_WARN,"failed to lock the memory pages (disable swap): %s [%d]\n",
349
+				strerror(errno), errno);
350
+		goto error;
351
+	}
352
+	return 0;
353
+error:
354
+	return -1;
355
+#else /* if MLOCKALL not defined return error */
356
+		LOG(L_WARN,"failed to lock the memory pages: no mlockall support\n");
357
+	return -1;
358
+#endif 
359
+}
360
+
361
+
362
+/* tries to set real time priority 
363
+ * policy: 0 - SCHED_OTHER, 1 - SCHED_RR, 2 - SCHED_FIFO */
364
+int set_rt_prio(int prio, int policy)
365
+{
366
+#ifdef HAVE_SCHED_SETSCHEDULER
367
+	struct sched_param sch_p;
368
+	int min_prio, max_prio;
369
+	int sched_policy;
370
+	
371
+	switch(policy){
372
+		case 0:
373
+			sched_policy=SCHED_OTHER;
374
+			break;
375
+		case 1:
376
+			sched_policy=SCHED_RR;
377
+			break;
378
+		case 2:
379
+			sched_policy=SCHED_FIFO;
380
+			break;
381
+		default:
382
+			LOG(L_WARN, "WARNING: invalid scheduling policy,using"
383
+						" SCHED_OTHER\n");
384
+			sched_policy=SCHED_OTHER;
385
+	}
386
+	memset(&sch_p, 0, sizeof(sch_p));
387
+	max_prio=sched_get_priority_max(policy);
388
+	min_prio=sched_get_priority_min(policy);
389
+	if (prio<min_prio){
390
+		LOG(L_WARN, "scheduling priority %d too small, using minimum value"
391
+					" (%d)\n", prio, min_prio);
392
+		prio=min_prio;
393
+	}else if (prio>max_prio){
394
+		LOG(L_WARN, "scheduling priority %d too big, using maximum value"
395
+					" (%d)\n", prio, max_prio);
396
+		prio=max_prio;
397
+	}
398
+	sch_p.sched_priority=prio;
399
+	if (sched_setscheduler(0, sched_policy, &sch_p) != 0){
400
+		LOG(L_WARN, "could not switch to real time priority: %s [%d]\n",
401
+					strerror(errno), errno);
402
+		return -1;
403
+	};
404
+	return 0;
405
+#else
406
+	LOG(L_WARN, "real time support not available\n");
407
+	return -1;
408
+#endif
409
+}
410
+
411
+
... ...
@@ -29,6 +29,7 @@
29 29
  * History:
30 30
  * --------
31 31
  *  2004-02-20  created by andrei
32
+ *  2007-06-07 added mem_lock_pages() (andrei)
32 33
  */
33 34
 
34 35
 #ifndef _daemonize_h
... ...
@@ -38,6 +39,8 @@ int daemonize(char* name);
38 38
 int do_suid();
39 39
 int increase_open_fds(int target);
40 40
 int set_core_dump(int enable, int size);
41
+int mem_lock_pages();
42
+int set_rt_prio(int prio, int policy);
41 43
 
42 44
 
43 45
 #endif