From nobody Wed Sep 10 08:36:08 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=1757261758; cv=none; d=zohomail.com; s=zohoarc; b=kYI3uETBzIkpEmJxjMYEpa6mollIXAJ3RuDQPnZPoY645Mbjsi07K+dew3wwYMmuj13iE7TFV69xVaMg8Yc5ybhPCz16X2g7EtcSUR97EE/wuld9OlYS8bl519EVH3Rqhem3G6fCku0zwgsUH3UqJ8RiYGmRcZ1OggHqYekPKTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757261758; 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=PTaeCc0jJZ6v4SiJ+F55XnFvKWiZFrzoLZItww1E4jk=; b=T1z+ePrP+7S3JFbXS4gnh83THCW2A7fE9FsXxURykntf2uZun1AGZOTke+bWufFa0VGFCRu27ljBFP3XhVnics0TjOqgk+qeWQ5mu3cvmLtDcXNMf5BYha/LsME3Ff9DoXjZo/yjK3S9QaC6vejBFjlgLYNF5HjLdkjLeMYJAwU= 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 1757261758443413.12130606472886; Sun, 7 Sep 2025 09:15:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.1114125.1461298 (Exim 4.92) (envelope-from ) id 1uvI3B-0000Hj-El; Sun, 07 Sep 2025 16:15:33 +0000 Received: by outflank-mailman (output) from mailman id 1114125.1461298; Sun, 07 Sep 2025 16:15:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uvI3B-0000HI-A4; Sun, 07 Sep 2025 16:15:33 +0000 Received: by outflank-mailman (input) for mailman id 1114125; Sun, 07 Sep 2025 16:15:32 +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 1uvI39-00009z-WC for xen-devel@lists.xenproject.org; Sun, 07 Sep 2025 16:15:32 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id de1eaa83-8c05-11f0-9809-7dc792cee155; Sun, 07 Sep 2025 18:15:27 +0200 (CEST) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-b04b869abb9so149718866b.1 for ; Sun, 07 Sep 2025 09:15:27 -0700 (PDT) Received: from MinisforumBD795m.phoenix-carat.ts.net ([2a02:1748:f7df:8cb1:5474:d7c3:6edd:e683]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b047b61cf00sm908263766b.15.2025.09.07.09.15.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Sep 2025 09:15:26 -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: de1eaa83-8c05-11f0-9809-7dc792cee155 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1757261727; x=1757866527; 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=PTaeCc0jJZ6v4SiJ+F55XnFvKWiZFrzoLZItww1E4jk=; b=PLN5XU9236vTRSXxf7AxvIsH1VkzJekntmRLSYgdMzlznr/lrxrb80EFEJXDdzhenk E/kXwI0bEbUQ/n6669oUhU6OCrHfM2oMs+bxD2WOzg6p/UZoB7q39ta0lCFfq9DNq0uZ 3X54wqcL6JdqvbxBI+tib5bSyaACGO3zVConY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757261727; x=1757866527; 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=PTaeCc0jJZ6v4SiJ+F55XnFvKWiZFrzoLZItww1E4jk=; b=OcxMg/4cMolaInqKr2DFPwnAN2pRsLcFO0ps0stJwWutwMLvmbHSvsJfBoHYWT9oiF in83eABDiXtbLkQVK72ZTpXtHraszwpO5u8K44WXFMTSov6e400T2yRM5AW30O5tUjJV zz1iU/oYRGt3X2tqy2UtIK7SDGPtbdpQejRByT7VmgShAgqDvvZ/I7vFW81Ijn97odOK ii1R0v8Ahl7WWYtfhCvPgXW3pcvM2BxXLhy8OuWFUXMFdNHrEDsrjdiEuTwOwJKvmcrb OWW2FDq948FdxqG0Jj25LKJrl0xnkPFID9XQAE7813B86UBvJCRIBxMutNRMCCiRTb65 VB/Q== X-Gm-Message-State: AOJu0YyyHjrxkGWJjWMUAHUomUB08fal8dw+iLBkiAstKLDErhF89pqG vhwxUzjmjm3aFSiaF4J2XNuy/74z9GwuKWd1FdaKp2HBb1N6TADyIKdj3m/vqB6N1TD01kTDWt6 aYLkTivE= X-Gm-Gg: ASbGncssaNeR0KuoroW7tfBb4xTqo0jz2XffUjWHrWLwuniwuktsXVX+qyBUAbbFvGZ Iva+2KCZGe4BFlpSlY/5nm74IQALnIeko1/tXN6KqtqwxLEL7q3QubagPhMTrtkZaGOmh2Eh1xk NivjA4aNoFfDDSgT5l7xHF6Guo6oUMMQdpUYU4pp3x/QcKkR+7qWNAPPRO4BsiMGllK3GKfR2Ca X3SzEtjvq0q8jNyEXQ7zI0TCosbqIRJGvd5FilRSLhy5CaKIiV7nQgG07sdp5R2/jy+js+LFMHx wk2kLxk4D1xwP0pyHm/apmdAASwFAxUs1qshtyYCmvNvD3M8OjKa7U53aPEJOS4CBPlT1dMRBHF VopplWXvaN5HNWAEatJ6RjSTiDhxWYaqZ9amxjwonUccWHE7fbTw7VGzVxhOC7MTFutI= X-Google-Smtp-Source: AGHT+IGQR9/J0pflFoZP8fpXWuEulGdjHQl4gGCXU4y13Rc3B7e+E6dWfnhdFZpDe8pf22mP59uS4g== X-Received: by 2002:a17:906:99c5:b0:b04:848f:a0b7 with SMTP id a640c23a62f3a-b04b1663cb3mr468611066b.41.1757261727086; Sun, 07 Sep 2025 09:15:27 -0700 (PDT) From: Bernhard Kaindl To: xen-devel@lists.xenproject.org Cc: Alejandro Vallejo , Bernhard Kaindl , Andrew Cooper , Anthony PERARD , Michal Orzel , Julien Grall , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Jan Beulich Subject: [PATCH v3 2/7] xen/page_alloc: Simplify domain_adjust_tot_pages() further Date: Sun, 7 Sep 2025 18:15:17 +0200 Message-ID: <15ae395c6933e74da0cdd8f9d71d349a7bfad3f3.1757261045.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: 1757261760441116600 Content-Type: text/plain; charset="utf-8" When domain memory is allocated, domain_adjust_tot_pages(), also reduces the outstanding claim. Replace the checks to not over-reduce the claim beyond 0 by using min() which prevents the claim to become negative (and also not be over-conumed for the node and globally) Cc: Jan Beulich Signed-off-by: Bernhard Kaindl --- Changes: - Was added as 2/7 in v2, the review by Jan Beulich is applied. --- xen/common/page_alloc.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 1f67b88a89..e056624583 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -510,8 +510,15 @@ 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. + * - On a domain's claims update, global outstanding_claims are updated as= well. + */ 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 +526,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 + 0UL, pages + 0UL); + d->outstanding_pages -=3D adjustment; + outstanding_claims -=3D adjustment; spin_unlock(&heap_lock); =20 out: --=20 2.43.0