From patchwork Tue Jan 7 20:40:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13929595 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 9574AE77197 for ; Tue, 7 Jan 2025 20:40:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC77A6B00AC; Tue, 7 Jan 2025 15:40:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C75216B00AD; Tue, 7 Jan 2025 15:40:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACAA56B00AE; Tue, 7 Jan 2025 15:40:25 -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 883556B00AC for ; Tue, 7 Jan 2025 15:40:25 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3837E140CCD for ; Tue, 7 Jan 2025 20:40:25 +0000 (UTC) X-FDA: 82981823610.19.99C3CA6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 01A31C0006 for ; Tue, 7 Jan 2025 20:40:22 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MBF+oQsU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.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=1736282423; 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=/+nsOFPsTLzwi0UWOyyE5ZOk1n60MXP64Ncf3blKR+I=; b=lDcj4/jt4GJMAB7saQ0soFy3svFGlv2Aixl7MKV4fjTZ0THiOCUFQaJrsCY2qZjXhSCuqI 95o3Y31J0XUDJQxhmUhZGUF/y3TzIjln+XU9CgyuUMgZU7nFj9Y1JPI87/H25vAdcpflOK DAAWDSFlcrsASJxXBN3Zc9pARjdd078= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736282423; a=rsa-sha256; cv=none; b=KdHm7W3Jli7VZc13AOCTLNAC6A7zCjOI6/gyw8x4QtOxQeSsOCQq3kbOXx1eIUlKO+LrB6 Y4Ek1UF2M6L14G7TM3KLcx3ulrzW0JwYSZ+scAJkRIRQ0jHDp/QD+knif5gwVd18TwNa2m DPgsfQ3WidRyaN+NkimGwR+/iGhHaWU= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MBF+oQsU; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736282422; 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=/+nsOFPsTLzwi0UWOyyE5ZOk1n60MXP64Ncf3blKR+I=; b=MBF+oQsUc2yNRjBDJQHh2ZMk7ChCkb9HcUaQBgLODU/nJ1NTr3JV+ZbY3fwJMNIz1BcTYQ arEntC4pAtgYnOZ0p2SWxyrKnyy3+RogcYc/efX5IAYkDwgLR8H8yQ7tPWaIfQGV8xVK1q eMC3pmFGtAA84yWZbRtHfbGsAV9/rPU= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-134-3d8ha9J4ML6-6dRm5gxtZw-1; Tue, 07 Jan 2025 15:40:20 -0500 X-MC-Unique: 3d8ha9J4ML6-6dRm5gxtZw-1 X-Mimecast-MFC-AGG-ID: 3d8ha9J4ML6-6dRm5gxtZw Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-467b0b0aed4so341173251cf.2 for ; Tue, 07 Jan 2025 12:40:20 -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=xSyE2aHpa9brrgx3Nq80vgQDb3q2a74BsVFCaOegc1oSyN829gvXVkcK1hR1TTnDt1 rXki3Ez8TOV/nHzonOA8ngTlM1DmSTp2uTry3atjaIcQoT0wWZ/A+LQisdiPUwd6WphB LEOd9hEiMC4np24A10IsXyTsVm5uVBV53DGnELJxpgxIsUt1qNvnQ9wEYesGQiv/obIu M1B2vhHxHw4hahBM5V/ToIuNL+g80kVmB174haQSoCl6OEijvjbyU8Y2ShKhqxZ2fLUG oI8kMUnogmXGuKVK+UdPoOchxi/3CnYRJxF/8c2jE8ABB40zXTLdQWeNKy243iIZO3Sr qtTQ== X-Gm-Message-State: AOJu0YxWJqp1HDyr1z5FDu6IMIFwkUb/aQHcgyOmCVvStjiUewmhqvP9 PbVLBr4FYIG598Nnr7O+mPl19kdwpnqA/YTcukgjpapJ+igwMKyYUqUVXtMabEHRt3fxY9SUhuA rs1eOV8YsioaQ+xqkJoM61QlOmA51+FN5I1JbujQKVDZP228383OoAe2uk47IwUIYO+bv2vqOFn QofhmsE/hiqPFh5KyZ7jF+eUOBRelBkw== X-Gm-Gg: ASbGncvdLnxOuGqraga5WEBG9qXrUjeNifAAQx1w7o7haOSmW5SPD92x2JS0QaWPraR SmTXWqepuBdhlChM0AhTVUsnUUkCmgv/zssEjujgawcaNxidptIDUiK360NjKM8dk3V0vyfagPK mEH4Go22d0xBNwtp0FHVHG06aBfq/mJU0ZMfIySaqfQ5lGd+Nh9mTsfauWSMEpChjUvasm7LORc mI0tbgifTDkr+GfpPk1yTr1YY9naC2f1xvOxsV3iFXR/4eDvuXbecvKMiTiSiFsHojtZ1zKicOW W7N4Ibizq/6ce6h4ap+iPoG8UutwP6lm X-Received: by 2002:a05:6214:31a0:b0:6d8:f7cf:a12 with SMTP id 6a1803df08f44-6df9b2ff012mr6628226d6.45.1736282418931; 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> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 2OPJKxdTOUMBsRh1Xm14li8U6PovpB8keF8LZHqmFr8_1736282420 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Stat-Signature: tajet51byuq7up5bdm4htpyor1i6hw5m X-Rspamd-Queue-Id: 01A31C0006 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1736282422-701029 X-HE-Meta: U2FsdGVkX1/gWUR6YFa1DzGj7ISrYX9w4BCiCK3LbedLUIG8s+wT19HZwOFkaftoHZOgyiq/b1d0Ef/SAefQdSr0NGtnXjRPozUo+0THSyOOp58hVyHKDx2ynYKpSbM2fEl4fc2f1sO4OKqHQadpehWwLXlfyvP8xKP3QZ6IE9qHmvL0TXVobbN1l9x5vUH8huNtGw9H4RpEUm2wIhVFqXI+vo6WQjzl0SjnWd7WZarfTnws9cNhrNdDFV4G3Juco/kXzDTjvLJ5biy6jiS/LZht+KOoXN2bmAv9rCyslktQdsgGhO2D1hAThfLWVt9p1U0K2+TyKaBDCc4VUbgXIf25WSnr8akLbclVhmTdVbYGuj/3eJ+OWlOXhB9LdA78non5RjrTUVr2Q9AUkqMBPQMRLSPYHZBOtR8Ux4sUAKfrb0wZFETh1hlR2hsiPyIwXqMfq6nWNyAskVAU9Kf9Yyn3NDwL6kthRCDelWdj/Rff9A4hgKw/PDa3iqWO0iTazx5sFAbaU0Rc/Ryh6QXchaKkFePQ5s04OLQ865mmTWNrDE0/RooXFfPQ+qF/36dZVjM0CUFx0XLAyYAXWz61loDkxzDgzHrrlGsFEo6Djk864+bxjcVvAEcPItNr4j2V/yiAc8LKkbeRKBwwewdsMaP2aZi8L9MAgn3a2Ad5Ve70OmkTESp14O6OIaMENSPBFHFam4qkH93YhiO1dy+qLhOOoF1yLCjrAQUSMs9bedPFksmn3Hrz/soCYkVO2kQQnL8vCXd7ZCh2ddml/W3rCPFZBt4mq7wpXXOJW0siT43+IrZ8JbzCdIlR1wsdSqwFHQGIqmPk/MZ7vv3BHwu+G9Dtj5KC70PAnbJPysQ1U5oVvoWQ3XmpYh22F5ozUPzVT+w7FV2z7nI0oHIAVO7xtDLYLOQqmIGhETR69PvFIr813+/vwmJoGWkZPRlTYvbJsFH1Drof9tnVRxvq+IM r6/LcftF xpMGT4vXN84KmGXzXixrcxbL0k0xoZefTFExdpleGzWjko6mWX2kENLRd3wdyls9esbgtpqx7Fe1j9+nX72PbT8n+vFG1z471x53oHhEPB0wRwdP3CEpdo4qNwBU0/RJZDV30V/VeM3TvJrtXUfD+sulLpNBlfZKUfgagyLpwkbmxFnYkf3iJN5oBzMSDkyg4hu28LgWNNhcdM9zDk832cscc38MtyUN1AEndG9dNUkaHu1TkRI4sOYrGmGyGfk16DN08AfrhyhIW9SdzK5GiPBzNppmxHe7jQ/HGClqcdGYgNL3VzVvNnvbJz6eQiFsxTRKQcUEHnsMegTjSoLbsBRfcuLSnEXNwYvL9L4AD1MvF7Yd/6qJMCu9cG4ztikusxh30dZZsIfh1G2F7N4cVpGATimNrHTUIE+UURltUQCQIerbti/J651uadg== 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 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.