From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752013AbbHMHm4 (ORCPT ); Thu, 13 Aug 2015 03:42:56 -0400 Received: from mail-la0-f42.google.com ([209.85.215.42]:35422 "EHLO mail-la0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751442AbbHMHmz (ORCPT ); Thu, 13 Aug 2015 03:42:55 -0400 From: Rasmus Villemoes To: Linus Torvalds Cc: Andrew Morton , Joonsoo Kim , Al Viro , Linux Kernel Mailing List Subject: Re: get_vmalloc_info() and /proc/meminfo insanely expensive Organization: D03 References: <20150812210027.88dfcf90.akpm@linux-foundation.org> X-Hashcash: 1:20:150813:torvalds@linux-foundation.org::zvjNqFrQHes2JvE4:000000000000000000000000000000000GaZ X-Hashcash: 1:20:150813:linux-kernel@vger.kernel.org::tsf896fDFrUix4Et:0000000000000000000000000000000001Eez X-Hashcash: 1:20:150813:iamjoonsoo.kim@lge.com::xog98pzkDoNONevT:0000000000000000000000000000000000000001gmc X-Hashcash: 1:20:150813:akpm@linux-foundation.org::1vle8dpIDyCLuk/R:0000000000000000000000000000000000002CB1 X-Hashcash: 1:20:150813:viro@zeniv.linux.org.uk::fXCWUx/GRUZcWonU:000000000000000000000000000000000000006vfk Date: Thu, 13 Aug 2015 09:42:52 +0200 In-Reply-To: (Linus Torvalds's message of "Wed, 12 Aug 2015 22:52:44 -0700") Message-ID: <87bnebk51f.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 13 2015, Linus Torvalds wrote: > On Wed, Aug 12, 2015 at 9:00 PM, Andrew Morton > wrote: >> >> Do your /proc/meminfo vmalloc numbers actually change during that build? >> Mine don't. Perhaps we can cache the most recent vmalloc_info and >> invalidate that cache whenever someone does a vmalloc/vfree/etc. > > Sure, that works too. > > Looking at that mm/vmalloc.c file, the locking is pretty odd. It looks > pretty strange in setup_vmalloc_vm(), for example. If that newly > allocated "va" that we haven't even exposed to anybody yet has its > address or size changed, we're screwed in so many ways. > > I get the feeling this file should be rewritten. But that's not going > to happen. The "let's just cache the last value for one jiffy" seemed > to be the minimal fixup to it. > I think it's simpler and better to fix glibc. Looking at the history, the code for get_[av]phys_pages was added in 1996 (in the git repo commit 845dcb57), with comments such as /* Return the number of pages of physical memory in the system. There is currently (as of version 2.0.21) no system call to determine the number. It is planned for the 2.1.x series to add this, though. and /* XXX Here will come a test for the new system call. */ And that syscall seems to be sysinfo(). So even though sysinfo() also returns much more than required, it is still more than an order of magnitude faster than reading and parsing /proc/meminfo (in the quick microbench I threw together): #include #include #include void do_get_phys_pages(void) { get_phys_pages(); } void do_get_avphys_pages(void) { get_avphys_pages(); } void do_sysinfo(void) { struct sysinfo info; sysinfo(&info); } void time_this(const char *name, void (*f)(void), int rep) { int i; unsigned long start, stop; start = rdtsc(); for (i = 0; i < rep; ++i) f(); stop = rdtsc(); printf("%-20s\t%d\t%lu\t%.1f\n", name, rep, stop-start, (double)(stop-start)/rep); } #define time_this(f, rep) time_this(#f, do_ ## f, rep) int main(void) { time_this(sysinfo, 1); time_this(get_phys_pages, 1); time_this(get_avphys_pages, 1); time_this(sysinfo, 1); time_this(get_phys_pages, 1); time_this(get_avphys_pages, 1); time_this(sysinfo, 10); time_this(get_phys_pages, 10); time_this(get_avphys_pages, 10); return 0; } $ ./sysinfo sysinfo 1 6056 6056.0 get_phys_pages 1 226744 226744.0 get_avphys_pages 1 84480 84480.0 sysinfo 1 2288 2288.0 get_phys_pages 1 73216 73216.0 get_avphys_pages 1 76692 76692.0 sysinfo 10 6856 685.6 get_phys_pages 10 626936 62693.6 get_avphys_pages 10 604440 60444.0 Rasmus