[nginx] svn commit: r4597 - trunk/src/os/unix

mdounin at mdounin.ru mdounin at mdounin.ru
Tue Apr 17 09:13:15 UTC 2012


Author: mdounin
Date: 2012-04-17 09:13:15 +0000 (Tue, 17 Apr 2012)
New Revision: 4597
URL: http://trac.nginx.org/nginx/changeset/4597/nginx

Log:
IOV_MAX handling microoptimization.

We now stop on IOV_MAX iovec entries only if we are going to add new one,
i.e. next buffer can't be coalesced into last iovec.

This also fixes incorrect checks for trailer creation on FreeBSD and
Mac OS X, header.nelts was checked instead of trailer.nelts.


Modified:
   trunk/src/os/unix/ngx_darwin_sendfile_chain.c
   trunk/src/os/unix/ngx_freebsd_sendfile_chain.c
   trunk/src/os/unix/ngx_linux_sendfile_chain.c
   trunk/src/os/unix/ngx_solaris_sendfilev_chain.c
   trunk/src/os/unix/ngx_writev_chain.c

Modified: trunk/src/os/unix/ngx_darwin_sendfile_chain.c
===================================================================
--- trunk/src/os/unix/ngx_darwin_sendfile_chain.c	2012-04-17 09:10:50 UTC (rev 4596)
+++ trunk/src/os/unix/ngx_darwin_sendfile_chain.c	2012-04-17 09:13:15 UTC (rev 4597)
@@ -103,10 +103,8 @@
         prev = NULL;
         iov = NULL;
 
