NetBSD Problem Report #55432

From www@netbsd.org  Tue Jun 30 07:01:34 2020
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 83E751A9217
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 30 Jun 2020 07:01:34 +0000 (UTC)
Message-Id: <20200630070133.71DC31A9218@mollari.NetBSD.org>
Date: Tue, 30 Jun 2020 07:01:33 +0000 (UTC)
From: rokuyama.rk@gmail.com
Reply-To: rokuyama.rk@gmail.com
To: gnats-bugs@NetBSD.org
Subject: Optimize uvm_fault for pagesize larger than 4k
X-Send-Pr-Version: www-1.0

>Number:         55432
>Category:       kern
>Synopsis:       Optimize uvm_fault for pagesize larger than 4k
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 30 07:05:00 +0000 2020
>Originator:     Rin Okuyama
>Release:        9.99.68 and netbsd-9 (and older release branches also)
>Organization:
Department of Physics, Meiji University
>Environment:
NetBSD obs266 9.99.68 NetBSD 9.99.68 (OBS266) #284: Mon Jun 29 23:06:25 JST 2020  rin@latipes:/usr/src/sys/arch/evbppc/compile/OBS266 evbppc

NetBSD erlite 9.0_STABLE NetBSD 9.0_STABLE (ERLITE) #1: Sun Jun 28 23:05:51 JST 2020  rin@latipes:/build/work/src/sys/arch/evbmips/compile/ERLITE evbmips
>Description:
uvm_fault() resolves not only a page containing the fault address, but
also pages around it speculatively. Number of pages to be resolved is
hardcoded for types of fault:

https://nxr.netbsd.org/xref/src/sys/uvm/uvm_fault.c#155

These values are taken from FreeBSD, whose main targets have 4k pages.

The problem is for pages larger than 4k, say, if the machine has 16k
pages, 4 times of pages are resolved speculatively. This seems too
much. Therefore, I would like to propose to rescale these values so
that amount of memory to be resolved is approximately same as that
for 4k page:

http://www.netbsd.org/~rin/uvm_fault_20200630.patch

With this patch, nothing changes for 4k pages. (Also, if pagesize is
smaller than 4k, i.e., mc68010, do not rescale for safety; it is
already suffering from memory shortage.)

For machines with pagesize larger than 4k, the performance is clearly
improved. I've carried out simple benchmark by measuring time to make
pkgsrc/lang/python37:

For PowerPC 405GPr (powerpc/ibm4xx, 16k pages):
before:	12414.44 real     11117.19 user      1172.01 sys
after:	12103.14 real     10859.51 user      1125.75 sys
Improve in real: 2.51%

For Cavium CN50xx (evbmips/mips64, 8k pages):
before:	3607.57 real      2862.35 user       472.94 sys
after:	3519.00 real      2844.17 user       430.26 sys
Improve in real: 2.46%

(Note that since -current is unstable for mips64, netbsd-9 is used
for Cavium CN50xx.)

Thoughts? Can I commit the patch?

Also, the current hard-coded value may be not optimal even for 4k
pages. It is take from FreeBSD as of 1998, and FreeBSD seems to adjust
# of pages on demand now. See their sys/vm/vm_fault.c.
>How-To-Repeat:
Code inspection and benchmark as described above.
>Fix:
Described above.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.