From nobody Fri Oct 31 03:41:53 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=1755343266; cv=none; d=zohomail.com; s=zohoarc; b=ckzadA1pHKzLtk+JYS46p4vzlVUbW8m+Wu9RPnxC2KCGKvCh4ay0WoeYvuDU6xi9tjWnarMlYm6a8C4Nj65SiYIOCdVnRi/UHcvF0R0cOx9PyB1k19nePYcZZpRg2Lcm4wUD7THKGaZAHJTu5xwu+zP9lxpZiuZcW5LqYgPPNBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755343266; 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=5WfLnf5/kvCLxvLOEfumWxUHPhaPlVs8I4oO2kdVd+M=; b=kECDgVD3dRJQZq8U1qUIMcSdDGd5Ofr8L9b3+CdIdkjT+FCkRg2PPRSN0je1ZWg9j2IfaFgrMmhSu0aHHdtCsb3ceEIqW/N6V/7l8y0/KgGvTDXLC1ZZLQzOnkU/oJ1pNf7ox8v61VbznTB18DULR8uxOhzDjkSuK1F5N2oRjmQ= 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 1755343266533437.47390288736665; Sat, 16 Aug 2025 04:21:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1084446.1443594 (Exim 4.92) (envelope-from ) id 1unExx-0006KD-8Z; Sat, 16 Aug 2025 11:20:53 +0000 Received: by outflank-mailman (output) from mailman id 1084446.1443594; Sat, 16 Aug 2025 11:20:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1unExx-0006K6-5p; Sat, 16 Aug 2025 11:20:53 +0000 Received: by outflank-mailman (input) for mailman id 1084446; Sat, 16 Aug 2025 11:20: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 1unExw-0006Jf-6x for xen-devel@lists.xenproject.org; Sat, 16 Aug 2025 11:20:52 +0000 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [2a00:1450:4864:20::32e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1113acd7-7a93-11f0-a328-13f23c93f187; Sat, 16 Aug 2025 13:20:51 +0200 (CEST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-45a1abf5466so14764555e9.0 for ; Sat, 16 Aug 2025 04:20:51 -0700 (PDT) Received: from MinisforumBD795m.citrite.net ([2a02:1748:f7df:8cb1:3992:b1e9:da8a:3f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a27ec6b71sm13852325e9.10.2025.08.16.04.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Aug 2025 04:20:50 -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: 1113acd7-7a93-11f0-a328-13f23c93f187 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1755343251; x=1755948051; 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=5WfLnf5/kvCLxvLOEfumWxUHPhaPlVs8I4oO2kdVd+M=; b=LLQThDwUqjnplM/TESg62YCQZHjTwCzdqLtdNiKRmPVtDRIXhpWlOPEmtlqyTVpB/L CrNy6dZJcpjTD3nc8A+2efqgeoFyZ6psZglYAaCDZbo3dgQO0z4eOfJlJ/S18+eD/bgT VqhavyxEgG9Q9j/+UjPz0zWTMbFdfumse41Dg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755343251; x=1755948051; 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=5WfLnf5/kvCLxvLOEfumWxUHPhaPlVs8I4oO2kdVd+M=; b=M/P0ptWKFNRKcVJjUPzDEKSX7xsnIvEH+Va4IBMa/aRoFK0qsMzESi2+le6wa3HKQ/ rxKv4C1S7FMj2+GX3uySYrDRbwq9Mb3CBY52Ytz1nXO885dD5l8P9H7VusQ/BUP3/IH8 irrqYIj684vO70mK/u424YEo8c5/YP+1MOT6mr5Als9r0Eg16mwpgCtajzmQ3i0NVoZP SAJrcMiXntlUBh/YpA7nbyN8WG3V/+0PB+BiWlp+f13en6eJrTX+nDMNjg0BO9Vye5Cg c3NUPh+p6XTN4iBo/q6NcquQnDwUYaMFUePc5cve5Vox7EgucmuGPXw+ea3zYr/UF4bg LqNA== X-Gm-Message-State: AOJu0YxvqMCyTBEqbDHpNwZRHenTo/wulEUpvYioGcW4ULP6UlTqSJA5 zgBnc3rQoEPsaa0UqARHyT5OvSikaAczYQRMxIkN2YL5bDc4BnAp6cEgcaNoHuzYhMenL9ebmHl JeFhMf+c= X-Gm-Gg: ASbGncs429WUsPzqvlpMLTpif8xOKbtXkgMDnwr/TiMvpUpbhsMaN2eIoP/kNfOJSz1 Uzjyb7NEWFCvsKSjGP+QSPeh6xTUppomSaQLt5qgPQ3/DN5TN++TOrqcFgnBS72W9d6fbyH6o1d WN7NxgTH1idijEpmjWIaHR7CFRrSxQqEam4nz7Dfqoj9QUPfTCPVZNNUIvPX7WODM38u3O17g77 zkjl6ClW2ZJNqBlpQGMdmuQtRa9fy+FubzIJYyaqk60EbkrgaErarvRIZbi7kpTILI8fc7pwTCo 9pOvDhSU4DokahAS54zYANup7aFkwz2fGaeoUWK3xCGesoHvvSexMQcJrPHHQC3grOfJSz3FwlH KO76CkzeBhBhtsvokVN/zfqAdP2gWN5XE6q96lh8tjU/LyNlW+Kx6XicHFZ9NE99mpg== X-Google-Smtp-Source: AGHT+IEzPs9FkQ63BOLIzEufxuBLYDjBbOgrJbqFTH4gdP1GhoFRqjout6kGca2aCgD/lZWY9mSK7Q== X-Received: by 2002:a05:600c:8b05:b0:459:eeee:2759 with SMTP id 5b1f17b1804b1-45a1b6c7e20mr80482885e9.14.1755343250703; Sat, 16 Aug 2025 04:20:50 -0700 (PDT) From: Bernhard Kaindl To: xen-devel@lists.xenproject.org Cc: Bernhard Kaindl , Andrew Cooper , Anthony PERARD , Michal Orzel , Jan Beulich , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Alejandro Vallejo Subject: [PATCH v2 1/7] xen/page_alloc: Simplify domain_adjust_tot_pages for future changes Date: Sat, 16 Aug 2025 13:19:27 +0200 Message-ID: <5f417fea5ca8e4da0d4b9679103c3eff4bc92900.1755341947.git.bernhard.kaindl@cloud.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1755343268595124100 Content-Type: text/plain; charset="utf-8" domain_adjust_tot_pages() is used to update the domain's total pages after allocating and freeing memory. Simplify the design for updating it for single and even more so for multi-node claims regarding the case where we could have allocated more memory than we had claims left. Replace it with min() to avoid reducing the outstadings claims by more than we had left to claim: When domain memory is freed, we skip changing the claim. Thus, this only handles reducing the claims after allocating. So, min() is fine. Signed-off-by: Bernhard Kaindl Cc: Alejandro Vallejo --- xen/common/page_alloc.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index ec9dec365e..e1ac22b9ed 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -510,8 +510,14 @@ static unsigned long avail_heap_pages( return free_pages; } =20 +/* + * Update the total number of pages and outstanding claims of a domain. + * - When pages were freed, we do not increase outstanding claims. + */ unsigned long domain_adjust_tot_pages(struct domain *d, long pages) { + unsigned long adjustment; + ASSERT(rspin_is_locked(&d->page_alloc_lock)); d->tot_pages +=3D pages; =20 @@ -519,23 +525,22 @@ unsigned long domain_adjust_tot_pages(struct domain *= d, long pages) * 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 the domain has no outstanding claims (or we freed pages instead), + * we don't update outstanding claims and skip the claims adjustment. */ if ( !d->outstanding_pages || pages <=3D 0 ) 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. */ - outstanding_claims -=3D d->outstanding_pages; - d->outstanding_pages =3D 0; - } - else - { - outstanding_claims -=3D pages; - d->outstanding_pages -=3D pages; - } + /* + * Reduce claims by outstanding claims or pages (whichever is smaller): + * If allocated > outstanding, reduce the claims only by outstanding p= ages. + */ + adjustment =3D min(d->outstanding_pages, (unsigned int)pages); + d->outstanding_pages -=3D adjustment; + outstanding_claims -=3D adjustment; spin_unlock(&heap_lock); =20 out: --=20 2.43.0