From patchwork Wed Nov 8 16:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brendan Jackman X-Patchwork-Id: 163107 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp1043719vqo; Wed, 8 Nov 2023 08:49:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwUSHUCJsP2fzdKf5YRzM3em4iPLmiJxPI/cO1md3PqBHVTNquXHErpkU45RLgZEX0yh3t X-Received: by 2002:a05:6a20:7487:b0:15d:1646:285a with SMTP id p7-20020a056a20748700b0015d1646285amr3496372pzd.21.1699462181693; Wed, 08 Nov 2023 08:49:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699462181; cv=none; d=google.com; s=arc-20160816; b=QASCZlbBOk1xQER6ReZDNlYGOPcJ4Pod//RVuvRM4D4jq2eq11IQqIQD3H3ORH4hRZ 8v+5LOQRrFRSb8gKLS1SLTZUACxa/39HOzztnj6cs/YebD7iN32jSdCxmLOlwebzo+Hu bXVtQVtevumPKxA9ouq8mnIFo/2KoCo1TcUEDKYMKomLUPOHfOMRP9X8/pakYXiNpKA8 QBFU7Xkz1YVGzcIRv+XeVu0s0c40Q/HM5gW76jMLHku+NaA2mEPnDsy9dLJGkemRLkeQ UGLigiOktyKvxyw2KiYN0NZrYit4J6krgDG66j+o/+0LJQhUjxVCFAGgnp04gv9ADOqg 8Jxg== 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=f+htJKZ/Y85O1839RGUSFWieIBLrRpnb2wXiA69z2nI=; fh=CR4OWYwDLACdnPDqVoTFbCRe8gEpK+hSIJwKTMadbCk=; b=Q8zGG3SQ81Sc0e4gaLkLFqKcIImKcOhaZBhQvjX1gjmId22PfQ2Tea9BgbOhktbSHf we4dYDho5y2DXO16K44b9P58kMZn9xNHb6HmOPFEPDPPkEyWYJchOmp0FayG+At9y5VU BqjfZDCkHgJC909W/JoELqfTS0dd+BXOH0kGcjoe7Ugu3lBwpCao6RBhp+++jjOd1aGN sMe663s6suJomXKmL8A9n3yrhFUvbnRtlkmT1fAcFbU9dyFDi6iA+U7jXcYeT8H8At2C RNy1Tr4d939BZIhN/VwGhyf8qa5tw8vW/KbkTxSxLURRv1EZ4q2BmeUhb5Vm6rFbKY8R KXaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IMchypkk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id z11-20020a634c0b000000b005b8f0c8ddbasi4818203pga.243.2023.11.08.08.49.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 08:49:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IMchypkk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 928F283852F2; Wed, 8 Nov 2023 08:49:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230023AbjKHQta (ORCPT + 32 others); Wed, 8 Nov 2023 11:49:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229816AbjKHQt2 (ORCPT ); Wed, 8 Nov 2023 11:49:28 -0500 Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A04FA1FD6 for ; Wed, 8 Nov 2023 08:49:26 -0800 (PST) Received: by mail-ej1-x64a.google.com with SMTP id a640c23a62f3a-9d216597f5fso533101766b.1 for ; Wed, 08 Nov 2023 08:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699462165; x=1700066965; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=f+htJKZ/Y85O1839RGUSFWieIBLrRpnb2wXiA69z2nI=; b=IMchypkkkkIeAyHe+k80g0EDc8tDHxpxZYSNZzFLqP1SwPod/sEp2mXwuKa4zqoIFg Q0qeZydacv3HIK5omOUxb69VVKalvzRyhBKMKErcrl8UnGoFz/kLLlossqfF5YZNNwJE EWQzl/CGX7S4sXDxofLQZJzHmjrZyRbPudvopJTEyWtHngWQUuUNWqlONh9yqRZsthRF +P2JrRDY8pikBVRN0GGb1cs+uZihWhD530oAlcc/wHtp9uklGXQstxqqyoA8snpW8ISP R0IKPRpLK13TrXLe/cQVW0TdPknV3aVXN05m7s0UkqQSGlEDDL22M11+tVUQwGw1u5Ku 2ntg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699462165; x=1700066965; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=f+htJKZ/Y85O1839RGUSFWieIBLrRpnb2wXiA69z2nI=; b=Ygsndwus/2mdNaw6Y8LJbk/ooXpD39GIPovdkdi044W4GT7Q9Axu4cEu7Is+M+EkZO gKfBdgbsm7jps0HSJWL+956n9oSy9q4lOWsLzIKDQrcMdjekaSGIRUPmhuhGkFW4os5R d0XBsDYBnJI+lAXgCrKG5reLuwSLNFiM7Ykj+ytw2dVkWq3X/OHPz8ZWx4X3to6fd473 PPKu1OcZ2idBo5TI7LXgHfMqT9ArHAYY5UclyTcSStKfxlllx01yjH5FjJB+YN7CrybP Lv6n3H1aZfPeHBZobI6mZaLe2DzXybMaNuesG7OVrFWbScVEEFi+hooQOSAOD5XKH2L2 XZKA== X-Gm-Message-State: AOJu0YwxCQp9Mt/jGBuLJy/ZWsrkPLdaWxfe21vmEjE2sVSrcUf+6vBE MMxwSEsgSzUlS2GdfIv1MkkbmA0ReHEFvw== X-Received: from beeg.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:11db]) (user=jackmanb job=sendgmr) by 2002:a17:906:dfe6:b0:9be:dbea:42a2 with SMTP id lc6-20020a170906dfe600b009bedbea42a2mr15361ejc.8.1699462165146; Wed, 08 Nov 2023 08:49:25 -0800 (PST) Date: Wed, 8 Nov 2023 16:49:20 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Message-ID: <20231108164920.3401565-1-jackmanb@google.com> Subject: [PATCH v2] mm/page_alloc: Dedupe some memcg uncharging logic From: Brendan Jackman To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song Cc: Andrew Morton , Brendan Jackman 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 (fry.vger.email [0.0.0.0]); Wed, 08 Nov 2023 08:49:39 -0800 (PST) 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,T_SCC_BODY_TEXT_LINE, 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 fry.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782015256722957438 X-GMAIL-MSGID: 1782015256722957438 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 Reviewed-by: Yosry Ahmed Acked-by: Shakeel Butt --- 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 733732e7e0ba..dd5e8a759d27 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1086,13 +1086,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; @@ -1123,8 +1121,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++;