From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Wed, 02 May 2007 23:42:18 +0000 Subject: Re: udevd on very large systems: again Message-Id: <1178149338.4346.30.camel@lov.localdomain> List-Id: References: <4637D051.7060103@sgi.com> In-Reply-To: <4637D051.7060103@sgi.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org On Wed, 2007-05-02 at 17:26 -0400, George Beshers wrote: > Kay Sievers wrote: > > Looks fine so far, but I still don't see how reading a seq-proc-file > > could miss entries. Are you expecting this to happen? Did you ever see > > this for any of these files? > The answer is slightly complex. No I never saw it happen, but I am > concerned about it. To illustrate that, consider the following test > program and the output log attached. Basically, the /proc/stat file > does seem to be changing dynamically and an open file does not > present a stable snapshot. Looking at the seq_file code, calling lseek() causes the buffer to be repopulated: seq_lseek() -> traverse() -> m->op->show() while show() is the method of the "stat" file that fills the buffer. A simple read() should not do that, and just copy the content (up to 128kB) of the kernel seq_file file buffer to the user-process: seq_read() -> copy_to_user(buf, m->buf + m->from, n) > So the danger is that the procs_running > might get split at a 4k boundary and the split changes by the time > the next read occurs so procs_running is corrupted. I'm pretty sure, that this doesn't happen, if you don't seek(). Here is a test, that opens /proc/stat, reads a single byte (which fills the buffer), forks a ton of processes and reads the rest of the buffer. You see that the "processes" value did not increase: $ ./seq processes 57425 processes 57425 processes 58203 #include #include #include #include #include int main(int argc, char *argv[]) { FILE* f; char buf[1024]; int i; system("grep processes /proc/stat"); f = fopen("/proc/stat", "r"); fread(buf, 1, 1, f); for (i = 0; i < 777; i++) system("/bin/true"); while (fgets(buf, sizeof(buf), f)) if (strncmp(buf, "processes", 9) = 0) printf("%s", buf); fclose(f); system("grep processes /proc/stat"); return 0; } Thanks, Kay ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel