From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23CD1C6FA9E for ; Thu, 22 Sep 2022 16:39:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C36C194000A; Thu, 22 Sep 2022 12:39:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B14F940008; Thu, 22 Sep 2022 12:39:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F3326B0073; Thu, 22 Sep 2022 12:39:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 01FE6940007 for ; Thu, 22 Sep 2022 12:39:46 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AD4451C6EF9 for ; Thu, 22 Sep 2022 16:39:46 +0000 (UTC) X-FDA: 79940282772.18.08CA73F Received: from ale.deltatee.com (ale.deltatee.com [204.191.154.188]) by imf11.hostedemail.com (Postfix) with ESMTP id 4405B40069 for ; Thu, 22 Sep 2022 16:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=deltatee.com; s=20200525; h=Subject:MIME-Version:References:In-Reply-To: Message-Id:Date:Cc:To:From:content-disposition; bh=55w4V1w11q9zjvxXiqXDCItXvw7MgUl3ug3CrLLmnIw=; b=OZN/AZUOfIgfOjP6ooObX1mD/z 0C6aPsUozqfInf00hOtNduDUliCS3P28Y3+gALxitullhCJGm2V3yuSFm/F5CNVrTdv0i+SOzb80R AShkraGn1LBqr6dGuFHxp/2RsA3aKj+Rrm2OM05egSqxplGXEPbvgy06OBm93U2eXw2bn1yL7yjv7 9REh05flbq5LZLN0J2me10EK8R4FTm+m1wh4UX23047qMkC7DrAeGQcTiYNkHxoXfuCz1GBhNif5m JJwGas6Cur79OhPuKLfOLiLK6+Ll+tbqsZzcLGHqQ40dvAi4xLr1CpxSeX8u08w+zwfmQ3jBIT7X+ fXWDB7Cg==; Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1obPEf-00862d-HN; Thu, 22 Sep 2022 10:39:39 -0600 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.94.2) (envelope-from ) id 1obPEb-0001rp-6K; Thu, 22 Sep 2022 10:39:33 -0600 From: Logan Gunthorpe To: 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 , Greg Kroah-Hartman , Dan Williams , Jason Gunthorpe , =?UTF-8?q?Christian=20K=C3=B6nig?= , John Hubbard , Don Dutile , Matthew Wilcox , Daniel Vetter , Minturn Dave B , Jason Ekstrand , Dave Hansen , Xiong Jianxin , Bjorn Helgaas , Ira Weiny , Robin Murphy , Martin Oliveira , Chaitanya Kulkarni , Ralph Campbell , Stephen Bates , Logan Gunthorpe Date: Thu, 22 Sep 2022 10:39:21 -0600 Message-Id: <20220922163926.7077-4-logang@deltatee.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220922163926.7077-1-logang@deltatee.com> References: <20220922163926.7077-1-logang@deltatee.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-pci@vger.kernel.org, linux-mm@kvack.org, hch@lst.de, gregkh@linuxfoundation.org, jgg@ziepe.ca, christian.koenig@amd.com, ddutile@redhat.com, willy@infradead.org, daniel.vetter@ffwll.ch, jason@jlekstrand.net, dave.hansen@linux.intel.com, helgaas@kernel.org, dan.j.williams@intel.com, dave.b.minturn@intel.com, jianxin.xiong@intel.com, ira.weiny@intel.com, robin.murphy@arm.com, martin.oliveira@eideticom.com, ckulkarnilinux@gmail.com, jhubbard@nvidia.com, rcampbell@nvidia.com, sbates@raithlin.com, logang@deltatee.com X-SA-Exim-Mail-From: gunthorp@deltatee.com Subject: [PATCH v10 3/8] block: add check when merging zone device pages X-SA-Exim-Version: 4.2.1 (built Sat, 13 Feb 2021 17:57:42 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663864786; a=rsa-sha256; cv=none; b=3dQVuzfMg3tAIwqj4cKrUkVJsO1HQE+4auy9R5RadZ52y9R4FHr9cal5qOMSGhqBDIpEft G4Qjotq31tgG1yKr/IVFh8NRDcWuBokJ2IVvjR++toEirXNXy+ds54C029pcyTV7Drhw/y +dHNbmMfPfvrZad4qQRJmeXaOkArY0s= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=deltatee.com header.s=20200525 header.b="OZN/AZUO"; spf=pass (imf11.hostedemail.com: domain of gunthorp@deltatee.com designates 204.191.154.188 as permitted sender) smtp.mailfrom=gunthorp@deltatee.com; dmarc=pass (policy=none) header.from=deltatee.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663864786; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=55w4V1w11q9zjvxXiqXDCItXvw7MgUl3ug3CrLLmnIw=; b=moJoWC3x6+0/3oPpYVxC1Yz1HrHCJPYPenzx22hKmOQkx+2TmTSqTCfiJcqAuMUreevAuJ 0uKtNSo7eibU4phVnJ230PpqUk0IzBqjl8QUsg46Y96iC/5tqDVu8BpHZRZ4VTcxcEifYd n8jnJg6+WgqG+a94aHo1OJIofvGhIfo= X-Stat-Signature: hk9pxg4hr9kpacdo8cg3ybeyosxzpeez X-Rspamd-Queue-Id: 4405B40069 X-Rspam-User: X-Rspamd-Server: rspam08 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=deltatee.com header.s=20200525 header.b="OZN/AZUO"; spf=pass (imf11.hostedemail.com: domain of gunthorp@deltatee.com designates 204.191.154.188 as permitted sender) smtp.mailfrom=gunthorp@deltatee.com; dmarc=pass (policy=none) header.from=deltatee.com X-HE-Tag: 1663864786-227624 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard --- block/bio.c | 2 ++ include/linux/mmzone.h | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/block/bio.c b/block/bio.c index 3d3a2678fea2..969607bc1f4d 100644 --- a/block/bio.c +++ b/block/bio.c @@ -865,6 +865,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_have_same_pgmap(bv->bv_page, page)) + return false; *same_page = ((vec_end_addr & PAGE_MASK) == page_addr); if (*same_page) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index e24b40c52468..2c31915b057e 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -794,6 +794,25 @@ 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_have_same_pgmap(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 @@ -801,6 +820,11 @@ static inline bool is_zone_device_page(const struct page *page) { return false; } +static inline bool zone_device_pages_have_same_pgmap(const struct page *a, + const struct page *b) +{ + return true; +} #endif static inline bool folio_is_zone_device(const struct folio *folio) -- 2.30.2