From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DEAA1F8668 for ; Tue, 7 Jan 2025 20:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736282422; cv=none; b=P3Ybgwf4IKYvb2fVBeBOP2f7vkPfprKO7CPqWksSK5tRGmSiCrtBq9JWuqsCli6fjz4rJG9aqb8/3LHkFZDJygzt/i3G824nJNA5f8M8iwdCE7l9obbkOqh74B2AIAJITxcITcOhMoU1oRp8Bh2SSnD+i1grUNFUxuNjqBOUwY4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736282422; c=relaxed/simple; bh=ChUJyn1ZvhYPvEL6LLT7uuYrXRhH1sWx06AedmXBNWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gQI+avki20qffMws313YxuDUjIZ/HnaZSCtk9EqtZZhygNdUrroxtPrjDTR+W6l6LzNnbnoaUQiXDAAoOJ4SY2wUzo49W5BVcwt5IswGcDwD0IlcnjUFLSqGIArD7lGv5HVhXWq6gVEU17Hl5MrviJQgH17SNSt4EZkEVNquqjM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eq5zGFPG; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eq5zGFPG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736282419; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tqf5zDG9MEFYyrwcky7SImgBB1+VbhDKSE1RWjLi9H0=; b=eq5zGFPG8quXNUlELHwuy93ZeoP9j1VjyF+1lhIZOIsW39B7DY2FcXK7tv0L5q/kBCSM3d +aCQPKv6TTM/csWksP7V1J6CvW4KJ3io/fAn4fAiS5UyLEzUN57uRouEPwBy0HvmHgm6We 5bl0SwEr7WswF3kLBaRF65K/RVjosws= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-13-CBi5-ArQOG6N9WcY2YPUhw-1; Tue, 07 Jan 2025 15:40:17 -0500 X-MC-Unique: CBi5-ArQOG6N9WcY2YPUhw-1 X-Mimecast-MFC-AGG-ID: CBi5-ArQOG6N9WcY2YPUhw Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6d8f6903d2eso261248686d6.2 for ; Tue, 07 Jan 2025 12:40:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736282417; x=1736887217; 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=UKarA355xhXZIVl5h8h0cSZY4CP1m/BUpgs4hEM69toIhtUUBMWSTQ3VFPuO10HwJn LrApI2zI6ZKpmcNsRyQCPQN8GEj3PlDeYXPMmIn6qHjP7B/tMBjh2SQbTJ9Y5b1Oz/8t uXKCqaH+Vo+EQm7/GAl+qRKMFCivr2YRHYHxANkyeFg2Lt8lj26PSV954X0m5Q2aLeqc 1saWH+d/mWBhXF4eBzFrUKaQBma94BMv8Xkl00maHW3jioq8p/pffs4+NZug2zx0mfNY ckU1G0l7+QV2Ihz3XtfUmwK/cjRjG0gS5Q3C0BR522VvpBpHZk5KsLEEmfIETwP6YJPQ vHxg== X-Forwarded-Encrypted: i=1; AJvYcCXMBOgmHVphwYVOTSg/RQsl1jeejWdvqZn1oC/G2lSpyZCur4yg9EcIoSHeh5MLlV8jWuUTCDvLAkXqPuI=@vger.kernel.org X-Gm-Message-State: AOJu0YzxwkuwTHLgH3TckMSS47fSdJefBHrD39uAgbnFaX9+IYQXmeVu JK4EjTDY8zIgH9nP9RMD55vWe7ACA9OliFHOVjW/E1qJspa/D8bp+VBXgneSYeAEndC762AtMkm 7n+s2MpUX6Zip/QnvkHbp+vdDc6fl6aR8nxDxEcrG4zhak6tHKzBChplap1Sr1A== X-Gm-Gg: ASbGncv7Q0hW/KuIkLtB+VDgqUlx1Z1zb6m3joUnstZ0eZtmZnvLXBq9j5/rXfcJWFv tctAZdjxoBqoEsNEVcJoHoDv66t2COTJxi4zi0AY/22HEGB45A3nw97NGgmLwFMmitl61kjUeAQ shfbJOL/+iMKL9o9EkxMP7Z+0one8mmB3oFHxVypm5Lke6LB2J3eNSjpKUpaMjjdmZDmDxo9ZEf P6VwaSV2/45qHXReXl9KLro1PT5vthq4oIL+PKbiT7zpZBm/qL/+VqFQzIcRoG0V+Tc99Bq2kZw 480QpvFUUw2hEiKA6IXCeOKGL50jP5eg X-Received: by 2002:ad4:5b8d:0:b0:6d8:a091:4f5c with SMTP id 6a1803df08f44-6df9b2ddae0mr7742876d6.33.1736282417316; 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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--; } -- 2.47.0