From owner-freebsd-hackers@freebsd.org Sun Oct 14 11:46:00 2018 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8932710D007E for ; Sun, 14 Oct 2018 11:46:00 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 14D6184792; Sun, 14 Oct 2018 11:45:59 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id w9EBjjdj013383 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 14 Oct 2018 14:45:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua w9EBjjdj013383 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id w9EBjivo013382; Sun, 14 Oct 2018 14:45:44 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 14 Oct 2018 14:45:44 +0300 From: Konstantin Belousov To: Thomas Munro Cc: freebsd-hackers@freebsd.org, alc@freebsd.org, mjg@freebsd.org Subject: Re: PostgresSQL vs super pages Message-ID: <20181014114544.GA5335@kib.kiev.ua> References: <20181011001954.GV5335@kib.kiev.ua> <20181013235021.GX5335@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on tom.home X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Oct 2018 11:46:00 -0000 On Sun, Oct 14, 2018 at 10:58:08PM +1300, Thomas Munro wrote: > On Sun, 14 Oct 2018 at 12:50, Konstantin Belousov wrote: > > On Thu, Oct 11, 2018 at 02:01:20PM +1300, Thomas Munro wrote: > > > On Thu, 11 Oct 2018 at 13:20, Konstantin Belousov wrote: > > > > On Thu, Oct 11, 2018 at 12:59:41PM +1300, Thomas Munro wrote: > > > > > shm_open("/PostgreSQL.1721888107",O_RDWR|O_CREAT|O_EXCL,0600) = 46 (0x2e) > > > > > ftruncate(46,0x400000) = 0 (0x0) > > > > Try to write zeroes instead of truncating. > > > > This should activate the fast path in the fault handler, and if the > > > > pages allocated for backing store of the shm object were from reservation, > > > > you should get superpage mapping on the first fault without promotion. > > > > > > If you just write() to a newly shm_open()'d fd you get a return code > > > of 0 so I assume that doesn't work. If you ftruncate() to the desired > > > size first, then loop writing 8192 bytes of zeroes at a time, it > > > works. But still no super pages. I tried also with a write buffer of > > > 2MB of zeroes, but still no super pages. I tried abandoning > > > shm_open() and instead using a mapped file, and still no super pages. > > > > I did not quite scientific experiment, but you would need to try to find > > the differences between what I did and what you observe. Below is the > > naive test program that directly implements my suggestion, and the > > output from the procstat -v for it after all things were set up. > > > ... > > 98579 0x800e00000 0x801200000 rw- 1024 1030 3 0 --S- df > > Huh. Your program doesn't result in an S mapping on my laptop, but I > tried on an EC2 t2.2xlarge machine and there it promotes to S, even if > I comment out the write() loop (the loop that assigned to every byte > is enough). The difference might be the amount of memory on the > system: on my 4GB laptop, it is very reluctant to use super pages (but > I have seen it do it, so I know it can). On a 32GB system, it does it > immediately, and it works nicely for PostgreSQL too. So perhaps my > problem is testing on a small RAM system, though I don't understand > why. How many free memory does your system have ? Free as reported by top. If the free memory is low and fragmented, and I suppose it is on 4G laptop which you use with X, browser and other memory-consuming applications, system would have troubles filling the reverve, i.e reserving 2M of 2M-aligned physical pages. You can try the test programs right after booting into single user mode.