shithub: front

Download patch

ref: 4d99c9c4c14b9bec61773bd7c84f296b8aa1ec2b
parent: 6ab5327d1ac3a50af584224dc3e563ff24bd36ae
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Jul 6 09:29:25 EDT 2025

kernel: embed the Mount.spec string into Mount structure

Instead of making a separate allocation for the Mount.spec
string, make it part of the Mount allocation itself.
This avoids kstrdup() -> smalloc() call while copying pgrp.

--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -686,7 +686,7 @@
 			srv = cm->to->mchan->srvname;
 			if(srv == nil)
 				srv = cm->to->mchan->path->s;
-			i = snprint(buf, nbuf, (cm->spec && *cm->spec)?
+			i = snprint(buf, nbuf, *cm->spec?
 				"mount %s %q %q %q\n": "mount %s %q %q\n", flag,
 				srv, mh->from->path->s, cm->spec);
 		}else{
--- a/sys/src/9/port/pgrp.c
+++ b/sys/src/9/port/pgrp.c
@@ -125,7 +125,7 @@
 			l = &mh->hash;
 			link = &mh->mount;
 			for(m = f->mount; m != nil; m = m->next) {
-				n = malloc(sizeof(Mount));
+				n = malloc(sizeof(Mount)+strlen(m->spec)+1);
 				if(n == nil)
 					error(Enomem);
 				n->mountid = m->mountid;
@@ -132,8 +132,7 @@
 				n->mflag = m->mflag;
 				n->to = m->to;
 				incref(n->to);
-				if(m->spec != nil)
-					kstrdup(&n->spec, m->spec);
+				strcpy(n->spec, m->spec);
 				pgrpinsert(&order, n);
 				*link = n;
 				link = &n->next;
@@ -266,7 +265,9 @@
 {
 	Mount *m;
 
-	m = malloc(sizeof(Mount));
+	if(spec == nil)
+		spec = "";
+	m = malloc(sizeof(Mount)+strlen(spec)+1);
 	if(m == nil)
 		error(Enomem);
 	m->to = to;
@@ -273,8 +274,7 @@
 	incref(to);
 	m->mountid = nextmount();
 	m->mflag = flag;
-	if(spec != nil)
-		kstrdup(&m->spec, spec);
+	strcpy(m->spec, spec);
 	setmalloctag(m, getcallerpc(&to));
 	return m;
 }
@@ -287,7 +287,6 @@
 	while((f = m) != nil) {
 		m = m->next;
 		cclose(f->to);
-		free(f->spec);
 		free(f);
 	}
 }
--- a/sys/src/9/port/portdat.h
+++ b/sys/src/9/port/portdat.h
@@ -263,7 +263,7 @@
 	Mount*	next;
 	Mount*	order;
 	Chan*	to;			/* channel replacing channel */
-	char*	spec;
+	char	spec[];
 };
 
 struct Mhead
--