svn commit: r266796 - in projects/sendfile/sys: dev/ti kern sys
Gleb Smirnoff
glebius at FreeBSD.org
Wed May 28 11:23:45 UTC 2014
Author: glebius
Date: Wed May 28 11:23:44 2014
New Revision: 266796
URL: http://svnweb.freebsd.org/changeset/base/266796
Log:
Couple of API improvements:
- SF_NOCACHE flag from userland says that when an mbuf is freed, the
referenced page should go into free pool, instead of being cached
with associated object.
This is achieved via alternative ext_free function. While here also
rename sf_buf_mext() to a more meaningful name.
- Bits above 16 in flags now count number of pages that sendfile(2)
is allowed to readahead when processing the request.
Sponsored by: Netflix
Sponsored by: Nginx, Inc.
Modified:
projects/sendfile/sys/dev/ti/if_ti.c
projects/sendfile/sys/kern/uipc_syscalls.c
projects/sendfile/sys/sys/sf_buf.h
projects/sendfile/sys/sys/socket.h
Modified: projects/sendfile/sys/dev/ti/if_ti.c
==============================================================================
--- projects/sendfile/sys/dev/ti/if_ti.c Wed May 28 10:33:06 2014 (r266795)
+++ projects/sendfile/sys/dev/ti/if_ti.c Wed May 28 11:23:44 2014 (r266796)
@@ -1629,7 +1629,7 @@ ti_newbuf_jumbo(struct ti_softc *sc, int
m[i]->m_data = (void *)sf_buf_kva(sf[i]);
m[i]->m_len = PAGE_SIZE;
MEXTADD(m[i], sf_buf_kva(sf[i]), PAGE_SIZE,
- sf_buf_mext, (void*)sf_buf_kva(sf[i]), sf[i],
+ sf_mext_free, (void*)sf_buf_kva(sf[i]), sf[i],
0, EXT_DISPOSABLE);
m[i]->m_next = m[i+1];
}
@@ -1694,7 +1694,7 @@ nobufs:
if (m[i])
m_freem(m[i]);
if (sf[i])
- sf_buf_mext((void *)sf_buf_kva(sf[i]), sf[i]);
+ sf_mext_free((void *)sf_buf_kva(sf[i]), sf[i]);
}
return (ENOBUFS);
}
Modified: projects/sendfile/sys/kern/uipc_syscalls.c
==============================================================================
--- projects/sendfile/sys/kern/uipc_syscalls.c Wed May 28 10:33:06 2014 (r266795)
+++ projects/sendfile/sys/kern/uipc_syscalls.c Wed May 28 11:23:44 2014 (r266796)
@@ -1989,7 +1989,7 @@ filt_sfsync(struct knote *kn, long hint)
* Detach mapped page and release resources back to the system.
*/
int
-sf_buf_mext(struct mbuf *mb, void *addr, void *args)
+sf_mext_free(struct mbuf *mb, void *addr, void *args)
{
vm_page_t m;
struct sendfile_sync *sfs;
@@ -2010,9 +2010,38 @@ sf_buf_mext(struct mbuf *mb, void *addr,
sfs = addr;
sf_sync_deref(sfs);
}
- /*
- * sfs may be invalid at this point, don't use it!
- */
+ return (EXT_FREE_OK);
+}
+
+/*
+ * Same as above, but forces the page to be detached from the object
+ * and go into free pool.
+ */
+static int
+sf_mext_free_nocache(struct mbuf *mb, void *addr, void *args)
+{
+ vm_page_t m;
+ struct sendfile_sync *sfs;
+
+ m = sf_buf_page(args);
+ sf_buf_free(args);
+ vm_page_lock(m);
+ vm_page_unwire(m, 0);
+ if (m->wire_count == 0) {
+ vm_object_t obj;
+
+ if ((obj = m->object) == NULL)
+ vm_page_free(m);
+ else if (!vm_page_xbusied(m) && VM_OBJECT_TRYWLOCK(obj)) {
+ vm_page_free(m);
+ VM_OBJECT_WUNLOCK(obj);
+ }
+ }
+ vm_page_unlock(m);
+ if (addr != NULL) {
+ sfs = addr;
+ sf_sync_deref(sfs);
+ }
return (EXT_FREE_OK);
}
@@ -3052,8 +3081,10 @@ retry_space:
else
npages = howmany(space, PAGE_SIZE);
+ rhpages = SF_READAHEAD(flags) ?
+ SF_READAHEAD(flags) : sfreadahead;
rhpages = min(howmany(obj_size - (off & ~PAGE_MASK) -
- (npages * PAGE_SIZE), PAGE_SIZE), sfreadahead);
+ (npages * PAGE_SIZE), PAGE_SIZE), rhpages);
sfio = malloc(sizeof(struct sf_io) +
(rhpages + npages) * sizeof(vm_page_t), M_TEMP, M_WAITOK);
@@ -3101,7 +3132,8 @@ retry_space:
*/
m0 = m_get(M_WAITOK, MT_DATA);
(void )m_extadd(m0, (caddr_t )sf_buf_kva(sf), PAGE_SIZE,
- sf_buf_mext, sfs, sf, M_RDONLY, EXT_SFBUF,
+ (flags & SF_NOCACHE) ? sf_mext_free_nocache :
+ sf_mext_free, sfs, sf, M_RDONLY, EXT_SFBUF,
M_WAITOK);
m0->m_data = (char *)sf_buf_kva(sf) +
(vmoff(i, off) & PAGE_MASK);
Modified: projects/sendfile/sys/sys/sf_buf.h
==============================================================================
--- projects/sendfile/sys/sys/sf_buf.h Wed May 28 10:33:06 2014 (r266795)
+++ projects/sendfile/sys/sys/sf_buf.h Wed May 28 11:23:44 2014 (r266796)
@@ -52,7 +52,7 @@ struct sfstat { /* sendfile statistic
#include <machine/sf_buf.h>
#include <sys/systm.h>
#include <sys/counter.h>
-struct mbuf; /* for sf_buf_mext() */
+struct mbuf; /* for sf_mext_free() */
extern counter_u64_t sfstat[sizeof(struct sfstat) / sizeof(uint64_t)];
#define SFSTAT_ADD(name, val) \
@@ -61,6 +61,7 @@ extern counter_u64_t sfstat[sizeof(struc
#define SFSTAT_INC(name) SFSTAT_ADD(name, 1)
#endif /* _KERNEL */
-int sf_buf_mext(struct mbuf *mb, void *addr, void *args);
+int sf_mext_free(struct mbuf *mb, void *addr, void *args);
+int sf_mext_free_nocache(struct mbuf *mb, void *addr, void *args);
#endif /* !_SYS_SF_BUF_H_ */
Modified: projects/sendfile/sys/sys/socket.h
==============================================================================
--- projects/sendfile/sys/sys/socket.h Wed May 28 10:33:06 2014 (r266795)
+++ projects/sendfile/sys/sys/socket.h Wed May 28 11:23:44 2014 (r266796)
@@ -602,12 +602,15 @@ struct sf_hdtr_all {
* Sendfile-specific flag(s)
*/
#define SF_NODISKIO 0x00000001
-#define SF_MNOWAIT 0x00000002
+#define SF_MNOWAIT 0x00000002 /* unused since 11.0 */
#define SF_SYNC 0x00000004
#define SF_KQUEUE 0x00000008
+#define SF_NOCACHE 0x00000010
+#define SF_FLAGS(rh, flags) (((rh) << 16) | (flags))
#ifdef _KERNEL
#define SFK_COMPAT 0x00000001
+#define SF_READAHEAD(flags) ((flags) >> 16)
#endif /* _KERNEL */
#endif /* __BSD_VISIBLE */
More information about the svn-src-projects
mailing list