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 293
 ADVERTISED_PORT		"advertised_port"
291 294
 DISABLE_CORE		"disable_core_dump"
292 295
 OPEN_FD_LIMIT		"open_files_limit"
296
+SHM_FORCE_ALLOC		"shm_force_alloc"
297
+MLOCK_PAGES			"mlock_pages"
298
+REAL_TIME			"real_time"
299
+RT_PRIO				"rt_prio"
300
+RT_POLICY			"rt_policy"
301
+RT_TIMER1_PRIO		"rt_timer1_prio"|"rt_fast_timer_prio"|"rt_ftimer_prio"
302
+RT_TIMER1_POLICY	"rt_timer1_policy"|"rt_ftimer_policy"
303
+RT_TIMER2_PRIO		"rt_timer2_prio"|"rt_stimer_prio"
304
+RT_TIMER2_POLICY	"rt_timer2_policy"|"rt_stimer_policy"
293 305
 MCAST_LOOPBACK		"mcast_loopback"
294 306
 MCAST_TTL		"mcast_ttl"
295 307
 TOS			"tos"
... ...
@@ -535,6 +547,24 @@ EAT_ABLE	[\ \t\b\r]
535 547
 									return DISABLE_CORE; }
536 548
 <INITIAL>{OPEN_FD_LIMIT}		{	count(); yylval.strval=yytext;
537 549
 									return OPEN_FD_LIMIT; }
550
+<INITIAL>{SHM_FORCE_ALLOC}		{	count(); yylval.strval=yytext;
551
+									return SHM_FORCE_ALLOC; }
552
+<INITIAL>{MLOCK_PAGES}		{	count(); yylval.strval=yytext;
553
+									return MLOCK_PAGES; }
554
+<INITIAL>{REAL_TIME}		{	count(); yylval.strval=yytext;
555
+									return REAL_TIME; }
556
+<INITIAL>{RT_PRIO}		{	count(); yylval.strval=yytext;
557
+									return RT_PRIO; }
558
+<INITIAL>{RT_POLICY}		{	count(); yylval.strval=yytext;
559
+									return RT_POLICY; }
560
+<INITIAL>{RT_TIMER1_PRIO}		{	count(); yylval.strval=yytext;
561
+									return RT_TIMER1_PRIO; }
562
+<INITIAL>{RT_TIMER1_POLICY}		{	count(); yylval.strval=yytext;
563
+									return RT_TIMER1_POLICY; }
564
+<INITIAL>{RT_TIMER2_PRIO}		{	count(); yylval.strval=yytext;
565
+									return RT_TIMER2_PRIO; }
566
+<INITIAL>{RT_TIMER2_POLICY}		{	count(); yylval.strval=yytext;
567
+									return RT_TIMER2_POLICY; }
538 568
 <INITIAL>{MCAST_LOOPBACK}		{	count(); yylval.strval=yytext;
539 569
 									return MCAST_LOOPBACK; }
540 570
 <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 331
 %token ADVERTISED_PORT
329 332
 %token DISABLE_CORE
330 333
 %token OPEN_FD_LIMIT
334
+%token SHM_FORCE_ALLOC
335
+%token MLOCK_PAGES
336
+%token REAL_TIME
337
+%token RT_PRIO
338
+%token RT_POLICY
339
+%token RT_TIMER1_PRIO
340
+%token RT_TIMER1_POLICY
341
+%token RT_TIMER2_PRIO
342
+%token RT_TIMER2_POLICY
331 343
 %token MCAST_LOOPBACK
332 344
 %token MCAST_TTL
333 345
 %token TOS
... ...
@@ -897,6 +909,24 @@ assign_stm:
897 909
 	| DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
898 910
 	| OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
899 911
 	| OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
