From patchwork Fri Oct 27 13:22:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Jackman X-Patchwork-Id: 158927 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp599669vqb; Fri, 27 Oct 2023 06:22:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlcfmIXlb+t4j1KaqNTgmMtTGxfYjrRmNITNJgb3+8KJhlfx/PLiEBCQzv3umwz7kbTWdo X-Received: by 2002:a25:d02:0:b0:d9a:45e7:c7f1 with SMTP id 2-20020a250d02000000b00d9a45e7c7f1mr4297294ybn.30.1698412976854; Fri, 27 Oct 2023 06:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698412976; cv=none; d=google.com; s=arc-20160816; b=ZaoAYtHGCghlMqRfPfPUMIIiEhZgx66vZxqdM7o+56o1DweboLKcQbKFkWo5IP24zd fAUu2nAmj4BkvhHcGndHq6h/PuYGA3VB5k6rvNSCofFgGfvVM/8/osbkM6lxlSexWOqz 2G/KMLWC2l9FIAlYRre8vAjcqO+JwCzoTieQIs1v6LVU7EnB3RaNKEerZELWu3YC6J+6 a3P9hk2OmJnfdLA3QcjTWWT7e9H44Cl/BqAXAJNEXzSVdl6GZLya+ZLpr2lhRRXpOnhe SorevUEX1Xnf855K5Ltja2GfWYczvAgRGz7CzgklEsJmMX5EC5Q60i1ttlYos5ajpYcG lj8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=97bswsbZUtfLtcRYk2QqxU2uMSJhqWkgINgMHmv0BiM=; fh=N4xY/h07aQc1gCJJ1Fdkee2GTLPGEJOBRqzbnaKNIag=; b=tnFBRsHrO5zfKY2te90E2kePBhdtIa/F9olsTEpxp2RUGtWaB8ELlZVBDRosNzbjYo iyfZgQD3qS0n/948Lpd6akXKQGIT+iVGzVMA9z+TJGFrkYogYGbZzjykp31uaeSRQQRx Axm3PbokAX+cdftmy1T/rGyXdvtTtFmCFKAZ05DeDFI8kI88yPrTVCb9kezXJkz3PHAt 5a0dUG5wYblX2P0b8Vb9u2BdVzHBnov/J8C0eh90wOSTOqYzcakJ1ejZrPazg5qaynUA NO3OIdaoPR/ZIRuOzdXRDt9yN7z/qyHF5DAO3ybQEFYgGzGXdnLxYNIubSJoRqHPHtcr b6Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FCF6UVxa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id t24-20020a252d18000000b00d71bf89f0fasi2990402ybt.491.2023.10.27.06.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 06:22:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FCF6UVxa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 1B87882430BC; Fri, 27 Oct 2023 06:22:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345882AbjJ0NWk (ORCPT + 25 others); Fri, 27 Oct 2023 09:22:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345688AbjJ0NWi (ORCPT ); Fri, 27 Oct 2023 09:22:38 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B5F1C9 for ; Fri, 27 Oct 2023 06:22:36 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5b02ed0f886so1265677b3.0 for ; Fri, 27 Oct 2023 06:22:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698412955; x=1699017755; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=97bswsbZUtfLtcRYk2QqxU2uMSJhqWkgINgMHmv0BiM=; b=FCF6UVxakvmAsOIuiOh+UJ4Him6U8MPB03Khvb+uUqVB28IbKIjU6ohZkg28P6Jh6n yecuDLaVWdkNN8xW+dj/CXcwXyn6PPZASqrgEfk9XXsL5RyX+DAjonqP02R/vNYe7+81 kZIDwXoJUZ2Ij2Gl41GFD1OWse+AoM8Tqsb8H4ZEdndD5zIzywfG+5CsD2GapttrK3av /RezKQ29PoIsvX0EGjrWQxFF0Ex8bg8wt8IOKUZqwFrz/VXib5ZaIfzwtASI72CXlQTq 98uGYqw0ICoDdlnYr1tV1aHZ5THVMczWbbpRShiYGpwaeYkVffkNDXpcn5Y644Is+4fc nmbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698412955; x=1699017755; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=97bswsbZUtfLtcRYk2QqxU2uMSJhqWkgINgMHmv0BiM=; b=AUchhgt0AX0WAFo5xCyetEcaGykNhxjYny4He5d/GEMNyDRtuJfp8ZGP9UPSIqBSDp QiFddV93TUjTSobcuumvv6aBCq6rMfDjOW/qkiODYDyKnlxkzq40oLiq/1YmhOKqPz2K ibQh4K9NjerzkpRxNurfpHxEC0Ybrn9+KZzxrK/VSURm+EaEw6d8B96eHtF3CxtX/QZM SOCKEl9qDNAJuNHZYtochO3jJrOIv2GflS2hFpehDEXz7V3Q4jJFOusXo7WO7vnXGSUb V91e1cLlne7Twm0z+r21WmoHX1++3XjMdhf53/cZwmMD/u1n/3rzyxgLgkmzU0eqGlJp gwxw== X-Gm-Message-State: AOJu0YyMNyFW8L2/qpGI58jTlbQw1xcFudk9YQ7SgvUSQGKjtnDzSPxt BMSzzArlfZtr0eHkEhuOv5mvCHHXthVxQw== X-Received: from beeg.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:11db]) (user=jackmanb job=sendgmr) by 2002:a0d:df48:0:b0:5a7:b496:5983 with SMTP id i69-20020a0ddf48000000b005a7b4965983mr49780ywe.9.1698412955678; Fri, 27 Oct 2023 06:22:35 -0700 (PDT) Date: Fri, 27 Oct 2023 13:22:13 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231027132213.3817924-1-jackmanb@google.com> Subject: [PATCH] mm/page_alloc: Dedupe some memcg uncharging logic From: Brendan Jackman To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yosryahmed@google.com, Brendan Jackman X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 27 Oct 2023 06:22:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780915085493209618 X-GMAIL-MSGID: 1780915085493209618 The duplication makes it seem like some work is required before uncharging in the !PageHWPoison case. But it isn't, so we can simplify the code a little. Note the PageMemcgKmem check is redundant, but I've left it in as it avoids an unnecessary function call. Signed-Off-By: Brendan Jackman Change-Id: Ibe0f9941b6b24fc98ea2510a75d0a0d1066a2a2e --- mm/page_alloc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 85741403948f..b9e81e416e73 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1084,13 +1084,11 @@ static __always_inline bool free_pages_prepare(struct page *page, trace_mm_page_free(page, order); kmsan_free_page(page, order); + if (memcg_kmem_online() && PageMemcgKmem(page)) + __memcg_kmem_uncharge_page(page, order); + if (unlikely(PageHWPoison(page)) && !order) { - /* - * Do not let hwpoison pages hit pcplists/buddy - * Untie memcg state and reset page's owner - */ - if (memcg_kmem_online() && PageMemcgKmem(page)) - __memcg_kmem_uncharge_page(page, order); + /* Do not let hwpoison pages hit pcplists/buddy */ reset_page_owner(page, order); page_table_check_free(page, order); return false; @@ -1122,8 +1120,6 @@ static __always_inline bool free_pages_prepare(struct page *page, } if (PageMappingFlags(page)) page->mapping = NULL; - if (memcg_kmem_online() && PageMemcgKmem(page)) - __memcg_kmem_uncharge_page(page, order); if (is_check_pages_enabled()) { if (free_page_is_bad(page)) bad++;