From patchwork Fri Mar 14 17:24:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017188 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B1F0C35FF3 for ; Fri, 14 Mar 2025 17:25:49 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.914866.1320489 (Exim 4.92) (envelope-from ) id 1tt8mt-0003Wj-Tu; Fri, 14 Mar 2025 17:25:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 914866.1320489; Fri, 14 Mar 2025 17:25:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8mt-0003Wc-QU; Fri, 14 Mar 2025 17:25:35 +0000 Received: by outflank-mailman (input) for mailman id 914866; Fri, 14 Mar 2025 17:25:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8mt-0003WI-Dg for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:25:35 +0000 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [2a00:1450:4864:20::62a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 55cd188f-00f9-11f0-9899-31a8f345e629; Fri, 14 Mar 2025 18:25:33 +0100 (CET) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-aaecf50578eso411397566b.2 for ; Fri, 14 Mar 2025 10:25:33 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:25:32 -0700 (PDT) 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: 55cd188f-00f9-11f0-9899-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973133; x=1742577933; 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=D88teVB8QraJI8UkkRbNWyapnCrKK4Sforaz0HF/IhM=; b=YtkYHTz0O6kd9sAc0a9JIH8KckLarfRGMhY/Y55TRx4qTe90cFyYWE2xkr7peYMRc1 bRTjhfA0nN0hHdaxCtwj5qD16JgUh5PtOH7ZQeD9IxsEZ4Qxkqie3c0icL0Vs/Jz3huV hW/rl8vovw04rxiODzVOUaVhAs1lUnk9sGnz4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973133; x=1742577933; 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=D88teVB8QraJI8UkkRbNWyapnCrKK4Sforaz0HF/IhM=; b=SPvsDOcYrCAVbo9PAhvNxuuT5aoqNwiroBHgNGe0IjIJDCeN9wUYbseN3IcylPrYxr EkEQ0VR3bgGjLmYELhLaMLHkNkmn08f/Tmu5C+ZYAqFdpGPcDtNO/xN8gQyxgy2zfJHS W6cZbtLQcgY7+7PcxmY72fv74AJuIF0+gwUKFms8HYp1JiErJoET7OJRd9W33LXGM/tN YnPU/tfWU+VuKc6Dv68kQnKpU1bupNib0dvAQ6lAT1iz5O0na8TBSpvmOMS97lbqvrNJ KTk0u/45iNvf//akYus6ArjH6WOqX3eNqu30UPX1EWsjWfZneSdzGw3dPT3ChjBLmt+4 O9HA== X-Gm-Message-State: AOJu0YyGPJLO0lv8XfF8+D5FGyyreDRTjMVguLaIoBRSWxbdWaMlcAyX kdbZiqoRso8vpaQg568xvLZydk4olbhuhjzoA6nd5Eu2VVzZUKt45NTvCnZmrNVxcd4YF+//Jaj e X-Gm-Gg: ASbGncueeobaSPZsU9seKso+cHGaQ4N5QnD6ibLrsvunG7YnLW8XQ4O5KfzSZAUXcAJ cSBSsN9KsW9P3c7/hDT1c902n/v6KZp551rSJRtaErCE2ObsL8PwEqapQsYHrT4KJeVQDMdVOBV bSKreJwHlFZBbfJGiYew5spV3ag9G+7J6C0aP08uueEor1h2mtE693g9le5E+bv3UJ9uv6OvXPZ 3sMdxGrlHx9uTE2Qlliz0lk3QX2qnQ0hNAaSw/QxJLXoIE56UEFiWofwWIldjSSF51ZzItbANh+ n5DxJIDT83XvWBuXSw/E38c4pvRNFI+Ek4ixqAzujoLxGgxV5VZJQlM5e8+/lh1vCkk= X-Google-Smtp-Source: AGHT+IHF+okTXpoKk3F3RN6+H/q9LDUWzo3CUgJjnS2eIVHjtz6xVjONzkwXnSSZJAQyrsQrJwTsJA== X-Received: by 2002:a17:907:9485:b0:ac3:2a77:cb4e with SMTP id a640c23a62f3a-ac330189240mr367576266b.13.1741973132888; Fri, 14 Mar 2025 10:25:32 -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_Pau_Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH 01/11] xen/memory: Mask XENMEMF_node() to 8 bits Date: Fri, 14 Mar 2025 17:24:52 +0000 Message-ID: <20250314172502.53498-2-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 As it is, it's incredibly easy for a buggy call to XENMEMF_node() to unintentionally overflow into bit 17 and beyond. Prevent it by masking, just like MEMF_* does. While at it, turn "x" into "n" and "f" to better indicate whether the macro takes nodes or mem_flags (just like their MEMF_* counterparts). Signed-off-by: Alejandro Vallejo --- xen/include/public/memory.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index bd9fc37b5297..077eef48c60d 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -32,8 +32,9 @@ #define XENMEMF_address_bits(x) (x) #define XENMEMF_get_address_bits(x) ((x) & 0xffu) /* NUMA node to allocate from. */ -#define XENMEMF_node(x) (((x) + 1) << 8) -#define XENMEMF_get_node(x) ((((x) >> 8) - 1) & 0xffu) +#define XENMEMF_node_mask (0xffu) +#define XENMEMF_node(n) ((((n) + 1) & XENMEMF_node_mask) << 8) +#define XENMEMF_get_node(f) ((((f) >> 8) - 1) & XENMEMF_node_mask) /* Flag to populate physmap with populate-on-demand entries */ #define XENMEMF_populate_on_demand (1<<16) /* Flag to request allocation only from the node specified */ From patchwork Fri Mar 14 17:24:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017189 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0318C282EC for ; Fri, 14 Mar 2025 17:25:51 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.914868.1320499 (Exim 4.92) (envelope-from ) id 1tt8mz-0003of-4z; Fri, 14 Mar 2025 17:25:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 914868.1320499; Fri, 14 Mar 2025 17:25:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8mz-0003oT-1h; Fri, 14 Mar 2025 17:25:41 +0000 Received: by outflank-mailman (input) for mailman id 914868; Fri, 14 Mar 2025 17:25:39 +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 1tt8mx-0003IK-MO for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:25:39 +0000 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [2a00:1450:4864:20::533]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5921db99-00f9-11f0-9ab9-95dc52dad729; Fri, 14 Mar 2025 18:25:39 +0100 (CET) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5e5b572e45cso4245438a12.0 for ; Fri, 14 Mar 2025 10:25:39 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:25:37 -0700 (PDT) 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: 5921db99-00f9-11f0-9ab9-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973138; x=1742577938; 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=351bdlLIbuxgol8ZF7V3o8BgsGOssbbNlMWXgCJ2hCs=; b=RC+bo7JKTvEZtae3Gr3izzQhXKVIBhrGVXgHQFrY/ou41vZ2AbDK/3Gh/uAp24N5pe SWp2MILYFC5DL7kBfN7YRkR5oMZAm25XservpB6NiBza1CZA8I6nml4s6zP+SRUCtKkd zX5ugudvxdE6Kvxrhc3864UqTQBXg9/1XjdmM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973138; x=1742577938; 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=351bdlLIbuxgol8ZF7V3o8BgsGOssbbNlMWXgCJ2hCs=; b=H0etzQr1tMBIXvxxf+/lQRLrY5HYeZv0aduhraZOpY8e0aXwawBThtwqm9JkKsvsp1 ECWEIvPRMKCgjyUmvsGxqC4XbjW1hhuwuaPora/ITh9HWn9AfwtOvhC1htse+sRo9vUB pjTLKgoFRg2odSM3pCusN9vOdhFlTHhrabxsPJ6iu6y0LDcWhmqy0DXL3mrfMUp/IJxG XSEQOFrz4Ee6xPvAb26Xtu09LP1ptGcjKs3nmbCUUdbbicqXCaODinHnR2V/NlPyFx78 wBB7BDYN4U7FHrGH50RJMx/DGr5O8HcwuzUhOZon/rQaz8qJvFWXFAUermAogDqbrPSS bbmA== X-Gm-Message-State: AOJu0YyXZHCcuxQq54/mWnBs/533BCCX8OcjOPkFRyWhQlZGN9O+26pf OizBU6RbXbfXiUSOmingQW4OOz08XEsmnDBeBDq02qZkxkGHCcgM4VnEg79w3nR6AbBl9tSZ+dw K X-Gm-Gg: ASbGnctxVM9/lPjSYATIafV4/lwpSIgho1dCmUzq0W4hNnyTzQY5NpYoZeRU1aoyjBW hJu3frP/f6GZygE+jsdB/JAS6HUieWe9tS1a6EvEIcbNU/KiG3jna3uoOOP2Cdgcp3YqW1XLoPc lnc7QN5YZoGnXNih+k4WUtQ0p1yt9wLDPvVEmMChBuLvi3I+Tt2SjFcUqnvFicPw4zg01MJhS2g eKVwc2fyp63ETml+OAyAHQOqR3/A3tRvnLqkb96jCPRg7GvQzfile+S0FGgTaz4sGVFQtMB7RNo nroz0mRWpDikg9ML5iHYfAKHoc6DeJeeAhec8L3SVN5sq/dnJkI5/EIjKNT6rLhPhtA= X-Google-Smtp-Source: AGHT+IFI/fvEfzg2jBcAL1WJKOGW6aGgqd1AEB2qnpko0+wGODBcJlNhhdY5u2rgrYI9d4Vgxr2unA== X-Received: by 2002:a17:907:60d5:b0:ac1:df33:25b9 with SMTP id a640c23a62f3a-ac3303ab8f3mr447537466b.40.1741973138357; Fri, 14 Mar 2025 10:25:38 -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_Pau_Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH 02/11] xen/page_alloc: Remove `claim` from domain_set_outstanding_pages() Date: Fri, 14 Mar 2025 17:24:53 +0000 Message-ID: <20250314172502.53498-3-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 With a single global count for the claims it's easy to substract domain_tot_pages() from the claim so the number given in the hypercall is the real reservation of the domain. This is the current behaviour. However, a later patch introduces exact-node claims and those interact very poorly with such a scheme. Since accounting domain_tot_pages() in one case but not the other seems strictly worse than not accounting them at all (which is at least consistent), this patch stops substracting tot_pages from the claim and instead checks that claimed memory + allocated memory don't exceed max_mem. Arguably it's also clearer for the caller to align the amount of claimed memory with that of the requested claim. Signed-off-by: Alejandro Vallejo --- xen/common/page_alloc.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index bd4538c28d82..49c3258169db 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -523,7 +523,7 @@ out: int domain_set_outstanding_pages(struct domain *d, unsigned long pages) { int ret = -ENOMEM; - unsigned long claim, avail_pages; + unsigned long avail_pages; /* * take the domain's page_alloc_lock, else all d->tot_page adjustments @@ -549,28 +549,21 @@ int domain_set_outstanding_pages(struct domain *d, unsigned long pages) goto out; } - /* disallow a claim not exceeding domain_tot_pages() or above max_pages */ - if ( (pages <= domain_tot_pages(d)) || (pages > d->max_pages) ) + /* Don't claim past max_pages */ + if ( (domain_tot_pages(d) + pages) > d->max_pages ) { ret = -EINVAL; goto out; } /* how much memory is available? */ - avail_pages = total_avail_pages; + avail_pages = total_avail_pages - outstanding_claims; - avail_pages -= outstanding_claims; - - /* - * Note, if domain has already allocated memory before making a claim - * then the claim must take domain_tot_pages() into account - */ - claim = pages - domain_tot_pages(d); - if ( claim > avail_pages ) + if ( pages > avail_pages ) goto out; /* yay, claim fits in available memory, stake the claim, success! */ - d->outstanding_pages = claim; + d->outstanding_pages = pages; outstanding_claims += d->outstanding_pages; ret = 0; From patchwork Fri Mar 14 17:24:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017190 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E2981C35FF3 for ; Fri, 14 Mar 2025 17:25:52 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.914872.1320509 (Exim 4.92) (envelope-from ) id 1tt8n3-00048A-Cv; Fri, 14 Mar 2025 17:25:45 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 914872.1320509; Fri, 14 Mar 2025 17:25:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8n3-000481-8W; Fri, 14 Mar 2025 17:25:45 +0000 Received: by outflank-mailman (input) for mailman id 914872; Fri, 14 Mar 2025 17:25:44 +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 1tt8n2-0003IK-87 for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:25:44 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5bdca9bb-00f9-11f0-9ab9-95dc52dad729; Fri, 14 Mar 2025 18:25:43 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-ac2a9a74d9cso482348166b.1 for ; Fri, 14 Mar 2025 10:25:43 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:25:42 -0700 (PDT) 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: 5bdca9bb-00f9-11f0-9ab9-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973143; x=1742577943; 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=TFenvx66HA+6v8NxSa9ViLoF7QrMBRbRtQz2J0bReoE=; b=Gbmf5vwTeDRdSDAA0MkgetkisQsjCn3zsqKpXTXyiNuelXdtguNh8xF7jjzcf0UCi1 67enMWv9V1nvO+WaF2jgWdoZ0yMXMPKHKGxJtxJh9dtQwWKNX01BpHMTHArfTv/dBk+F Z9EYtKPgFTBTpoiHDyg2tZfFfIsSozqCMpRLA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973143; x=1742577943; 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=TFenvx66HA+6v8NxSa9ViLoF7QrMBRbRtQz2J0bReoE=; b=KFMVVTTEP9u0AnlVTqTytJoFi7uxC3NTAgCuXaHeI4F16JRDfSqH4SkIq5xBKJ3Z8u KgLn+k3idlsUaQslgw9dOAwo/yGhHKvZRgjrxcbspEv7gNNvmsqxZBqL4qJxuFw3LG1I R77IxqFDTSazIrYmGGSb/r/8BVfzxY/6uKnR9aLPHkuLBdy/eLdxD8vJezjkH03T6PNA MLxgWRZIGBuHzFoh4ZhCcBFuJVPQ4OGPTQa3rxYQOCRKmKgFv7r/8W2yfJOLjsrW5XT4 VBy1SwcZW9cPfDN7/dWHs2pE4muPjhk/PYd60vcyd2Ixp+XXgV4VxBkYL0zJbHMQ78TE zw6A== X-Gm-Message-State: AOJu0YwS1CB+FP8cGioylBg2MFAnr2xLPqFuyskCE0CX2aVM3sChbRZE DzYtRB3xz8Ym45Ahqf0P7JtiXa8MYhu5lgXro3L49xqnyyLcH7tkzqHqbh75VMRZapEq1LtxLtP c X-Gm-Gg: ASbGncsBgyotF67Olg03ldIG84/EVG5sbDXhd4imv+vX1qYDV6tEHN0nAlFgcmQSbE/ jeQ1NUubCwiqqVByTKyEloOETLwQqWKyt+499Bs5HPTJs6G+cvxptUvuGsmfCQEn+fNao2FIW3A JcBeFA42OMZ201LwPuyBMuDHZ0U6DMvN0EVbYnAfBFXAJHCWZVNuEz86KUgNEHjy9ZvY+VkSHJR roRYQb6a1WPtn0HeIhz4iU6dCwWtt3oRUiuC79TMirv0D+jxp7fHRlNag8pT3z25OiLV3OIBXAg iGT23+FyM9jh4XrI5vG+1TRWmPjzd0/7eE80lEkvWi6gGtoc/jKyOvb3wTSgobUcVIM= X-Google-Smtp-Source: AGHT+IG8xBocfTx86Mu0vxS3AmDloPZohIWbVfv2YZa+3EWOiP2ooez9VIyHoRUuoFpOT57DzDG6cg== X-Received: by 2002:a17:907:7215:b0:ac2:9ac:a062 with SMTP id a640c23a62f3a-ac3301ea35dmr297824366b.23.1741973142916; Fri, 14 Mar 2025 10:25:42 -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_Pau_Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH 03/11] xen/page_alloc: Add static per-node counts of free pages Date: Fri, 14 Mar 2025 17:24:54 +0000 Message-ID: <20250314172502.53498-4-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 These are effectively the sum of free memory in all zones of each node. It's an optimization to avoid doing that operation frequently in following patches that introduce exact-node claims. Signed-off-by: Alejandro Vallejo --- xen/common/page_alloc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 49c3258169db..733b0300a767 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -485,6 +485,9 @@ static unsigned long node_need_scrub[MAX_NUMNODES]; static unsigned long *avail[MAX_NUMNODES]; static long total_avail_pages; +/* Per-node counts of free pages */ +static unsigned long pernode_avail_pages[MAX_NUMNODES]; + static DEFINE_SPINLOCK(heap_lock); static long outstanding_claims; /* total outstanding claims by all domains */ @@ -1033,6 +1036,7 @@ static struct page_info *alloc_heap_pages( ASSERT(avail[node][zone] >= request); avail[node][zone] -= request; + pernode_avail_pages[node] -= request; total_avail_pages -= request; ASSERT(total_avail_pages >= 0); @@ -1191,6 +1195,8 @@ static int reserve_offlined_page(struct page_info *head) continue; avail[node][zone]--; + ASSERT(pernode_avail_pages[node] > 0); + pernode_avail_pages[node]--; total_avail_pages--; ASSERT(total_avail_pages >= 0); @@ -1515,6 +1521,7 @@ static void free_heap_pages( } avail[node][zone] += 1 << order; + pernode_avail_pages[node] += 1 << order; total_avail_pages += 1 << order; if ( need_scrub ) { From patchwork Fri Mar 14 17:24:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017191 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 37421C35FF1 for ; Fri, 14 Mar 2025 17:25:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.914875.1320519 (Exim 4.92) (envelope-from ) id 1tt8n6-0004TX-LQ; Fri, 14 Mar 2025 17:25:48 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 914875.1320519; Fri, 14 Mar 2025 17:25:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8n6-0004TM-GO; Fri, 14 Mar 2025 17:25:48 +0000 Received: by outflank-mailman (input) for mailman id 914875; Fri, 14 Mar 2025 17:25:47 +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 1tt8n5-0003IK-CN for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:25:47 +0000 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [2a00:1450:4864:20::529]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5d9c9aa1-00f9-11f0-9ab9-95dc52dad729; Fri, 14 Mar 2025 18:25:46 +0100 (CET) Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-5e6194e9d2cso4149984a12.2 for ; Fri, 14 Mar 2025 10:25:46 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:25:45 -0700 (PDT) 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: 5d9c9aa1-00f9-11f0-9ab9-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973146; x=1742577946; 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=p2oB9p9SaE6fLAIDKnikCVppfz5uU7uJrmpyg+tR1os=; b=S6yeMTYPEpViCxDwdzH8Fg0PTkhlMbGA1nELtkiWcGQlxIj6sF1c3QgIf843zJ+uS+ 12XRicMJN0AjHrPEvlTQJuOofAYsnRrHjJ19DgiDxZasRYsc1xFbB+8vEcPWMUx6QrCb nE6TMazeJDUZVm70S2vil2tf/Nf3S1IqfAd4E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973146; x=1742577946; 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=p2oB9p9SaE6fLAIDKnikCVppfz5uU7uJrmpyg+tR1os=; b=V0NtAqlimBqLI2ol1vPdc3qUg2fbr7HLnGZYcH4wNaOKZFveQYeDKgVoZ59GYJqQQq tEaxV7eN6HUR99ukid99ScXo9eIDT9iQvX9zFMjW2PdBpj/RpulZJKswSW+FLMPeaMTH QABaZ/FkAeManbCTn8nsIGh5StfFsmZCYeaYABNFy5dWgCpI4+giMwrQzMqF1tw6DjLe oTU9YwCdiK23cmekGCpdIE7fynzTeI03+s6rLsXNixfBvPQoKBPKZQiMpOvCHNeHNqbs 8sDS/dKw34xBZZsKoEgSFttgj6hTGHzddcnvT9SGC7uSKsDS7uhifIqrMYKBhJ7GY5BY 45HA== X-Gm-Message-State: AOJu0YySNz7ROQpmbVbAsTjpSwxeUilXDsKONmd5aLYg7ftTgid3MZU8 LC8b33tqnRKlCF2RXeJzgoioNdsC3mw0bC33g2sWuZNTn8BIb1cx5wg2KTcmkWgp5z9aBeuRb/i H X-Gm-Gg: ASbGncvijmZVhSOSxun0E7qRpBiw6tvu3V5hXXqxoGgM3ZGgpP75ICNT53zKrTlsPob xNT7HvKodQtD6gylVsvnBn2r0hmB6MliIuNDBCYz0tNwpZeXpK58vAoDfZPvdAqzkD5CBljP3HA ZlnIyLVhQ0APyh3/Wer8gjY9wHibUHFJ61ApGSfpEiap3GAA/gt430HR7F4LUJZ7tQEvMVUC9xS hwxV9OdpKKYzNyrs55/nsncWj/UhNpcx7Qe4VpXM92uxyLNWF3bm0fPCHQD2ajt2iOIERnfvJtI iFKHOoqrNIe/TBhKeDTsaM7PoH7EBiFHlMX9ZB9vgU36vTtcEJ/fsBTcpNKqsCqcjS0= X-Google-Smtp-Source: AGHT+IGYDsF4nOyhHTVwVja8lWm+p2gw5JmYoTSGjOjZXctFy6CAvBALmxOqLNzSRuBvGptN3Qo7TA== X-Received: by 2002:a17:906:794d:b0:ac2:d0e6:2b99 with SMTP id a640c23a62f3a-ac33039806bmr378513366b.36.1741973145848; Fri, 14 Mar 2025 10:25:45 -0700 (PDT) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Bernhard Kaindl , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Anthony PERARD , Michal Orzel , Julien Grall , Stefano Stabellini , Tamas K Lengyel Subject: [PATCH 04/11] xen: Add node argument to domain_{adjust_tot_pages,set_outstanding_pages}() Date: Fri, 14 Mar 2025 17:24:55 +0000 Message-ID: <20250314172502.53498-5-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 domain_adjust_tot_pages() decreases the outstanding claims of a domain as pages are allocated, so that'll need to take into account the node in which an allocation is done. Deallocations just pass NUMA_NO_NODE. domain_set_outstanding_pages() takes the node on which to to stake an exact-node claim, or NUMA_NO_NODE if it's a non-exact claim. Not a functional change, as neither function uses the arguments for anything yet. It's a prerequisite to simplify for the following patch that introduces per-node claim counts. Signed-off-by: Alejandro Vallejo --- xen/arch/x86/mm.c | 3 ++- xen/arch/x86/mm/mem_sharing.c | 4 ++-- xen/common/domain.c | 2 +- xen/common/grant_table.c | 4 ++-- xen/common/memory.c | 6 ++++-- xen/common/page_alloc.c | 17 ++++++++++++----- xen/include/xen/mm.h | 6 ++++-- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index bfdc8fb01949..89f87d013099 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4458,7 +4458,8 @@ int steal_page( page_list_del(page, &d->page_list); /* Unlink from original owner. */ - if ( !(memflags & MEMF_no_refcount) && !domain_adjust_tot_pages(d, -1) ) + if ( !(memflags & MEMF_no_refcount) && + !domain_adjust_tot_pages(d, NUMA_NO_NODE, -1) ) drop_dom_ref = true; nrspin_unlock(&d->page_alloc_lock); diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c index da28266ef076..2551c0d86e80 100644 --- a/xen/arch/x86/mm/mem_sharing.c +++ b/xen/arch/x86/mm/mem_sharing.c @@ -720,7 +720,7 @@ static int page_make_sharable(struct domain *d, if ( !validate_only ) { page_set_owner(page, dom_cow); - drop_dom_ref = !domain_adjust_tot_pages(d, -1); + drop_dom_ref = !domain_adjust_tot_pages(d, NUMA_NO_NODE, -1); page_list_del(page, &d->page_list); } @@ -766,7 +766,7 @@ static int page_make_private(struct domain *d, struct page_info *page) ASSERT(page_get_owner(page) == dom_cow); page_set_owner(page, d); - if ( domain_adjust_tot_pages(d, 1) == 1 ) + if ( domain_adjust_tot_pages(d, page_to_nid(page), 1) == 1 ) get_knownalive_domain(d); page_list_add_tail(page, &d->page_list); nrspin_unlock(&d->page_alloc_lock); diff --git a/xen/common/domain.c b/xen/common/domain.c index 585fd726a941..72d8d62bc1e8 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1205,7 +1205,7 @@ int domain_kill(struct domain *d) rspin_barrier(&d->domain_lock); argo_destroy(d); vnuma_destroy(d->vnuma); - domain_set_outstanding_pages(d, 0); + domain_set_outstanding_pages(d, NUMA_NO_NODE, 0); /* fallthrough */ case DOMDYING_dying: rc = domain_teardown(d); diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 6c77867f8cdd..d8c5321185c6 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -2403,7 +2403,7 @@ gnttab_transfer( } /* Okay, add the page to 'e'. */ - if ( unlikely(domain_adjust_tot_pages(e, 1) == 1) ) + if ( unlikely(domain_adjust_tot_pages(e, page_to_nid(page), 1) == 1) ) get_knownalive_domain(e); /* @@ -2429,7 +2429,7 @@ gnttab_transfer( * page in the page total */ nrspin_lock(&e->page_alloc_lock); - drop_dom_ref = !domain_adjust_tot_pages(e, -1); + drop_dom_ref = !domain_adjust_tot_pages(e, NUMA_NO_NODE, -1); nrspin_unlock(&e->page_alloc_lock); if ( okay /* i.e. e->is_dying due to the surrounding if() */ ) diff --git a/xen/common/memory.c b/xen/common/memory.c index 8ca4e1a8425b..1ab0bac4e7da 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -773,7 +773,8 @@ static long memory_exchange(XEN_GUEST_HANDLE_PARAM(xen_memory_exchange_t) arg) nrspin_lock(&d->page_alloc_lock); drop_dom_ref = (dec_count && - !domain_adjust_tot_pages(d, -dec_count)); + !domain_adjust_tot_pages(d, NUMA_NO_NODE, + -dec_count)); nrspin_unlock(&d->page_alloc_lock); if ( drop_dom_ref ) @@ -1680,7 +1681,8 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) rc = xsm_claim_pages(XSM_PRIV, d); if ( !rc ) - rc = domain_set_outstanding_pages(d, reservation.nr_extents); + rc = domain_set_outstanding_pages(d, NUMA_NO_NODE, + reservation.nr_extents); rcu_unlock_domain(d); diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 733b0300a767..9243c4f51370 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -491,7 +491,8 @@ static unsigned long pernode_avail_pages[MAX_NUMNODES]; static DEFINE_SPINLOCK(heap_lock); static long outstanding_claims; /* total outstanding claims by all domains */ -unsigned long domain_adjust_tot_pages(struct domain *d, long pages) +unsigned long domain_adjust_tot_pages(struct domain *d, nodeid_t node, + long pages) { ASSERT(rspin_is_locked(&d->page_alloc_lock)); d->tot_pages += pages; @@ -523,7 +524,8 @@ out: return d->tot_pages; } -int domain_set_outstanding_pages(struct domain *d, unsigned long pages) +int domain_set_outstanding_pages(struct domain *d, nodeid_t node, + unsigned long pages) { int ret = -ENOMEM; unsigned long avail_pages; @@ -2600,6 +2602,8 @@ int assign_pages( if ( !(memflags & MEMF_no_refcount) ) { + nodeid_t node = page_to_nid(&pg[0]); + if ( unlikely(d->tot_pages + nr < nr) ) { gprintk(XENLOG_INFO, @@ -2611,7 +2615,9 @@ int assign_pages( goto out; } - if ( unlikely(domain_adjust_tot_pages(d, nr) == nr) ) + ASSERT(node == page_to_nid(&pg[nr - 1])); + + if ( unlikely(domain_adjust_tot_pages(d, node, nr) == nr) ) get_knownalive_domain(d); } @@ -2744,7 +2750,8 @@ void free_domheap_pages(struct page_info *pg, unsigned int order) } } - drop_dom_ref = !domain_adjust_tot_pages(d, -(1 << order)); + drop_dom_ref = !domain_adjust_tot_pages(d, NUMA_NO_NODE, + -(1 << order)); rspin_unlock(&d->page_alloc_lock); @@ -2957,7 +2964,7 @@ void free_domstatic_page(struct page_info *page) arch_free_heap_page(d, page); - drop_dom_ref = !domain_adjust_tot_pages(d, -1); + drop_dom_ref = !domain_adjust_tot_pages(d, NUMA_NO_NODE, -1); unprepare_staticmem_pages(page, 1, scrub_debug); diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index ae1c48a61545..e577a450681c 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -129,8 +130,9 @@ mfn_t xen_map_to_mfn(unsigned long va); int populate_pt_range(unsigned long virt, unsigned long nr_mfns); /* Claim handling */ unsigned long __must_check domain_adjust_tot_pages(struct domain *d, - long pages); -int domain_set_outstanding_pages(struct domain *d, unsigned long pages); + nodeid_t node, long pages); +int domain_set_outstanding_pages(struct domain *d, nodeid_t node, + unsigned long pages); void get_outstanding_claims(uint64_t *free_pages, uint64_t *outstanding_pages); /* Domain suballocator. These functions are *not* interrupt-safe.*/ From patchwork Fri Mar 14 17:24:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017192 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67C6EC35FF1 for ; Fri, 14 Mar 2025 17:26:03 +0000 (UTC) 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 X-Outflank-Mailman: Message body and most headers restored to incoming version 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-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_Pau_Monn=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 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]; 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 claims */ 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 <= 0 ) + if ( !d->outstanding_pages || pages <= 0 || + (d->claim_node != NUMA_NO_NODE && d->claim_node != node) ) goto out; + 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 != NUMA_NO_NODE ) + pernode_oc[d->claim_node] -= d->outstanding_pages; + outstanding_claims -= d->outstanding_pages; d->outstanding_pages = 0; } else { + if ( d->claim_node != NUMA_NO_NODE ) + pernode_oc[d->claim_node] -= pages; + outstanding_claims -= pages; d->outstanding_pages -= pages; } @@ -542,6 +554,10 @@ int domain_set_outstanding_pages(struct domain *d, nodeid_t node, if ( pages == 0 ) { outstanding_claims -= d->outstanding_pages; + + if ( d->claim_node != NUMA_NO_NODE ) + pernode_oc[d->claim_node] -= d->outstanding_pages; + d->outstanding_pages = 0; ret = 0; goto out; @@ -564,12 +580,26 @@ int domain_set_outstanding_pages(struct domain *d, nodeid_t node, /* how much memory is available? */ avail_pages = total_avail_pages - outstanding_claims; + /* This check can't be skipped for the NUMA case, or we may overclaim */ if ( pages > avail_pages ) goto out; + if ( node != NUMA_NO_NODE ) + { + avail_pages = 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 = pages; outstanding_claims += d->outstanding_pages; + d->claim_node = node; + + if ( node != NUMA_NO_NODE ) + pernode_oc[node] += pages; + ret = 0; 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_pages() */ unsigned int extra_pages; /* pages not included in domain_tot_pages() */ + /* NUMA node from which outstanding pages have been reserved */ + unsigned int claim_node; + #ifdef CONFIG_MEM_SHARING atomic_t shr_pages; /* shared pages */ #endif From patchwork Fri Mar 14 17:24:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017193 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14EB2C282EC for ; Fri, 14 Mar 2025 17:26:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.914887.1320539 (Exim 4.92) (envelope-from ) id 1tt8nF-0005Nn-CQ; Fri, 14 Mar 2025 17:25:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 914887.1320539; Fri, 14 Mar 2025 17:25:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8nF-0005NX-7z; Fri, 14 Mar 2025 17:25:57 +0000 Received: by outflank-mailman (input) for mailman id 914887; Fri, 14 Mar 2025 17:25:55 +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 1tt8nD-0003IK-S9 for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:25:55 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 62c9cc77-00f9-11f0-9ab9-95dc52dad729; Fri, 14 Mar 2025 18:25:55 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-ac298c8fa50so442924466b.1 for ; Fri, 14 Mar 2025 10:25:55 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:25:54 -0700 (PDT) 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: 62c9cc77-00f9-11f0-9ab9-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973154; x=1742577954; 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=Rdh/nRp2GmOU7roCTz/BcdnWbFJ7a9N+rEjKItErqUM=; b=eKRB1iWXLDSEB5gZyzMO3hvVdVUNYWC+Ue1cO7+mEPkBt6+LSL/W9x0PIy/q87yquN PMGsaT0HRhWrTIC6KsVBBlYhSy5WX9mpIRAqvbR0kzasj/eFzaWr2VDc12B7OEY/f428 fcOQYTLwX7fHXclSuLH/u9oh4ewrVIcfSkF+E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973154; x=1742577954; 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=Rdh/nRp2GmOU7roCTz/BcdnWbFJ7a9N+rEjKItErqUM=; b=gGk1wPKJoTYJUBTcqO2zLk29DHY3djmAm6GDVlUrz52jn0oby+Dkgm5riJ+mQTi4Fk GgcLB0URoaRo6iN+/Q9yuVpvcf+XAbGmUCGCldL3P5DPjMKdZHSor04klZK2UvZuo90n X0SxLDde/WeN8ZgPs2Uk9OirInLDu0yir20AsH1l7LqbKkRje9NbW4fWqRg4ZIZ3LB+a zyP9SRlvSWXxksPzSqae/1Gg+lf9JyqaxVas2HwSxnv3Xu7QShcq2/69DmNTY8ZAg+Sl trc6390owb5Ce5XnkLDmITqTvjphTSjuclIDaTRrXKeQmS6r1s4MNnBcfmN+FrQLjOlm JW8A== X-Gm-Message-State: AOJu0YwxRRYxuZQ/VMsIAltkyAnma4CjQ6O60vVdpXQS2aWp6h9sXHmB 66MBnJhBfJxkkXm2f6jFbOFzk0u0ePe4E8MwOaoyJICBYlYrir7uve9MRyK7LgcMC1fo88Dfdds g X-Gm-Gg: ASbGncsMerED8kTsO+ozzFN/28Y1ENzOjP/ahC790xelurFAbSTUB45QuLgVs2NCQWI byOXTCWqrZXs8Pz2q9XlQV9bxyzt9KB4qIgWcvUBthofNZcTbdA136aNQO3N9bmGFheviqjKclG mQSJLSY0cxmaOhjfsps9n3PteHeNQTg+g6gjMiMtjHk56Zyn2fAuX51hwXDLdmwI4B+sYnYXA8O bc9Z7HzvDX/8N3RdcWeljSrrEYYU40nUhf7TKWTgsUDG1xFHgAq4SarpO8x8GNB2h4Jw1cQOn+V 96rytlfKm+W+GZhSNDP6tPqYt5C9x6E+d8Ci6bfte2zCRD09DBBcv8SXEfUouOar4rw= X-Google-Smtp-Source: AGHT+IEk8nbANZEXxTyw0X2Q7BGwqyDIUuQMlWuNOdLVVwuv2DgDtuJtPUADZ4WCiPLZq08dAnvteA== X-Received: by 2002:a17:906:4795:b0:ac1:fbf8:6ae7 with SMTP id a640c23a62f3a-ac33026213amr390563666b.13.1741973154557; Fri, 14 Mar 2025 10:25:54 -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_Pau_Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH 06/11] xen/page_alloc: Hook per-node claims to alloc_heap_pages() Date: Fri, 14 Mar 2025 17:24:57 +0000 Message-ID: <20250314172502.53498-7-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 Extend the claim checks in alloc_heap_pages() to exact-node claims. The logic is slightly more complicated, so the patch moves it all to an auxiliary function. exact-node claims also follow global claims in order to ensure both can coexist in the same system. Signed-off-by: Alejandro Vallejo --- xen/common/page_alloc.c | 44 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 7fe574b29407..cfaa64d3b858 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -991,6 +991,46 @@ static void init_free_page_fields(struct page_info *pg) page_set_owner(pg, NULL); } +/* + * Determine whether a heap allocation is allowed after considering all + * outstanding claims in the system. + * + * Exact-node allocations must also take into account global claims! + * + * e.g: + * Consider a domain for which toolstack issued a non-exact claim of 75% of + * host memory and another domain for which toolstack tries to issue an + * exact-node claim of 50% of host memory. If the exact claim didn't consider + * non-exact claims too we would overallocate, which is exactly what claims + * are trying to prevent. + */ +static bool can_alloc(struct domain *d, unsigned int memflags, + unsigned long request) +{ + nodeid_t node = (memflags & MEMF_exact_node) ? MEMF_get_node(memflags) : + NUMA_NO_NODE; + + if ( outstanding_claims + request <= total_avail_pages ) + { + if ( node == NUMA_NO_NODE ) + return true; + + if ( pernode_oc[node] + request <= pernode_avail_pages[node] ) + return true; + } + + /* + * Not enough unclaimed memory. Only allow if it's already claimed on the + * right node. d->claim_node == NUMA_NO_NODE if the claim isn't on an + * exact node. + * + * Only refcounted allocs attributed to domains may have been claimed + */ + + return d && d->claim_node == node && d->outstanding_pages >= request && + !(memflags & MEMF_no_refcount); +} + /* Allocate 2^@order contiguous pages. */ static struct page_info *alloc_heap_pages( unsigned int zone_lo, unsigned int zone_hi, @@ -1021,9 +1061,7 @@ static struct page_info *alloc_heap_pages( * Claimed memory is considered unavailable unless the request * is made by a domain with sufficient unclaimed pages. */ - if ( (outstanding_claims + request > total_avail_pages) && - ((memflags & MEMF_no_refcount) || - !d || d->outstanding_pages < request) ) + if ( !can_alloc(d, memflags, request) ) { spin_unlock(&heap_lock); return NULL; From patchwork Fri Mar 14 17:24:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017216 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C28E7C282EC for ; Fri, 14 Mar 2025 17:32:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.914976.1320659 (Exim 4.92) (envelope-from ) id 1tt8t9-00051y-Ay; Fri, 14 Mar 2025 17:32:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 914976.1320659; Fri, 14 Mar 2025 17:32:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8t9-00051h-6M; Fri, 14 Mar 2025 17:32:03 +0000 Received: by outflank-mailman (input) for mailman id 914976; Fri, 14 Mar 2025 17:32:01 +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 1tt8nL-0003IK-5c for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:26:03 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6720e508-00f9-11f0-9ab9-95dc52dad729; Fri, 14 Mar 2025 18:26:02 +0100 (CET) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-ac2bb7ca40bso444803866b.3 for ; Fri, 14 Mar 2025 10:26:02 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:26:01 -0700 (PDT) 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: 6720e508-00f9-11f0-9ab9-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973162; x=1742577962; 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=WOoPVJhq5a/XEAMxWlBgBdgROSgA1Iks8/9HeBPk9Vk=; b=kwFwRMX/icEl6/PGslirYjI0YHysECTgiUie6QxjAMGhIO4TflSp4N3km3+a/X41sL cQ+R2bTWSrc8NYu64P3lwFMGfz+uiBJyZi3NSMAZvruHu7lnTyypHn6VinkqeuFviVR7 vjhFRtsXf/xACzengGUDi/AasZH3M7P5cVMEM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973162; x=1742577962; 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=WOoPVJhq5a/XEAMxWlBgBdgROSgA1Iks8/9HeBPk9Vk=; b=N8JJA5BFNRvZDmvCGZPmSvHYC9jQtAnhZuvADBoc5IZlatT4iVujxTNIQOX3oIUXBI sd7yRldV460cjYJM3vFJuuNtsEA7mwtOvsUUdB1Vz1j65ibj24NZkPEI1Q2xwqUlTIlx 8WVFfVbDI4hr+1qdCCyS17a4VNFHupQvLGRqKXqPSrGXqptVn+xQt9IM3zkLz02eKVvi CXhy1ozyZXsKBu4BJQgkPR6dEBmWkn860Lm/HBUJrTKx1hR2FGryaerPdXkFxj+kOCJT y9qB1NId7oREdkag8zQzCCIxEaz9ySVRKhO9REP3BOiUHFv/sBWeMoFxZq1LqOwcqYyK vdwg== X-Gm-Message-State: AOJu0Yxa+/cjQ8xamjrkNoNTJd8fGh55oNXe2By+1dQxyQoqG2mOQvTE 1Tue16Te/UQq9fvQhKvgWPY5zFKSum4WFiH+e952OD+3KzgMZsH6qrF85CsRsvDBI2U/BKMcpzI v X-Gm-Gg: ASbGncuyvzvwWZ5uoS5LymcQGsGtrZwzfllBAshJ7K8+V3bJDPKPT9gO4KjlUGnDPFc /OnOyxCYySnjlBYrWJgFQE82sM075EQaaBq7dXmSt2JcDGdkmQ2HDpDXomUkfa0u95BBMfaAz57 32cnRTit2t4wQ6ufgYS0kHqu4cA9IY14DE82HytwKuCn0yMqpOrFRA0X/Ra2YXRwxN+wbubC08j 70aWBEX1IxkZN5j/NigJKVkqJpe2XgVOQyqRUeGz4k+uXK2l9M7BnKZ3jbhppYbn0JhURQeZput tHcIc0vO0CRDlj8bvixfokxKOxhQIU0zzwVpgal876ARCo1uBUYsKF0qbkSA/ssRi7E= X-Google-Smtp-Source: AGHT+IH7BlA4vCgTd4VLYiuH5xIPV1du5rzeNPEjhgKwzB0hRnTvUWdLLIXdHbXU2JzPDm4QdcUwAg== X-Received: by 2002:a17:907:9713:b0:ac2:7e56:5ca5 with SMTP id a640c23a62f3a-ac3302771cdmr393348266b.34.1741973161918; Fri, 14 Mar 2025 10:26:01 -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_Pau_Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH 07/11] xen/page_alloc: Set node affinity when claiming pages from an exact node Date: Fri, 14 Mar 2025 17:24:58 +0000 Message-ID: <20250314172502.53498-8-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 Set the domain's node affinity to the claimed node if the claim specified an exact node. Do it immediately before making any changes in case setting the affinity fails (even though it shouldn't). This allows preferentially allocating from the closest NUMA node when "exact" is not specified (e.g: p2m tables, etc). Signed-off-by: Alejandro Vallejo --- Toolstacks can just do it themselves, but it's more error prone. If it claimed pages from an exact node (and remember we can only hold a single claim at a time) it makes no sense for the domain to be intentionally allocating from NUMA nodes other than its home node. --- xen/common/page_alloc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index cfaa64d3b858..e69a5fcc8d31 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -586,10 +586,16 @@ int domain_set_outstanding_pages(struct domain *d, nodeid_t node, if ( node != NUMA_NO_NODE ) { - avail_pages = pernode_avail_pages[node] - pernode_oc[node]; + nodemask_t affinity = NODE_MASK_NONE; + avail_pages = pernode_avail_pages[node] - pernode_oc[node]; if ( pages > avail_pages ) goto out; + + node_set(node, affinity); + ret = domain_set_node_affinity(d, &affinity); + if ( ret ) + goto out; } /* yay, claim fits in available memory, stake the claim, success! */ From patchwork Fri Mar 14 17:24:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017196 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1BC4AC282EC for ; Fri, 14 Mar 2025 17:30:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.914922.1320548 (Exim 4.92) (envelope-from ) id 1tt8rq-0008OG-S3; Fri, 14 Mar 2025 17:30:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 914922.1320548; Fri, 14 Mar 2025 17:30:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8rq-0008O9-PS; Fri, 14 Mar 2025 17:30:42 +0000 Received: by outflank-mailman (input) for mailman id 914922; Fri, 14 Mar 2025 17:30:41 +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 1tt8nM-0003IK-8K for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:26:04 +0000 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [2a00:1450:4864:20::62d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 67bd6e5a-00f9-11f0-9ab9-95dc52dad729; Fri, 14 Mar 2025 18:26:03 +0100 (CET) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-ab7430e27b2so432440766b.3 for ; Fri, 14 Mar 2025 10:26:03 -0700 (PDT) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac3146aeb24sm250677566b.9.2025.03.14.10.26.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:26:02 -0700 (PDT) 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: 67bd6e5a-00f9-11f0-9ab9-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973163; x=1742577963; 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=VE78O4y1CQrjvnjU/sv6CX84h6wiIa5A36mM72fUABs=; b=Jvk38QZZ8GOKvvSiZGYZSjtelHZW2dNvfUFuoydPbJKSRl7lIqiNBwL4HWHrGHYxzq 0GUZ3aZY7S+6dIFa1P24UzjTfn1t5JF3DSghqx+01XeJeNTuf/X7Z2Mc4Gfh+eUmuq97 TdwAyTP5lVBraGsHaPYzTX2+Vx+KmqxBPgllU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973163; x=1742577963; 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=VE78O4y1CQrjvnjU/sv6CX84h6wiIa5A36mM72fUABs=; b=oSacrO302I0aOdbuGOzi6WQsB3EYS4tnY0pdrv+x6anmvxjLbZE66rA0iaFnlmj6qD CHy/sTRskQtquKa4NGEgamm+x4nYqqKy1v4808bx28KDHFUaoyRcoZfq2urwTz0v+z0P 06sP0wBECT4LkgIUI1Rr3N00BiwjjwU/cY2OSfiKULNhIyfyEVpA0kAPrDeiMhxI4KKA yJTBq7PMyAFS9reMGZ4MBBxtK0irMXr0zxV4ZX6MwbEJaZAp6R5bd+KgPgKBW3v9vt39 pquzvXDv7x3CalkrVV+fQJyJ9XXvE3HG9ofZslMLvXYY7aAB75kk1J3uBJDR/huvRpTy t3pQ== X-Gm-Message-State: AOJu0YzxKB1vMonfEVkQRMzu3Qa5yeUq1SUlN8pU6W7N9/dUSgZnRCV2 kMNU3Nqus52FG0SvsiYKZ2yvHstyMPImUCZHiCWY+7vydOin6bUD4G+ao5Gh13/4FQJFnXtgZci O X-Gm-Gg: ASbGncshsLxQiJwHma+wZMCKhXes2CrnlJcOSWumvTyfmWYnvzZdUV83GjWDmdLnfbp aNcloptpnVGGLBZ+0X8xuYtPqKoyS5NQFug4M0zi3+ekV8iyXWjLEy5xFxy793zbS5thBIH4T7h 2nL+v2jE+svQ/ObVGpkI2DMzdn9Sh5oj/hYBTk6hYn0TGyRw0GB3qiIpO2vK7e1OizdB61aNIRS Ypg3rXG32cUHQGMdeMRqIyJOiDFlHOXHwHMdeX2FcxLAH40aH7fA1QnClsY5tSxs9kbS6udd4he I2khJDGMHDO5iZl9OetkZiC/h/p1Pj+92F7VKfjhIBtvxXuPrTjUzTt3VU4K1QQq9Fs= X-Google-Smtp-Source: AGHT+IEdopHbhE1LscWV8fC/ITAGnDYTgseivOma1qqY5jAv9prfwdGhdthegQG/gWPHu/DlBzBzUA== X-Received: by 2002:a17:907:2d91:b0:ac2:d6d1:fe65 with SMTP id a640c23a62f3a-ac3303bb742mr421704566b.41.1741973162944; Fri, 14 Mar 2025 10:26:02 -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_Pau_Monn=C3=A9?= , Stefano Stabellini Subject: [PATCH 08/11] xen/memory: Enable parsing NUMA node argument in XENMEM_claim_pages Date: Fri, 14 Mar 2025 17:24:59 +0000 Message-ID: <20250314172502.53498-9-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 Extract a NUMA node from mem_flags. This _must_ be an exact node, and has the semantics of making a claim on a specific node. Signed-off-by: Alejandro Vallejo --- xen/common/memory.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index 1ab0bac4e7da..28f9db89ba62 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1659,6 +1659,9 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) break; case XENMEM_claim_pages: + { + nodeid_t node; + if ( unlikely(start_extent) ) return -EINVAL; @@ -1671,9 +1674,23 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) if ( reservation.extent_order != 0 ) return -EINVAL; - if ( reservation.mem_flags != 0 ) + /* Only allow NUMA-related memory flags to claim on exact nodes */ + if ( (reservation.mem_flags & + !XENMEMF_exact_node(XENMEMF_node_mask - 1)) != 0 ) return -EINVAL; + node = XENMEMF_get_node(reservation.mem_flags); + if ( node != NUMA_NO_NODE ) + { + /* Disallow advisory nodes. If present, must be exact */ + if ( !(reservation.mem_flags & XENMEMF_exact_node_request) ) + return -EINVAL; + + /* Disallow nodes that would overflow the in-hypervisor arrays */ + if ( node >= MAX_NUMNODES ) + return -EINVAL; + } + d = rcu_lock_domain_by_id(reservation.domid); if ( d == NULL ) return -EINVAL; @@ -1681,13 +1698,13 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) rc = xsm_claim_pages(XSM_PRIV, d); if ( !rc ) - rc = domain_set_outstanding_pages(d, NUMA_NO_NODE, - reservation.nr_extents); + rc = domain_set_outstanding_pages(d, node, reservation.nr_extents); rcu_unlock_domain(d); break; + } case XENMEM_get_vnumainfo: { struct xen_vnuma_topology_info topology; From patchwork Fri Mar 14 17:25:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017208 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CCE89C35FF3 for ; Fri, 14 Mar 2025 17:31:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.914961.1320569 (Exim 4.92) (envelope-from ) id 1tt8ss-00027B-IF; Fri, 14 Mar 2025 17:31:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 914961.1320569; Fri, 14 Mar 2025 17:31:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8ss-000274-Ew; Fri, 14 Mar 2025 17:31:46 +0000 Received: by outflank-mailman (input) for mailman id 914961; Fri, 14 Mar 2025 17:31:45 +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 1tt8nP-0003IK-3g for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:26:07 +0000 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [2a00:1450:4864:20::62d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 697c3ddf-00f9-11f0-9ab9-95dc52dad729; Fri, 14 Mar 2025 18:26:06 +0100 (CET) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-abbb12bea54so470398766b.0 for ; Fri, 14 Mar 2025 10:26:06 -0700 (PDT) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac3146aeb24sm250677566b.9.2025.03.14.10.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:26:05 -0700 (PDT) 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: 697c3ddf-00f9-11f0-9ab9-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973166; x=1742577966; 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=MOjAhdF7qm8ksHnQkFS3/1fokHq1z8lXtNWmszHnXSE=; b=d81bqqgmBJso9gkC6tpSq/i/bgIqqf2qcnZqYuQBDH2EqSFaN3qzFNOul1DmQ+m1ZJ XcH6cPRES+mxBG6BE9sSGm/L0cG7j7umZihcfSr92YPVtL/fV8NW8Nwpc4y1tHOt9FlV PxmW7Z1TccvfsMxW4pWFKtZAR8v7B4SYSj/+4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973166; x=1742577966; 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=MOjAhdF7qm8ksHnQkFS3/1fokHq1z8lXtNWmszHnXSE=; b=onvfNBZQvTEWTF0JIz/R9cLxyWSj7uw0QgGogYaVp9asc9h9QOqQy17xLfVyr6ygCT kk0iGrS+2e3ibaNOF3IiWTMTyoxgZfmMNt5pxPE/35llOosB9+UVx9nu8T6I3Rc/d0Uw rxPrYza252DrQ+L/VZo3cWQv02lS/DFwT0pAiOqBZZ9JDhciI5Kb4sk+pYOK7x0fyE6K 5yFbxs0Si9WCbPBaNAPoNwGjTB3yUquzsiL8eAB/4toWpYtX4F5lzV8qik4FFNfAS16m tQBzB85QtQI8XtMa8nGtoN219VGojEAi5ZHPUn/GCbFSCkvcRgrne8n02X90OwQIlXL/ V7Lg== X-Gm-Message-State: AOJu0YywwUlAjnOXnqj58btz0VMBctPPLGAkuCg7kpNHl7lVk+iQt86F 31KwWAvCK0YaCQCjjPH3/jxr510aLHtV20R8fjwRWEKMai+BtDuZa+jHWLTisYSdqgavyNj9Nip l X-Gm-Gg: ASbGncv8DYNaMB/mxc6a2VTmvOb3B1MAylqu5b7K3S/a5XN2WHQq+ol2418YM6zwxc2 Ed2mOggfV7+AHNtATsKR4byQ2dkTXuVO3FUOwtz3YCYY3/3M3GkF4x4hV8Z4KJoDSCRTdhIztyn p8+0SPb4cTTTuwntmz9bX6yFk6QnbLTtl6MMYVVsRjKvjieX60k5uwmtv05VaiYsX0ylHdUxAuZ DU9yNH3WaQ58yIYHtOCCICtiETaI9V4ct4gZM9oCuzxx/35uYkiEJDbCWc9OmZZvjDIKWhBqdg4 c7ViWY0UainClPfJLicNl64FvQctFdDSXLkIOSGU79ZKXeM6ydxhTSsMyI7qhpWvteA= X-Google-Smtp-Source: AGHT+IFTtWZo8oNgpaaF/0kjmDvlIbxSdV9ixIZGHstTxzXk8JN8Qx0wCV70Trz4hr56UcZiaQbMnQ== X-Received: by 2002:a17:907:868c:b0:ac2:8a4:b9db with SMTP id a640c23a62f3a-ac33017726fmr415971366b.16.1741973165827; Fri, 14 Mar 2025 10:26:05 -0700 (PDT) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Bernhard Kaindl , Anthony PERARD , Juergen Gross Subject: [PATCH 09/11] tools/xc: Add `node` argument to xc_domain_claim_pages() Date: Fri, 14 Mar 2025 17:25:00 +0000 Message-ID: <20250314172502.53498-10-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 Add a node argument to make an exact-node claim. NUMA_NO_NODE means to make a regular any-node claim. No functional change. Signed-off-by: Alejandro Vallejo --- tools/include/xenctrl.h | 1 + tools/libs/ctrl/xc_domain.c | 13 ++++++++++++- tools/libs/guest/xg_dom_x86.c | 8 +++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 495598123133..2b63992e1246 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1322,6 +1322,7 @@ int xc_domain_populate_physmap_exact(xc_interface *xch, int xc_domain_claim_pages(xc_interface *xch, uint32_t domid, + unsigned int node, unsigned long nr_pages); int xc_domain_memory_exchange_pages(xc_interface *xch, diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index 2ddc3f4f426d..f2c6eda875dc 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -20,6 +20,7 @@ */ #include "xc_private.h" +#include "xenguest.h" #include #include @@ -1072,13 +1073,23 @@ int xc_domain_remove_from_physmap(xc_interface *xch, int xc_domain_claim_pages(xc_interface *xch, uint32_t domid, + unsigned int node, unsigned long nr_pages) { int err; + unsigned int mem_flags = 0; + + if ( node != XC_NUMA_NO_NODE ) + { + if ( node >= 0xFF ) + return -EINVAL; + mem_flags = XENMEMF_exact_node(node); + } + struct xen_memory_reservation reservation = { .nr_extents = nr_pages, .extent_order = 0, - .mem_flags = 0, /* no flags */ + .mem_flags = mem_flags, .domid = domid }; diff --git a/tools/libs/guest/xg_dom_x86.c b/tools/libs/guest/xg_dom_x86.c index cba01384ae75..ac05106a8c1c 100644 --- a/tools/libs/guest/xg_dom_x86.c +++ b/tools/libs/guest/xg_dom_x86.c @@ -1199,6 +1199,7 @@ static int meminit_pv(struct xc_dom_image *dom) if ( dom->claim_enabled ) { rc = xc_domain_claim_pages(dom->xch, dom->guest_domid, + XC_NUMA_NO_NODE, dom->total_pages); if ( rc ) return rc; @@ -1327,7 +1328,8 @@ static int meminit_pv(struct xc_dom_image *dom) /* Ensure no unclaimed pages are left unused. * OK to call if hadn't done the earlier claim call. */ - xc_domain_claim_pages(dom->xch, dom->guest_domid, 0 /* cancel claim */); + xc_domain_claim_pages(dom->xch, dom->guest_domid, XC_NUMA_NO_NODE, + 0 /* cancel claim */); return rc; } @@ -1442,7 +1444,7 @@ static int meminit_hvm(struct xc_dom_image *dom) * allocated is pointless. */ if ( claim_enabled ) { - rc = xc_domain_claim_pages(xch, domid, + rc = xc_domain_claim_pages(xch, domid, XC_NUMA_NO_NODE, target_pages - dom->vga_hole_size); if ( rc != 0 ) { @@ -1642,7 +1644,7 @@ static int meminit_hvm(struct xc_dom_image *dom) out: /* ensure no unclaimed pages are left unused */ - xc_domain_claim_pages(xch, domid, 0 /* cancels the claim */); + xc_domain_claim_pages(xch, domid, XC_NUMA_NO_NODE, 0 /* cancel claim */); return rc; } From patchwork Fri Mar 14 17:25:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017197 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1F073C35FF1 for ; Fri, 14 Mar 2025 17:31:04 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.914927.1320559 (Exim 4.92) (envelope-from ) id 1tt8s2-0000Qu-3c; Fri, 14 Mar 2025 17:30:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 914927.1320559; Fri, 14 Mar 2025 17:30:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8s2-0000Qn-0J; Fri, 14 Mar 2025 17:30:54 +0000 Received: by outflank-mailman (input) for mailman id 914927; Fri, 14 Mar 2025 17:30:52 +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 1tt8nQ-0003IK-KG for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:26:08 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6a4edf74-00f9-11f0-9ab9-95dc52dad729; Fri, 14 Mar 2025 18:26:08 +0100 (CET) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-ac298c8fa50so442965766b.1 for ; Fri, 14 Mar 2025 10:26:08 -0700 (PDT) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac3146aeb24sm250677566b.9.2025.03.14.10.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:26:06 -0700 (PDT) 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: 6a4edf74-00f9-11f0-9ab9-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973167; x=1742577967; 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=1ad2q/lNaa8nGqhVkQjql1BQSL/I28Cvr3/N4q8Vco4=; b=U76r3I6gjKJm5jsbFB+qyFaRosiiox8NSIaBK0B43EKgDLzREQDZcua8x2aaLhTZjN DXRNaDiT2T83HqWirelVMZ4OOHkg3OqyFmruFdLu+M8E5M/bNye5qb+TJ3KNqeQoQUO9 5FYIS2A6JW8qnhFgj+VjP8pTfLNcnsutkkcOA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973167; x=1742577967; 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=1ad2q/lNaa8nGqhVkQjql1BQSL/I28Cvr3/N4q8Vco4=; b=TTm3QDa09IuVsAYtaXBPjyh6tXijax0LiBavLut621cJYr9lefgJvu6LotSFyQH76q 1VuyqtxNLbFw3PrXYN8oSycxbEczWSwnwMvGDeWwxLCCAPp0cKVZXE1ooEoTV1R951lk sAIg1/FSJ5XVuJbEwTdtPLwCXwCGhEV65B/BSFzoK1euolrQLEKw9OWZQpR+BtDgyJ1z xb8IUUgdUZL/9PmFSpt+FgULVexL3hq2WzcU3nKWqK7GUQeoVuWVA74mzBPdiLVIp6V4 Fl/ajOh19gnR2NvMh7Ag+/MAd8OmGx/sV6ByMd7D3J+opThv9m0qWtI0m7BVCilxmmdr wW1w== X-Gm-Message-State: AOJu0YyA2D5Bt6VLVG4gvHUVJmhtevao9QPa0k8gvuXiMswGW9Wd1lH9 6mt2w9kTqfLsa6st8GwzkmWZWZAmzFvsqjUPehUBMQq73RVdgAV8MVEXM2GAyXNL2/ZGYSzpKAA h X-Gm-Gg: ASbGncuA2t3o09Q4ytA8LM9fMVROZwWbVa76TcvO2nPIfbTyTlPl8aEq67mO/M7rKk7 TkD+E6ZwsIl3m8gtJFEp6kBGshvQhZRMg4eZzDvdxTWJg493ohAggEsLb8Jiyg5gCPsToSwna+v gU002/0TTvMinkK3p0l9fdtQse4R4CljCLsjrH9Vy2JmJ38V6WvTy49SAt8Zb2wzEEq4+XPMCRI e3Fg1WOSm8PoNXfyerVGNa2XLRox1fo9IUnVWaVg5aOw8jOV6wKnFeZkTIo0eOkxkoFNlOg5VE6 OCFrods7Z7T9lldrtmgLGxk/x7w/svV7IIxON/zl+6/EnRgV8Uu2jZ49N3wqdW/QaqQ= X-Google-Smtp-Source: AGHT+IGnOtlOn5MCkxiSggIOkGMsP3nNHIaHWre+D8PwogdaxXdi3HQeeBQNfbBXkVi4PeSs/lvyKw== X-Received: by 2002:a17:907:7fa1:b0:ac2:4fe0:1dae with SMTP id a640c23a62f3a-ac3302c7536mr424144566b.24.1741973167063; Fri, 14 Mar 2025 10:26:07 -0700 (PDT) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Bernhard Kaindl , Nick Rosbrook , George Dunlap , Anthony PERARD , Juergen Gross Subject: [PATCH 10/11] tools/xl: Expose a "claim_on_node" setting in xl.cfg Date: Fri, 14 Mar 2025 17:25:01 +0000 Message-ID: <20250314172502.53498-11-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 Expose a setting to explicitly select a NUMA node for created domains If the hypervisor can't reserve enough memory in the relevant NUMA node it fails the claim early. Also, disable automatic NUMA placement when this new option is enabled. Signed-off-by: Alejandro Vallejo --- tools/golang/xenlight/helpers.gen.go | 2 ++ tools/golang/xenlight/types.gen.go | 1 + tools/include/xenguest.h | 7 +++++++ tools/libs/guest/xg_dom_core.c | 1 + tools/libs/guest/xg_dom_x86.c | 18 +++++++++--------- tools/libs/light/libxl_dom.c | 2 ++ tools/libs/light/libxl_types.idl | 3 ++- tools/xl/xl_parse.c | 11 +++++++++++ 8 files changed, 35 insertions(+), 10 deletions(-) diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/helpers.gen.go index 90846ea8e882..9204020224d5 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1108,6 +1108,7 @@ x.LlcColors[i] = uint32(v) if err := x.ClaimMode.fromC(&xc.claim_mode);err != nil { return fmt.Errorf("converting field ClaimMode: %v", err) } +x.ClaimOnNode = uint32(xc.claim_on_node) x.EventChannels = uint32(xc.event_channels) x.Kernel = C.GoString(xc.kernel) x.Cmdline = C.GoString(xc.cmdline) @@ -1472,6 +1473,7 @@ cLlcColors[i] = C.uint32_t(v) if err := x.ClaimMode.toC(&xc.claim_mode); err != nil { return fmt.Errorf("converting field ClaimMode: %v", err) } +xc.claim_on_node = C.uint32_t(x.ClaimOnNode) xc.event_channels = C.uint32_t(x.EventChannels) if x.Kernel != "" { xc.kernel = C.CString(x.Kernel)} diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/types.gen.go index e7667f1ce3a3..1c6319200411 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -577,6 +577,7 @@ Irqs []uint32 Iomem []IomemRange LlcColors []uint32 ClaimMode Defbool +ClaimOnNode uint32 EventChannels uint32 Kernel string Cmdline string diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h index e01f494b772a..08aae1e24e4c 100644 --- a/tools/include/xenguest.h +++ b/tools/include/xenguest.h @@ -185,6 +185,13 @@ struct xc_dom_image { uint32_t guest_domid; int claim_enabled; /* 0 by default, 1 enables it */ + /* + * Exact NUMA node on which to allocate memory from. + * + * XC_NUMA_NO_NODE by default. + */ + unsigned int claim_on_node; + int xen_version; xen_capabilities_info_t xen_caps; diff --git a/tools/libs/guest/xg_dom_core.c b/tools/libs/guest/xg_dom_core.c index 595b0a667c03..152ec8ea6591 100644 --- a/tools/libs/guest/xg_dom_core.c +++ b/tools/libs/guest/xg_dom_core.c @@ -775,6 +775,7 @@ struct xc_dom_image *xc_dom_allocate(xc_interface *xch, dom->parms->p2m_base = UNSET_ADDR; dom->flags = SIF_VIRT_P2M_4TOOLS; + dom->claim_on_node = XC_NUMA_NO_NODE; dom->alloc_malloc += sizeof(*dom); return dom; diff --git a/tools/libs/guest/xg_dom_x86.c b/tools/libs/guest/xg_dom_x86.c index ac05106a8c1c..4fe816b9bcb4 100644 --- a/tools/libs/guest/xg_dom_x86.c +++ b/tools/libs/guest/xg_dom_x86.c @@ -1199,7 +1199,7 @@ static int meminit_pv(struct xc_dom_image *dom) if ( dom->claim_enabled ) { rc = xc_domain_claim_pages(dom->xch, dom->guest_domid, - XC_NUMA_NO_NODE, + dom->claim_on_node, dom->total_pages); if ( rc ) return rc; @@ -1209,9 +1209,10 @@ static int meminit_pv(struct xc_dom_image *dom) * that this is a valid state if libxl doesn't provide any * vNUMA information. * - * The dummy values make libxc allocate all pages from - * arbitrary physical nodes. This is the expected behaviour if - * no vNUMA configuration is provided to libxc. + * If there's an outstanding claim on a node, memory is allocated from that + * node. Otherwise the dummy values make libxc allocate all pages from + * arbitrary physical nodes. This is the expected behaviour if no vNUMA + * configuration is provided to libxc and. * * Note that the following hunk is just for the convenience of * allocation code. No defaulting happens in libxc. @@ -1227,7 +1228,7 @@ static int meminit_pv(struct xc_dom_image *dom) nr_vnodes = 1; vnode_to_pnode = dummy_vnode_to_pnode; - vnode_to_pnode[0] = XC_NUMA_NO_NODE; + vnode_to_pnode[0] = dom->claim_on_node; } else { @@ -1357,7 +1358,6 @@ static int meminit_hvm(struct xc_dom_image *dom) unsigned long stat_normal_pages = 0, stat_2mb_pages = 0, stat_1gb_pages = 0; unsigned int memflags = 0; - int claim_enabled = dom->claim_enabled; uint64_t total_pages; xen_vmemrange_t dummy_vmemrange[2]; unsigned int dummy_vnode_to_pnode[1]; @@ -1397,7 +1397,7 @@ static int meminit_hvm(struct xc_dom_image *dom) nr_vmemranges++; } - dummy_vnode_to_pnode[0] = XC_NUMA_NO_NODE; + dummy_vnode_to_pnode[0] = dom->claim_on_node; nr_vnodes = 1; vmemranges = dummy_vmemrange; vnode_to_pnode = dummy_vnode_to_pnode; @@ -1443,8 +1443,8 @@ static int meminit_hvm(struct xc_dom_image *dom) * actually allocates memory for the guest. Claiming after memory has been * allocated is pointless. */ - if ( claim_enabled ) { - rc = xc_domain_claim_pages(xch, domid, XC_NUMA_NO_NODE, + if ( dom->claim_enabled ) { + rc = xc_domain_claim_pages(xch, domid, dom->claim_on_node, target_pages - dom->vga_hole_size); if ( rc != 0 ) { diff --git a/tools/libs/light/libxl_dom.c b/tools/libs/light/libxl_dom.c index 94fef374014e..1a5500702239 100644 --- a/tools/libs/light/libxl_dom.c +++ b/tools/libs/light/libxl_dom.c @@ -663,6 +663,7 @@ int libxl__build_pv(libxl__gc *gc, uint32_t domid, dom->xenstore_evtchn = state->store_port; dom->xenstore_domid = state->store_domid; dom->claim_enabled = libxl_defbool_val(info->claim_mode); + dom->claim_on_node = info->claim_on_node; dom->max_vcpus = info->max_vcpus; if (info->num_vnuma_nodes != 0) { @@ -1090,6 +1091,7 @@ int libxl__build_hvm(libxl__gc *gc, uint32_t domid, mem_size = (uint64_t)(info->max_memkb - info->video_memkb) << 10; dom->target_pages = (uint64_t)(info->target_memkb - info->video_memkb) >> 2; dom->claim_enabled = libxl_defbool_val(info->claim_mode); + dom->claim_on_node = info->claim_on_node; if (info->u.hvm.mmio_hole_memkb) { uint64_t max_ram_below_4g = (1ULL << 32) - (info->u.hvm.mmio_hole_memkb << 10); diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_types.idl index bd4b8721ff19..a252b36c2b5d 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -617,7 +617,8 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("irqs", Array(uint32, "num_irqs")), ("iomem", Array(libxl_iomem_range, "num_iomem")), ("llc_colors", Array(uint32, "num_llc_colors")), - ("claim_mode", libxl_defbool), + ("claim_mode", libxl_defbool), + ("claim_on_node", uint32), ("event_channels", uint32), ("kernel", string), ("cmdline", string), diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 089a88935aff..5880a032e6d6 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1558,6 +1558,17 @@ void parse_config_data(const char *config_source, exit(1); libxl_defbool_set(&b_info->claim_mode, claim_mode); + e = xlu_cfg_get_bounded_long (config, "claim_on_node", 0, + 254, &l, 1); + if (e == ESRCH) /* not specified */ + b_info->claim_on_node = ~0U; + else if (!e) { + libxl_defbool_set(&b_info->numa_placement, false); + libxl_defbool_set(&b_info->claim_mode, true); + b_info->claim_on_node = l; + } + else + exit(1); if (xlu_cfg_get_string (config, "on_poweroff", &buf, 0)) buf = "destroy"; From patchwork Fri Mar 14 17:25:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Vallejo X-Patchwork-Id: 14017207 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7CD96C282EC for ; Fri, 14 Mar 2025 17:31:55 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.914963.1320575 (Exim 4.92) (envelope-from ) id 1tt8ss-0002AN-S2; Fri, 14 Mar 2025 17:31:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 914963.1320575; Fri, 14 Mar 2025 17:31:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tt8ss-00029c-M8; Fri, 14 Mar 2025 17:31:46 +0000 Received: by outflank-mailman (input) for mailman id 914963; Fri, 14 Mar 2025 17:31:45 +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 1tt8nV-0003IK-3V for xen-devel@lists.xenproject.org; Fri, 14 Mar 2025 17:26:13 +0000 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [2a00:1450:4864:20::633]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6d0d8caa-00f9-11f0-9ab9-95dc52dad729; Fri, 14 Mar 2025 18:26:12 +0100 (CET) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-ac2ed007aacso471710366b.0 for ; Fri, 14 Mar 2025 10:26:12 -0700 (PDT) Received: from localhost.localdomain ([66.81.170.107]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac3146aeb24sm250677566b.9.2025.03.14.10.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 10:26:11 -0700 (PDT) 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: 6d0d8caa-00f9-11f0-9ab9-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1741973172; x=1742577972; 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=xM6Gpx3RAeeK1cS7aS7L8nNeRymkrBxeUEa3FM/T9W8=; b=VwcO7GDdwGkhy8sl5JtDbfF8GMUPD1u4jETFbeHSOMNBguBHiK0oLrLHrVxnrAk0ES nDBd7whfajuc39g3QwL8iLmugkOaMJmrwXNluo7UO6zeawc5Aih4uyexsyrdEoHegxb6 Sg9jakSdlCPK55VBqWwgkH9phzUDZdR5nzRlI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741973172; x=1742577972; 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=xM6Gpx3RAeeK1cS7aS7L8nNeRymkrBxeUEa3FM/T9W8=; b=jaM4M9D+FUMa6uFA6y/Gl4XCyMFNgU9ej3zxCKKsK6a6aJ+/JHramQjgMwltNoKyyR CR/aSF+r1HWBwq7YZ9jxH/ji24Wdolv3dlkS869DoBzQ5NbqgBeXEtSuQVSW7za9MXqH Lyv3h1UTl3nG+iiBJiVMuvoCkOYXHU9UTbcvvGtODFdIPjK2c86F1GsjIVpcjgzRKHqC wkX5TS9/YmWIILjjNyvplp0bNR03vS+ql4kuicmdrftZtm4hy40q3kAQhytiIf2Kntj0 yG1cDnxt1PHti1v2iizr7dwhIw990ryeTxNXiNsDsYF1i9eZ0G4I/ufvX/groQ2tNRPK dFvg== X-Gm-Message-State: AOJu0Yzb4oMoVftWo3njCUcNB8WgGVCktdB/h0K0fahpisTNORk6479K SNqNReJ911WholptRg+tzhmjMBQktAc34/jbHgbM8HBEiSkeGE/QCbGjS1HHgc8oiuinWzwh+Q/ + X-Gm-Gg: ASbGncvbz/uvpdpq9tid1AaOkj7j4qwKPtO0UUqSS35qeoW0CaEPrZkBY5n+dybRhSX QgQ5e1aYxG7ip0QOVRkagg3bQ+I4j7Lpsq0dojCksaIA5BTCv4xGk/elVBY2wXb3mwsmvfPKH0h lXFNPVlsEoBGuYTzsIJ7JcVOoRJbytuaaW+VBjoNYyD2PjE6RN/Iy8YoBSLsT3DiuPYb4wP9MVx CLqTHywtexnaJgaUTDdq0r1ZYi1tH2LNJrKbWuQakS4+rsvOgg9bT25qqgTS5e9Zv2t2HrRq2K0 3AgOSORi2To5FrEmt8YghyO9xuO8aODzaAmzWghrjZn/o7r9KCrxbLcZBSJge+nBqOY= X-Google-Smtp-Source: AGHT+IGfbH9E97ClSGH+YxIoQoOpNF6fagjScq5vU+UIamVvniNyic7xwyEhG5dNza9bp8wEwncgRQ== X-Received: by 2002:a17:906:4795:b0:ac3:2d43:2249 with SMTP id a640c23a62f3a-ac330104b97mr460261266b.2.1741973171738; Fri, 14 Mar 2025 10:26:11 -0700 (PDT) From: Alejandro Vallejo To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Bernhard Kaindl , Anthony PERARD Subject: [PATCH 11/11] docs/man: Document the new claim_on_node option Date: Fri, 14 Mar 2025 17:25:02 +0000 Message-ID: <20250314172502.53498-12-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 ... and while at it, add missing relevant links to xl-numa-placement(7) in xl.1.pod.in and xl.cfg.5.pod.in, which describes libxl's behaviour on NUMA placement. Signed-off-by: Alejandro Vallejo --- docs/man/xl-numa-placement.7.pod | 8 ++++++++ docs/man/xl.1.pod.in | 2 +- docs/man/xl.cfg.5.pod.in | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/docs/man/xl-numa-placement.7.pod b/docs/man/xl-numa-placement.7.pod index 4d83f26d412e..287ad41e5071 100644 --- a/docs/man/xl-numa-placement.7.pod +++ b/docs/man/xl-numa-placement.7.pod @@ -173,6 +173,14 @@ soft affinity belong. =back +It's possible to force memory to be allocated from a specific NUMA node via the +"claim_on_node" option (See B in L for more details on +claims). "claim_on_node" associates the domain with a single NUMA node. Domain +creation fails if not enough memory can be reserved in the node and memory is +preferentially allocated from that node at runtime. The downside is that +claiming memory on a node via "claim_on_node" doesn't automatically set +soft-affinity for the vCPUs, so that must still be done manually for a fully +optimised single-node domain. =head2 Placing the guest automatically diff --git a/docs/man/xl.1.pod.in b/docs/man/xl.1.pod.in index fe38724b2b82..27a972486296 100644 --- a/docs/man/xl.1.pod.in +++ b/docs/man/xl.1.pod.in @@ -2012,7 +2012,7 @@ otherwise behavior is undefined. Setting to 0 disables the timeout. The following man pages: L, L, L, L -L +L, L And the following documents on the xenproject.org website: diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 7339c44efd54..c1ffc29d312a 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -278,6 +278,18 @@ memory=8096 will report significantly less memory available for use than a system with maxmem=8096 memory=8096 due to the memory overhead of having to track the unused pages. +=item B + +Binds guest memory to a particular host NUMA node. Creation only starts if +enough memory on this NUMA node can be reserved beforehand on the hypervisor. +Failure to claim memory aborts creation early. + +See B in L for further details on memory claims. + +Overriding B forces B to be set on this guest and +disables automatic NUMA placement (See L for further +details on NUMA placement and the effects of this option.) + =back =head3 Guest Virtual NUMA Configuration @@ -3143,6 +3155,8 @@ If using this option is necessary to fix an issue, please report a bug. =item L +=item L + =item L =back