Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1740136 > unrolled thread
| Started by | Alexey Dobriyan <adobriyan@gmail.com> |
|---|---|
| First post | 2017-09-26 21:10 +0200 |
| Last post | 2017-09-28 12:20 +0200 |
| Articles | 6 — 4 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH 1/2 v2] fdmap(2) Alexey Dobriyan <adobriyan@gmail.com> - 2017-09-26 21:10 +0200
Re: [PATCH 1/2 v2] fdmap(2) Andy Lutomirski <luto@amacapital.net> - 2017-09-27 17:10 +0200
Re: [PATCH 1/2 v2] fdmap(2) "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2017-09-28 09:30 +0200
Re: [PATCH 1/2 v2] fdmap(2) Alexey Dobriyan <adobriyan@gmail.com> - 2017-09-28 13:00 +0200
Re: [PATCH 1/2 v2] fdmap(2) Andy Lutomirski <luto@kernel.org> - 2017-09-28 17:10 +0200
Re: [PATCH 1/2 v2] fdmap(2) Alexey Dobriyan <adobriyan@gmail.com> - 2017-09-28 12:20 +0200
| From | Alexey Dobriyan <adobriyan@gmail.com> |
|---|---|
| Date | 2017-09-26 21:10 +0200 |
| Subject | Re: [PATCH 1/2 v2] fdmap(2) |
| Message-ID | <uu3p0-jm-9@gated-at.bofh.it> |
On Mon, Sep 25, 2017 at 09:42:58AM +0200, Michael Kerrisk (man-pages) wrote: > [Not sure why original author is not in CC; added] > > Hello Alexey, > > On 09/24/2017 10:06 PM, Alexey Dobriyan wrote: > > From: Aliaksandr Patseyenak <Aliaksandr_Patseyenak1@epam.com> > > > > Implement system call for bulk retrieveing of opened descriptors > > in binary form. > > > > Some daemons could use it to reliably close file descriptors > > before starting. Currently they close everything upto some number > > which formally is not reliable. Other natural users are lsof(1) and CRIU > > (although lsof does so much in /proc that the effect is thoroughly buried). > > > > /proc, the only way to learn anything about file descriptors may not be > > available. There is unavoidable overhead associated with instantiating > > 3 dentries and 3 inodes and converting integers to strings and back. > > > > Benchmark: > > > > N=1<<22 times > > 4 opened descriptors (0, 1, 2, 3) > > opendir+readdir+closedir /proc/self/fd vs fdmap > > > > /proc 8.31 ± 0.37% > > fdmap 0.32 ± 0.72% > > From the text above, I'm still trying to understand: whose problem > does this solve? I mean, we've lived with the daemon-close-all-files > technique forever (and I'm not sure that performance is really an > important issue for the daemon case) . > And you say that the effect for lsof(1) will be buried. If only fdmap(2) is added, then effect will be negligible for lsof because it has to go through /proc anyway. The idea is to start process. In ideal world, only bynary system calls would exist and shells could emulate /proc/* same way bash implement /dev/tcp > So, who does this new system call > really help? (Note: I'm not saying don't add the syscall, but from > explanation given here, it's not clear why we should.) For fdmap(2) natural users are lsof(), CRIU. At some point, checkpointing was moved to userspace forcing them to run all over /proc extracting information which could be recovered in couple of locks, bunch of list iterations and dereferences (just read CRIU). All of this could not be beneficial for performance. Parsing text files doesn't help either: most of the numbers in /proc/*/stat et al are unpadded decimals so that user can't rewind to exact field he wants.
[toc] | [next] | [standalone]
| From | Andy Lutomirski <luto@amacapital.net> |
|---|---|
| Date | 2017-09-27 17:10 +0200 |
| Message-ID | <uum8j-4P4-63@gated-at.bofh.it> |
| In reply to | #1740136 |
On Tue, Sep 26, 2017 at 12:00 PM, Alexey Dobriyan <adobriyan@gmail.com> wrote:
> On Mon, Sep 25, 2017 at 09:42:58AM +0200, Michael Kerrisk (man-pages) wrote:
>> [Not sure why original author is not in CC; added]
>>
>> Hello Alexey,
>>
>> On 09/24/2017 10:06 PM, Alexey Dobriyan wrote:
>> > From: Aliaksandr Patseyenak <Aliaksandr_Patseyenak1@epam.com>
>> >
>> > Implement system call for bulk retrieveing of opened descriptors
>> > in binary form.
>> >
>> > Some daemons could use it to reliably close file descriptors
>> > before starting. Currently they close everything upto some number
>> > which formally is not reliable. Other natural users are lsof(1) and CRIU
>> > (although lsof does so much in /proc that the effect is thoroughly buried).
>> >
>> > /proc, the only way to learn anything about file descriptors may not be
>> > available. There is unavoidable overhead associated with instantiating
>> > 3 dentries and 3 inodes and converting integers to strings and back.
>> >
>> > Benchmark:
>> >
>> > N=1<<22 times
>> > 4 opened descriptors (0, 1, 2, 3)
>> > opendir+readdir+closedir /proc/self/fd vs fdmap
>> >
>> > /proc 8.31 ą 0.37%
>> > fdmap 0.32 ą 0.72%
>>
>> From the text above, I'm still trying to understand: whose problem
>> does this solve? I mean, we've lived with the daemon-close-all-files
>> technique forever (and I'm not sure that performance is really an
>> important issue for the daemon case) .
>
>> And you say that the effect for lsof(1) will be buried.
>
> If only fdmap(2) is added, then effect will be negligible for lsof
> because it has to go through /proc anyway.
>
> The idea is to start process. In ideal world, only bynary system calls
> would exist and shells could emulate /proc/* same way bash implement
> /dev/tcp
Then start the process by doing it for real and making it obviously
useful. We should not add a pair of vaguely useful, rather weak
syscalls just to start a process of modernizing /proc.
>
>> So, who does this new system call
>> really help? (Note: I'm not saying don't add the syscall, but from
>> explanation given here, it's not clear why we should.)
>
> For fdmap(2) natural users are lsof(), CRIU.
lsof does:
int
main(argc, argv)
int argc;
char *argv[];
{
...
if ((MaxFd = (int) GET_MAX_FD()) < 53)
MaxFd = 53;
for (i = 3; i < MaxFd; i++)
(void) close(i);
The solution isn't to wrangle fdmap(2) into this code. The solution
is to remove the code entirely.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> |
|---|---|
| Date | 2017-09-28 09:30 +0200 |
| Message-ID | <uuBqG-5Tq-15@gated-at.bofh.it> |
| In reply to | #1740815 |
On 27 September 2017 at 17:03, Andy Lutomirski <luto@amacapital.net> wrote: > On Tue, Sep 26, 2017 at 12:00 PM, Alexey Dobriyan <adobriyan@gmail.com> wrote: >> On Mon, Sep 25, 2017 at 09:42:58AM +0200, Michael Kerrisk (man-pages) wrote: >>> [Not sure why original author is not in CC; added] >>> >>> Hello Alexey, >>> >>> On 09/24/2017 10:06 PM, Alexey Dobriyan wrote: >>> > From: Aliaksandr Patseyenak <Aliaksandr_Patseyenak1@epam.com> >>> > >>> > Implement system call for bulk retrieveing of opened descriptors >>> > in binary form. >>> > >>> > Some daemons could use it to reliably close file descriptors >>> > before starting. Currently they close everything upto some number >>> > which formally is not reliable. Other natural users are lsof(1) and CRIU >>> > (although lsof does so much in /proc that the effect is thoroughly buried). >>> > >>> > /proc, the only way to learn anything about file descriptors may not be >>> > available. There is unavoidable overhead associated with instantiating >>> > 3 dentries and 3 inodes and converting integers to strings and back. >>> > >>> > Benchmark: >>> > >>> > N=1<<22 times >>> > 4 opened descriptors (0, 1, 2, 3) >>> > opendir+readdir+closedir /proc/self/fd vs fdmap >>> > >>> > /proc 8.31 ą 0.37% >>> > fdmap 0.32 ą 0.72% >>> >>> From the text above, I'm still trying to understand: whose problem >>> does this solve? I mean, we've lived with the daemon-close-all-files >>> technique forever (and I'm not sure that performance is really an >>> important issue for the daemon case) . >> >>> And you say that the effect for lsof(1) will be buried. >> >> If only fdmap(2) is added, then effect will be negligible for lsof >> because it has to go through /proc anyway. >> >> The idea is to start process. In ideal world, only bynary system calls >> would exist and shells could emulate /proc/* same way bash implement >> /dev/tcp > > Then start the process by doing it for real and making it obviously > useful. We should not add a pair of vaguely useful, rather weak > syscalls just to start a process of modernizing /proc. I concur. Alexey, you still have not wxplained who specifically needs this right now, and how, precisely, they plan to use the new system calls. It is all very arm-wavey so far. Thanks, Michael
[toc] | [prev] | [next] | [standalone]
| From | Alexey Dobriyan <adobriyan@gmail.com> |
|---|---|
| Date | 2017-09-28 13:00 +0200 |
| Message-ID | <uuEHW-7Wb-37@gated-at.bofh.it> |
| In reply to | #1741231 |
On 9/28/17, Michael Kerrisk (man-pages) <mtk.manpages@gmail.com> wrote:
> On 27 September 2017 at 17:03, Andy Lutomirski <luto@amacapital.net> wrote:
>>> The idea is to start process. In ideal world, only bynary system calls
>>> would exist and shells could emulate /proc/* same way bash implement
>>> /dev/tcp
>>
>> Then start the process by doing it for real and making it obviously
>> useful. We should not add a pair of vaguely useful, rather weak
>> syscalls just to start a process of modernizing /proc.
Before doing it for real it would be nice to have at least a nod
from people in charge that syscalls which return binary
information are OK. Otherwise some EIATF guy will just say
"NAK /proc is fine, it always was fine".
Or look from another angle: sched_setaffinity exists but there is
no /proc counterpart, shells must use taskset(1) and world didn't end.
> I concur.
>
> Alexey, you still have not wxplained who specifically needs this
> right now, and how, precisely, they plan to use the new system calls.
> It is all very arm-wavey so far.
It is not if you read even example program in the original patch.
Any program which queries information about file descriptors
will benefit both in CPU and memory usage.
void closefrom(int start)
{
int fd[1024];
int n;
while ((n = fdmap(0, fd, sizeof(fd)/sizeof(fd[0]), start)) > 0) {
unsigned int i;
for (i = 0; i < n; i++)
close(fd[i]);
start = fd[n - 1] + 1;
}
}
CRIU naturally to know everything about descriptors of target processes:
It does:
int predump_task_files(int pid)
{
struct dirent *de;
DIR *fd_dir;
int ret = -1;
pr_info("Pre-dump fds for %d)\n", pid);
fd_dir = opendir_proc(pid, "fd");
if (!fd_dir)
return -1;
while ((de = readdir(fd_dir))) {
if (dir_dots(de))
continue;
if (predump_one_fd(pid, atoi(de->d_name)))
goto out;
}
ret = 0;
out:
closedir(fd_dir);
return ret;
}
which is again inefficient.
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-09-28 17:10 +0200 |
| Message-ID | <uuIBQ-289-25@gated-at.bofh.it> |
| In reply to | #1741434 |
On Thu, Sep 28, 2017 at 3:55 AM, Alexey Dobriyan <adobriyan@gmail.com> wrote:
> On 9/28/17, Michael Kerrisk (man-pages) <mtk.manpages@gmail.com> wrote:
>> On 27 September 2017 at 17:03, Andy Lutomirski <luto@amacapital.net> wrote:
>
>>>> The idea is to start process. In ideal world, only bynary system calls
>>>> would exist and shells could emulate /proc/* same way bash implement
>>>> /dev/tcp
>>>
>>> Then start the process by doing it for real and making it obviously
>>> useful. We should not add a pair of vaguely useful, rather weak
>>> syscalls just to start a process of modernizing /proc.
>
> Before doing it for real it would be nice to have at least a nod
> from people in charge that syscalls which return binary
> information are OK. Otherwise some EIATF guy will just say
> "NAK /proc is fine, it always was fine".
There's nothing inherently wrong with syscalls that return binary
information. There is something wrong with reinventing the world with
insufficient justification, though.
/proc may be old, clunky, and kind of slow, but it has a lot of good
things going for it. It supports access control (DAC and MAC). It
handles namespacing in a way that's awkward but supported by all the
existing namespace managers. It may soon support mount options, which
is rather important.
I feel like we've been discussing this performance issue for over a
year, and I distinctly recall discussing it in Santa Fe. I suggested
a two-pronged approach:
1. Add a new syscall that will, in a single call, open, read, and
close a proc file and maybe even a regular non-proc file. Like this:
long readfileat(int dirfd, const char *path, void *buf, size_t len, int flags);
2. Where needed, add new /proc files with lighter-weight
representations. I think we discussed something that's like status
but in nl_attr format.
This doesn't end up with a bunch of code duplication the way that a
full-blown syscall-based reimplementation would. It supports all the
/proc features rather than just a subset. It fully respects access
control, future mount options, and the potential lack of a /proc
mount.
>
> Or look from another angle: sched_setaffinity exists but there is
> no /proc counterpart, shells must use taskset(1) and world didn't end.
sched_setaffinity() modifies the caller. /proc wouldn't have made much sense.
>
>> I concur.
>>
>> Alexey, you still have not wxplained who specifically needs this
>> right now, and how, precisely, they plan to use the new system calls.
>> It is all very arm-wavey so far.
>
> It is not if you read even example program in the original patch.
> Any program which queries information about file descriptors
> will benefit both in CPU and memory usage.
>
> void closefrom(int start)
> {
> int fd[1024];
> int n;
>
> while ((n = fdmap(0, fd, sizeof(fd)/sizeof(fd[0]), start)) > 0) {
> unsigned int i;
>
> for (i = 0; i < n; i++)
> close(fd[i]);
>
> start = fd[n - 1] + 1;
> }
> }
>
> CRIU naturally to know everything about descriptors of target processes:
> It does:
>
> int predump_task_files(int pid)
> {
> struct dirent *de;
> DIR *fd_dir;
> int ret = -1;
>
> pr_info("Pre-dump fds for %d)\n", pid);
>
> fd_dir = opendir_proc(pid, "fd");
> if (!fd_dir)
> return -1;
>
> while ((de = readdir(fd_dir))) {
> if (dir_dots(de))
> continue;
>
> if (predump_one_fd(pid, atoi(de->d_name)))
> goto out;
> }
>
> ret = 0;
> out:
> closedir(fd_dir);
> return ret;
> }
>
> which is again inefficient.
And /proc/PID/fds would solve this.
[toc] | [prev] | [next] | [standalone]
| From | Alexey Dobriyan <adobriyan@gmail.com> |
|---|---|
| Date | 2017-09-28 12:20 +0200 |
| Message-ID | <uuE5b-7Jz-1@gated-at.bofh.it> |
| In reply to | #1740815 |
On 9/27/17, Andy Lutomirski <luto@amacapital.net> wrote:
> On Tue, Sep 26, 2017 at 12:00 PM, Alexey Dobriyan <adobriyan@gmail.com>
> wrote:
>> On Mon, Sep 25, 2017 at 09:42:58AM +0200, Michael Kerrisk (man-pages)
>> wrote:
>>> [Not sure why original author is not in CC; added]
>>>
>>> Hello Alexey,
>>>
>>> On 09/24/2017 10:06 PM, Alexey Dobriyan wrote:
>>> > From: Aliaksandr Patseyenak <Aliaksandr_Patseyenak1@epam.com>
>>> >
>>> > Implement system call for bulk retrieveing of opened descriptors
>>> > in binary form.
>>> >
>>> > Some daemons could use it to reliably close file descriptors
>>> > before starting. Currently they close everything upto some number
>>> > which formally is not reliable. Other natural users are lsof(1) and
>>> > CRIU
>>> > (although lsof does so much in /proc that the effect is thoroughly
>>> > buried).
>>> >
>>> > /proc, the only way to learn anything about file descriptors may not
>>> > be
>>> > available. There is unavoidable overhead associated with instantiating
>>> > 3 dentries and 3 inodes and converting integers to strings and back.
>>> >
>>> > Benchmark:
>>> >
>>> > N=1<<22 times
>>> > 4 opened descriptors (0, 1, 2, 3)
>>> > opendir+readdir+closedir /proc/self/fd vs fdmap
>>> >
>>> > /proc 8.31 ą 0.37%
>>> > fdmap 0.32 ą 0.72%
>>>
>>> From the text above, I'm still trying to understand: whose problem
>>> does this solve? I mean, we've lived with the daemon-close-all-files
>>> technique forever (and I'm not sure that performance is really an
>>> important issue for the daemon case) .
>>
>>> And you say that the effect for lsof(1) will be buried.
>>
>> If only fdmap(2) is added, then effect will be negligible for lsof
>> because it has to go through /proc anyway.
>>
>> The idea is to start process. In ideal world, only bynary system calls
>> would exist and shells could emulate /proc/* same way bash implement
>> /dev/tcp
>
> Then start the process by doing it for real and making it obviously
> useful. We should not add a pair of vaguely useful, rather weak
> syscalls just to start a process of modernizing /proc.
>
>>
>>> So, who does this new system call
>>> really help? (Note: I'm not saying don't add the syscall, but from
>>> explanation given here, it's not clear why we should.)
>>
>> For fdmap(2) natural users are lsof(), CRIU.
>
> lsof does:
>
> int
> main(argc, argv)
> int argc;
> char *argv[];
> {
> ...
> if ((MaxFd = (int) GET_MAX_FD()) < 53)
> MaxFd = 53;
> for (i = 3; i < MaxFd; i++)
> (void) close(i);
>
> The solution isn't to wrangle fdmap(2) into this code. The solution
> is to remove the code entirely.
What do you think about this code from OpenSSH?
/*
* Discard other fds that are hanging around. These can cause problem
* with backgrounded ssh processes started by ControlPersist.
*/
closefrom(STDERR_FILENO + 1);
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web