Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix non-responsive Ctrl-C during disk-usage sorting #1236

Closed
wants to merge 1 commit into from
Closed

fix non-responsive Ctrl-C during disk-usage sorting #1236

wants to merge 1 commit into from

Conversation

danfarino
Copy link

Ctrl-C wasn't being noticed during a disk-usage sorting, effectively meaning there was no way to cancel the operation except to wait it out.

Tested on Ubuntu 20.04 and an old MacOS 10.11.6 (El Capitan).

Thanks for a great program!
-Dan

@jarun
Copy link
Owner

jarun commented Nov 14, 2021

We want to skip a check at every file. Can we do this when we encounter a directory instead?

Please share the performance data of current and new in cache-dropped state as well.

@jarun
Copy link
Owner

jarun commented Nov 14, 2021

Unrelated to this PR, currently 1 thread processes a sub-directory tree under the directory where you do du. Say, at /, 1 thread processes each thread. The problem is - /bin pr /lib takes muck longer. See if we can do 1 dir (not the full tree) per thread. I guess if we try that, we will have to store the subtree's top directory info with the directories as the size should reflect for that dir visually.

@@ -346,6 +346,7 @@ typedef struct {

/* Non-persistent program-internal states (alphabeical order) */
typedef struct {
uint_t interrupt; /* Program received an interrupt */
Copy link
Owner

Choose a reason for hiding this comment

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

We can't add a full uint here. Why is the bit not working? It is written in global scope and the threads only read it.

Copy link
Owner

Choose a reason for hiding this comment

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

I don't think the threads need to read this atomically as none of them changes it.

@danfarino
Copy link
Author

Thanks for taking a look. I'm pretty new to nnn, and don't have the bandwidth to really dig in and learn the code in depth. That said, I saw that g_state.interrupt was being written to in the signal handler but those writes weren't being noticed in other parts of the program. Adding atomic operations fixed that issue on my machines. I had to make interrupt a uint_t instead of a bit field so that it would work with the atomic operations. (It's been years since I've done any serious C programming, so if I missed an obvious way to make it work without changing that, even better.)

I added the atomic operations around access to active_threads since I saw while (active_threads == NUM_DU_THREADS); and spinlocks definitely need atomic operations to work properly.

Please feel free to incorporate whatever ideas from this PR you'd like, and change the rest.

Thanks!

@jarun
Copy link
Owner

jarun commented Nov 14, 2021

That said, I saw that g_state.interrupt was being written to in the signal handler

That's global. Also we clear in global scope. Currently dirwalk doesn't add a new dir when the interrupt is set.

I'm pretty new to nnn, and don't have the bandwidth to really dig in and learn the code in depth.

Please feel free to incorporate whatever ideas from this PR you'd like, and change the rest.

I will refer to this PR and incorporate the changes when I get the time.

@jarun jarun closed this Nov 14, 2021
@jarun
Copy link
Owner

jarun commented Nov 14, 2021

Commit 4c705a9 should work for you.

@danfarino
Copy link
Author

Yes! Works great so far. Much simpler than what I had. Thanks!

@danfarino danfarino deleted the fix-du-ctrl-c branch November 14, 2021 19:26
@danfarino danfarino restored the fix-du-ctrl-c branch November 14, 2021 19:26
@jarun
Copy link
Owner

jarun commented Nov 14, 2021

Thanks for the confirmation.

@danfarino danfarino deleted the fix-du-ctrl-c branch November 14, 2021 19:45
@jarun jarun mentioned this pull request Nov 17, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants