From: John Hubbard <jhubbard@nvidia.com>
To: Logan Gunthorpe <logang@deltatee.com>,
linux-kernel@vger.kernel.org, linux-nvme@lists.infradead.org,
linux-block@vger.kernel.org, linux-pci@vger.kernel.org,
linux-mm@kvack.org
Cc: "Christoph Hellwig" <hch@lst.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Dan Williams" <dan.j.williams@intel.com>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"Christian König" <christian.koenig@amd.com>,
"Don Dutile" <ddutile@redhat.com>,
"Matthew Wilcox" <willy@infradead.org>,
"Daniel Vetter" <daniel.vetter@ffwll.ch>,
"Minturn Dave B" <dave.b.minturn@intel.com>,
"Jason Ekstrand" <jason@jlekstrand.net>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
"Xiong Jianxin" <jianxin.xiong@intel.com>,
"Bjorn Helgaas" <helgaas@kernel.org>,
"Ira Weiny" <ira.weiny@intel.com>,
"Robin Murphy" <robin.murphy@arm.com>,
"Martin Oliveira" <martin.oliveira@eideticom.com>,
"Chaitanya Kulkarni" <ckulkarnilinux@gmail.com>,
"Ralph Campbell" <rcampbell@nvidia.com>,
"Stephen Bates" <sbates@raithlin.com>
Subject: Re: [PATCH v9 4/8] lib/scatterlist: add check when merging zone device pages
Date: Mon, 5 Sep 2022 17:21:03 -0700 [thread overview]
Message-ID: <f25d6ce8-b2aa-42ce-00b3-28818cd50f34@nvidia.com> (raw)
In-Reply-To: <20220825152425.6296-5-logang@deltatee.com>
On 8/25/22 08:24, Logan Gunthorpe wrote:
> Consecutive zone device pages should not be merged into the same sgl
> or bvec segment with other types of pages or if they belong to different
> pgmaps. Otherwise getting the pgmap of a given segment is not possible
> without scanning the entire segment. This helper returns true either if
> both pages are not zone device pages or both pages are zone device
> pages with the same pgmap.
>
> Factor out the check for page mergability into a pages_are_mergable()
> helper and add a check with zone_device_pages_are_mergeable().
>
> Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
> ---
> lib/scatterlist.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/lib/scatterlist.c b/lib/scatterlist.c
> index c8c3d675845c..a0ad2a7959b5 100644
> --- a/lib/scatterlist.c
> +++ b/lib/scatterlist.c
> @@ -410,6 +410,15 @@ static struct scatterlist *get_next_sg(struct sg_append_table *table,
> return new_sg;
> }
>
> +static bool pages_are_mergeable(struct page *a, struct page *b)
> +{
> + if (page_to_pfn(a) != page_to_pfn(b) + 1)
Instead of "a" and "b", how about naming these args something like
"page" and "prev_page", in order to avoid giving the impression that
comparing a and b is the same as comparing b and a?
In other words, previously, as an unrolled function, the code made
sense:
page_to_pfn(pages[j]) != page_to_pfn(pages[j - 1]) + 1)
But now, the understanding that this *must* be called with a page and
its previous page has gotten lost during refactoring, and we are left
with a check that is, on its own, not understandable.
Otherwise, the diffs look good. With some sort of naming change to
the args there, please feel free to add:
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
thanks,
--
John Hubbard
NVIDIA
> + return false;
> + if (!zone_device_pages_have_same_pgmap(a, b))
> + return false;
> + return true;
> +}
> +
> /**
> * sg_alloc_append_table_from_pages - Allocate and initialize an append sg
> * table from an array of pages
> @@ -447,6 +456,7 @@ int sg_alloc_append_table_from_pages(struct sg_append_table *sgt_append,
> unsigned int chunks, cur_page, seg_len, i, prv_len = 0;
> unsigned int added_nents = 0;
> struct scatterlist *s = sgt_append->prv;
> + struct page *last_pg;
>
> /*
> * The algorithm below requires max_segment to be aligned to PAGE_SIZE
> @@ -460,21 +470,17 @@ int sg_alloc_append_table_from_pages(struct sg_append_table *sgt_append,
> return -EOPNOTSUPP;
>
> if (sgt_append->prv) {
> - unsigned long paddr =
> - (page_to_pfn(sg_page(sgt_append->prv)) * PAGE_SIZE +
> - sgt_append->prv->offset + sgt_append->prv->length) /
> - PAGE_SIZE;
> -
> if (WARN_ON(offset))
> return -EINVAL;
>
> /* Merge contiguous pages into the last SG */
> prv_len = sgt_append->prv->length;
> - while (n_pages && page_to_pfn(pages[0]) == paddr) {
> + last_pg = sg_page(sgt_append->prv);
> + while (n_pages && pages_are_mergeable(last_pg, pages[0])) {
> if (sgt_append->prv->length + PAGE_SIZE > max_segment)
> break;
> sgt_append->prv->length += PAGE_SIZE;
> - paddr++;
> + last_pg = pages[0];
> pages++;
> n_pages--;
> }
> @@ -488,7 +494,7 @@ int sg_alloc_append_table_from_pages(struct sg_append_table *sgt_append,
> for (i = 1; i < n_pages; i++) {
> seg_len += PAGE_SIZE;
> if (seg_len >= max_segment ||
> - page_to_pfn(pages[i]) != page_to_pfn(pages[i - 1]) + 1) {
> + !pages_are_mergeable(pages[i], pages[i - 1])) {
> chunks++;
> seg_len = 0;
> }
> @@ -504,8 +510,7 @@ int sg_alloc_append_table_from_pages(struct sg_append_table *sgt_append,
> for (j = cur_page + 1; j < n_pages; j++) {
> seg_len += PAGE_SIZE;
> if (seg_len >= max_segment ||
> - page_to_pfn(pages[j]) !=
> - page_to_pfn(pages[j - 1]) + 1)
> + !pages_are_mergeable(pages[j], pages[j - 1]))
> break;
> }
>
next prev parent reply other threads:[~2022-09-06 0:21 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-25 15:24 [PATCH v9 0/8] Userspace P2PDMA with O_DIRECT NVMe devices Logan Gunthorpe
2022-08-25 15:24 ` [PATCH v9 1/8] mm: introduce FOLL_PCI_P2PDMA to gate getting PCI P2PDMA pages Logan Gunthorpe
2022-09-05 22:27 ` John Hubbard
2022-08-25 15:24 ` [PATCH v9 2/8] iov_iter: introduce iov_iter_get_pages_[alloc_]flags() Logan Gunthorpe
2022-09-05 14:33 ` Christoph Hellwig
2022-09-05 23:21 ` John Hubbard
2022-09-06 16:52 ` Logan Gunthorpe
2022-08-25 15:24 ` [PATCH v9 3/8] block: add check when merging zone device pages Logan Gunthorpe
2022-09-05 14:34 ` Christoph Hellwig
2022-09-05 23:58 ` John Hubbard
2022-08-25 15:24 ` [PATCH v9 4/8] lib/scatterlist: " Logan Gunthorpe
2022-09-05 14:34 ` Christoph Hellwig
2022-09-06 0:21 ` John Hubbard [this message]
2022-08-25 15:24 ` [PATCH v9 5/8] block: set FOLL_PCI_P2PDMA in __bio_iov_iter_get_pages() Logan Gunthorpe
2022-09-05 14:36 ` Christoph Hellwig
2022-09-06 0:48 ` John Hubbard
2022-08-25 15:24 ` [PATCH v9 6/8] block: set FOLL_PCI_P2PDMA in bio_map_user_iov() Logan Gunthorpe
2022-09-05 14:36 ` Christoph Hellwig
2022-09-06 0:54 ` John Hubbard
2022-08-25 15:24 ` [PATCH v9 7/8] PCI/P2PDMA: Allow userspace VMA allocations through sysfs Logan Gunthorpe
2022-09-01 16:20 ` Greg Kroah-Hartman
2022-09-01 16:32 ` Logan Gunthorpe
2022-09-01 16:42 ` Greg Kroah-Hartman
2022-09-01 18:14 ` Logan Gunthorpe
2022-09-01 18:36 ` Greg Kroah-Hartman
2022-09-01 19:16 ` Logan Gunthorpe
2022-09-02 5:53 ` Greg Kroah-Hartman
2022-09-02 18:46 ` Logan Gunthorpe
2022-09-20 6:46 ` Christoph Hellwig
2022-09-22 8:38 ` Greg Kroah-Hartman
2022-09-22 14:58 ` Logan Gunthorpe
2022-08-25 15:24 ` [PATCH v9 8/8] ABI: sysfs-bus-pci: add documentation for p2pmem allocate Logan Gunthorpe
2022-09-01 16:18 ` Greg Kroah-Hartman
2022-09-01 16:33 ` Logan Gunthorpe
2022-09-06 1:03 ` John Hubbard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f25d6ce8-b2aa-42ce-00b3-28818cd50f34@nvidia.com \
--to=jhubbard@nvidia.com \
--cc=christian.koenig@amd.com \
--cc=ckulkarnilinux@gmail.com \
--cc=dan.j.williams@intel.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dave.b.minturn@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=ddutile@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=helgaas@kernel.org \
--cc=ira.weiny@intel.com \
--cc=jason@jlekstrand.net \
--cc=jgg@ziepe.ca \
--cc=jianxin.xiong@intel.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=martin.oliveira@eideticom.com \
--cc=rcampbell@nvidia.com \
--cc=robin.murphy@arm.com \
--cc=sbates@raithlin.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox