From owner-svn-src-projects@FreeBSD.ORG Fri Mar 7 23:26:14 2014 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9CE355D2; Fri, 7 Mar 2014 23:26:14 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 84194C4A; Fri, 7 Mar 2014 23:26:14 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s27NQEhw005628; Fri, 7 Mar 2014 23:26:14 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s27NQE63005627; Fri, 7 Mar 2014 23:26:14 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201403072326.s27NQE63005627@svn.freebsd.org> From: Gleb Smirnoff Date: Fri, 7 Mar 2014 23:26:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r262913 - projects/sendfile/sys/kern X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Mar 2014 23:26:14 -0000 Author: glebius Date: Fri Mar 7 23:26:14 2014 New Revision: 262913 URL: http://svnweb.freebsd.org/changeset/base/262913 Log: Simplify code a lot removing the SF_MNOWAIT. It was useless from the very beginning, since many allocation at deeper levels of kernel are done with M_WAITOK regardless of the flag, and that is actually manifested in the manual page. This experimental flag shouldn't ever reached the head/ in the first place. Sponsored by: Netflix Sponsored by: Nginx, Inc. Modified: projects/sendfile/sys/kern/uipc_syscalls.c Modified: projects/sendfile/sys/kern/uipc_syscalls.c ============================================================================== --- projects/sendfile/sys/kern/uipc_syscalls.c Fri Mar 7 23:01:35 2014 (r262912) +++ projects/sendfile/sys/kern/uipc_syscalls.c Fri Mar 7 23:26:14 2014 (r262913) @@ -2902,7 +2902,7 @@ vn_sendfile(struct file *fp, int sockfd, struct shmfd *shmfd; struct vattr va; off_t off, sbytes, rem, obj_size; - int error, serror, bsize, hdrlen, mwait, merror, sfwait; + int error, serror, bsize, hdrlen; obj = NULL; so = NULL; @@ -2917,21 +2917,6 @@ vn_sendfile(struct file *fp, int sockfd, if (error != 0) goto out; - /* - * Do not wait on memory allocations but return ENOMEM for - * caller to retry later. - * XXX: Experimental. - */ - if (flags & SF_MNOWAIT) { - mwait = M_NOWAIT; - merror = EAGAIN; - sfwait = SFB_NOWAIT; - } else { - mwait = M_WAITOK; - merror = ENOBUFS; - sfwait = SFB_CATCH; - } - #ifdef MAC error = mac_socket_check_send(td->td_ucred, so); if (error != 0) @@ -2953,11 +2938,7 @@ vn_sendfile(struct file *fp, int sockfd, else nbytes = 0; } - mh = m_uiotombuf(hdr_uio, mwait, 0, 0, 0); - if (mh == NULL) { - error = merror; - goto out; - } + mh = m_uiotombuf(hdr_uio, M_WAITOK, 0, 0, 0); hdrlen = m_length(mh, &mhtail); } else hdrlen = 0; @@ -3083,13 +3064,7 @@ retry_space: else npages = howmany(space, PAGE_SIZE); sfio = malloc(sizeof(struct sf_io) + - npages * sizeof(vm_page_t), M_TEMP, mwait); - if (sfio == NULL) { - if (vp != NULL) - VOP_UNLOCK(vp, 0); - error = merror; - goto done; - } + npages * sizeof(vm_page_t), M_TEMP, M_WAITOK); refcount_init(&sfio->nios, 1); sfio->npages = npages; @@ -3143,7 +3118,7 @@ retry_space: * deadlock. */ sf = sf_buf_alloc(pa[i], - m != NULL ? SFB_NOWAIT : sfwait); + m != NULL ? SFB_NOWAIT : SFB_CATCH); if (sf == NULL) { SFSTAT_INC(sf_allocfail); for (int j = i; j < npages; j++) { @@ -3152,7 +3127,7 @@ retry_space: vm_page_unlock(pa[j]); } if (m == NULL) - error = merror; + error = ENOBUFS; fixspace(npages, i, off, &space); break; } @@ -3161,32 +3136,10 @@ retry_space: * Get an mbuf and set it up as having * external storage. */ - m0 = m_get(mwait, MT_DATA); - if (m0 == NULL) { - for (int j = i; j < npages; j++) { - vm_page_lock(pa[j]); - vm_page_unwire(pa[j], 0); - vm_page_unlock(pa[j]); - } - (void)sf_buf_mext(NULL, NULL, sf); - error = merror; - fixspace(npages, i, off, &space); - break; - } - if (m_extadd(m0, (caddr_t )sf_buf_kva(sf), PAGE_SIZE, - sf_buf_mext, sfs, sf, M_RDONLY, EXT_SFBUF, mwait) - != 0) { - for (int j = i; j < npages; j++) { - vm_page_lock(pa[j]); - vm_page_unwire(pa[j], 0); - vm_page_unlock(pa[j]); - } - (void)sf_buf_mext(NULL, NULL, sf); - m_freem(m0); - error = merror; - fixspace(npages, i, off, &space); - break; - } + 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, + M_WAITOK); m0->m_data = (char *)sf_buf_kva(sf) + (vmoff(i, off) & PAGE_MASK); m0->m_len = xfsize(i, npages, off, space);