svn commit: r292380 - in projects/sendfile: sys/kern sys/sys usr.bin/netstat

Gleb Smirnoff glebius at FreeBSD.org
Wed Dec 16 22:34:43 UTC 2015


Author: glebius
Date: Wed Dec 16 22:34:41 2015
New Revision: 292380
URL: https://svnweb.freebsd.org/changeset/base/292380

Log:
  Add a bunch of extra statistics for the new sendfile(2).

Modified:
  projects/sendfile/sys/kern/uipc_syscalls.c
  projects/sendfile/sys/sys/sf_buf.h
  projects/sendfile/usr.bin/netstat/mbuf.c

Modified: projects/sendfile/sys/kern/uipc_syscalls.c
==============================================================================
--- projects/sendfile/sys/kern/uipc_syscalls.c	Wed Dec 16 22:26:28 2015	(r292379)
+++ projects/sendfile/sys/kern/uipc_syscalls.c	Wed Dec 16 22:34:41 2015	(r292380)
@@ -2161,6 +2161,7 @@ sendfile_swapin(vm_object_t obj, struct 
 		if (vm_page_is_valid(pa[i], vmoff(i, off) & PAGE_MASK,
 		    xfsize(i, npages, off, len))) {
 			vm_page_xunbusy(pa[i]);
+			SFSTAT_INC(sf_pages_valid);
 			i++;
 			continue;
 		}
@@ -2172,8 +2173,10 @@ sendfile_swapin(vm_object_t obj, struct 
 		 */
 		for (j = i + 1; j < npages; j++)
 			if (vm_page_is_valid(pa[j], vmoff(j, off) & PAGE_MASK,
-			    xfsize(j, npages, off, len)))
+			    xfsize(j, npages, off, len))) {
+				SFSTAT_INC(sf_pages_valid);
 				break;
+			}
 
 		/*
 		 * Now we got region of invalid pages between 'i' and 'j'.
@@ -2220,16 +2223,20 @@ sendfile_swapin(vm_object_t obj, struct 
 			}
 		}
 
+		SFSTAT_INC(sf_iocnt);
+		if (j > npages) {
+			SFSTAT_ADD(sf_pages_read, npages - i);
+			SFSTAT_ADD(sf_rhpages_read, j - npages);
+		} else
+			SFSTAT_ADD(sf_pages_read, count);
+
+		nios++;
 		refcount_acquire(&sfio->nios);
 		rv = vm_pager_get_pages_async(obj, pa + i, count, NULL, NULL,
 		    &sf_iodone, sfio);
-
 		KASSERT(rv == VM_PAGER_OK, ("%s: pager fail obj %p page %p",
 		    __func__, obj, pa[i]));
 
-		SFSTAT_INC(sf_iocnt);
-		nios++;
-
 		for (j = i; j < i + count && j < npages; j++)
 			KASSERT(pa[j] == vm_page_lookup(obj,
 			    OFF_TO_IDX(vmoff(j, off))),
@@ -2241,6 +2248,9 @@ sendfile_swapin(vm_object_t obj, struct 
 
 	VM_OBJECT_WUNLOCK(obj);
 
+	if (nios == 0 && npages != 0)
+		SFSTAT_INC(sf_noiocnt);
+
 	return (nios);
 }
 
@@ -2372,18 +2382,21 @@ vn_sendfile(struct file *fp, int sockfd,
 	if (error != 0)
 		goto out;
 
-	if (flags & SF_SYNC) {
-		sfs = malloc(sizeof *sfs, M_TEMP, M_WAITOK | M_ZERO);
-		mtx_init(&sfs->mtx, "sendfile", NULL, MTX_DEF);
-		cv_init(&sfs->cv, "sendfile");
-	}
-
 #ifdef MAC
 	error = mac_socket_check_send(td->td_ucred, so);
 	if (error != 0)
 		goto out;
 #endif
 
+	SFSTAT_INC(sf_syscalls);
+	SFSTAT_ADD(sf_rhpages_requested, SF_READAHEAD(flags));
+
+	if (flags & SF_SYNC) {
+		sfs = malloc(sizeof *sfs, M_TEMP, M_WAITOK | M_ZERO);
+		mtx_init(&sfs->mtx, "sendfile", NULL, MTX_DEF);
+		cv_init(&sfs->cv, "sendfile");
+	}
+
 	/* If headers are specified copy them into mbufs. */
 	if (hdr_uio != NULL && hdr_uio->uio_resid > 0) {
 		hdr_uio->uio_td = td;

Modified: projects/sendfile/sys/sys/sf_buf.h
==============================================================================
--- projects/sendfile/sys/sys/sf_buf.h	Wed Dec 16 22:26:28 2015	(r292379)
+++ projects/sendfile/sys/sys/sf_buf.h	Wed Dec 16 22:34:41 2015	(r292380)
@@ -31,7 +31,13 @@
 #define _SYS_SF_BUF_H_
 
 struct sfstat {				/* sendfile statistics */
+	uint64_t	sf_syscalls;	/* times sendfile was called */
+	uint64_t	sf_noiocnt;	/* times sendfile didn't require I/O */
 	uint64_t	sf_iocnt;	/* times sendfile had to do disk I/O */
+	uint64_t	sf_pages_read;	/* pages read as part of a request */
+	uint64_t	sf_pages_valid;	/* pages were valid for a request */
+	uint64_t	sf_rhpages_requested;	/* readahead pages requested */
+	uint64_t	sf_rhpages_read;	/* readahead pages read */
 	uint64_t	sf_allocfail;	/* times sfbuf allocation failed */
 	uint64_t	sf_allocwait;	/* times sfbuf allocation had to wait */
 };

Modified: projects/sendfile/usr.bin/netstat/mbuf.c
==============================================================================
--- projects/sendfile/usr.bin/netstat/mbuf.c	Wed Dec 16 22:26:28 2015	(r292379)
+++ projects/sendfile/usr.bin/netstat/mbuf.c	Wed Dec 16 22:34:41 2015	(r292380)
@@ -326,13 +326,30 @@ mbpr(void *kvmd, u_long mbaddr)
 	    kread_counters) != 0)
 		goto out;
 
