Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
export AWS_LC_FIPS_SYS_NO_ASM=1
fi
# shellcheck disable=SC2046
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo clippy --workspace --all-targets --all-features -- -D warnings $([ ${{ matrix.rust_version }} = 1.84.1 ] || echo -Aclippy::manual_is_multiple_of)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion but this should probably be discussed in #libdatadog

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've done that in the past already for cases where our MSRV did not support APIs which became the only solution to satisfy a clippy lint in future. It misses a comment though, when we'll be able to drop this.

licensecheck:
runs-on: ubuntu-latest
Expand Down
27 changes: 24 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions datadog-ipc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ publish = false

[dependencies]
anyhow = { version = "1.0" }
zwohash = "0.1.2"
bincode = { version = "1" }
futures = { version = "0.3", default-features = false }
io-lifetimes = { version = "1.0" }
Expand All @@ -19,6 +20,9 @@ libdd-tinybytes = { path = "../libdd-tinybytes", optional = true }


libdd-common = { path = "../libdd-common" }
libdd-ddsketch = { path = "../libdd-ddsketch" }
libdd-trace-protobuf = { path = "../libdd-trace-protobuf" }
libdd-trace-stats = { path = "../libdd-trace-stats" }
datadog-ipc-macros = { path = "../datadog-ipc-macros" }
tracing = { version = "0.1", default-features = false }

Expand Down
1 change: 1 addition & 0 deletions datadog-ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod handles;

pub mod platform;
pub mod rate_limiter;
pub mod shm_stats;

pub mod client;
pub mod codec;
Expand Down
17 changes: 14 additions & 3 deletions datadog-ipc/src/platform/mem_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::platform::{mmap_handle, munmap_handle, OwnedFileHandle, PlatformHandl
#[cfg(feature = "tiny-bytes")]
use libdd_tinybytes::UnderlyingBytes;
use serde::{Deserialize, Serialize};
#[cfg(target_os = "linux")]
use std::os::fd::AsRawFd;
use std::{ffi::CString, io, ptr::NonNull};

#[derive(Clone, Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -87,10 +89,19 @@ where
unsafe {
self.set_mapping_size(size)?;
}
nix::unistd::ftruncate(
self.get_shm().handle.as_owned_fd()?,
self.get_shm().size as libc::off_t,
let new_size = self.get_shm().size as libc::off_t;
let fd = self.get_shm().handle.as_owned_fd()?;
// Use fallocate on Linux to eagerly commit the new pages: ENOSPC at resize time is
// recoverable; a later SIGBUS mid-execution is not.
#[cfg(target_os = "linux")]
nix::fcntl::fallocate(
fd.as_raw_fd(),
nix::fcntl::FallocateFlags::empty(),
0,
new_size,
)?;
#[cfg(not(target_os = "linux"))]
nix::unistd::ftruncate(&fd, new_size)?;
Ok(())
}
/// # Safety
Expand Down
7 changes: 7 additions & 0 deletions datadog-ipc/src/platform/unix/mem_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::platform::{
use io_lifetimes::OwnedFd;
use libc::{chmod, off_t};
use nix::errno::Errno;
#[cfg(target_os = "linux")]
use nix::fcntl::{fallocate, FallocateFlags};
use nix::fcntl::{open, OFlag};
use nix::sys::mman::{self, mmap, munmap, MapFlags, ProtFlags};
use nix::sys::stat::Mode;
Expand Down Expand Up @@ -163,6 +165,11 @@ impl NamedShmHandle {

pub fn create_mode(path: CString, size: usize, mode: Mode) -> io::Result<NamedShmHandle> {
let fd = shm_open(path.as_bytes(), OFlag::O_CREAT | OFlag::O_RDWR, mode)?;
// Use fallocate on Linux to eagerly commit pages: if /dev/shm is full we get ENOSPC
// here (recoverable) rather than SIGBUS mid-execution when a worker writes a slot.
#[cfg(target_os = "linux")]
fallocate(fd.as_raw_fd(), FallocateFlags::empty(), 0, size as off_t)?;
#[cfg(not(target_os = "linux"))]
ftruncate(&fd, size as off_t)?;
if let Some(uid) = shm_owner_uid() {
let _ = fchown(fd.as_raw_fd(), Some(Uid::from_raw(uid)), None);
Expand Down
2 changes: 1 addition & 1 deletion datadog-ipc/src/platform/unix/mem_handle_macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::os::fd::{AsFd, OwnedFd};
use std::os::unix::io::AsRawFd;
use std::sync::atomic::{AtomicI32, AtomicU32, AtomicUsize, Ordering};

const MAPPING_MAX_SIZE: usize = 1 << 17; // 128 MiB ought to be enough for everybody?
const MAPPING_MAX_SIZE: usize = 1 << 27; // 128 MiB ought to be enough for everybody?
const NOT_COMMITTED: usize = 1 << (usize::BITS - 1);

pub(crate) fn mmap_handle<T: FileBackedHandle>(mut handle: T) -> io::Result<MappedMem<T>> {
Expand Down
Loading
Loading