Subject: Re: bufq and sysctl question
To: Iain Hibbert <plunky@rya-online.net>
From: Juan RP <juan@xtrarom.org>
List: tech-kern
Date: 01/22/2006 13:15:29
--Boundary-00=_hd30DnqXWIUtkoV
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
El Domingo, 22 de Enero de 2006 11:58, Iain Hibbert escribi=F3:
> shouldnt this be the sizeof the variable if you want sysctl to copy the
> value over?
You are right, or at least it seems to work now. Thank you :-)
Patch attached.
[juan@Nocturno][~]> sysctl kern.bufq
kern.bufq.priocscan.burst.noncritical =3D 256
kern.bufq.priocscan.burst.limited =3D 64
kern.bufq.priocscan.burst.critical =3D 32
kern.bufq.readprio.read_burst =3D 128
kern.bufq.readprio.write_req =3D 64
kern.bufq.strategies =3D disksort fcfs priocscan readprio
[juan@Nocturno][~]>
[juan@Nocturno][~]> sudo sysctl -w kern.bufq.readprio.read_burst=3D512
kern.bufq.readprio.read_burst: 128 -> 512
[juan@Nocturno][~]> sysctl kern.bufq.readprio
kern.bufq.readprio.read_burst =3D 512
kern.bufq.readprio.write_req =3D 64
[juan@Nocturno][~]>
yamt, is it ready to commit?
Cheers!
--Boundary-00=_hd30DnqXWIUtkoV
Content-Type: text/x-diff;
charset="iso-8859-1";
name="b.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="b.diff"
Index: sys/kern/bufq_priocscan.c
===================================================================
RCS file: /cvsroot/src/sys/kern/bufq_priocscan.c,v
retrieving revision 1.7
diff -u -p -r1.7 bufq_priocscan.c
--- sys/kern/bufq_priocscan.c 24 Dec 2005 19:12:23 -0000 1.7
+++ sys/kern/bufq_priocscan.c 22 Jan 2006 12:08:48 -0000
@@ -35,6 +35,7 @@ __KERNEL_RCSID(0, "$NetBSD: bufq_priocsc
#include <sys/bufq.h>
#include <sys/bufq_impl.h>
#include <sys/malloc.h>
+#include <sys/sysctl.h>
/*
* Cyclical scan (CSCAN)
@@ -158,15 +159,17 @@ struct bufq_priocscan {
/*
* how many requests to serve when having pending requests on other queues.
*
- * XXX tune
*/
-const int priocscan_burst[] = {
- 64, 16, 4
-};
+
+int priocscan_burst_noncritical = 64;
+int priocscan_burst_limited = 16;
+int priocscan_burst_critical = 4;
static void bufq_priocscan_init(struct bufq_state *);
static void bufq_priocscan_put(struct bufq_state *, struct buf *);
static struct buf *bufq_priocscan_get(struct bufq_state *, int);
+static int sysctl_priocscan_burst_minmaxsize(SYSCTLFN_PROTO);
+static int priocscan_burst(int);
BUFQ_DEFINE(priocscan, 40, bufq_priocscan_init);
@@ -262,7 +265,7 @@ bufq_priocscan_get(struct bufq_state *bu
if (remove) {
for (i = 0; i < PRIOCSCAN_NQUEUE; i++) {
pq = &q->bq_queue[i];
- pq->q_burst = priocscan_burst[i];
+ pq->q_burst = priocscan_burst(i);
}
}
@@ -298,3 +301,96 @@ bufq_priocscan_init(struct bufq_state *b
cscan_init(cq);
}
}
+
+static int
+priocscan_burst(int number)
+{
+ switch(number) {
+ case 0:
+ return priocscan_burst_noncritical;
+ case 1:
+ return priocscan_burst_limited;
+ case 2:
+ return priocscan_burst_critical;
+ default:
+ /* NOTREACHED */
+ return 128;
+ }
+}
+
+static int
+sysctl_priocscan_burst_minmaxsize(SYSCTLFN_ARGS)
+{
+ int newsize, error;
+ struct sysctlnode node;
+
+ node = *rnode;
+ node.sysctl_data = &newsize;
+ newsize = *(int *)rnode->sysctl_data;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ if (newsize < 0 || newsize > 1024)
+ return EINVAL;
+
+ *(int *)rnode->sysctl_data = newsize;
+
+ return 0;
+}
+
+/*
+ * This will create kern.bufq.priocscan.burst.<queue name>.
+ * This may be one of the following: noncritical, critical and limited.
+ */
+
+SYSCTL_SETUP(sysctl_priocscan_setup, "sysctl bufq priocscan setup")
+{
+
+ const struct sysctlnode *cnode, *rnode;
+
+ sysctl_createv(clog, 0, NULL, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "kern", NULL,
+ NULL, 0, NULL, 0,
+ CTL_KERN, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "bufq", NULL,
+ NULL, 0, NULL, 0,
+ CTL_CREATE, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "priocscan", NULL,
+ NULL, 0, NULL, 0,
+ CTL_CREATE, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "burst", NULL,
+ NULL, 0, NULL, 0,
+ CTL_CREATE, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "noncritical",
+ SYSCTL_DESCR("size of the noncritical queue"),
+ sysctl_priocscan_burst_minmaxsize, 0,
+ &priocscan_burst_noncritical,
+ sizeof(priocscan_burst_noncritical),
+ CTL_CREATE, rnode->sysctl_num, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "limited",
+ SYSCTL_DESCR("size of the limited queue"),
+ sysctl_priocscan_burst_minmaxsize, 0,
+ &priocscan_burst_limited,
+ sizeof(priocscan_burst_limited),
+ CTL_CREATE, rnode->sysctl_num, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "critical",
+ SYSCTL_DESCR("size of the critical queue"),
+ sysctl_priocscan_burst_minmaxsize, 0,
+ &priocscan_burst_critical,
+ sizeof(priocscan_burst_critical),
+ CTL_CREATE, rnode->sysctl_num, CTL_EOL);
+}
Index: sys/kern/bufq_readprio.c
===================================================================
RCS file: /cvsroot/src/sys/kern/bufq_readprio.c,v
retrieving revision 1.7
diff -u -p -r1.7 bufq_readprio.c
--- sys/kern/bufq_readprio.c 11 Dec 2005 12:24:29 -0000 1.7
+++ sys/kern/bufq_readprio.c 22 Jan 2006 12:08:48 -0000
@@ -83,6 +83,7 @@ __KERNEL_RCSID(0, "$NetBSD: bufq_readpri
#include <sys/bufq.h>
#include <sys/bufq_impl.h>
#include <sys/malloc.h>
+#include <sys/sysctl.h>
/*
* Seek sort for disks.
@@ -98,6 +99,9 @@ __KERNEL_RCSID(0, "$NetBSD: bufq_readpri
#define PRIO_READ_BURST 48
#define PRIO_WRITE_REQ 16
+int readprio_read_burst = PRIO_READ_BURST;
+int readprio_write_req = PRIO_WRITE_REQ;
+
struct bufq_prio {
TAILQ_HEAD(, buf) bq_read, bq_write; /* actual list of buffers */
struct buf *bq_write_next; /* next request in bq_write */
@@ -183,10 +187,10 @@ bufq_prio_get(struct bufq_state *bufq, i
* to PRIO_READ_BURST times, then select the write
* list PRIO_WRITE_REQ times.
*/
- if (prio->bq_read_burst++ < PRIO_READ_BURST)
+ if (prio->bq_read_burst++ < readprio_read_burst)
prio->bq_next = TAILQ_FIRST(&prio->bq_read);
else if (prio->bq_read_burst <
- PRIO_READ_BURST + PRIO_WRITE_REQ)
+ readprio_read_burst + readprio_write_req)
prio->bq_next = prio->bq_write_next;
else {
prio->bq_next = TAILQ_FIRST(&prio->bq_read);
@@ -232,3 +236,60 @@ bufq_readprio_init(struct bufq_state *bu
TAILQ_INIT(&prio->bq_write);
}
+static int
+sysctl_readprio_minmaxsize(SYSCTLFN_ARGS)
+{
+ int newsize, error;
+ struct sysctlnode node;
+
+ node = *rnode;
+ node.sysctl_data = &newsize;
+ newsize = *(int *)rnode->sysctl_data;
+ error = sysctl_lookup(SYSCTLFN_CALL(&node));
+ if (error || newp == NULL)
+ return error;
+
+ if (newsize < 0 || newsize > 1024)
+ return EINVAL;
+
+ *(int *)rnode->sysctl_data = newsize;
+
+ return 0;
+}
+
+SYSCTL_SETUP(sysctl_readprio_setup, "sysctl bufq readprio setup")
+{
+ const struct sysctlnode *rnode, *cnode;
+
+ sysctl_createv(clog, 0, NULL, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "kern", NULL,
+ NULL, 0, NULL, 0,
+ CTL_KERN, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "bufq", NULL,
+ NULL, 0, NULL, 0,
+ CTL_CREATE, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &rnode,
+ CTLFLAG_PERMANENT,
+ CTLTYPE_NODE, "readprio", NULL,
+ NULL, 0, NULL, 0,
+ CTL_CREATE, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "read_burst",
+ SYSCTL_DESCR("size of the read queue"),
+ sysctl_readprio_minmaxsize, 0,
+ &readprio_read_burst,
+ sizeof(readprio_read_burst),
+ CTL_CREATE, rnode->sysctl_num, CTL_EOL);
+ sysctl_createv(clog, 0, &rnode, &cnode,
+ CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+ CTLTYPE_INT, "write_req",
+ SYSCTL_DESCR("number of write requests"),
+ sysctl_readprio_minmaxsize, 0,
+ &readprio_write_req,
+ sizeof(readprio_write_req),
+ CTL_CREATE, rnode->sysctl_num, CTL_EOL);
+}
--Boundary-00=_hd30DnqXWIUtkoV--