+        xo_emit("{:sendfile-syscalls/%ju} {N:sendfile syscalls}\n",
+	    (uintmax_t)sfstat.sf_syscalls); 
+        xo_emit("{:sendfile-no-io/%ju} "
+	    "{N:sendfile syscalls completed without I\\/O request}\n", 
+            (uintmax_t)sfstat.sf_noiocnt);
+	xo_emit("{:sendfile-io-count/%ju} "
+	    "{N:requests for I\\/O initiated by sendfile}\n",
+	    (uintmax_t)sfstat.sf_iocnt);
+        xo_emit("{:sendfile-pages-sent/%ju} "
+	    "{N:pages read by sendfile as part of a request}\n",
+            (uintmax_t)sfstat.sf_pages_read);
+        xo_emit("{:sendfile-pages-valid/%ju} "
+	    "{N:pages were valid at time of a sendfile request}\n",
+            (uintmax_t)sfstat.sf_pages_valid);
+        xo_emit("{:sendfile-requested-readahead/%ju} "
+	    "{N:pages were requested for read ahead by applications}\n",
+            (uintmax_t)sfstat.sf_rhpages_requested);
+        xo_emit("{:sendfile-readahead/%ju} "
+	    "{N:pages were read ahead by sendfile}\n",
+            (uintmax_t)sfstat.sf_rhpages_read);
 	xo_emit("{:sfbufs-alloc-failed/%ju} {N:requests for sfbufs denied}\n",
 	    (uintmax_t)sfstat.sf_allocfail);
 	xo_emit("{:sfbufs-alloc-wait/%ju} {N:requests for sfbufs delayed}\n",
 	    (uintmax_t)sfstat.sf_allocwait);
-	xo_emit("{:sfbufs-io-count/%ju} "
-	    "{N:requests for I\\/O initiated by sendfile}\n",
-	    (uintmax_t)sfstat.sf_iocnt);
 out:
 	xo_close_container("mbuf-statistics");
 	memstat_mtl_free(mtlp);


More information about the svn-src-projects mailing list