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.133.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 8AF471F8683 for ; Tue, 7 Jan 2025 20:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736282423; cv=none; b=XzIO+tbI2eVFgasFXF68YTiZk/zgupWFWWkh4e0LXP2KHH2/ulQM2GSObJcx4SFR/RYyNBNicYncM/qozgCAanMV3yQ6aePReMxddFvia1Lr0YFu3t2NPK66hC0h0Gni70yB6phmXDID8XDHUY0YXCm2vrxl8BuCiOFwcnRypJg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736282423; c=relaxed/simple; bh=jsqM6u/y4O8sZhbKgXb0JpfUTRY92+S5FEjDF4D7UAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dgpyyUe2GJB9KbPhOMhkOckW4LktgCGQ/BlCNo8h2p+Nwez3dr2yVan55DTlmlIH7EEqqdw3q8MFpaHLJ2FsTtkjUI9mbJCt/nCyctbLXzKfyoXUjNlG/7oDYmSEK59hnLF/+CAxFYV0/+rTxb7QGUBw1PI6Du7pDyk8t9cKqKw= 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=a5R81oWc; arc=none smtp.client-ip=170.10.133.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="a5R81oWc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736282420; 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=/+nsOFPsTLzwi0UWOyyE5ZOk1n60MXP64Ncf3blKR+I=; b=a5R81oWcymzm++EjDZfjn8SXfPFaAv9s2umpNkisoQvQfAxHVUJPpg4I8OtxcHW3tY/uda 8E68+eeBfTly/hiQyglgi82K9vbUO77GlqA14C+Nt2BCpQS3odavo0MlTYCsHicLkIxsMH faP/pXCXiLm8QX5Mo5WQWcn212pZzSI= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-104-uUWLeflHMkKcvxRrntf8Ig-1; Tue, 07 Jan 2025 15:40:19 -0500 X-MC-Unique: uUWLeflHMkKcvxRrntf8Ig-1 X-Mimecast-MFC-AGG-ID: uUWLeflHMkKcvxRrntf8Ig Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6d8f78fdad0so241925026d6.2 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=/+nsOFPsTLzwi0UWOyyE5ZOk1n60MXP64Ncf3blKR+I=; b=ErCKEYyWhKmgk0UcKJ8j6NgQ1s4+hsfYY1s15Ey4DL+01kZpLR9fUConCbRCDVebi6 tRXfphHmOGEnmqy9KFIviCzISBilbuTUVk+gaHj77j0foek2LFpSn81KiORHAyxpye3T X1H+wc32QT6IIqZ9B5MsQyv8gIBi4OoEj+wpSGJ0HsnTrm4w4lSEyJXphsaPluvbxLLy 0mmqyjSyN7OJO7p/HBGqNp1kqyv5wVle/6pbAWVuA35TTL+Bn/2mNi8SDm/vkoOiattW vO1Hw1h/sZF8wp1G3Iqzoq8/jmCM1nQWHOXrCpUXvRTPCLKTpoXKFRvUmPjZ3WlRnTnC 6RIQ== X-Forwarded-Encrypted: i=1; AJvYcCVvGqKN2Y85xns9NsmBNdEPdrRp263s8SrbyxdCmyp2jB8cinTrkZOBvuCqCW/+K9ZqAMLpLp03q69Urtk=@vger.kernel.org X-Gm-Message-State: AOJu0YzKGCFG4+g+3K5ubPmNpjT6+bh19N/I03mJIgTCx/t0AJoFPXWy 6TfGXcymJRi3jcXqlV8uhZgUDwX2xEU84vzo9ms51x3nLg3fEA72FRewUyvnlqyHbTmM0tMYdJv 18IZjj+yvZ03hCmLoWSs+hU+LkOdxEdNgTcZWC9nkoReo6eM5dTbtCnNBOAdfrA== X-Gm-Gg: ASbGncvKovGrxDzOMQ+j+o2KQmaq6XnQQJQtCQM9gLo/GJCxI8sj5BrgQFYbCyoGnIp qS/bwfjtFYSgPvE4drFinvnW36vkUfEaIq8NwXgQA8WUKa13E8n42nlEuf83hioqP5QyeU4bfD9 H/FlLwvv5AF1ecdRsX8e8t6ILkIGmV5Zt8MxFJjDgruUwSdoWS5ElEZ8v9yJVACIIkh0ILYLBGe 8CHdvbv3IWWwf/rw4/TziIPdw6PWoZ7lLqkAwND/Pf5gWl1n+CHlY/HZNYGufau0/piikUIqn52 k66dIHZtGHAjrA1wRdtAHlljM/es6y5Z X-Received: by 2002:a05:6214:31a0:b0:6d8:f7cf:a12 with SMTP id 6a1803df08f44-6df9b2ff012mr6628136d6.45.1736282418864; Tue, 07 Jan 2025 12:40:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3x2JnYKqYDGZceKkbdYysg3OVrQ5XZc6PkLXZvto1IqyPEH4R4CSwLbtkmwcRm2B/Q8ATbw== X-Received: by 2002:a05:6214:31a0:b0:6d8:f7cf:a12 with SMTP id 6a1803df08f44-6df9b2ff012mr6627846d6.45.1736282418604; Tue, 07 Jan 2025 12:40:18 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2025 12:40:17 -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 7/7] mm/hugetlb: Unify restore reserve accounting for new allocations Date: Tue, 7 Jan 2025 15:40:02 -0500 Message-ID: <20250107204002.2683356-8-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 Either hugetlb pages dequeued from hstate, or newly allocated from buddy, would require restore-reserve accounting to be managed properly. Merge the two paths on it. Add a small comment to make it slightly nicer. Signed-off-by: Peter Xu --- mm/hugetlb.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 922d57e2413a..3b27840de36f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1361,11 +1361,6 @@ static struct folio *dequeue_hugetlb_folio_vma(struct hstate *h, folio = dequeue_hugetlb_folio_nodemask(h, gfp_mask, nid, nodemask); - if (folio && !gbl_chg) { - folio_set_hugetlb_restore_reserve(folio); - h->resv_huge_pages--; - } - mpol_cond_put(mpol); return folio; @@ -3052,15 +3047,20 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, if (!folio) goto out_uncharge_cgroup; spin_lock_irq(&hugetlb_lock); - if (!gbl_chg) { - folio_set_hugetlb_restore_reserve(folio); - h->resv_huge_pages--; - } list_add(&folio->lru, &h->hugepage_activelist); folio_ref_unfreeze(folio, 1); /* Fall through */ } + /* + * Either dequeued or buddy-allocated folio needs to add special + * mark to the folio when it consumes a global reservation. + */ + if (!gbl_chg) { + folio_set_hugetlb_restore_reserve(folio); + h->resv_huge_pages--; + } + hugetlb_cgroup_commit_charge(idx, pages_per_huge_page(h), h_cg, folio); /* If allocation is not consuming a reservation, also store the * hugetlb_cgroup pointer on the page. -- 2.47.0