svn commit: r269807 - in head/sys: kern sys

Gleb Smirnoff glebius at FreeBSD.org
Mon Aug 11 12:59:56 UTC 2014


Author: glebius
Date: Mon Aug 11 12:59:55 2014
New Revision: 269807
URL: http://svnweb.freebsd.org/changeset/base/269807

Log:
  Provide sf_buf_ref() to optimize refcounting of already allocated
  sendfile(2) buffers.
  
  Sponsored by:	Netflix
  Sponsored by:	Nginx, Inc.

Modified:
  head/sys/kern/subr_sfbuf.c
  head/sys/kern/uipc_syscalls.c
  head/sys/sys/sf_buf.h

Modified: head/sys/kern/subr_sfbuf.c
==============================================================================
--- head/sys/kern/subr_sfbuf.c	Mon Aug 11 12:26:48 2014	(r269806)
+++ head/sys/kern/subr_sfbuf.c	Mon Aug 11 12:59:55 2014	(r269807)
@@ -201,6 +201,22 @@ sf_buf_free(struct sf_buf *sf)
 	mtx_unlock(&sf_buf_lock);
 }
 
+void
+sf_buf_ref(struct sf_buf *sf)
+{
+
+#ifdef SFBUF_OPTIONAL_DIRECT_MAP
+	if (SFBUF_OPTIONAL_DIRECT_MAP)
+		return;
+#endif
+
+	KASSERT(sf->ref_count > 0, ("%s: sf %p not allocated", __func__, sf));
+
+	mtx_lock(&sf_buf_lock);
+	sf->ref_count++;
+	mtx_unlock(&sf_buf_lock);
+}
+
 #ifdef SFBUF_PROCESS_PAGE
 /*
  * Run callback function on sf_buf that holds a certain page.

Modified: head/sys/kern/uipc_syscalls.c
==============================================================================
--- head/sys/kern/uipc_syscalls.c	Mon Aug 11 12:26:48 2014	(r269806)
+++ head/sys/kern/uipc_syscalls.c	Mon Aug 11 12:59:55 2014	(r269807)
@@ -1993,8 +1993,7 @@ sf_ext_ref(void *arg1, void *arg2)
 	struct sendfile_sync *sfs = arg2;
 	vm_page_t pg = sf_buf_page(sf);
 
-	/* XXXGL: there should be sf_buf_ref() */
-	sf_buf_alloc(sf_buf_page(sf), SFB_NOWAIT);
+	sf_buf_ref(sf);
 
 	vm_page_lock(pg);
 	vm_page_wire(pg);

Modified: head/sys/sys/sf_buf.h
==============================================================================
--- head/sys/sys/sf_buf.h	Mon Aug 11 12:26:48 2014	(r269806)
+++ head/sys/sys/sf_buf.h	Mon Aug 11 12:59:55 2014	(r269807)
@@ -106,6 +106,7 @@ struct sf_buf;
 #ifdef SFBUF
 struct sf_buf *sf_buf_alloc(struct vm_page *, int);
 void sf_buf_free(struct sf_buf *);
+void sf_buf_ref(struct sf_buf *);
 
 static inline vm_offset_t
 sf_buf_kva(struct sf_buf *sf)
@@ -168,6 +169,11 @@ static inline void
 sf_buf_free(struct sf_buf *sf)
 {
 }
+
+static inline void
+sf_buf_ref(struct sf_buf *sf)
+{
+}
 #endif /* SFBUF */
 
 /*


More information about the svn-src-head mailing list