about summary refs log tree commit homepage
path: root/lib/PublicInbox/Git.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-09-22 09:45:17 +0000
committerEric Wong <e@80x24.org>2021-09-23 04:52:06 +0000
commit356439a571c536eaa487031802b436d087113f4f (patch)
treecab628111eefa6f5a059cbc405d8e01a2ccb8670 /lib/PublicInbox/Git.pm
parent7d2f9f7caf63256bab7b3342c52a1d97c889ada4 (diff)
downloadpublic-inbox-356439a571c536eaa487031802b436d087113f4f.tar.gz
Check for unlinked mmap-ed files via /proc/$PID/maps every 60s
or so.

ExtSearch (extindex) is compatible-enough with Inbox objects to
be wired into the old per-inbox code, but the startup cost is
projected to be much higher down the line when there's >30K
inboxes, so we scan /proc/$PID/maps for deleted files before
unlinking.  With old Inbox objects, it was (and is) simpler to
just kill processes w/o checking due to the low startup cost
(and non-portability of checking).

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210921144754.gulkneuulzo27qbw@meerkat.local/
Diffstat (limited to 'lib/PublicInbox/Git.pm')
-rw-r--r--lib/PublicInbox/Git.pm16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 5ef1db2f..cf51239f 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -12,7 +12,7 @@ use v5.10.1;
 use parent qw(Exporter);
 use POSIX ();
 use IO::Handle; # ->autoflush
-use Errno qw(EINTR EAGAIN);
+use Errno qw(EINTR EAGAIN ENOENT);
 use File::Glob qw(bsd_glob GLOB_NOSORT);
 use File::Spec ();
 use Time::HiRes qw(stat);
@@ -523,6 +523,20 @@ sub manifest_entry {
         $ent;
 }
 
+sub cleanup_if_unlinked {
+        my ($self) = @_;
+        return cleanup($self) if $^O ne 'linux';
+        # Linux-specific /proc/$PID/maps access
+        # TODO: support this inside git.git
+        for my $fld (qw(pid pid_c)) {
+                my $pid = $self->{$fld} // next;
+                open my $fh, '<', "/proc/$pid/maps" or next;
+                while (<$fh>) {
+                        return cleanup($self) if /\.(?:idx|pack) \(deleted\)$/;
+                }
+        }
+}
+
 1;
 __END__
 =pod