Skip to content

Fix bufferpool puts (ref #4976) - #6125

Merged
AudriusButkevicius merged 15 commits into
syncthing:masterfrom
calmh:bufferpool
Nov 6, 2019
Merged

AudriusButkevicius merged 15 commits into
syncthing:masterfrom
calmh:bufferpool

Conversation

@calmh

@calmh calmh commented Nov 4, 2019

Copy link
Copy Markdown
Member

There was a logic error in Put() which made us put all large blocks into
segment zero, where we subsequently did not look for them.

I also added a lowest threshold, as we otherwise allocate a 128KiB
buffer when we need 24 bytes for a header and such.

After:

2019/11/04 18:21:49 Result: Wall time: 2.665497ms / MiB
2019/11/04 18:21:49 Result: 3.84e+05 KiB/s synced
2019/11/04 18:21:49 Receiver: Utime: 4.506592ms / MiB
2019/11/04 18:21:49 Receiver: Stime: 1.126973ms / MiB
2019/11/04 18:21:49 Receiver: MaxRSS: 321632 KiB
2019/11/04 18:21:49 Sender: Utime: 4.163059ms / MiB
2019/11/04 18:21:49 Sender: Stime: 963.312µs / MiB
2019/11/04 18:21:49 Sender: MaxRSS: 113696 KiB

Before:

2019/11/04 17:16:03 Result: Wall time: 2.77946ms / MiB
2019/11/04 17:16:03 Result: 3.68e+05 KiB/s synced
2019/11/04 17:16:03 Receiver: Utime: 4.580026ms / MiB
2019/11/04 17:16:03 Receiver: Stime: 1.283715ms / MiB
2019/11/04 17:16:03 Receiver: MaxRSS: 644452 KiB
2019/11/04 17:16:03 Sender: Utime: 4.62121ms / MiB
2019/11/04 17:16:03 Sender: Stime: 1.075979ms / MiB
2019/11/04 17:16:03 Sender: MaxRSS: 1790704 KiB

There was a logic error in Put() which made us put all large blocks into
segment zero, where we subsequently did not look for them.

I also added a lowest threshold, as we otherwise allocate a 128KiB
buffer when we need 24 bytes for a header and such.
@calmh

calmh commented Nov 4, 2019

Copy link
Copy Markdown
Member Author

This is still broken, I'mma add some tests

@AudriusButkevicius

Copy link
Copy Markdown
Member

Why are we not using it for small slices? There shouldn't be any downsides.

I guess for things like headers we should just have a "static" slice, not to churn trash.

@calmh

calmh commented Nov 4, 2019 •

Copy link
Copy Markdown
Member Author

The difference is only in when we don't have a block available in any bucket. Previously we'd allocate a 128 KiB block and return that. Granted, this is a block we can maybe reuse and that's good. But we've also just allocated 128 KiB when we just needed 24 bytes or whatever which comes from a completely different allocator area in Go... So... 🤷

And yes, I guess we should. But this is about making the buffer pool actually do buffer pooly things and not just allocate bytes forever...

@calmh

calmh commented Nov 4, 2019

Copy link
Copy Markdown
Member Author
2019/11/04 18:48:51 Verifying...
2019/11/04 18:48:57 Result: Wall time: 2.626817ms / MiB
2019/11/04 18:48:57 Result: 3.9e+05 KiB/s synced
2019/11/04 18:48:57 Receiver: Utime: 4.599636ms / MiB
2019/11/04 18:48:57 Receiver: Stime: 1.166088ms / MiB
2019/11/04 18:48:57 Receiver: MaxRSS: 324292 KiB
2019/11/04 18:48:57 Sender: Utime: 4.278935ms / MiB
2019/11/04 18:48:57 Sender: Stime: 978.709µs / MiB
2019/11/04 18:48:57 Sender: MaxRSS: 89528 KiB

Comment thread lib/protocol/bufferpool_test.go Resolved
@AudriusButkevicius

Copy link
Copy Markdown
Member

Different allocator area? First time I've heard that there is more than a single area.

@calmh

calmh commented Nov 4, 2019 •

Copy link
Copy Markdown
Member Author

Small blocks come from arenas containing lots of equally sized blocks, allocated in chunks (pages). Large blocks are rounded up to page size and handled individually. So the cost for allocating a (say) 24 byte block is often near zero as we already have a page full of such blocks and just need to pick one, while a large allocation is seldom free.

@calmh

calmh commented Nov 4, 2019

Copy link
Copy Markdown
Member Author

Made it a bit less chill and more panicky so we'll see if it's misused.

Comment thread lib/protocol/bufferpool_test.go Resolved
Comment thread lib/protocol/bufferpool_test.go Resolved
@calmh

calmh commented Nov 6, 2019

Copy link
Copy Markdown
Member Author

PTAL

Comment thread lib/protocol/bufferpool_test.go Resolved
Comment thread lib/protocol/bufferpool_test.go Resolved
Comment thread lib/protocol/bufferpool.go Resolved
Comment thread lib/protocol/bufferpool.go Resolved
Comment thread lib/protocol/bufferpool.go Resolved
Comment thread lib/protocol/bufferpool_test.go Resolved
Comment thread lib/protocol/bufferpool_test.go Resolved
@AudriusButkevicius
AudriusButkevicius merged commit 6755a9c into syncthing:master Nov 6, 2019
@AudriusButkevicius

Copy link
Copy Markdown
Member

Baaah. squash message. We should have a hook that prevents quickfire merges with bad names.

@calmh calmh added this to the v1.3.2 milestone Nov 8, 2019
@calmh
calmh deleted the bufferpool branch November 10, 2019 18:07
calmh added a commit to calmh/syncthing that referenced this pull request Nov 11, 2019
* master:
  docker: Add stdiscosrv and strelaysrv Dockerfiles (syncthing#6143)
  lib/protocol: Buffer allocation when compressing (fixes syncthing#6146) (syncthing#6147)
  golang-ci: Upgrade, skipping the white space complainer
  all: Cleanups enabled by Go 1.12
  lib/tlsutil: Remove Go 1.12 TLS 1.3 beta opt-in
  lib/api: Make theme paths relative (syncthing#6142)
  gui, lib/api: Adds support for prefers-color-scheme (fixes syncthing#6115)
  lib/api: Reset mtime after theme change (fixes syncthing#5810) (syncthing#6140)
  lib/model: Remove some testing deadlocks (syncthing#6138)
  lib/model: Add test for previous commit
  lib/model: Add initial deviceStatRefs on model creation (fixes syncthing#6136) (syncthing#6137)
  lib/model: Add folders on start in model (syncthing#6135)
  cmd/stbench: rm -r cmd/stbench (syncthing#6131)
  lib/api: Slightly unflake TestCSRFRequired by allowing longer timeout
  Fix bufferpool puts (ref syncthing#4976) (syncthing#6125)
  all: Remove dead code, fix lost msgLen checks (syncthing#6129)
  lib/upnp: Fix outdated comment (syncthing#6110)
calmh added a commit to calmh/syncthing that referenced this pull request Nov 11, 2019
* dbastr3: (37 commits)
  docker: Add stdiscosrv and strelaysrv Dockerfiles (syncthing#6143)
  lib/protocol: Buffer allocation when compressing (fixes syncthing#6146) (syncthing#6147)
  golang-ci: Upgrade, skipping the white space complainer
  all: Cleanups enabled by Go 1.12
  lib/tlsutil: Remove Go 1.12 TLS 1.3 beta opt-in
  lib/api: Make theme paths relative (syncthing#6142)
  gui, lib/api: Adds support for prefers-color-scheme (fixes syncthing#6115)
  lib/api: Reset mtime after theme change (fixes syncthing#5810) (syncthing#6140)
  lib/model: Remove some testing deadlocks (syncthing#6138)
  lib/model: Add test for previous commit
  lib/model: Add initial deviceStatRefs on model creation (fixes syncthing#6136) (syncthing#6137)
  lib/model: Add folders on start in model (syncthing#6135)
  wip
  wip
  wip
  wip
  cmd/stbench: rm -r cmd/stbench (syncthing#6131)
  lib/api: Slightly unflake TestCSRFRequired by allowing longer timeout
  Fix bufferpool puts (ref syncthing#4976) (syncthing#6125)
  wip
  ...
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Nov 6, 2020
@syncthing syncthing locked and limited conversation to collaborators Nov 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants