From dom@host217-41-34-37.in-addr.btopenworld.com  Sat Aug 31 18:49:12 2002
Return-Path: <dom@host217-41-34-37.in-addr.btopenworld.com>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id F0E0837B400
	for <freebsd-gnats-submit@freebsd.org>; Sat, 31 Aug 2002 18:49:11 -0700 (PDT)
Received: from host217-41-34-37.in-addr.btopenworld.com (host217-41-34-37.in-addr.btopenworld.com [217.41.34.37])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 1282343E6A
	for <freebsd-gnats-submit@freebsd.org>; Sat, 31 Aug 2002 18:49:11 -0700 (PDT)
	(envelope-from dom@host217-41-34-37.in-addr.btopenworld.com)
Received: by host217-41-34-37.in-addr.btopenworld.com (Postfix, from userid 1001)
	id 5419B4F9; Sun,  1 Sep 2002 02:49:22 +0100 (BST)
Message-Id: <20020901014922.5419B4F9@host217-41-34-37.in-addr.btopenworld.com>
Date: Sun,  1 Sep 2002 02:49:22 +0100 (BST)
From: Dominic Marks <dominic_marks@btinternet.com>
Reply-To: Dominic Marks <dominic_marks@btinternet.com>
To: freebsd-gnats-submit@freebsd.org
Cc:
Subject: Convert defined variable into tuneable as suggested
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         42274
>Category:       kern
>Synopsis:       [kernel] [patch] Convert defined variable into tuneable as suggested
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug 31 18:50:01 PDT 2002
>Closed-Date:    
>Last-Modified:  Tue Oct 25 23:59:00 GMT 2005
>Originator:     Dominic Marks
>Release:        FreeBSD 4.6-STABLE i386
>Organization:
National Physical Laboratory, UK
>Environment:
System: FreeBSD gallium 4.6-STABLE FreeBSD 4.6-STABLE #2:
Sun Sep 1 02:15:28 BST 2002 dom@gallium:/usr/obj/usr/src/sys/GENERIC i386
	
>Description:
	In kern_event.c the following line currently exists:

	#define	KN_HASHSIZE	64	/* XXX should be tunable */

	I have created another sysctl using the same naming scheme which
	is used elsewhere in the file which implements (I believe) what
	the comment suggests.
	
	
>How-To-Repeat:
	I have successfully built and tested a 4.6-STABLE kernel with
	the small diff below, it seems to work as expected:

	> sysctl kern | grep kq_
	kern.kq_calloutmax: 4096
	kern.kq_hashsize: 128
	(the default is still 64, but I wanted to test with a different
	size so I modified this in loader.conf)
	
	A test application for kqueue that I have written works as it is
	expected to also:

	> ./kqtest
	im going to make a new kqueue
	now i am going to wait for events on that queue
	(here it blocks for events as expected)

	I have supplied diffs against -CURRENT and -STABLE below.

	Thanks.
	
>Fix:

Against -CURRENT:

Index: kern_event.c
===================================================================
RCS file: /media/cvs/freebsd/src/sys/kern/kern_event.c,v
retrieving revision 1.45
diff -u -3 -p -r1.45 kern_event.c
--- kern_event.c	17 Aug 2002 02:36:16 -0000	1.45
+++ kern_event.c	1 Sep 2002 01:35:26 -0000
@@ -111,8 +111,12 @@ static struct filterops timer_filtops =
 static uma_zone_t	knote_zone;
 static int 		kq_ncallouts = 0;
 static int 		kq_calloutmax = (4 * 1024);
+static int		kq_hashsize = 64;
+
 SYSCTL_INT(_kern, OID_AUTO, kq_calloutmax, CTLFLAG_RW,
     &kq_calloutmax, 0, "Maximum number of callouts allocated for kqueue");
+SYSCTL_INT(_kern, OID_AUTO, kq_hashsize, CTLFLAG_RW, &kq_hashsize, 0,
+	"Size of the KNote hash used by kqueue");
 
 #define KNOTE_ACTIVATE(kn) do { 					\
 	kn->kn_status |= KN_ACTIVE;					\
