Re: Benchmarked tcpserver dlopen() -> qmail_smtpd() VS tcpserver --> fork() --> exec qmail-smtpd
Manvendra Bhangui <[email protected]> Tue, 4 Apr 2017 23:35:11 +0530
| Newsgroups | gmane.mail.qmail.general |
|---|---|
| Message-ID | <CAOqj+1NkzzmYb5FPsVoJE8N4qmBoYXmko-xmxmALMdr2A352Hw@mail.gmail.com> |
On 4 April 2017 at 23:12, Charles Cazabon <[email protected]> wrote: > Manvendra Bhangui <[email protected]> wrote: >> badmailfrom, there is a huge difference. In the case of indimail-mta, >> I loaded 50 Mib of control file. > > And what was your control-file read buffer size? 64 bytes? That's nearly > 800,000 syscalls just to read the bloody file. No wonder you think it's slow. > static char inbuf[64]; ..... buffer_init(&ss, read, fd, inbuf, sizeof inbuf); BTW I don't use such huge files without using cdb or using MySQL. The control.c which I have already uses .cdb if the control file name has .cdb extension and MySQL if the file has .sql extension. The point I am trying to make is that in the dlopen() method, I load the control file just once in the lifetime - Just once. The crazy 25 MiB control file was just an experiment. Even in the normal scenario where the control files are just few KiB, I am seeing a very small performance gain. I have the code read, working and tested. It is just that I am struggling to make the tcpserver symbols private. Yesterday I discovered that one can make the namespace private by using dlmopen() call instead of dlopen(). However, I have been struggling to make dlmopen() work with tcpserver. The tcpserver goes into consuming 100% cpu. With the help of gdb, I have just figured out the reason. The culprit is prot_uid() and prot_gid() functions in tcpserver. They use int data type for uid and gid. The moment I call setgid(), setgroups() or setuid(), these calls do not return and goes into an infinite loop. It is a situation like errno.h. I need to change the data type for uid and gid to uid_t and gid_t as they are defined in sys/types.h. If I do that, tcpserver is working perfectly and securely without its namespace exposed to other externally loaded library and hence as safe as execv(). I think this could be a bug with dlmopen() or the kernel that I have uncovered. Even strace stops working as soon as setuid(), setgid() or setgroups() gets called, with an error strace: process runs in x32 mode This entire exercise has been an academic exercise and an attempt to learn about how the unix loader works Cheers :) and even as I write this, I think I have figured out the