Linux Community · Why does linux use twice the memory of comparable tools?

224
LIr/linux·posted by mike_xu·6 hours agoPostmortem

Why does linux use twice the memory of comparable tools?

It took me two weeks of on-and-off digging and plenty of wrong turns. Writing the process down as it happened so the next person spends less time.

We also fixed monitoring along the way: replaced average-based alerts with percentiles and split them per endpoint. False alerts dropped by about seventy percent and the on-call rotation visibly cheered up.

Image placeholder · object storage in production
POST /api/uploads → CDN origin pull
126 comments

126 comments

· first 120 loaded
M
Sslow_query·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

467
Ttang_haoOP·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

406
Rrase·12 minutes ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

232
Aalice_dev·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

445
Bbob_chen·5 hours ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

435
WwinterMod·2 days agoedited

This is not a linux problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

67
Rran_bo·2 days ago

One counter-example: below linux 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

415
Mmike_xu·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

399
Rran_boOP·2 days ago

One counter-example: below linux 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

318
Mmike_xu·2 days agoedited

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

367
Aalice_dev·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

364
LlinlinOP·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

284
Sslow_query·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

332
Zzhou_yi·1 hour ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

315
Sslow_query·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

3
RraseOP·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

231
Nnikic·2 days ago

One counter-example: below linux 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

285
Zzhou_yi·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

267
Bbob_chen·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

258
Cchen_dev·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

59
Kkernel_panicOP·3 minutes ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

198
Aalice_devOP·just now

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

33
Zzhou_yi·12 minutes ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

274
Mmike_xuOP·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

148
Nnikic·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

31
Mmike_xu·1 hour agoedited

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

160
Ttang_hao·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

88
Rrase·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

270
Hhuang_ke·2 days agoLevel 6

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

1
Aalice_dev·2 days ago

I just read the linux source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

86
Ttang_hao·2 days agoLevel 6

Saved. I am reworking this area this week — this saves a lot of wrong turns.

489
Ttang_hao·2 days agoedited

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

12
Cchen_dev·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

120
Rrase·2 days ago

I just read the linux source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

57
Rran_bo·1 hour ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

241
Llinlin·3 minutes ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

234
Rrase·2 days agoedited

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

42
Ttang_haoOP·just now

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

184
Rrase·28 minutes ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

144
Oops_wang·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

11
Aalice_dev·2 days agoedited

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

20
Rrase·just now

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

210
Lli_ming·2 days ago

This is not a linux problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

418
Mmike_xuOP·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

1
Mmike_xu·2 days ago

I just read the linux source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

276
Hhuang_keMod·2 days ago

This is not a linux problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

16
Hhuang_ke·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

1
Sslow_query·2 days agoedited

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

204
Bbob_chen·3 minutes ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

178
NnikicMod·2 days ago

I just read the linux source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

203
Rran_bo·12 minutes ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

159
Nnikic·28 minutes ago

I just read the linux source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

143
Ttang_hao·5 hours ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

443
Rran_boMod·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

503
Zzhu_zong·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

369
Kkite·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

5
Sswoole_leeOP·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

250
Bbob_chen·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

307
Wwinter·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

264
Lli_ming·1 hour agoedited

Saved. I am reworking this area this week — this saves a lot of wrong turns.

94
Ttang_hao·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

338
Zzhou_yi·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

35
Sslow_queryOP·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

22
Rrase·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

5
Hhuang_ke·2 days agoLevel 6

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

1
Oops_wang·2 hours ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

173
Sslow_query·28 minutes ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

477
Ddev_zhou·2 days agoedited

I just read the linux source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

34
Kkite·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

429
Sslow_query·1 hour ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

51
Sswoole_lee·yesterday

This is not a linux problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

155
Kkite·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

62
Kkernel_panic·2 hours ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

1
Sswoole_lee·2 days ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

274
Hhuang_keMod·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

3
Mmike_xu·5 hours ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

18
Zzhu_zong·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

3
Kkernel_panicOP·2 days ago

One counter-example: below linux 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

75
Kkernel_panic·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

130
Rran_boOP·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

52
Mmike_xu·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

145
Ddev_zhouOP·2 days ago

This is not a linux problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

105
Zzhou_yi·2 days agoedited

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

23
Aalice_dev·2 days ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

42
Llinlin·2 days agoedited

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

101
Sswoole_leeOP·1 hour ago

One counter-example: below linux 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

37
Aalice_dev·yesterday

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

23
Hhuang_ke·yesterday

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

88
Aalice_dev·1 hour ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

72
Rrase·yesterday

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

68
Llinlin·just now

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

67
Bbob_chen·2 days ago

I just read the linux source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

192
Hhuang_ke·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

23
Bbob_chenOP·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

1
Hhuang_ke·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

57
Ttang_haoOP·28 minutes ago

This is not a linux problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

60
Rran_boMod·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

73
Zzhou_yi·12 minutes ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

49
Kkite·12 minutes ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

27
Zzhu_zong·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

24
Aalice_devMod·12 minutes ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

23
Ttang_hao·2 days ago

This is not a linux problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

1
Ddev_zhou·2 days agoedited

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

16
Zzhu_zong·2 days agoedited

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

16
Zzhou_yi·2 days agoedited

One counter-example: below linux 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

1
Rrase·2 hours ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

15
Cchen_dev·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

12
Sslow_query·5 hours ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

3
Ddev_zhou·28 minutes ago

One counter-example: below linux 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

200
Mmike_xu·5 hours ago

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

16
Wwinter·2 days ago

This is not a linux problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

15
Hhuang_ke·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

11
Hhuang_ke·2 days ago

I just read the linux source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

261
Rrase·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

16
Llinlin·1 hour agoedited

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

2
Rrase·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

1
Zzhu_zong·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

1
Kkite·just now

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

332
Llinlin·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

361
Rrase·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

1

This is the post detail page /en/c/linux/post/p7. Posts and comments are generated deterministically from a seeded PRNG, so the same post always renders the same content and the link can be shared, reloaded and indexed. In production this page reads MySQL for the post, Redis for hot-post caching, and fetches the whole comment tree in a single query on the path column.

See the database schema →