VirtualBox

Ignore:
Timestamp:
Jan 30, 2019 8:04:25 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
128510
Message:

linux/vboxsf: Optimization of small reads (<= 3/4 page size) by embedding the data buffer into the request. bugref:9172

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/sharedfolders/regops.c

    r77054 r77064  
    262262 * @param buf           the buffer
    263263 * @param size          length of the buffer
    264  * @param off           offset within the file
     264 * @param off           offset within the file (in/out).
    265265 * @returns the number of read bytes on success, Linux error code otherwise
    266266 */
    267 static ssize_t sf_reg_read(struct file *file, char *buf, size_t size,
    268                            loff_t * off)
     267static ssize_t sf_reg_read(struct file *file, char /*__user*/ *buf, size_t size,
     268                           loff_t *off)
    269269{
    270270        int err;
     
    290290                return 0;
    291291
    292         tmp =
    293             alloc_bounce_buffer(&tmp_size, &tmp_phys, size,
    294                                 __PRETTY_FUNCTION__);
     292#ifndef VBOXSF_USE_DEPRECATED_VBGL_INTERFACE
     293        /*
     294         * For small requests, try use an embedded buffer provided we get a heap block
     295         * that does not cross page boundraries (see host code).
     296         */
     297        if (size <= PAGE_SIZE / 4 * 3 /* see allocator */) {
     298                uint32_t const         cbReq = RT_UOFFSETOF(VBOXSFREADEMBEDDEDREQ, abData[0]) + size;
     299                VBOXSFREADEMBEDDEDREQ *pReq  = (VBOXSFREADEMBEDDEDREQ *)VbglR0PhysHeapAlloc(cbReq);
     300                if (   pReq
     301                    && (PAGE_SIZE - ((uintptr_t)pReq & PAGE_OFFSET_MASK)) >= cbReq) {
     302                        ssize_t cbRet;
     303                        int vrc = VbglR0SfHostReqReadEmbedded(sf_g->map.root, pReq, sf_r->handle, pos, (uint32_t)size);
     304                        if (RT_SUCCESS(vrc)) {
     305                                cbRet = pReq->Parms.cb32Read.u.value32;
     306                                if (copy_to_user(buf, pReq->abData, cbRet) == 0)
     307                                        *off += cbRet;
     308                                else
     309                                        cbRet = -EPROTO;
     310                        } else
     311                                cbRet = -EPROTO;
     312                        VbglR0PhysHeapFree(pReq);
     313                        return cbRet;
     314                }
     315                if (pReq)
     316                        VbglR0PhysHeapFree(pReq);
     317        }
     318
     319//      /*
     320//       * For other requests, use a bounce buffer.
     321//       */
     322//      VBOXSFREADPGLSTREQ *pReq  = (VBOXSFREADEMBEDDEDREQ *)VbglR0PhysHeapAlloc(cbReq);
     323#endif
     324
     325        tmp = alloc_bounce_buffer(&tmp_size, &tmp_phys, size, __PRETTY_FUNCTION__);
    295326        if (!tmp)
    296327                return -ENOMEM;
     
    787818        uint32_t nread = PAGE_SIZE;
    788819        char *buf;
    789         loff_t off = ((loff_t) page->index) << PAGE_SHIFT;
     820        loff_t off = (loff_t)page->index << PAGE_SHIFT;
    790821        int ret;
    791822
     
    876907
    877908        buf = kmap(page);
    878         err =
    879             sf_reg_write_aux(__func__, sf_g, sf_r, buf + from, &nwritten, pos);
     909        err = sf_reg_write_aux(__func__, sf_g, sf_r, buf + from, &nwritten, pos);
    880910        kunmap(page);
    881911
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette