From patchwork Tue Jan 7 20:40:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13929596 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 451ACE77198 for ; Tue, 7 Jan 2025 20:40:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC36C6B00AE; Tue, 7 Jan 2025 15:40:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E4CDF6B00AF; Tue, 7 Jan 2025 15:40:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8B6E6B00B0; Tue, 7 Jan 2025 15:40:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 99EAF6B00AE for ; Tue, 7 Jan 2025 15:40:27 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 633A1A036D for ; Tue, 7 Jan 2025 20:40:27 +0000 (UTC) X-FDA: 82981823694.09.AE27566 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 33E5640015 for ; Tue, 7 Jan 2025 20:40:25 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C8Sw9ES3; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736282425; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Tqf5zDG9MEFYyrwcky7SImgBB1+VbhDKSE1RWjLi9H0=; b=jw5DiETREmsmFa/Kb1z/CA0ekcP790Sn3SSnffMpA7WY2S7xh3YSme77DJVyNoQ2h+Iig0 e5m+gQvREryuhqW3+iZvWvKmwwfSyLpdlK3fhSBVxi+M0+UFbmUc6NIGeE2uCtT6sJ5Gqw 3/cB38xSdEiUzcsho+o33bTPwmF3rqc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=C8Sw9ES3; spf=pass (imf07.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736282425; a=rsa-sha256; cv=none; b=OJASBNaldprZYLwBqTnT7DBc2C4BqNot95HX+EsjTiwRrnEuCGw4xG4bchRRoIjjovQ64/ AiQgEXnvGOIQff0+isfL5v+sowhaupE3uMfP5nbq01PWezkKFwd10MGXqia7tAr3ztODLJ d0Oi2siCHFsREXdy/1B3+uw6OHB1zyU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736282424; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tqf5zDG9MEFYyrwcky7SImgBB1+VbhDKSE1RWjLi9H0=; b=C8Sw9ES3b2hTYmg7arr1/aXAIHS1VsEAiT24/2hYc8sXH0WsfVaHQrrqagV/rwCp3CmhGU BEIx3aw4vsue6ZWk6Z0+/WVMCR/nBQx9OSxFEZh0kZxQWY1KjkwPJZV+6ZD+6i34fEilus +GRNely3qrnDkvzA55+QRZwPqiloIvg= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-120-S3jTBcwMOy2iNZ5Q3F1kUA-1; Tue, 07 Jan 2025 15:40:19 -0500 X-MC-Unique: S3jTBcwMOy2iNZ5Q3F1kUA-1 X-Mimecast-MFC-AGG-ID: S3jTBcwMOy2iNZ5Q3F1kUA Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7b6e7f07332so699901985a.1 for ; Tue, 07 Jan 2025 12:40:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736282419; x=1736887219; 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=Tqf5zDG9MEFYyrwcky7SImgBB1+VbhDKSE1RWjLi9H0=; b=luSTu2u7NeeloN29ynsYETe9TfJPZLpPLAKXcZpRAjCs96UY+R3o6vFj+4NH5z3TDm mQC6ZVQvrqrxV/sK0+jb4AHY2jFRsqluRFZ7FNxxhlzLzH9Hr4D/WcAAtmyp6xVlm2cb gRR3Ss2jjK7cWgpXSH/sJPgBrwPNervEs1hz6z921JFqUJnSKRnBfIw5by4DkgAVasEh a0x2Vad+imOZj4/OLc7Kow+V5ihIocbFSBQhgdLcDNFxAfi6JJzbyKkkiRvSOwX0DyR1 6RhrC8inpXMKLG6YWFrVb4x+nrKaJYEi6RrVQ4bWbLkQTj7S5XyEELsTsVPYEL2zV9bb nzkg== X-Gm-Message-State: AOJu0YzoMuIWkjrNcJR/8ZRaV5vEDZRr3sY3mVLpVFtiRAWVwnhS2Awq /3d3ZAHNh7VZNZ8o5xEWwAEIJ44bkG9OO8vOKxFN8zQ/2FwliIc4lVRzuGlfyvhRr6tLigC1ljd Y5wKEGfhIlTvPdOhNSQ208aqx9NRUj6AahgoNLX/ud/jB9+Vxf1TzC1F03hsMY1VpQoKG90g3AK Bq/JsmLwVscllwcHcuiuxsr2NyVzxiTA== X-Gm-Gg: ASbGnct3mHt5rfIQnuL4g7Y5bPbZI2XPoHKUXWiV9acnwWWSIasGiI3rKARNc3Lw6rf y+WA+2rd3NwEK9+4LEa3nCJVWOh3FiY80J6HRDmoW68WhLtMcu7MSIbVeMzXWigM5w4BYQG+H91 6+XZqRK625ydMxvc4cPRnhd44z37IJXM2pbGttRZA83Ui9rkXNUzq9Gm/WiRnUZd9HR0bi/hbGX KHmXyHLUICuQYYEE5m0kDHGGXx2ghzeyDV6lNU+ueBV0nYpk9t2BzmAtvBCXOjtN26F9LW2WkfL +9JJiPWWTfBnTDu60Mi5JdUHN/PjWk0P X-Received: by 2002:ad4:5b8d:0:b0:6d8:a091:4f5c with SMTP id 6a1803df08f44-6df9b2ddae0mr7742976d6.33.1736282417373; Tue, 07 Jan 2025 12:40:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEO5EEzKoo4b8+dAKo+7OX2D+ltSzCgzDPjxXEVdIBKDurWSenXTIIEcfAQvgTlo32tr/LGYA== X-Received: by 2002:ad4:5b8d:0:b0:6d8:a091:4f5c with SMTP id 6a1803df08f44-6df9b2ddae0mr7742556d6.33.1736282416972; Tue, 07 Jan 2025 12:40:16 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dd181373f6sm184478306d6.62.2025.01.07.12.40.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 12:40:16 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Breno Leitao , Rik van Riel , Muchun Song , Naoya Horiguchi , Roman Gushchin , Ackerley Tng , Andrew Morton , peterx@redhat.com, Oscar Salvador Subject: [PATCH v2 6/7] mm/hugetlb: Drop vma_has_reserves() Date: Tue, 7 Jan 2025 15:40:01 -0500 Message-ID: <20250107204002.2683356-7-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250107204002.2683356-1-peterx@redhat.com> References: <20250107204002.2683356-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 5xUNE_BsARsFpoTx4wfWAZNUut0JubJklhVfsHYGEJo_1736282419 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Queue-Id: 33E5640015 X-Rspamd-Server: rspam12 X-Stat-Signature: nnozc6p93zkbnexf6kny833rf5i8bdyp X-Rspam-User: X-HE-Tag: 1736282425-70733 X-HE-Meta: U2FsdGVkX1/eKYKNxReUqNzUb9t1UYDqMret6f9SInSg1zSCSqoYzUh122vgJsnUYMYAcvRiz4RsGU7IbAPLyvt3hIaYHHPO/YIhMRLJNDKH0G7LRxrevUAaMI2Z1EogcP516Z0VYMCrjvX3G2FDforXsClnJSRuzbwUu/tDdlTrFoC7ObdklOSqeAKDw1+hFZbL3btHVrD5yXj+lvZkFN4DVX0DPtWJQqpFfos5DX8Ull3EqZDQ3Fh8qRicgvpufSCTR4JIALeyav6s2PXA1J4mCHTwTsqRrIXOdsyFE/v7bFD4eTDGkJETNnstgBC3w88P58cEMHWFgmDs+iFMvVWUq8eRNemfllAy3RynsKm/GNh6PdVpAdJRVkAZez9sp7ETs/roRqCefDdceCQOZ9Ba9OJX1kFbdNH/4BIqM9AbdnsZEKGNWfJolqG+tTpLUsM3ZuuRYhhFr/vz+ekppKw0RZshnb7X9WDAABoW+jZG+KEjIHqzyGAzJ5uivJKTANoL7EdqgFB7vElldt35H4atwow5tlga28JRqVi8cI3N3/N04dSMzyhT1EQI7wNx+NVTrLJe5c8TrX2yews7I+l0b1VgM7xy9/Zu0Ehic3ShaXBU9f2Q3mZ1x7E/wNNQidxjHtZyFSvnH/8QHED97gcUGLbY124ZWKT35YDNwWjSHwNAKE41Nd1wiliyMYGSnmIrDY7vbafenj4qKWvIolUF48iEOR8oqtEED3vmuOJM4SepUCCH2Si/1IiPvpNOJXdGqdFwSIDwbbTkZhEdcnHMQ1SDqaRTv1sul0iKwkgEpvcchdq/UkJpf+jbtmm4KPO7ZeLn90ED9hPWhD8oSR1xoOeAsy+J4lEYLyBW59089xzpP+y1AzgaWa1iQZe+i9A28EfJrBCa1L70NYsmDMhLAr3yFM9g4zDsoe++1DnJ+ghi+coeaLwh41ZlI67o17moz+tX9FNYvvJH3Hp H7W2FCxH NXu04r4ZoC3osWEex6n/kH2wA+hXY8ydbNHmRtx+n0sT5tYxLcQ0N8efmLkigXhmKj7rqXUU8EDUXWjB5hSfFbuauCoqaFQLyEZJ4xTKEm4TS5CTUJw8BF4EIyPUSIYYXlT3zaI8ALWkhLICGkanKB0JXvYyZTjLa1AZMcGDW9MegaioZLoiLwOpqBGBBlkz53I5MVZGj0wV6eAHSMLSCwVDtna9Y9VCV7VFWaNW45FpOVSdedxCYsGWA2xTcPpHlMsg5yJHxBexOHjje+SBhi5qdplNpLGg0wYfMF3+MaKPyCdIGmEGYsNmmFqt/830QUXlc9sHEg4e1ofzpuqtKhfSQr/byWWmO8vOhSaRMoIrSZd0Q5bDlpEfLh6oeOgmIIj3MvuyAL6bZBLQYQ0ccLCCcaiwp9TRulhZK61wSn7lL1e7rQ1TVdG6rjFE0yShCThSBdd9n2rkOaMwcZooMBkTXmrNIRMQNhhBnp2TczK3gUBM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: After the previous cleanup, vma_has_reserves() is mostly an empty helper except that it says "use reserve count" is inverted meaning from "needs a global reserve count", which is still true. To avoid confusions on having two inverted ways to ask the same question, always use the gbl_chg everywhere, and drop the function. When at it, rename "chg" to "gbl_chg" in dequeue_hugetlb_folio_vma(). It might be helpful for readers to see that the "chg" here is the global reserve count, not the vma resv count. Signed-off-by: Peter Xu --- mm/hugetlb.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5ec079f32f44..922d57e2413a 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1246,16 +1246,6 @@ void clear_vma_resv_huge_pages(struct vm_area_struct *vma) hugetlb_dup_vma_private(vma); } -/* Returns true if the VMA has associated reserve pages */ -static bool vma_has_reserves(long chg) -{ - /* - * Now "chg" has all the conditions considered for whether we - * should use an existing reservation. - */ - return chg == 0; -} - static void enqueue_hugetlb_folio(struct hstate *h, struct folio *folio) { int nid = folio_nid(folio); @@ -1341,7 +1331,7 @@ static unsigned long available_huge_pages(struct hstate *h) static struct folio *dequeue_hugetlb_folio_vma(struct hstate *h, struct vm_area_struct *vma, - unsigned long address, long chg) + unsigned long address, long gbl_chg) { struct folio *folio = NULL; struct mempolicy *mpol; @@ -1350,11 +1340,10 @@ static struct folio *dequeue_hugetlb_folio_vma(struct hstate *h, int nid; /* - * A child process with MAP_PRIVATE mappings created by their parent - * have no page reserves. This check ensures that reservations are - * not "stolen". The child may still get SIGKILLed + * gbl_chg==1 means the allocation requires a new page that was not + * reserved before. Making sure there's at least one free page. */ - if (!vma_has_reserves(chg) && !available_huge_pages(h)) + if (gbl_chg && !available_huge_pages(h)) goto err; gfp_mask = htlb_alloc_mask(h); @@ -1372,7 +1361,7 @@ static struct folio *dequeue_hugetlb_folio_vma(struct hstate *h, folio = dequeue_hugetlb_folio_nodemask(h, gfp_mask, nid, nodemask); - if (folio && vma_has_reserves(chg)) { + if (folio && !gbl_chg) { folio_set_hugetlb_restore_reserve(folio); h->resv_huge_pages--; } @@ -3063,7 +3052,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, if (!folio) goto out_uncharge_cgroup; spin_lock_irq(&hugetlb_lock); - if (vma_has_reserves(gbl_chg)) { + if (!gbl_chg) { folio_set_hugetlb_restore_reserve(folio); h->resv_huge_pages--; }