Mercurial > hg > nginx
annotate src/os/unix/ngx_time.c @ 7985:ec2e6893caaa
Simplified sendfile(SF_NODISKIO) usage.
Starting with FreeBSD 11, there is no need to use AIO operations to preload
data into cache for sendfile(SF_NODISKIO) to work. Instead, sendfile()
handles non-blocking loading data from disk by itself. It still can, however,
return EBUSY if a page is already being loaded (for example, by a different
process). If this happens, we now post an event for the next event loop
iteration, so sendfile() is retried "after a short period", as manpage
recommends.
The limit of the number of EBUSY tolerated without any progress is preserved,
but now it does not result in an alert, since on an idle system event loop
iteration might be very short and EBUSY can happen many times in a row.
Instead, SF_NODISKIO is simply disabled for one call once the limit is
reached.
With this change, sendfile(SF_NODISKIO) is now used automatically as long as
sendfile() is enabled, and no longer requires "aio on;".
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 27 Dec 2021 19:48:33 +0300 |
parents | d620f497c50f |
children |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
6 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
9 #include <ngx_core.h> |
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
10 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
2220 | 12 /* |
13 * FreeBSD does not test /etc/localtime change, however, we can workaround it | |
14 * by calling tzset() with TZ and then without TZ to update timezone. | |
15 * The trick should work since FreeBSD 2.1.0. | |
16 * | |
17 * Linux does not test /etc/localtime change in localtime(), | |
18 * but may stat("/etc/localtime") several times in every strftime(), | |
19 * therefore we use it to update timezone. | |
20 * | |
21 * Solaris does not test /etc/TIMEZONE change too and no workaround available. | |
22 */ | |
23 | |
24 void | |
25 ngx_timezone_update(void) | |
26 { | |
27 #if (NGX_FREEBSD) | |
28 | |
29 if (getenv("TZ")) { | |
30 return; | |
31 } | |
32 | |
33 putenv("TZ=UTC"); | |
34 | |
35 tzset(); | |
36 | |
37 unsetenv("TZ"); | |
38 | |
39 tzset(); | |
40 | |
41 #elif (NGX_LINUX) | |
42 time_t s; | |
43 struct tm *t; | |
44 char buf[4]; | |
45 | |
46 s = time(0); | |
47 | |
48 t = localtime(&s); | |
49 | |
50 strftime(buf, 4, "%H", t); | |
51 | |
52 #endif | |
53 } | |
54 | |
55 | |
563 | 56 void |
57 ngx_localtime(time_t s, ngx_tm_t *tm) | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
58 { |
469 | 59 #if (NGX_HAVE_LOCALTIME_R) |
563 | 60 (void) localtime_r(&s, tm); |
178
a8ff48d26cca
nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
61 |
179
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
62 #else |
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
63 ngx_tm_t *t; |
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
64 |
563 | 65 t = localtime(&s); |
179
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
66 *tm = *t; |
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
67 |
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
68 #endif |
9f3a78b06c48
nginx-0.0.1-2003-11-11-21:13:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
178
diff
changeset
|
69 |
28
a117a7fdf042
nginx-0.0.1-2002-12-16-00:08:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
70 tm->ngx_tm_mon++; |
a117a7fdf042
nginx-0.0.1-2002-12-16-00:08:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
71 tm->ngx_tm_year += 1900; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 } |
509 | 73 |
74 | |
563 | 75 void |
76 ngx_libc_localtime(time_t s, struct tm *tm) | |
509 | 77 { |
78 #if (NGX_HAVE_LOCALTIME_R) | |
563 | 79 (void) localtime_r(&s, tm); |
509 | 80 |
81 #else | |
82 struct tm *t; | |
83 | |
563 | 84 t = localtime(&s); |
509 | 85 *tm = *t; |
86 | |
87 #endif | |
88 } | |
89 | |
90 | |
563 | 91 void |
92 ngx_libc_gmtime(time_t s, struct tm *tm) | |
509 | 93 { |
94 #if (NGX_HAVE_LOCALTIME_R) | |
563 | 95 (void) gmtime_r(&s, tm); |
509 | 96 |
97 #else | |
98 struct tm *t; | |
99 | |
563 | 100 t = gmtime(&s); |
509 | 101 *tm = *t; |
102 | |
103 #endif | |
104 } |