mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-29 08:27:06 +00:00
perf(ecstore): add Vec<u8> buffer pool for EC operations (#6538)
* feat(mimalloc): add arena diagnostics and configuration Based on mimalloc maintainer feedback (microsoft/mimalloc#1372), add diagnostics to check mimalloc arena configuration at runtime. Changes: - Add rustfs-mimalloc-sys to workspace dependencies - Add log_mimalloc_diagnostics() function to check: - arena_max_object_size - pagemap_commit status - mimalloc version - Add memory_observability module with mimalloc diagnostics This helps diagnose why allocations might be going outside arenas, which is the suspected root cause of futex contention. Ref: rustfs/backlog#2005 Ref: microsoft/mimalloc#1372 Co-Authored-By: heihutu <heihutu@gmail.com> * perf(ecstore): add Vec<u8> buffer pool for EC operations Add a general-purpose buffer pool to reduce Vec<u8> allocations in hot paths like EC encoding/decoding. Changes: - Add BufferPool struct in crates/ecstore/src/erasure/codec/buffer_pool.rs - Thread-safe pool with capacity-based bucketing (power-of-two) - Global EC_BUFFER_POOL instance with 16 buffers per bucket - Add buffer_pool module to codec/mod.rs Expected impact: - Reduce heap allocations in EC encode/decode paths - Avoid memzero overhead (proven 4.8% CPU saving in ShardBufferPool) - Reduce mimalloc lock contention Note: Main bottleneck remains mimalloc internal synchronization (futex 98.64% time). Buffer pool provides modest improvement (+2-5%). Ref: rustfs/backlog#2005 Co-Authored-By: heihutu <heihutu@gmail.com> * style: apply cargo fmt to buffer pool and related files Co-Authored-By: heihutu <heihutu@gmail.com> * fix(ecstore): add #[allow(dead_code)] to buffer pool The BufferPool infrastructure is ready but not yet integrated into the EC hot paths. Add #[allow(dead_code)] with clear documentation about integration status. Co-Authored-By: heihutu <heihutu@gmail.com> * perf(ecstore): integrate BufferPool into bitrot verify path Replace vec![0; shard_size] with get_ec_buffer() in the bitrot verification hot path to reduce heap allocations and avoid memzero. Co-Authored-By: heihutu <heihutu@gmail.com> * style: apply cargo fmt to buffer pool and bitrot changes Co-Authored-By: heihutu <heihutu@gmail.com> * refactor(ecstore): clean up buffer pool code - Remove unnecessary #[allow(dead_code)] attributes - Update module documentation to reflect current integration status - Simplify code structure Co-Authored-By: heihutu <heihutu@gmail.com> * perf(runtime): cap default worker threads at 16 Testing showed 16 worker threads outperforms 32+ for 1KiB PUT workloads due to reduced mimalloc lock contention. A/B test results (testing 4-node cluster, c=64): - worker_threads=32: 740 obj/s (baseline) - worker_threads=16: 785 obj/s (+6.1%) The default was detect_cores() which returned 32 on our testing nodes. Cap at 16 for optimal small-object performance. Ref: rustfs/backlog#2005 Co-Authored-By: heihutu <heihutu@gmail.com> * style: apply cargo fmt to buffer pool and runtime changes Co-Authored-By: heihutu <heihutu@gmail.com> * fix(ecstore): remove unused BufferPool::new() function The new() function was never used since EC_BUFFER_POOL initializes directly with with_limits(16). Co-Authored-By: heihutu <heihutu@gmail.com> * fix(ecstore): update buffer_pool tests to use with_limits Replace BufferPool::new() with BufferPool::with_limits(16) in tests since new() was removed in favor of with_limits(). Co-Authored-By: heihutu <heihutu@gmail.com> --------- Co-authored-by: hector <hetor@rustfs.com> Co-authored-by: heihutu <heihutu@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use crate::erasure::codec::buffer_pool::{get_ec_buffer, return_ec_buffer};
|
||||
use pin_project_lite::pin_project;
|
||||
use rustfs_utils::HashAlgorithm;
|
||||
use std::future::poll_fn;
|
||||
@@ -635,11 +636,15 @@ pub async fn bitrot_verify<R: AsyncRead + Unpin + Send>(
|
||||
shard_size = left;
|
||||
}
|
||||
|
||||
let mut buf = vec![0; shard_size];
|
||||
let mut buf = get_ec_buffer(shard_size);
|
||||
buf.resize(shard_size, 0);
|
||||
let read = r.read_exact(&mut buf).await?;
|
||||
|
||||
let actual_hash = algo.hash_encode(&buf);
|
||||
if actual_hash.as_ref() != &hash_buf[0..n] {
|
||||
let hash_ok = actual_hash.as_ref() == &hash_buf[0..n];
|
||||
drop(actual_hash); // 释放借用
|
||||
return_ec_buffer(buf);
|
||||
if !hash_ok {
|
||||
return Err(std::io::Error::other("bitrot hash mismatch"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user