From patchwork Mon Jan 27 23:22:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank van der Linden X-Patchwork-Id: 13951863 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 88EC3C0218A for ; Mon, 27 Jan 2025 23:23:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A749828013A; Mon, 27 Jan 2025 18:23:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 68B072801CE; Mon, 27 Jan 2025 18:23:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DC2A2801D9; Mon, 27 Jan 2025 18:23:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8173C2801CD for ; Mon, 27 Jan 2025 18:23:03 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3EAB9C0802 for ; Mon, 27 Jan 2025 23:23:03 +0000 (UTC) X-FDA: 83054809446.01.8271951 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf27.hostedemail.com (Postfix) with ESMTP id 7949540004 for ; Mon, 27 Jan 2025 23:23:01 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FeWDCtCk; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 3VBWYZwQKCCMEUCKFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--fvdl.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3VBWYZwQKCCMEUCKFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--fvdl.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738020181; a=rsa-sha256; cv=none; b=rcA5x5cDWGP8wGxaOPYwZO9bAfe2SmqXW/BcBaPkM/LynYzQuFQv0xNUOlsHxvAA/kMhhu NZWKVdkoGPb51V2dhwejtnYKwL+PdKYLqW7NsZtQE5QUg30zg35lcb0tWqpqAfSnIwSvxb AFH1VV4DxGMXHG63w66q9OApheqQNz8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FeWDCtCk; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of 3VBWYZwQKCCMEUCKFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--fvdl.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=3VBWYZwQKCCMEUCKFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--fvdl.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738020181; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hCniTRl/lA/PuLQ+BNMwksXzOFV25yjBBKkil3bBQiY=; b=qGu4I1209mH1MGpFtVe9DL09i7883DRgovFHhZc5WOOpEucvRmixw0k/V+N5N6Pii+1q4v kDduVFG270uxhffVVjFYjoQAZLk0OY0Zd0tF9F73NT//Gk9Ajr1UAyIckC2JjmsAOy5tti g7MCxtfjdaqg2DLsf1X+5PJMQ02+ojE= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2162259a5dcso155125835ad.3 for ; Mon, 27 Jan 2025 15:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738020180; x=1738624980; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hCniTRl/lA/PuLQ+BNMwksXzOFV25yjBBKkil3bBQiY=; b=FeWDCtCkboyWNJJZRG7i9wklguChzc4lskAAXvUUgssptZOKkie05DIqgl51QqWCrf ecQIK0WUslIL96m3q/duNbsLXsy8qqJY79p+eK4RvXWqXi4ha9goIRZgJ71hWSaXbN6f 463IlBaUaetu3i4mtXgcb9PpkJC5Imku8+q9ihWnxXLJhYUL18YTbKitcMs9p0UfygrB js/RwhXLMkInQlFwmAj8PXecQY/exHaVhRfsjRYmMHTw0mE72SG8fr1V09yhUQl3rZZb NsrZF5EQphXftBIgcXVgyisub7KBKpvizERGFnXbP0KzY8+WJ63AeWhqwj9V7cK65qWz uAHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738020180; x=1738624980; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hCniTRl/lA/PuLQ+BNMwksXzOFV25yjBBKkil3bBQiY=; b=dlGPd805i64WZNkykNl6IAQi11YNGozGIgsg/3xkgZPScYj9mXHgtam2gWNKOZC0Wd hYg7uI25Ni6QZHgPckNMUXbpBfji6sWDPqhqLW5Npy0RbW16D+0bwXT8f35gLcqTZDQq AzlptHcN1+RYEBDCJL8BG3vM0s9zFLrjs9OrFx9lIthyaDjFXf6UtLstOFqr5VyHHcjX TQgNwTekXBSa1LEzx4sVqmryVBumc/yY5Z5g6m2a1QhDz9LK/I5nNeb7KiwYRqQhApwI B0oMCtrkUI5CZGT3tYdA2O4Gh0eMVRrflfIlNwKMqa+8JjQw+YZKyOuPI7TvTxMWYbH3 M0ug== X-Forwarded-Encrypted: i=1; AJvYcCXopMpZlWrLjuy+R+rTgq0Wmr+Q6PG71GX+JSWY9bbE/U2sWmKhUC/tX7YQjvJcGxj3S0X6qwkUDw==@kvack.org X-Gm-Message-State: AOJu0Yz/UkAKol8SazhLbiGi9QYlHyogFZDVq0/qupj3Ii1a4YEh3Vj8 khYsmhJk1+M1qe+NXm9bphbuPBz/QiC/K4fNGNIvs3yEM4vC3vLs0qU7GrrxPKnuPBKh1A== X-Google-Smtp-Source: AGHT+IHzO0EISgReM0dLIWHi2YCB+4i3HiviP+HCYttMVTZD0GYiJiyEaV9yehlN7QlnVFYvPUvUBi+s X-Received: from pfxa31.prod.google.com ([2002:a05:6a00:1d1f:b0:726:d6e6:a38]) (user=fvdl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:78a1:b0:1e1:becc:1c91 with SMTP id adf61e73a8af0-1eb2157fbddmr69783403637.28.1738020180426; Mon, 27 Jan 2025 15:23:00 -0800 (PST) Date: Mon, 27 Jan 2025 23:22:03 +0000 In-Reply-To: <20250127232207.3888640-1-fvdl@google.com> Mime-Version: 1.0 References: <20250127232207.3888640-1-fvdl@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127232207.3888640-24-fvdl@google.com> Subject: [PATCH 23/27] mm/cma: simplify zone intersection check From: Frank van der Linden To: akpm@linux-foundation.org, muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: yuzhao@google.com, usama.arif@bytedance.com, joao.m.martins@oracle.com, roman.gushchin@linux.dev, Frank van der Linden X-Rspam-User: X-Rspamd-Queue-Id: 7949540004 X-Rspamd-Server: rspam10 X-Stat-Signature: bojj3oc978d944pmjtzpia3gqarf5o1p X-HE-Tag: 1738020181-316090 X-HE-Meta: U2FsdGVkX1/tEaSxNfJlcE3LatDNEdEBU/ipcelDvDUMqG7JLa067R8ppgP8WSnzjCLamtSKxnJjA5UppMurHiN2SUlkaQ6Xg30neu51dTYjcLNa6T4LzQtG4udT2YgTzuT65CYkoRzlQsQXwEqQtnBdZq7P3mRK9k6SYdTw3uejukyngpMNSgQCMRm2Dum+XYEsDGBh/+pdisAJD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kJvjWanNXgzWkBbeYnr8LXLxFoLX0Hb9C293CVK7RnSP3wXGisqTNew6RHY7WJAY/09LgEtVEz7H70Mm+q3UZ3C44jK8y+6JUBYpPbr3emP70MJtVa5sPZ35iYfXjjQQJIp29RYFAeoFPUqKgqel3YwvNbE1i7vmABhmc/EWzo1pUNVZYOp7xikEH2gSQ7Krwr48uR+/ZfxUkXBX+bR8op9oxgU7nF18ygyJX5Aa9gyw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000055, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: cma_activate_area walks all pages in the area, checking their zone individually to see if the area resides in more than one zone. Make this a little more efficient by using the recently introduced pfn_range_intersects_zones() function. Store the NUMA node id (if any) in the cma structure to facilitate this. Signed-off-by: Frank van der Linden --- mm/cma.c | 13 ++++++------- mm/cma.h | 2 ++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 1704d5be6a07..6ad631c9fdca 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -103,7 +103,6 @@ static void __init cma_activate_area(struct cma *cma) { unsigned long pfn, base_pfn; int allocrange, r; - struct zone *zone; struct cma_memrange *cmr; for (allocrange = 0; allocrange < cma->nranges; allocrange++) { @@ -124,12 +123,8 @@ static void __init cma_activate_area(struct cma *cma) * CMA resv range to be in the same zone. */ WARN_ON_ONCE(!pfn_valid(base_pfn)); - zone = page_zone(pfn_to_page(base_pfn)); - for (pfn = base_pfn + 1; pfn < base_pfn + cmr->count; pfn++) { - WARN_ON_ONCE(!pfn_valid(pfn)); - if (page_zone(pfn_to_page(pfn)) != zone) - goto cleanup; - } + if (pfn_range_intersects_zones(cma->nid, base_pfn, cmr->count)) + goto cleanup; for (pfn = base_pfn; pfn < base_pfn + cmr->count; pfn += pageblock_nr_pages) @@ -261,6 +256,7 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, cma->ranges[0].base_pfn = PFN_DOWN(base); cma->ranges[0].count = cma->count; cma->nranges = 1; + cma->nid = NUMA_NO_NODE; *res_cma = cma; @@ -497,6 +493,7 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size, } cma->nranges = nr; + cma->nid = nid; *res_cma = cma; out: @@ -684,6 +681,8 @@ static int __init __cma_declare_contiguous_nid(phys_addr_t base, if (ret) memblock_phys_free(base, size); + (*res_cma)->nid = nid; + return ret; } diff --git a/mm/cma.h b/mm/cma.h index 601af7cdb495..b70a6c763f7d 100644 --- a/mm/cma.h +++ b/mm/cma.h @@ -48,6 +48,8 @@ struct cma { struct cma_kobject *cma_kobj; #endif bool reserve_pages_on_error; + /* NUMA node (NUMA_NO_NODE if unspecified) */ + int nid; }; extern struct cma cma_areas[MAX_CMA_AREAS];