X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx2.hub.org [200.46.204.254]) by postgresql.org (Postfix) with ESMTP id 0CB5411F8CB4 for ; Fri, 21 Apr 2006 04:15:54 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: -0.367 X-Spam-Level: X-Spam-Status: No, score=-0.367 required=5 tests=[BAYES_00=-2.599, RCVD_IN_WHOIS_INVALID=2.234, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] Received: from postgresql.org ([200.46.204.71]) by localhost (mx2.hub.org [200.46.204.254]) (amavisd-new, port 10024) with ESMTP id 5HeeSGiHyPhi for ; Fri, 21 Apr 2006 04:15:46 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mx1.ustc.edu.cn (ns.ustc.edu.cn [202.38.64.1]) by postgresql.org (Postfix) with ESMTP id 293A511F8C96 for ; Fri, 21 Apr 2006 04:15:41 -0300 (ADT) Received: from localhost.localdomain ([211.86.144.78]) by mx1.ustc.edu.cn (8.11.6/8.11.6) with ESMTP id k3L7BXw11816; Fri, 21 Apr 2006 15:11:36 +0800 Received: from wfg by localhost.localdomain with local (Exim 4.50) id 1FWprD-0001II-7x; Fri, 21 Apr 2006 15:15:11 +0800 Date: Fri, 21 Apr 2006 15:15:11 +0800 From: Wu Fengguang To: "Jim C. Nasby" Cc: pgsql-performance@postgresql.org Subject: Re: Introducing a new linux readahead framework Message-ID: <20060421071511.GA4885@mail.ustc.edu.cn> Mail-Followup-To: Wu Fengguang , "Jim C. Nasby" , pgsql-performance@postgresql.org References: <20060421013826.GA5217@mail.ustc.edu.cn> <20060421043147.GV49405@pervasive.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060421043147.GV49405@pervasive.com> User-Agent: Mutt/1.5.11+cvs20060126 X-Archive-Number: 200604/492 X-Sequence-Number: 18576 On Thu, Apr 20, 2006 at 11:31:47PM -0500, Jim C. Nasby wrote: > > In adaptive readahead, the context based method may be of particular > > interest to postgresql users. It works by peeking into the file cache > > and check if there are any history pages present or accessed. In this > > way it can detect almost all forms of sequential / semi-sequential read > > patterns, e.g. > > - parallel / interleaved sequential scans on one file > > - sequential reads across file open/close > > - mixed sequential / random accesses > > - sparse / skimming sequential read > > > > It also have methods to detect some less common cases: > > - reading backward > > - seeking all over reading N pages > > Are there any ways to inform the kernel that you either are or aren't > doing a sequential read? It seems that in some cases it would be better This call will disable readahead totally for fd: posix_fadvise(fd, any, any, POSIX_FADV_RANDOM); This one will reenable it: posix_fadvise(fd, any, any, POSIX_FADV_NORMAL); This one will enable readahead _and_ set max readahead window to 2*max_readahead_kb: posix_fadvise(fd, any, any, POSIX_FADV_SEQUENTIAL); > to bypass a bunch of tricky logic trying to determine that it's doing a > sequential read. A sequential scan in PostgreSQL would be such a case. You do not need to worry about the detecting `overhead' on sequential scans :) The adaptive readahead framework has a fast code path(the stateful method) to handle normal sequential reads, the detection of which is really trivial. > The opposite example would be an index scan of a highly uncorrelated > index, which would produce mostly random reads from the table. In that > case, reading ahead probably makes very little sense, though your logic > might have a better idea of the access pattern than PostgreSQL does. As for the index scans, the failsafe code path(i.e. the context based one) will normally be used, and it does have a little overhead in looking up the page cache(about 0.4% more CPU time). However, the penalty of random disk access is so large that if ever it helps reducing a small fraction of disk accesses, you wins. Thanks, Wu