From patchwork Thu Jan 12 15:33:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 42512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3952624wrt; Thu, 12 Jan 2023 07:45:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXtA8LP0y9RIHkTY1PjjSIRCOfT9gKE1s3uw+yXwikcGE/RigM8Qrzlrv1NI6Md/U6zldkZ8 X-Received: by 2002:a05:6402:2065:b0:499:bf1b:5de with SMTP id bd5-20020a056402206500b00499bf1b05demr11437146edb.37.1673538307656; Thu, 12 Jan 2023 07:45:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673538307; cv=none; d=google.com; s=arc-20160816; b=s/3rx2mWl4WfMGYTKgq5KF4EOE7GXK62S8kay4fI9RW2N6fFbhSkzbSHO3CVae8O9p pDFv3Xi/wKlXIUYCRFradSqbCwmyYkhs3czJD72MlccuptNJ36ShK7iapmZ4mi/9U2h+ QCFWEDI2owzHjJwE5mLE1RWDcjSEAgMe79ERMAyEc4bTHt7L2aj4oHs2mRk3PRUhZCzg VZMbdp5zyvROjdEK89usy0RpuKNR6rGj04M6PzgN3igterRG8CFmFi21+yV5lxu1ru2i TTepG/izy9rFeJKd9/CjCXvlVVtc1zHM7kKs2LEWOaLMOdxZ/0aVz4+a0aqENTz3yNPP wo3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=3ubEBjBZWCZprxvg3hFb0J7l69r3LVSgsyPzd+ncfrs=; b=rQCa5Vrei1BytlaHEiKIsnLY8nAI4J+6S+ieWtmCZ/OLy07iVIWxGMhTG4cOogfHAP ka4MLst416xVBOtVG8K6x54hcT71h4xom0heCSYMWcW8VS+YacU39gK27nAbPahF8vMl F78WOgdUKfp8l6ar0zsz+KCfjqwwyo78A78kF/b15PLx8bv4dZi4GePR6c83OHZxM/5F 30l5Ezz5d8fnf/g/x1rW1xxYMXPWVEXNO3Y7KsXnjDxAfWP1s3JEcfqjJhYU6JMgDFPS KJpscr1b3iauwTniLgTGWDwUmdmM6RSqcmCyHiF8hXbsKNXIULkeWOflsMwB14JVEMlE gUdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="F/vNL4nc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht14-20020a170907608e00b007c0fa2e0fa1si17921935ejc.888.2023.01.12.07.44.42; Thu, 12 Jan 2023 07:45:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b="F/vNL4nc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240553AbjALPoJ (ORCPT + 99 others); Thu, 12 Jan 2023 10:44:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240642AbjALPne (ORCPT ); Thu, 12 Jan 2023 10:43:34 -0500 Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAFC71A399 for ; Thu, 12 Jan 2023 07:33:52 -0800 (PST) Received: by mail-oo1-xc31.google.com with SMTP id b10-20020a4a9fca000000b004e6f734c6b4so4899570oom.9 for ; Thu, 12 Jan 2023 07:33:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=3ubEBjBZWCZprxvg3hFb0J7l69r3LVSgsyPzd+ncfrs=; b=F/vNL4ncA2Wx1v6nHhyPY2j1Q6TgA7m1qi0ck+kX4IfwwviTOxM4YNEonMibKmrMgG 2U4yyzaBkI/wf4kFyXlzFQzfHD3p+rBmQtdE85GOIFMOeXpPVtQ54OMh1e87Am4CPdFm DPjuttNKso0QHW4cVVr0dDKvVV/HwrT257jH7NDWbXzPB+SW7D56JnDqK0CJDr9S1rl5 G2Pzk8BjRkof8WHiPNLH8TFHTQxR6IVlZdVoytWvDBiCkZhYpOti2pb71HiuO3egOTON 0z2iQgADIaQ2TjIBRAqvgOs7Moc+UKZd+H6XwJrp4pspbWvQ8TWDi5bJ48u5irNal845 2nLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3ubEBjBZWCZprxvg3hFb0J7l69r3LVSgsyPzd+ncfrs=; b=VRqE2gx1dMiN8XQfLDJ8ERpfctKvo15yUrRXpUz7wbqsMHuNl6LlvXmWddYNX72WK+ YWAAYamrfwLtw+8iZKJ6s1pZFfCtyz/X/J+6sXwZvkZNHj6HKPkQxkMfHdqM7ax0C84p vsizhzA6L+8tTCkcwiXdOGtMWfyMdS/nikkOpKt9pO3yKrXwpY2PGaR1+M/v+eY9I+gv nAC7SP3dODUk8kb216bEq2jiaRzPg/CVIlWbrxZYnqnu6wcpgfXKN4sg4B2RPMiRfWXI u13xHRKGeytDltxWlanPPc/52a0os2O23NHMntLbBQxqKxY9jGUwJRGijIDSEPpSuA/+ TsCg== X-Gm-Message-State: AFqh2kqJcrno9jrU0roJ/3zGaT/0Gi0S7HhjFbVRSMXPjkV8wxmeWoNv PnxRluxjPI8XusW81v0YAobtHA== X-Received: by 2002:a05:6358:5bce:b0:ec:ed9a:9b4b with SMTP id i14-20020a0563585bce00b000eced9a9b4bmr154475rwf.7.1673537631552; Thu, 12 Jan 2023 07:33:51 -0800 (PST) Received: from soleen.c.googlers.com.com (193.132.150.34.bc.googleusercontent.com. [34.150.132.193]) by smtp.gmail.com with ESMTPSA id u8-20020a05620a454800b006fc7302cf89sm11113288qkp.28.2023.01.12.07.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 07:33:50 -0800 (PST) From: Pasha Tatashin To: pasha.tatashin@soleen.com, akpm@linux-foundation.org, mhocko@suse.com, vbabka@suse.cz, david@redhat.com, quic_charante@quicinc.com, lizhe.67@bytedance.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2] mm/page_ext: Do not allocate space for page_ext->flags if not needed Date: Thu, 12 Jan 2023 15:33:48 +0000 Message-Id: <20230112153348.3202173-1-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754832104694180697?= X-GMAIL-MSGID: =?utf-8?q?1754832104694180697?= There is 8 byte page_ext->flags field allocated per page whenever CONFIG_PAGE_EXTENSION is enabled. However, not every user of page_ext uses flags. Therefore, check whether flags is needed at least by one user and if so allocate space for it. For example when page_table_check is enabled, on a machine with 128G of memory before the fix: [ 2.244288] allocated 536870912 bytes of page_ext after the fix: [ 2.160154] allocated 268435456 bytes of page_ext Signed-off-by: Pasha Tatashin --- include/linux/page_ext.h | 7 +++++++ mm/page_ext.c | 12 +++++++++++- mm/page_owner.c | 1 + mm/page_table_check.c | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) Changelog: v2: Fixed field name in page_owner.c that caused build error. diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index 22be4582faae..29909e135052 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -12,10 +12,14 @@ struct page_ext_operations { size_t size; bool (*need)(void); void (*init)(void); + bool using_shared_ext_flags; }; #ifdef CONFIG_PAGE_EXTENSION +/* + * The page_ext_flags users must set using_shared_ext_flags to true. + */ enum page_ext_flags { PAGE_EXT_OWNER, PAGE_EXT_OWNER_ALLOCATED, @@ -31,6 +35,9 @@ enum page_ext_flags { * page_ext helps us add more information about the page. * All page_ext are allocated at boot or memory hotplug event, * then the page_ext for pfn always exists. + * Note: that if none of the users of page_ext is setting + * using_shared_ext_flags to true, the field cannot be used, + * as it will be overlapped with another data. */ struct page_ext { unsigned long flags; diff --git a/mm/page_ext.c b/mm/page_ext.c index 4ee522fd381c..7443a797b96b 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -71,6 +71,7 @@ static bool need_page_idle(void) } static struct page_ext_operations page_idle_ops __initdata = { .need = need_page_idle, + .using_shared_ext_flags = true, }; #endif @@ -86,7 +87,7 @@ static struct page_ext_operations *page_ext_ops[] __initdata = { #endif }; -unsigned long page_ext_size = sizeof(struct page_ext); +unsigned long page_ext_size; static unsigned long total_usage; static struct page_ext *lookup_page_ext(const struct page *page); @@ -105,6 +106,15 @@ static bool __init invoke_need_callbacks(void) int entries = ARRAY_SIZE(page_ext_ops); bool need = false; + for (i = 0; i < entries; i++) { + if (page_ext_ops[i]->need && page_ext_ops[i]->need()) { + if (page_ext_ops[i]->using_shared_ext_flags) { + page_ext_size = sizeof(struct page_ext); + break; + } + } + } + for (i = 0; i < entries; i++) { if (page_ext_ops[i]->need && page_ext_ops[i]->need()) { page_ext_ops[i]->offset = page_ext_size; diff --git a/mm/page_owner.c b/mm/page_owner.c index 2d27f532df4c..1a62ab3fc00e 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -99,6 +99,7 @@ struct page_ext_operations page_owner_ops = { .size = sizeof(struct page_owner), .need = need_page_owner, .init = init_page_owner, + .using_shared_ext_flags = true, }; static inline struct page_owner *get_page_owner(struct page_ext *page_ext) diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 93e633c1d587..74cfe89d5f53 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -45,6 +45,7 @@ struct page_ext_operations page_table_check_ops = { .size = sizeof(struct page_table_check), .need = need_page_table_check, .init = init_page_table_check, + .using_shared_ext_flags = false, }; static struct page_table_check *get_page_table_check(struct page_ext *page_ext)