Index: sys/kern/kern_sendfile.c =================================================================== --- sys/kern/kern_sendfile.c +++ sys/kern/kern_sendfile.c @@ -52,6 +52,8 @@ #include #include +#include +#include #include #include @@ -119,6 +121,12 @@ SYSCTL_PROC(_kern_ipc, OID_AUTO, sfstat, CTLTYPE_OPAQUE | CTLFLAG_RW, NULL, 0, sfstat_sysctl, "I", "sendfile statistics"); +bool sendfile_numa_local = true; + +SYSCTL_BOOL(_kern_ipc, OID_AUTO, sendfile_numa_local, CTLFLAG_RWTUN, + &sendfile_numa_local, 0, + "Allocate NUMA local memory for sendfile when SF_NOCACHE is set"); + /* * Detach mapped page and release resources back to the system. Called * by mbuf(9) code when last reference to a page is freed. @@ -545,8 +553,9 @@ struct shmfd *shmfd; struct sendfile_sync *sfs; struct vattr va; + struct inpcb *inp; off_t off, sbytes, rem, obj_size; - int error, softerr, bsize, hdrlen; + int domain, error, softerr, bsize, hdrlen; obj = NULL; so = NULL; @@ -742,6 +751,23 @@ refcount_init(&sfio->nios, 1); sfio->so = so; sfio->error = 0; + /* + * If the network connection is associated with a NUMA + * domain, and if the user has requested the data be + * quickly freed, then allocate backing pages from the + * domain which is local to the network connection + * (when allowed to by kern.ipc.sendfile_numa_local). + */ + if ((flags & SF_NOCACHE) != 0 && sendfile_numa_local && + (inp = sotoinpcb(so)) != NULL && + (domain = inp->inp_numa_domain) != M_NODOM && + obj->domain.dr_policy != DOMAINSET_PREF(domain)) { + VM_OBJECT_WLOCK(obj); + if (obj->domain.dr_policy != DOMAINSET_PREF(domain)) + obj->domain.dr_policy = + DOMAINSET_PREF(domain); + VM_OBJECT_WUNLOCK(obj); + } nios = sendfile_swapin(obj, sfio, off, space, npages, rhpages, flags);