- Notifications
You must be signed in to change notification settings - Fork5
Commit62c8421
committed
Reduce stack space consumption in tzload().
While syncing our timezone code with IANA's updates in commit1c1a7cb,I'd chosen not to adopt the code they conditionally compile under #ifdefALL_STATE. The main thing that that drives is that the space for gmtimeand localtime timezone definitions isn't statically allocated, but ismalloc'd on first use. I reasoned we didn't need that logic: we don't havelocaltime() at all, and we always initialize TimeZone to GMT so we alwaysneed that one. But there is one other thing ALL_STATE does, which is tomake tzload() malloc its transient workspace instead of just declaring itas a local variable. It turns out that that local variable occupies 78K.Even worse is that, at least for common US timezone settings, there's arecursive call to parse the "posixrules" zone name, making peak stackconsumption to select a time zone upwards of 150K. That's an uncomfortablylarge fraction of our STACK_DEPTH_SLOP safety margin, and could result inoutright crashes if we try to reduce STACK_DEPTH_SLOP as has been discussedrecently. Furthermore, this means that the postmaster's peak stackconsumption is several times that of a backend running typical queries(since, except on Windows, backends inherit the timezone GUC values anddon't ever run this code themselves unless you do SET TIMEZONE). That'scompletely backwards from a safety perspective.Hence, adopt the ALL_STATE rather than non-ALL_STATE variant of tzload(),while not changing the other code aspects that symbol controls. Therisk of an ENOMEM error from malloc() seems less than that of a SIGSEGVfrom stack overrun.This should probably get back-patched along with1c1a7cb and followonfixes, whenever we decide we have enough confidence in the updates to dothat.1 parent60d5076 commit62c8421
1 file changed
+10
-2
lines changedLines changed: 10 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
536 | 536 |
| |
537 | 537 |
| |
538 | 538 |
| |
539 |
| - | |
| 539 | + | |
540 | 540 |
| |
541 |
| - | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
542 | 550 |
| |
543 | 551 |
| |
544 | 552 |
| |
|
0 commit comments
Comments
(0)