@@ -120,7 +124,6 @@ SYSCTL_INT(_kern, OID_AUTO, kq_calloutma
 		knote_enqueue(kn);					\
 } while(0)
 
-#define	KN_HASHSIZE		64		/* XXX should be tunable */
 #define KN_HASH(val, mask)	(((val) ^ (val >> 8)) & (mask))
 
 static int
@@ -960,7 +963,7 @@ knote_attach(struct knote *kn, struct fi
 
 	if (! kn->kn_fop->f_isfd) {
 		if (fdp->fd_knhashmask == 0)
-			fdp->fd_knhash = hashinit(KN_HASHSIZE, M_KQUEUE,
+			fdp->fd_knhash = hashinit(kq_hashsize, M_KQUEUE,
 			    &fdp->fd_knhashmask);
 		list = &fdp->fd_knhash[KN_HASH(kn->kn_id, fdp->fd_knhashmask)];
 		goto done;

Against -STABLE:

Index: kern_event.c
===================================================================
RCS file: /media/cvs/freebsd/src/sys/kern/kern_event.c,v
retrieving revision 1.2.2.8
diff -u -3 -p -r1.2.2.8 kern_event.c
--- kern_event.c	14 Dec 2001 19:24:42 -0000	1.2.2.8
+++ kern_event.c	1 Sep 2002 01:45:37 -0000
@@ -108,8 +108,13 @@ static struct filterops timer_filtops =
 static vm_zone_t	knote_zone;
 static int 		kq_ncallouts = 0;
 static int 		kq_calloutmax = (4 * 1024);
-SYSCTL_INT(_kern, OID_AUTO, kq_calloutmax, CTLFLAG_RW,
-    &kq_calloutmax, 0, "Maximum number of callouts allocated for kqueue");
+static int		kq_hashsize = 64;
+
+SYSCTL_INT(_kern, OID_AUTO, kq_calloutmax, CTLFLAG_RW, &kq_calloutmax,
+	0, "Maximum number of callouts allocated for kqueue");
+SYSCTL_INT(_kern, OID_AUTO, kq_hashsize, CTLFLAG_RW, &kq_hashsize, 0,
+	"Size of the KNote hash used by kqueue");
+
 
 #define KNOTE_ACTIVATE(kn) do { 					\
 	kn->kn_status |= KN_ACTIVE;					\
@@ -117,7 +122,6 @@ SYSCTL_INT(_kern, OID_AUTO, kq_calloutma
 		knote_enqueue(kn);					\
 } while(0)
 
-#define	KN_HASHSIZE		64		/* XXX should be tunable */
 #define KN_HASH(val, mask)	(((val) ^ (val >> 8)) & (mask))
 
 extern struct filterops aio_filtops;
@@ -873,7 +877,7 @@ knote_attach(struct knote *kn, struct fi
 
 	if (! kn->kn_fop->f_isfd) {
 		if (fdp->fd_knhashmask == 0)
-			fdp->fd_knhash = hashinit(KN_HASHSIZE, M_KQUEUE,
+			fdp->fd_knhash = hashinit(kq_hashsize, M_KQUEUE,
 			    &fdp->fd_knhashmask);
 		list = &fdp->fd_knhash[KN_HASH(kn->kn_id, fdp->fd_knhashmask)];
 		goto done;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jlemon 
Responsible-Changed-By: schweikh 
Responsible-Changed-When: Sun Sep 1 01:28:56 PDT 2002 
Responsible-Changed-Why:  
Jonathan, as you have added the line 
#define	KN_HASHSIZE	64	/* XXX should be tunable */ 
and now somebody did the work, could you look at the patch 
and commit it if you think it's fine? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=42274 
Responsible-Changed-From-To: jlemon->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Sep 13 06:00:09 GMT 2004 
Responsible-Changed-Why:  
With bugmeister hat on, reassign from recently inactive committer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=42274 
>Unformatted:
