Skip to content

Commit

Permalink
block: add check when merging zone device pages
Browse files Browse the repository at this point in the history
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.

Add a helper to determine if zone device pages are mergeable and use
this helper in page_is_mergeable().

Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
  • Loading branch information
lsgunth committed Sep 30, 2021
1 parent 065f0fc commit 2f33a09
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions block/bio.c
Expand Up @@ -784,6 +784,8 @@ static inline bool page_is_mergeable(const struct bio_vec *bv,
return false;
if (xen_domain() && !xen_biovec_phys_mergeable(bv, page))
return false;
if (!zone_device_pages_are_mergeable(bv->bv_page, page))
return false;

*same_page = ((vec_end_addr & PAGE_MASK) == page_addr);
if (*same_page)
Expand Down
23 changes: 23 additions & 0 deletions include/linux/mm.h
Expand Up @@ -1136,13 +1136,36 @@ static inline bool is_zone_device_page(const struct page *page)
{
return page_zonenum(page) == ZONE_DEVICE;
}

/*
* 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.
*/
static inline bool zone_device_pages_are_mergeable(const struct page *a,
const struct page *b)
{
if (is_zone_device_page(a) != is_zone_device_page(b))
return false;
if (!is_zone_device_page(a))
return true;
return a->pgmap == b->pgmap;
}
extern void memmap_init_zone_device(struct zone *, unsigned long,
unsigned long, struct dev_pagemap *);
#else
static inline bool is_zone_device_page(const struct page *page)
{
return false;
}
static inline bool zone_device_pages_are_mergable(const struct page *a,
const struct page *b)
{
return true;
}
#endif

static inline bool is_zone_movable_page(const struct page *page)
Expand Down

0 comments on commit 2f33a09

Please sign in to comment.