NetBSD Problem Report #41765

From Wolfgang.Stukenbrock@nagler-company.com  Wed Jul 22 11:59:07 2009
Return-Path: <Wolfgang.Stukenbrock@nagler-company.com>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id D2FD463B879
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 22 Jul 2009 11:59:07 +0000 (UTC)
Message-Id: <20090722115903.9D3BF4EA9FE@s012.nagler-company.com>
Date: Wed, 22 Jul 2009 13:59:03 +0200 (CEST)
From: Wolfgang.Stukenbrock@nagler-company.com
Reply-To: Wolfgang.Stukenbrock@nagler-company.com
To: gnats-bugs@gnats.NetBSD.org
Subject: kernel panic while allocating swap space pages
X-Send-Pr-Version: 3.95

>Number:         41765
>Category:       kern
>Synopsis:       kernel panic while allocating swap space pages
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 22 12:00:00 +0000 2009
>Closed-Date:    Wed Jun 01 22:30:05 +0000 2016
>Last-Modified:  Wed Jun 01 22:30:05 +0000 2016
>Originator:     Wolfgang Stukenbrock
>Release:        NetBSD 4.0
>Organization:
Dr. Nagler & Company GmbH

>Environment:


System: NetBSD s012 4.0 NetBSD 4.0 (NSW-S012) #9: Fri Mar 13 12:31:52 CET 2009 wgstuken@s012:/usr/src/sys/arch/amd64/compile/NSW-S012 amd64
Architecture: x86_64
Machine: amd64
>Description:
	There is a limitation in the blist implementation in kern/subr_blist.c.
	It cannot allocate more pages at once as specified by BLIST_BMAP_RADIX.
	For this purpose there is a definition BLIST_MAX_ALLOC in blist.h.
	In uvm/uvm_swap.c uvm_swap_alloc() there is no check against this number and if
	the e.g. the pagedeamon tries to swap out more, the system will panic with
	"panic: blist_meta_alloc: allocation too large".
	Remark: this will only happen if MAXPHYS is larger than the space in BLIST_MAX_ALLOC
	pages. Normaly this is not the case (64k < 128k). We have changed MAXPHYS on the
	system to something more suitable for a backup server, because 64k blocksize is
	much to small - we use 1MB.
>How-To-Repeat:
	Compile a kernel with MAXPHYS larger than 128k and allocate a large amount of memory
	in tmpfs. The system will try to allocate pages for MAXPHYS Kbyte and will panic.
>Fix:
	The fix is easy. Just check the number of pages in uvm_swap_alloc() prio calling blist_alloc().
	Due to the fact, that umv_swap_alloc() may fail and the caller must be able to handle this,
	we can abort the allocation if we may not return a smaller number of pages as requested.
	Otherwise we just clamp it to BLIST_MAX_ALLOC.
	The following fix runs fine on our system without any problems with pagedeamon anymore.
	remark: I assume, that I can change *nslots without allocating the uvm.swap_data_lock lock.
	Otherwise this code must be moved behind the simple_lock(), that comes two lines below
	the unified diff and the lock must be freed prior the "return 0;".

	Of cause it would be better to fix the allocation problem in subr_blist.c, but this is
	a small and effectiv work-around for the allocation problem.

	The following patch should be applyed to uvm/uvm_swap.c:
--- uvm_swap.c  2009/07/22 11:30:38     1.1
+++ uvm_swap.c  2009/07/22 11:39:44
@@ -1447,6 +1447,14 @@
        if (uvmexp.nswapdev < 1)
                return 0;

+	if (*nslots > BLIST_MAX_ALLOC) {
+		/* avoid panic in blist_alloc() below - cannot handle this amount of blocks
+		 * see comment in subr_blist.c
+		 */
+		if (!lessok) return 0; /* sorry - cannot handle this ... */
+		*nslots = BLIST_MAX_ALLOC;
+	}
+
        /*
         * lock data lock, convert slots into blocks, and enter loop
         */

>Release-Note:

>Audit-Trail:
From: "Jonathan A. Kollasch" <jakllsch@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/41765 CVS commit: src/sys/uvm
Date: Tue, 27 Nov 2012 20:15:55 +0000

 Module Name:	src
 Committed By:	jakllsch
 Date:		Tue Nov 27 20:15:55 UTC 2012

 Modified Files:
 	src/sys/uvm: uvm_swap.c

 Log Message:
 Until such time as the swap subsystem can be converted to use The One True
 Allocator, prevent panics if (MAXPHYS/PAGE_SIZE) > BLIST_MAX_ALLOC.
 From Wolfgang Stukenbrock in PR#41765.


 To generate a diff of this commit:
 cvs rdiff -u -r1.161 -r1.162 src/sys/uvm/uvm_swap.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: pgoyette@NetBSD.org
State-Changed-When: Wed, 01 Jun 2016 22:30:05 +0000
State-Changed-Why:
Fix to prevent the panic was committed on Nov 27 20:15:55 UTC 2012 by jakllsch


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.