From patchwork Wed Jan 29 22:41:52 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: 13954220 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 54AAFC02193 for ; Wed, 29 Jan 2025 22:43:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 23630280270; Wed, 29 Jan 2025 17:42:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E5A628026C; Wed, 29 Jan 2025 17:42:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01048280270; Wed, 29 Jan 2025 17:42:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D6D0A28026C for ; Wed, 29 Jan 2025 17:42:55 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 98221AEC57 for ; Wed, 29 Jan 2025 22:42:55 +0000 (UTC) X-FDA: 83061965910.02.7912231 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf07.hostedemail.com (Postfix) with ESMTP id BEBCA40012 for ; Wed, 29 Jan 2025 22:42:53 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=EhJcfzkD; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 37K6aZwQKCPceuckfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--fvdl.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=37K6aZwQKCPceuckfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--fvdl.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738190573; a=rsa-sha256; cv=none; b=mZOLmZvhXaZWeKuuLC9Gr2eIz/HBdei6liaGYtTM+NusWtzqM/E0vp3PuZpcHUkuRdCRGg 7M7dkz8aT+FraM93zByd/U7m8IdMo8leVjRtkUx87oMlCl+Kmq0+3zWiGGGxVENjUGdWV+ FMdY44dK08bMM8eOn+Yi55HkjvqQYgY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=EhJcfzkD; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 37K6aZwQKCPceuckfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--fvdl.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=37K6aZwQKCPceuckfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--fvdl.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738190573; 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=B9+SFAfifGO+4WMyk38z+oj+T8+477UR0bm18OCN8QQ=; b=hYQPVSlThWhCLhYQxwdYH9Ef8mk/qGFkrmbvXPvW54F9PihS9DfsEGVc/TDa2wswoO6LVu YfDKBye1YES4m4a/o44AGm5we6Y8bobRx10TdGyWqkYXxXdu2T7jcW3VnpV+iytlItqJHr W2mkbIyqK/XkxD0G5cV85ELfc5zc29I= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2163c2f32fdso4086465ad.2 for ; Wed, 29 Jan 2025 14:42:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738190572; x=1738795372; 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=B9+SFAfifGO+4WMyk38z+oj+T8+477UR0bm18OCN8QQ=; b=EhJcfzkDXngWOIOgbTIGVRjjF/8L4VYd6KC94oeXHFllldTNU9av+eH3w4MItJAMN4 BAT0TlIlJiDhRTUGuldkWYtWRYQuCvVXa5PuOB8YdFzysxEnG3WtCeqhrHWssI2+nPKg wFkjzef3oXhNX8OWC/K2mQiae7+LkgtOkSdEOZiQk9oVwEdyW+jADTa+h4ym836tKRS3 YzRwASlfXLhJHu9pwklycAblSlq66korTJk+PScsyJGsYWCfG6Rah6h5qEzmHqsbxdjZ /kgkQWbUYkLw9uOhwrv/HqHE6l0kXUGVjdze+eQh4K2R/OdOu33GSugw/Vr92Oc7cVaJ tAww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738190572; x=1738795372; 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=B9+SFAfifGO+4WMyk38z+oj+T8+477UR0bm18OCN8QQ=; b=YbBre2gYuf03/sfluClJ/5drUrn/KRvzKD5uctwBd1U3yW8t/KWhT/+0Bj5LZp53Nb Y/yccgWT4YS2tMTE6muYIQPZWoJEE4YviohqNF1ZbTil6V5721L6BgiGQ/6D2slS0NeS 8DqUAnKrc8KFbRPOm09n1w/ge2eWBR4aElzL38gAg2uiEPsvCmiHPXD19xSTArzOb4F9 zf+6KjHUuviA6mQO7JIutpk0+gycbtLrwacHZFnyAtzrZOnRft4X85r1CYqMj8JRHDww gS42EZsGOovIwCE6vq7uQudGiErffuPsDqRsDAEBvvOEsI70DuIrnJRslFU8btxFwLVk pyaQ== X-Forwarded-Encrypted: i=1; AJvYcCUEKETdEwj3iTQYa/Yq3ocAnSTOMaE8T5aATJQOeQtc2g2cTxIqotMCfLlLorV232frLnyH31FijQ==@kvack.org X-Gm-Message-State: AOJu0YzLM1oul9qYYBgWJ3a16Vcg1C+zXLYJC/KWKOT23ClP6d+6Ta1V 47kAH1njE9xCAFkxGQfWvBD32yyP0JwEsESJT9dQWQ9mX9U2sGkqfI3/gD/VeWqUKZn02A== X-Google-Smtp-Source: AGHT+IEfESeGYmpm9QvSf55e7+bojIZbnayRY5HSnlK9/hO+fi+i5SAew2Blg7kqEkcf7da+HHBE7s7h X-Received: from pgbca33.prod.google.com ([2002:a05:6a02:6a1:b0:801:9268:c344]) (user=fvdl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3387:b0:1e0:c9a9:a950 with SMTP id adf61e73a8af0-1ed7a61d4admr7290847637.39.1738190572647; Wed, 29 Jan 2025 14:42:52 -0800 (PST) Date: Wed, 29 Jan 2025 22:41:52 +0000 In-Reply-To: <20250129224157.2046079-1-fvdl@google.com> Mime-Version: 1.0 References: <20250129224157.2046079-1-fvdl@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250129224157.2046079-24-fvdl@google.com> Subject: [PATCH v2 23/28] 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, usamaarif642@gmail.com, joao.m.martins@oracle.com, roman.gushchin@linux.dev, Frank van der Linden X-Rspam-User: X-Rspamd-Queue-Id: BEBCA40012 X-Rspamd-Server: rspam10 X-Stat-Signature: trzb3pwkfs6pbs7owuogf66irzhx7kt3 X-HE-Tag: 1738190573-208121 X-HE-Meta: U2FsdGVkX1+SjbP3DLutbM9y9BXh3/Fmlj1UkHjlEvnVTotjTHqG3RaCD45yvDWC8gmq8RXdyk93B0gNC0phhKNi5MK89TK1rhWRYVXh8N8yu+HtFmBa4i0Iw9d1MMafq0jiQjY+Fdpb8zGyK4YEcXygYQPI+3El+hMD1JAIxln0KURfBiybXWugt2XGdBCzxcxpPMN4qpLRVP1CfSoPms9qfn0U3P678eZMQEXveh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zTjh1wkvA0qjHSaWOjvnVOdSArN6s/F2cqqWqr8m20nIwf1i1pCICZbLwJEUTtaBIZ85IvBHvHk9IZVGDFEh2CQs/yD1E3J0Ovy/TrHKxeoGK3atBGQ4p/kz173bAuolsShVjFUVtPzpMM1+aNJzLzmKo1VzJvyKQqlbRgbSv0mzzfIdm7uumeg03SJFIOlUfGxCDrHc1xy8etJ7UarA== 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: 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 5f39dd1aac91..ff79dba5508c 100644 --- a/mm/cma.h +++ b/mm/cma.h @@ -50,6 +50,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];