From patchwork Sun Dec 1 21:22:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13889657 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 D515ED49789 for ; Sun, 1 Dec 2024 21:23:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20B0B6B0099; Sun, 1 Dec 2024 16:23:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 194C36B009A; Sun, 1 Dec 2024 16:23:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB4686B009B; Sun, 1 Dec 2024 16:23:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B43406B0099 for ; Sun, 1 Dec 2024 16:23:07 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 77474A1346 for ; Sun, 1 Dec 2024 21:23:07 +0000 (UTC) X-FDA: 82847665068.27.BA4F1D4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id CC913140008 for ; Sun, 1 Dec 2024 21:22:56 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZE9pwFXK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733088174; a=rsa-sha256; cv=none; b=gnlBGVPDuHyCbwxgxa0c4BskiJnV4WwNBOQWMArupo5NbFc5EQZpfqY58FOVB2npP8rmwj yD2DkSfo1l3J5ZGw3rnG7jTKUlKhSOZEpGd2qsFDd9nFf5yQuIsMsP7ZHFCXlNt/AdcPlk Q0nosHCgcg0EtIa8UjbRyKzi0WBx3vM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZE9pwFXK; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733088174; 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=286MOANtSnZ8I6XGYWwioLKp0ba2wutq5KAnTtwnT/g=; b=1NwtpE7dzs+HT5MYclJ0vWYALz2/279xGqNZsdU/A4goVoM2iO/rVI9z4rxnxJy76UILyu BXf0gQaLYtfcA+TJW1CekzBQ0LoZVZurYuayIzuxZYa+66SaHrTbJfT2TbngYD7s+2DDCs 4ApfCjpqmhJDm6ZVz6aLltIbBGYvHVU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1733088184; 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=286MOANtSnZ8I6XGYWwioLKp0ba2wutq5KAnTtwnT/g=; b=ZE9pwFXKbN9QfFDObIKSkhQQP6HqaywPBAKi9bRNVl7l5/3Wk49Iuvw1mwFap2UYMhQlZ2 IlDtOwbmTDCD279jFeo+nL4jwqiPGZsZiz3dN5EpXqBY49u49Z5Pfy9ukgEiTBi8BPTFiZ Arpl8u8C8Tp0cL+LptAmSRA+Ujbz+EQ= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-493-pvkTX4vVMxmyDE_HLwUbZQ-1; Sun, 01 Dec 2024 16:23:03 -0500 X-MC-Unique: pvkTX4vVMxmyDE_HLwUbZQ-1 X-Mimecast-MFC-AGG-ID: pvkTX4vVMxmyDE_HLwUbZQ Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-466ba17bb88so57816211cf.2 for ; Sun, 01 Dec 2024 13:23:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733088183; x=1733692983; 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=286MOANtSnZ8I6XGYWwioLKp0ba2wutq5KAnTtwnT/g=; b=w65EcIfuN76RxUD8cZD4vsi1yplLPMbM3PPQXcs0jwGwgOkGiMhCABtfA13K1WLPq1 URH5T7+SYWB8S/XyjoBg/FptRgItuyXz/OlRRMYR+vj3WEX8joSWsHu0YwpSmx9ZAuX7 Lu3FbJNRkGnrXHRa3iOAF0alQ4nasRW4wwJqaaBad9yaGTf4ieQIKU4SRC+eGEiCD60m edP3H61/SUa8uP3eLgdwYWhnvUs869BpBOApRyqVtqBVBhG7XPVdygOSAaOl5mxIrdPT 414spAhC1IYbeDfLeZjCxTI3g7KSQxR0h1TmiyC4EdakpnOQbKxU2UVxfmEj0HqS2lwW hUOw== X-Forwarded-Encrypted: i=1; AJvYcCV9Q0BUpBNx0wXNYrwEYRRP2F6GJqRY+YjAi4N16joztikq7Su7WjNhVoiPAzMpK/TsWy5jdOSB2Q==@kvack.org X-Gm-Message-State: AOJu0Yw78i43yWBCxF8EDA+HJPx5FG0DgSXEFUS1zdmguaHaCDOLxyGg fdDiEOifyyGcQA5bs3R3gjevEhKR9fRH3hanZpN8EHbpyu+L6FFz4cd439uhz3aGSnsXrfZPZDK 2DE9B/35jKuhierf2Um+3CoBKgFO6YUcv4GsVmr+Y+vLsw26I X-Gm-Gg: ASbGncsOwDSXquVjHTpmEzHLVRLUwNQ3FdftVqCXsXakHDrh1bD3PmMcs/4CmykMWsW m1+KOClGyFK6iFydf6l+q34DzbpUwtBWxkOvjYx1zxbva2aULTPEHGVHkKyZjQF7sFp3TDmyAGv N783v78lNIV0DYOgGpnyUmafEBPeMrweHXTQCjqlyvf+JvhRoIEBwW2ivbuf7W3XoakVWzSsKth wnGot3FjoVFj90zZH9PzXtRok+uCgd+90byeCJ2JgGG5I//fY+RePhzJtVht3FRhKfPK5rDVtnr pCKR36xO6mEw9YoqpfAmqXIT8w== X-Received: by 2002:ac8:5d94:0:b0:464:c8f2:e553 with SMTP id d75a77b69052e-466b36549f8mr229630721cf.42.1733088183111; Sun, 01 Dec 2024 13:23:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcAYLfsmzWB1NZC0VaVby3ei9BnOo2eK+B/fq4AhdvJKUiO4tdmK0mrgEzoTHHOBn14RPVSQ== X-Received: by 2002:ac8:5d94:0:b0:464:c8f2:e553 with SMTP id d75a77b69052e-466b36549f8mr229630581cf.42.1733088182855; Sun, 01 Dec 2024 13:23:02 -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 d75a77b69052e-466c4249f0asm41278911cf.81.2024.12.01.13.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Dec 2024 13:23:01 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Rik van Riel , Breno Leitao , Andrew Morton , peterx@redhat.com, Muchun Song , Oscar Salvador , Roman Gushchin , Naoya Horiguchi , Ackerley Tng Subject: [PATCH 7/7] mm/hugetlb: Unify restore reserve accounting for new allocations Date: Sun, 1 Dec 2024 16:22:40 -0500 Message-ID: <20241201212240.533824-8-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241201212240.533824-1-peterx@redhat.com> References: <20241201212240.533824-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ECrHhrPAKP80tadeGut45bZD_n_7eWnL-oYcImPAFW0_1733088183 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CC913140008 X-Stat-Signature: 5yokbz73gg4x8ouxsonryc7akbizhwuj X-Rspam-User: X-HE-Tag: 1733088176-304157 X-HE-Meta: U2FsdGVkX1+yqhJvB6pMsHu1qVzaYw++/7TesnaG3qRcJz14uHm4u7p6pY0gC6IFgFmsk/ti6K33cpxMdNOL5ToxyvmB39a4TVT+/ZGcz3eTXzXryw7jFQNDPLgDlJcEmRqVITO7ESSMF/1MmqWFXaj2hZvRwzoXokSQ1qgGy2z0DC2igen8G6t/t4X7KdC8FdyzdEOiPCVZv5yu7glPLmujRN2PyRyOCaKD3ByBd0Ngv0a4XUFzwlyxUBN6bth7pDdp9MUwPf5XX1KJJDbdKTmqeZpX9tgF8OPbNfAWmTnO4gPPaQUSyd7XXv5s3fNZTl9JSfERzMGCh6TNV79OotTR5dax8cSAQUxPqzUbQo9SIs1E/LfzpDLtIDb/06mVD/3PUc7ZNhnwBgGazYtRuF5YSmtaYFjl3J9QBSHavQQ4vILyLOPAhS0mgrn+8kPuyIQ90Et6Kz5KEwC8boQIRHnV4wdrDHvtWsmF5GZIqenDVb6bfxraGribUt50jDZwEokrkbGCB0UohKmgbbmpGQIO1efw1B4tUbPJfXrsfqkZ7y7PqTZMq7AT8mGywaEydnkZMPVnplMcRfLNOSfJ0PYBfnjQan/dRz0/EK0TacW1ge0mTi9tfxfRyrw/3a/J/TrAprxtA3O7eiwEc4t2m0tdQecmrYcRzN1TvWJRoMJ8jGBCeSuY/ve2VmTBt40xNDeKmm5Ed0C9+zgBm2REE0vqtg6AI/m1DQmexWNMUOGoASnC3exqmkLbGrCVJzJR9MC2XOObRuDzwHHBk4nqVEooFhreijMVWxXR3cNilRZVkd9I/JBdrrP4Dm1Ie4fwofF7gxvxB/3wwaXKeHtqTI1iIFx+NGc1+MiBVposFboL0I5CRq8Z51z1CdVbzuCLSqny7QsWKn52FC5qmkXwfpfK8Xyd95A4GDTd/fgmYjOcb313lo0YTxrPNq6T5gpj0evRp8M0iQRez9icAVK se5EawyR Z8SPNSXPZMmlqq9gCqwBop1l6GDh+36nHlbRbX0vGIUb9mAyagOR4Xs9Bi15hdBjD12KAOAeVUCz6oM3kgNKlf4kpMqxiVYryISoKOplXLZQ8zHoPJgxwUlUAJ1llv6esNo4rUeQ57rmKi/Qh7VSufxv1y1Ks4hKGMNre3UcyuqF9+zaZSxI2gzSNFmTONRJqcLsrfp7VVdN66EgMnK0jrfOmNubaJst9E179yBat7AIAvBnZIjTLX6wo3Acj0dg4VUDtpcPZtdsmwl9AAEdF/Gd1uQASy//9Kus9EJSlex3m1Yrl2QnzidEwgx1yHxbjMEXopkmJxtfJzOcy7sZnTaRSUpOwM9Zha+VYq9nSGGgSZ7+UcAfNcI2DiIyT5QeE4woypJ+s+dzwLtiv3+okUgjchk3gUe4gv+U/066+PkndqEj1TQuCUIVKrg== 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: 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 10251ef3289a..64e690fe52bf 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; @@ -3012,15 +3007,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.