From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexander Shishkin Subject: Re: [PATCH] [RFC] List per-process file descriptor consumption when hitting file-max Date: Sun, 11 Oct 2009 15:17:42 +0300 Message-ID: <71a0d6ff0910110517v1068d7cyd8bb076abab23ed5@mail.gmail.com> References: <1244461122-3303-1-git-send-email-alexander.shishckin@gmail.com> <71a0d6ff0907290917u1f0c0e68p8036d53c69320392@mail.gmail.com> <28675.1248957636@turing-police.cc.vt.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-fsdevel@vger.kernel.org, akpm@linux-foundation.org, viro@zeniv.linux.org.uk, Linux Kernel Mailing List To: Valdis.Kletnieks@vt.edu Return-path: In-Reply-To: <28675.1248957636@turing-police.cc.vt.edu> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org 2009/7/30 : > On Wed, 29 Jul 2009 19:17:00 +0300, Alexander Shishkin said: >>Is there anything dramatically wrong with this one, or could someone = please review this? > > >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for_each_process(= p) { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 files =3D get_files_struct(p); >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 if (!files) >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 continue; >> + >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 spin_lock(&files->file_lock); >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 fdt =3D files_fdtable(files); >> + >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 /* we have to actually *count* the fds */ >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 for (count =3D i =3D 0; i < fdt->max_fds; i++) >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 count +=3D !!fcheck_files(files,= i); >> + >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 printk(KERN_INFO "=3D> %s [%d]: %d\n", p->comm, >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 p->p= id, count); > > 1) Splatting out 'count' without a hint of what it is isn't very user= friendly. > Consider something like "=3D> %s[%d]: open=3D%d\n" instead, or add a = second line > to the 'VFS: file-max' printk to provide a header. =46air enough. > 2) What context does this run in, and what locks/scheduling considera= tions > are there? On a large system with many processes running, this could = conceivably > wrap the logmsg buffer before syslog has a chance to get scheduled an= d read > the stuff out. That's a good point. > 3) This can be used by a miscreant to spam the logs - consider a prog= ram > that does open() until it hits the limit, then goes into a close()/op= en() > loop to repeatedly bang up against the limit. Every 2 syscalls by the > abuser could get them another 5,000+ lines in the log - an incredible > amplification factor. > > Now, if you fixed it to only print out the top 10 offending processes= , it would > make it a lot more useful to the sysadmin, and a lot of those conside= rations go > away, but it also makes the already N**2 behavior even more expensive= =2E.. That's a good idea. I think some kind of rate-limiting can be applied h= ere too. > At that point, it would be good to report some CPU numbers by running= a abusive > program that repeatedly hit the limit, and be able to say "Even under= full > stress, it only used 15% of a CPU on a 2.4Ghz Core2" or similar... I'll see what I can do. Thanks for your comments and ideas! Regards, -- Alex