912
+	| SHM_FORCE_ALLOC EQUAL NUMBER { shm_force_alloc=$3; }
913
+	| SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
914
+	| MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
915
+	| MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
916
+	| REAL_TIME EQUAL NUMBER { real_time=$3; }
917
+	| REAL_TIME EQUAL error { yyerror("boolean value expected"); }
918
+	| RT_PRIO EQUAL NUMBER { rt_prio=$3; }
919
+	| RT_PRIO EQUAL error { yyerror("boolean value expected"); }
920
+	| RT_POLICY EQUAL NUMBER { rt_policy=$3; }
921
+	| RT_POLICY EQUAL error { yyerror("boolean value expected"); }
922
+	| RT_TIMER1_PRIO EQUAL NUMBER { rt_timer1_prio=$3; }
923
+	| RT_TIMER1_PRIO EQUAL error { yyerror("boolean value expected"); }
924
+	| RT_TIMER1_POLICY EQUAL NUMBER { rt_timer1_policy=$3; }
925
+	| RT_TIMER1_POLICY EQUAL error { yyerror("boolean value expected"); }
926
+	| RT_TIMER2_PRIO EQUAL NUMBER { rt_timer2_prio=$3; }
927
+	| RT_TIMER2_PRIO EQUAL error { yyerror("boolean value expected"); }
928
+	| RT_TIMER2_POLICY EQUAL NUMBER { rt_timer2_policy=$3; }
929
+	| RT_TIMER2_POLICY EQUAL error { yyerror("boolean value expected"); }
900 930
 	| MCAST_LOOPBACK EQUAL NUMBER {
901 931
 		#ifdef USE_MCAST
902 932
 			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 58
 #include <sys/resource.h> /* setrlimit */
57 59
 #include <unistd.h>
58 60
 
61
+#ifdef HAVE_SCHED_SETSCHEDULER
62
+#include <sched.h>
63
+#endif
64
+
65
+#ifdef _POSIX_MEMLOCK
66
+#define HAVE_MLOCKALL
67
+#include <sys/mman.h>
68
+#endif
69
+
59 70
 #include "daemonize.h"
60 71
 #include "globals.h"
61 72
 #include "dprint.h"
... ...
@@ -337,3 +348,75 @@ done:
337 348
 error:
338 349
 	return -1;
339 350
 }
351
+
352
+
353
+
354
+/* lock pages in memory (make the process not swapable) */
355
+int mem_lock_pages()
356
+{
357
+#ifdef HAVE_MLOCKALL
358
+	if (mlockall(MCL_CURRENT|MCL_FUTURE) !=0){
359
+		LOG(L_WARN,"failed to lock the memory pages (disable swap): %s [%d]\n",
360
+				strerror(errno), errno);
361
+		goto error;
362
+	}
363
+	return 0;
364
+error:
365
+	return -1;
366
+#else /* if MLOCKALL not defined return error */
367
+		LOG(L_WARN,"failed to lock the memory pages: no mlockall support\n");
368
+	return -1;
369
+#endif 
370
+}
371
+
372
+
373
+/* tries to set real time priority 
374
+ * policy: 0 - SCHED_OTHER, 1 - SCHED_RR, 2 - SCHED_FIFO */
375
+int set_rt_prio(int prio, int policy)
376
+{
377
+#ifdef HAVE_SCHED_SETSCHEDULER
378
+	struct sched_param sch_p;
379
+	int min_prio, max_prio;
380
+	int sched_policy;
381
+	
382
+	switch(policy){
383
+		case 0:
384
+			sched_policy=SCHED_OTHER;
385
+			break;
386
+		case 1:
387
+			sched_policy=SCHED_RR;
388
+			break;
389
+		case 2:
390
+			sched_policy=SCHED_FIFO;
391
+			break;
392
+		default:
393
+			LOG(L_WARN, "WARNING: invalid scheduling policy,using"
394
+						" SCHED_OTHER\n");
395
+			sched_policy=SCHED_OTHER;
396
+	}
397
+	memset(&sch_p, 0, sizeof(sch_p));
398
+	max_prio=sched_get_priority_max(policy);
399
+	min_prio=sched_get_priority_min(policy);
400
+	if (prio<min_prio){
401
+		LOG(L_WARN, "scheduling priority %d too small, using minimum value"
402
+					" (%d)\n", prio, min_prio);
403
+		prio=min_prio;
404
+	}else if (prio>max_prio){
405
+		LOG(L_WARN, "scheduling priority %d too big, using maximum value"
406
+					" (%d)\n", prio, max_prio);
407
+		prio=max_prio;
408
+	}
409
+	sch_p.sched_priority=prio;
410
+	if (sched_setscheduler(0, sched_policy, &sch_p) != 0){
411
+		LOG(L_WARN, "could not switch to real time priority: %s [%d]\n",
412
+					strerror(errno), errno);
413
+		return -1;
414
+	};
415
+	return 0;
416
+#else
417
+	LOG(L_WARN, "real time support not available\n");
418
+	return -1;
419
+#endif
420
+}
421
+
422
+
... ...
@@ -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 39
 int do_suid();
39 40
 int increase_open_fds(int target);
40 41
 int set_core_dump(int enable, int size);
42
+int mem_lock_pages();
43
+int set_rt_prio(int prio, int policy);
41 44
 
42 45
 
43 46
 #endif