Skip to content

uucore::pipes: guard unnecessary fcntl & cache pipe size - #15668

Open
oech3 wants to merge 1 commit into
uutils:mainfrom
oech3:uupipes-resize-var
Open

oech3 wants to merge 1 commit into
uutils:mainfrom
oech3:uupipes-resize-var

Conversation

@oech3

@oech3 oech3 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Followup to #15516 .

  • Don't fcntl if broker pipe was not resized since resizing target does not improve throughput for the case.
  • Cache pipe size too.
  • Freeze pipe size by 1 MiB for cached pipe. Pipe size is not a real RAM usage (it contains refs of page caches).

Comment thread src/uucore/src/lib/features/pipes.rs Outdated
// expected that input is already extended if it is coming from splice
if resize_pipe && fcntl_setpipe_size(&pair.0, MAX_ROOTLESS_PIPE_SIZE).is_ok() {
// improve throughput if output is pipe
let _ = fcntl_setpipe_size(&target, MAX_ROOTLESS_PIPE_SIZE);

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.

With head -n -1 small big, the small file caches an unresized broker, and the big file then gets neither resize, since the target resize now only happens when the broker is created. Main still resized the target there. Fine if that's intended, since the broker is stuck at 64 KiB either way.

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.

I'll cache resized state.

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.

uucore as a library should have PIPE_IS_RESIZED as global variable, but I made it local for our usecase.

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.04 MB (-308 KB, -0.19%)

Significant per-binary changes:
  date     2.61 MB ->    2.30 MB  (-316 KB, -11.81%)

@oech3
oech3 force-pushed the uupipes-resize-var branch from effe7e4 to 03182f8 Compare October 23, 2026 03:41
@oech3 oech3 changed the title uucore::pipes: guard unnecessary fcntl & simplify code uucore::pipes: guard unnecessary fcntl & cache pipe size Oct 23, 2026
@oech3
oech3 force-pushed the uupipes-resize-var branch 2 times, most recently from f54d9ee to 31e101e Compare October 23, 2026 03:54
@oech3

oech3 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

This change also avoids N fcntl for N inputs at hot code path.

Comment thread src/uucore/src/lib/features/pipes.rs Resolved
@oech3
oech3 force-pushed the uupipes-resize-var branch from 31e101e to 5421332 Compare October 24, 2026 03:38
Comment thread src/uucore/src/lib/features/pipes.rs Resolved
thread_local! {
static PIPE_IS_RESIZED: Cell<bool> = const { Cell::new(false) };
}
let mut pipe_is_resized = PIPE_IS_RESIZED.get();

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.

this flag is only read when PIPE_CACHE is empty, so after the first call it is almost never used
head -n -1 small big still caches an unresized broker and never resizes it, no?
do we need it, or should the resize check happen on the cached pipe too?

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.

pipe cache is refleshed if and only if we met I/O error which is cold code-path. I'm not sure if we should cache the size too for the case.

@oech3 oech3 Dec 1, 2026 •

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.

Actually, we save state if and only if we recycled broker (PIPE_CACHE.set). So it is already done.

Comment thread src/uucore/src/lib/features/pipes.rs Resolved
@oech3
oech3 force-pushed the uupipes-resize-var branch from 5421332 to 05b8fb9 Compare December 1, 2026 07:49

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants