From nobody Fri Dec 19 07:01:59 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1741973172; cv=none; d=zohomail.com; s=zohoarc; b=UO50BpUVcK5K7yxVyDI9nUbnEVHmA+ls4gqcEN/IKi9mldtC3IsTwhi1f3Z62RHxp9mVblGeOI3kgAxqGGmerByBrFfCD1dHmcad8EKxqyMJPvACXYf3s5s1n8l/kCDkVoNInIZ1t+obRGYBh0ZnItzODFGeiH4DuxsEgiFe22k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1741973172; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zi0U1tBM2T4W2AEbnFZA5/T7OE3SmD5RxZSu3R3MuvQ=; b=BKXNippgxdXp3nkn1IQ415vQUqYPa23Kca+qFbQ9tiSyLcNonrkbTEe5cw2cSUw8vL8TaZJKV3RSjXgZZwmaauuyG5yIpaV5TgBFtN/GYxcW/qPX6oyoLFqcPnP+N8LS2YTzG/Arnk8fuWPedxoUCR2itvrHZi4muRChFV++Vic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1741973172040573.981286185695; Fri, 14 Mar 2025 10:26:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.914883.1320528 (Exim 4.92) (envelope-from ) id 1tt8nD-0004zi-27; Fri, 14 Mar 2025 17:25:55 +0000 Received: by outflank-mailman (output) from mailman id 914883.1320528; Fri, 14 Mar 2025 17:25:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8nC-0004za-Ul; Fri, 14 Mar 2025 17:25:54 +0000 Received: by outflank-mailman (input) for mailman id 914883; Fri, 14 Mar 2025 17:25:54 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8nC-0003IK-4d for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:25:54 +0000 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [2a00:1450:4864:20::634]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6198a550-00f9-11f0-9ab9-95dc52dad729; Fri, 14 Mar 2025 18:25:53 +0100 (CET) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-ac34257295dso55171666b.2 for ; Fri, 14 Mar 2025 10:25:53 -0700 (PDT) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac3146aeb24sm250677566b.9.2025.03.14.10.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:25:52 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 6198a550-00f9-11f0-9ab9-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973152; x=1742577952; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zi0U1tBM2T4W2AEbnFZA5/T7OE3SmD5RxZSu3R3MuvQ=; b=GmUdB/RFDvZR/WWwjBKSSbs9MNuoMfMfdKmDzPCEw9I7e3/S0y4T2IuVJlvlHH89ka g08CPZMphARd/dsfgbr6DtYbzf0ks9YXpDA7JwxOIFx0bxp/ju2IDc2gpwZrRrqzOkMF CGab5FnJ6/EfcSyaY158Zae7NdZE8C/OgXAFc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973152; x=1742577952; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zi0U1tBM2T4W2AEbnFZA5/T7OE3SmD5RxZSu3R3MuvQ=; b=azMjd+8i709wZVGc9xv+OLMJB2OFp6lrYrcifFVoxv6TU2HyIfS4bMo0NMAONF+u3a g4ISOqBnAaXPdhR4sxiaDF/kvtvjRDfXCjp9AffThJbzWDv2xYG8cRoK4w7jiesLYUc6 A+7PxtmjH8O7ANN3NC4HJvhX3FgjGc0xwf1FAVhvKVidxSYwnEzJJ2AalnMbA47SSnuM AgOQPg7zD7YtGglShgExXBubxlAndjQp66zSl7hjFW3AAag8C5B0vtChkAImZnaJjb6R ZN7xDhCRSBa4JT9CW1iVfa0xJ4eunz7WjGiRiOTOwdT9tzPvmkiRklOl1d1uxzzx+tX6 ISzA== X-Gm-Message-State: AOJu0Yxgx+JkilJGpCYRNcozZGznkA2t6Lrvjmznh1l2TbzS8foNuWd9 6KrZZfcAvW7vrKYISWM5Q4lMoHmRrlHZdQeVcrtg6LJLmtvz+467T6Wl2eG7WncXg/4hVF4geO5 p X-Gm-Gg: ASbGncvSXOm5VEDtAha8mhGoRQF1SzZWSyEvsrY7rcV8tujmeFp6A5QsSPqE0LdwVVL ApysuFAAEj7l8xfYcqlpDmggaTJCppNQc40tD/eVdSXRoVx3+kq1DwKXrH4MbUalCMAvxph4+W1 KZsQoavlQNu7hQvtAi5lvFiJUnVyDqZ9+I6XJ1POT9CL4e7EEL6SRnRpt2Y8iYKa5a+rcnf1L5r nLcvFVuLI690+Y9DsJwz3wGx4yjUZLJcd3Qvkf5PkIUbWvXT2kXcKXtEkE8uZJ4Y4UzGm7zDPir r4XZdasmnCwGempnhUdvBB6s9l2gezmTsuxcXkuKR4gVEUy9ZdAQk7FDvpmB2IRRXB4= X-Google-Smtp-Source: AGHT+IFADtQYmIHTCQjkqGKIQUUkHpagvgpqQ3Bb9SjUIRU2mCKX4RN/qddSc0+Q25vOp0lX6f4pWw== X-Received: by 2002:a17:906:6a27:b0:ac2:7be7:95c5 with SMTP id a640c23a62f3a-ac3303225c3mr432322766b.33.1741973152447; Fri, 14 Mar 2025 10:25:52 -0700 (PDT) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Bernhard Kaindl , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH 05/11] xen: Create per-node outstanding claims Date: Fri, 14 Mar 2025 17:24:56 +0000 Message-ID: <20250314172502.53498-6-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250314172502.53498-1-alejandro.vallejo@cloud.com> References: <20250314172502.53498-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1741973172991019000 Content-Type: text/plain; charset="utf-8" Extends domain_set_outstanding_claims() to allow staking claims on an exact node. Also creates global per-node claim counts analogous to `outstanding_claims`. Note that the per-node counts can't replace the global one if we want exact-node claims to coexist with non-exact claims. Signed-off-by: Alejandro Vallejo --- xen/common/page_alloc.c | 32 +++++++++++++++++++++++++++++++- xen/include/xen/sched.h | 3 +++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 9243c4f51370..7fe574b29407 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -490,6 +490,7 @@ static unsigned long pernode_avail_pages[MAX_NUMNODES]; =20 static DEFINE_SPINLOCK(heap_lock); static long outstanding_claims; /* total outstanding claims by all domains= */ +static unsigned long pernode_oc[MAX_NUMNODES]; /* per-node outstanding cla= ims */ =20 unsigned long domain_adjust_tot_pages(struct domain *d, nodeid_t node, long pages) @@ -501,20 +502,31 @@ unsigned long domain_adjust_tot_pages(struct domain *= d, nodeid_t node, * can test d->outstanding_pages race-free because it can only change * if d->page_alloc_lock and heap_lock are both held, see also * domain_set_outstanding_pages below + * + * If `d` has an exact-node claim, we must exit early if this is an + * adjustment attributed to another node. */ - if ( !d->outstanding_pages || pages <=3D 0 ) + if ( !d->outstanding_pages || pages <=3D 0 || + (d->claim_node !=3D NUMA_NO_NODE && d->claim_node !=3D node) ) goto out; =20 + spin_lock(&heap_lock); BUG_ON(outstanding_claims < d->outstanding_pages); if ( d->outstanding_pages < pages ) { /* `pages` exceeds the domain's outstanding count. Zero it out. */ + if ( d->claim_node !=3D NUMA_NO_NODE ) + pernode_oc[d->claim_node] -=3D d->outstanding_pages; + outstanding_claims -=3D d->outstanding_pages; d->outstanding_pages =3D 0; } else { + if ( d->claim_node !=3D NUMA_NO_NODE ) + pernode_oc[d->claim_node] -=3D pages; + outstanding_claims -=3D pages; d->outstanding_pages -=3D pages; } @@ -542,6 +554,10 @@ int domain_set_outstanding_pages(struct domain *d, nod= eid_t node, if ( pages =3D=3D 0 ) { outstanding_claims -=3D d->outstanding_pages; + + if ( d->claim_node !=3D NUMA_NO_NODE ) + pernode_oc[d->claim_node] -=3D d->outstanding_pages; + d->outstanding_pages =3D 0; ret =3D 0; goto out; @@ -564,12 +580,26 @@ int domain_set_outstanding_pages(struct domain *d, no= deid_t node, /* how much memory is available? */ avail_pages =3D total_avail_pages - outstanding_claims; =20 + /* This check can't be skipped for the NUMA case, or we may overclaim = */ if ( pages > avail_pages ) goto out; =20 + if ( node !=3D NUMA_NO_NODE ) + { + avail_pages =3D pernode_avail_pages[node] - pernode_oc[node]; + + if ( pages > avail_pages ) + goto out; + } + /* yay, claim fits in available memory, stake the claim, success! */ d->outstanding_pages =3D pages; outstanding_claims +=3D d->outstanding_pages; + d->claim_node =3D node; + + if ( node !=3D NUMA_NO_NODE ) + pernode_oc[node] +=3D pages; + ret =3D 0; =20 out: diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 559d201e0c7e..307a9d749f5d 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -406,6 +406,9 @@ struct domain unsigned int max_pages; /* maximum value for domain_tot_pa= ges() */ unsigned int extra_pages; /* pages not included in domain_to= t_pages() */ =20 + /* NUMA node from which outstanding pages have been reserved */ + unsigned int claim_node; + #ifdef CONFIG_MEM_SHARING atomic_t shr_pages; /* shared pages */ #endif --=20 2.48.1