From owner-svn-src-all@freebsd.org Fri Jun 1 12:09:08 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B2C8DF7A2A0; Fri, 1 Jun 2018 12:09:08 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 611977818F; Fri, 1 Jun 2018 12:09:08 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 23B4C288D2; Fri, 1 Jun 2018 12:09:08 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w51C974s077307; Fri, 1 Jun 2018 12:09:07 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w51C97qh077306; Fri, 1 Jun 2018 12:09:07 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201806011209.w51C97qh077306@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Fri, 1 Jun 2018 12:09:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334484 - head/sys/compat/linuxkpi/common/include/linux X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: head/sys/compat/linuxkpi/common/include/linux X-SVN-Commit-Revision: 334484 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jun 2018 12:09:09 -0000 Author: hselasky Date: Fri Jun 1 12:09:07 2018 New Revision: 334484 URL: https://svnweb.freebsd.org/changeset/base/334484 Log: Implement the __sg_alloc_table_from_pages() function based on the existing sg_alloc_table_from_pages() function in the LinuxKPI. This basically allow segments to have a limit, max_segment. Submitted by: Johannes Lundberg MFC after: 1 week Sponsored by: Mellanox Technologies Sponsored by: Limelight Networks Modified: head/sys/compat/linuxkpi/common/include/linux/scatterlist.h Modified: head/sys/compat/linuxkpi/common/include/linux/scatterlist.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/scatterlist.h Fri Jun 1 11:42:09 2018 (r334483) +++ head/sys/compat/linuxkpi/common/include/linux/scatterlist.h Fri Jun 1 12:09:07 2018 (r334484) @@ -64,6 +64,8 @@ struct sg_page_iter { } internal; }; +#define SCATTERLIST_MAX_SEGMENT (-1U & ~(PAGE_SIZE - 1)) + #define SG_MAX_SINGLE_ALLOC (PAGE_SIZE / sizeof(struct scatterlist)) #define SG_MAGIC 0x87654321UL @@ -286,18 +288,26 @@ sg_alloc_table(struct sg_table *table, unsigned int ne } static inline int -sg_alloc_table_from_pages(struct sg_table *sgt, +__sg_alloc_table_from_pages(struct sg_table *sgt, struct page **pages, unsigned int count, unsigned long off, unsigned long size, - gfp_t gfp_mask) + unsigned int max_segment, gfp_t gfp_mask) { - unsigned int i, segs, cur; + unsigned int i, segs, cur, len; int rc; struct scatterlist *s; + if (__predict_false(!max_segment || offset_in_page(max_segment))) + return (-EINVAL); + + len = 0; for (segs = i = 1; i < count; ++i) { - if (page_to_pfn(pages[i]) != page_to_pfn(pages[i - 1]) + 1) + len += PAGE_SIZE; + if (len >= max_segment || + page_to_pfn(pages[i]) != page_to_pfn(pages[i - 1]) + 1) { ++segs; + len = 0; + } } if (__predict_false((rc = sg_alloc_table(sgt, segs, gfp_mask)))) return (rc); @@ -307,10 +317,13 @@ sg_alloc_table_from_pages(struct sg_table *sgt, unsigned long seg_size; unsigned int j; - for (j = cur + 1; j < count; ++j) - if (page_to_pfn(pages[j]) != + len = 0; + for (j = cur + 1; j < count; ++j) { + len += PAGE_SIZE; + if (len >= max_segment || page_to_pfn(pages[j]) != page_to_pfn(pages[j - 1]) + 1) break; + } seg_size = ((j - cur) << PAGE_SHIFT) - off; sg_set_page(s, pages[cur], min(size, seg_size), off); @@ -321,6 +334,16 @@ sg_alloc_table_from_pages(struct sg_table *sgt, return (0); } +static inline int +sg_alloc_table_from_pages(struct sg_table *sgt, + struct page **pages, unsigned int count, + unsigned long off, unsigned long size, + gfp_t gfp_mask) +{ + + return (__sg_alloc_table_from_pages(sgt, pages, count, off, size, + SCATTERLIST_MAX_SEGMENT, gfp_mask)); +} static inline int sg_nents(struct scatterlist *sg)