-        for (cl = in;
-             cl && header.nelts < IOV_MAX && send < limit;
-             cl = cl->next)
-        {
+        for (cl = in; cl && send < limit; cl = cl->next) {
+
             if (ngx_buf_special(cl->buf)) {
                 continue;
             }
@@ -125,6 +123,10 @@
                 iov->iov_len += (size_t) size;
 
             } else {
+                if (header.nelts >= IOV_MAX) {
+                    break;
+                }
+
                 iov = ngx_array_push(&header);
                 if (iov == NULL) {
                     return NGX_CHAIN_ERROR;
@@ -178,7 +180,7 @@
             prev = NULL;
             iov = NULL;
 
-            while (cl && header.nelts < IOV_MAX && send < limit) {
+            while (cl && send < limit) {
 
                 if (ngx_buf_special(cl->buf)) {
                     cl = cl->next;
@@ -199,6 +201,10 @@
                     iov->iov_len += (size_t) size;
 
                 } else {
+                    if (trailer.nelts >= IOV_MAX) {
+                        break;
+                    }
+
                     iov = ngx_array_push(&trailer);
                     if (iov == NULL) {
                         return NGX_CHAIN_ERROR;

Modified: trunk/src/os/unix/ngx_freebsd_sendfile_chain.c
===================================================================
--- trunk/src/os/unix/ngx_freebsd_sendfile_chain.c	2012-04-17 09:10:50 UTC (rev 4596)
+++ trunk/src/os/unix/ngx_freebsd_sendfile_chain.c	2012-04-17 09:13:15 UTC (rev 4597)
@@ -107,10 +107,8 @@
         prev = NULL;
         iov = NULL;
 
-        for (cl = in;
-             cl && header.nelts < IOV_MAX && send < limit;
-             cl = cl->next)
-        {
+        for (cl = in; cl && send < limit; cl = cl->next) {
+
             if (ngx_buf_special(cl->buf)) {
                 continue;
             }
@@ -129,6 +127,10 @@
                 iov->iov_len += (size_t) size;
 
             } else {
+                if (header.nelts >= IOV_MAX){
+                    break;
+                }
+
                 iov = ngx_array_push(&header);
                 if (iov == NULL) {
                     return NGX_CHAIN_ERROR;
@@ -183,7 +185,7 @@
             prev = NULL;
             iov = NULL;
 
-            while (cl && header.nelts < IOV_MAX && send < limit) {
+            while (cl && send < limit) {
 
                 if (ngx_buf_special(cl->buf)) {
                     cl = cl->next;
@@ -204,6 +206,10 @@
                     iov->iov_len += (size_t) size;
 
                 } else {
+                    if (trailer.nelts >= IOV_MAX){
+                        break;
+                    }
+
                     iov = ngx_array_push(&trailer);
                     if (iov == NULL) {
                         return NGX_CHAIN_ERROR;

Modified: trunk/src/os/unix/ngx_linux_sendfile_chain.c
===================================================================
--- trunk/src/os/unix/ngx_linux_sendfile_chain.c	2012-04-17 09:10:50 UTC (rev 4596)
+++ trunk/src/os/unix/ngx_linux_sendfile_chain.c	2012-04-17 09:13:15 UTC (rev 4597)
@@ -89,10 +89,8 @@
 
         /* create the iovec and coalesce the neighbouring bufs */
 
-        for (cl = in;
-             cl && header.nelts < IOV_MAX && send < limit;
-             cl = cl->next)
-        {
+        for (cl = in; cl && send < limit; cl = cl->next) {
+
             if (ngx_buf_special(cl->buf)) {
                 continue;
             }
@@ -132,6 +130,10 @@
                 iov->iov_len += (size_t) size;
 
             } else {
+                if (header.nelts >= IOV_MAX) {
+                    break;
+                }
+
                 iov = ngx_array_push(&header);
                 if (iov == NULL) {
                     return NGX_CHAIN_ERROR;

Modified: trunk/src/os/unix/ngx_solaris_sendfilev_chain.c
===================================================================
--- trunk/src/os/unix/ngx_solaris_sendfilev_chain.c	2012-04-17 09:10:50 UTC (rev 4596)
+++ trunk/src/os/unix/ngx_solaris_sendfilev_chain.c	2012-04-17 09:13:15 UTC (rev 4597)
@@ -94,8 +94,8 @@
 
         /* create the sendfilevec and coalesce the neighbouring bufs */
 
-        for (cl = in; cl && vec.nelts < IOV_MAX && send < limit; cl = cl->next)
-        {
+        for (cl = in; cl && send < limit; cl = cl->next) {
+
             if (ngx_buf_special(cl->buf)) {
                 continue;
             }
@@ -113,6 +113,10 @@
                     sfv->sfv_len += (size_t) size;
 
                 } else {
+                    if (vec.nelts >= IOV_MAX) {
+                        break;
+                    }
+
                     sfv = ngx_array_push(&vec);
                     if (sfv == NULL) {
                         return NGX_CHAIN_ERROR;
@@ -147,6 +151,10 @@
                     sfv->sfv_len += (size_t) size;
 
                 } else {
+                    if (vec.nelts >= IOV_MAX) {
+                        break;
+                    }
+
                     sfv = ngx_array_push(&vec);
                     if (sfv == NULL) {
                         return NGX_CHAIN_ERROR;

Modified: trunk/src/os/unix/ngx_writev_chain.c
===================================================================
--- trunk/src/os/unix/ngx_writev_chain.c	2012-04-17 09:10:50 UTC (rev 4596)
+++ trunk/src/os/unix/ngx_writev_chain.c	2012-04-17 09:13:15 UTC (rev 4597)
@@ -71,8 +71,8 @@
 
         /* create the iovec and coalesce the neighbouring bufs */
 
-        for (cl = in; cl && vec.nelts < IOV_MAX && send < limit; cl = cl->next)
-        {
+        for (cl = in; cl && send < limit; cl = cl->next) {
+
             if (ngx_buf_special(cl->buf)) {
                 continue;
             }
@@ -93,6 +93,10 @@
                 iov->iov_len += size;
 
             } else {
+                if (vec.nelts >= IOV_MAX) {
+                    break;
+                }
+
                 iov = ngx_array_push(&vec);
                 if (iov == NULL) {
                     return NGX_CHAIN_ERROR;



More information about the nginx-devel mailing list