From mboxrd@z Thu Jan 1 00:00:00 1970 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 6B82FC61DB3 for ; Fri, 13 Jan 2023 14:44:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D55BA8E0002; Fri, 13 Jan 2023 09:44:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D06508E0001; Fri, 13 Jan 2023 09:44:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA6CC8E0002; Fri, 13 Jan 2023 09:44:43 -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 A55FE8E0001 for ; Fri, 13 Jan 2023 09:44:43 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6BA2D1A0D2E for ; Fri, 13 Jan 2023 14:44:43 +0000 (UTC) X-FDA: 80350047246.03.4FA91A8 Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) by imf30.hostedemail.com (Postfix) with ESMTP id D953A80019 for ; Fri, 13 Jan 2023 14:44:40 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="Rp/Ifn8d"; spf=pass (imf30.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.174 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673621081; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OHw3k7LrErv7fYTTvWXg9NIs8GnGGGZAXtd7K+9HpQU=; b=DAnxswxVo6gQg3ifW4braT+RrME0uZ5PKEE58o71uGQnjkn5qYkcT7j/cIqY6YX6uSBE7E 5ozhPkT6utdn2wK3+f4ZYVhnXcGlIu/PikKrFlEDpbzSUSpXRlQgiF6hByT8vepPdiCHpI qMuumFt8ygtvSvRviEfHzhqAoPyPi5c= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b="Rp/Ifn8d"; spf=pass (imf30.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.174 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673621081; a=rsa-sha256; cv=none; b=oSXUk+PnVIiIowuoVb3cFZ2uMnPn73I5oLwNX83VOoezkl3Jwb1oALUKcg/BPOQb3fCYvd +ATFTxbFHeFpk9s0dsSZGpisJGRiAkxoE1iB6z5LriGYB1XhGd0Evj3LzOVglTketTFfjX uZgiL1klpfMDn8xyOUz0CQXeVXQcIhk= Received: by mail-yb1-f174.google.com with SMTP id 20so3511733ybl.0 for ; Fri, 13 Jan 2023 06:44:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=OHw3k7LrErv7fYTTvWXg9NIs8GnGGGZAXtd7K+9HpQU=; b=Rp/Ifn8dxC3xWcv7T/XAUSYC3w6fwjT7YZBN1n8xB8xc35lZXvJY8wiXxPs/E4lonQ AS0UF5r2S6NAJ7CIkUHFbEI6PRapCsqSaZP8VbmGpNMhQ3K/5vgmzUsWTgbIxnXqIcYl 5HMibKhwjEpXyi8gMC4tbDjNvpn0E6ksclTRl1XTVUnJT3RjnD2Q9zdF54XH7N1ISKhJ u8+US36xvpOzgb55RMzrfs8Kr4CLEQBpvvlHImCoDB2z7hcTSiIq1C6qAATmT2a5QQur GRtn2wbLmDg871HQh2yLsEUL0NAEM9M0HErF2SMKXCNI1UtNI/dRUAb2zGeOQw/NNrfG IrnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OHw3k7LrErv7fYTTvWXg9NIs8GnGGGZAXtd7K+9HpQU=; b=dCoH66LuC48tu7/WOkduQTGe/TWwwtuF9PzEEBnu/spaIy1eQDFxt/7L2UvwBvnYDO guRB1ngC5AL1j3KgzH1B8VpA7dkCzsG6bRmyPigDVdgDWf0sZG3MTF/BB9TYny0kupJ3 GvSSw6RxgbgqKU+bA+aGtQYbtaT18jIBWrXIRtiaOnFjX1kfnmbh8HABXw0MYJ9t7fh2 7CqV4ULg3eJfwbZJV2BZogkTNPOy/+FdhdJ/pIaY4mBgjJFf2x93fRizZh0vMFLdqdn5 t6qZx1hyu+dyIxcjx6SoAdov4HNWUlffBDpCIFM/l6orrULSaYZDOL5ckfFUk5+WHdkO E4rQ== X-Gm-Message-State: AFqh2koK365Nhucxz2pJVBpihSlcnmsQxDbdk2VRfShliOuznIR9g8ri NRuP78ZKnNhdz5cDzVp+o0/Tvd9F5kI9lbOvg8o+dA== X-Google-Smtp-Source: AMrXdXs665I27NS//jndHFdQEwk95kthSZVJdVhRJXzUHYLy+us2ns+UsPdUj637qQNawIbhigf/dGpBqGrDFDbjDe8= X-Received: by 2002:a25:2d3:0:b0:7c2:d9f1:3b06 with SMTP id 202-20020a2502d3000000b007c2d9f13b06mr1037342ybc.571.1673621079856; Fri, 13 Jan 2023 06:44:39 -0800 (PST) MIME-Version: 1.0 References: <20230112153348.3202173-1-pasha.tatashin@soleen.com> <20230112132957.6cb97c2afad17cdeb06fcd10@linux-foundation.org> In-Reply-To: <20230112132957.6cb97c2afad17cdeb06fcd10@linux-foundation.org> From: Pasha Tatashin Date: Fri, 13 Jan 2023 09:44:02 -0500 Message-ID: Subject: Re: [PATCH v2] mm/page_ext: Do not allocate space for page_ext->flags if not needed To: Andrew Morton Cc: 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 Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: ftw3ea7utx5big6fe8p897itxb7jieyd X-Rspamd-Queue-Id: D953A80019 X-HE-Tag: 1673621080-237836 X-HE-Meta: U2FsdGVkX19jskeABWdqayQ4jv7iIuda42ppR+1zJeeteLjx59hXWk869G7YLWRkgbH0ENAyTXv1FghVQ4TbxKqTWSZgmye7q6OrLSv03iTxqGXEtuO1zXRyCrso3XObGVseeVWk3y3PBop7Gc3x6QvCl1jZnMeMhT3OZfPY4DVklhtKjbXGe4d8r2V07nxZGgk6HNGyapyNR+cMKaxrYar9Z063wb+akcUrS0+yBbuRgCn4f5qW+MXctgyL4do1GGCshDc8b60JgzCtEnxMZurVvGg/WK3M0tBiQNhaRvXEgqZ83KamA/7J/GEvRTff/QIU/ONW0JsWx+wMocYWBZfE/TDu9yEgzUgKALisIzM2Pc6kj4STeo2u+hSoF9xewVf+kEQ8+iMHs7vlPzJtsXmGs7Pz5v7kgj0775yui4qn9IqVfAO/zJAcgU1DhqarKCdRAVQ47TPiRBv43VRzY7jxcLyKXtKsBzgvD0pI4PBI9A1WVgBcyEESCJ2Q4z6jI5KTtoO0a7m2W4oKgxs3YrN3jkTL4KZmThFd4wtshf1zaIkMwNt9EPW/hhe1YwMtBcU7B8ad/RF31OIJTpF/7SbcYVKfSWysdbu7sLoH1lXuuww0+L0l+aNlpwI8mhjRXtfNlWIfEh3w/CPMnmMhmZGtR2S0TrXOMVIrArsxYJagcm4FdblWD+BiRVPplLcBi9FAbrBtbKOFovzzPkSpSw87LkX8vQ4Pn3n9flyChJTSQQkPfCWFIpFcMjM1AMAa73eXnvz6QXlCRe5900OVwWEbo9QbKo8lybpp8Acxw42j6AeKQldXUNyeSQN6tin3UlCpDhBenmBb+HkvWjMBZCxmc1Ad1MvXUMpzcmcaghCYzp/xpxHCjSa5Nq9imkr4AkCSqg5K7hL4oVs1e5NgKKT5yHfEttWU5wKbIVfnNPGYae/pT8Oi0b1FRTdN47xpZlTC18fyIRYAzBiR1dF nLwaiNi5 227uPUBDgAhtsjF1+CVEj8h9kLScaC5Kb2xqE 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: On Thu, Jan 12, 2023 at 4:29 PM Andrew Morton wrote: > > On Thu, 12 Jan 2023 15:33:48 +0000 Pasha Tatashin wrote: > > > 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 > > > > Looks nice. Hi Andrew, Thanks for looking at this patch. > > Does it work correctly with early_page_ext=1? Yes, early_page_ext=1 moves page_ext_init() earlier, and disables deferred page initialization, but that is not an issue for the changes in this patch. > > > --- 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; > > }; > > Seems overly complicated. Can we change the three early-init > functions such as setup_early_page_ext() to simply set some global bool > flag? We can't because , in the following loop: 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; page_ext_size must already either include or not the space for the shared flag field. > > > #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()) { > > I don't think this (or the below) need to check for ->need==NULL? Good point, I will remove the check, and also update the comment that the "need" function must be defined for every item in the page_ext_ops array. Thanks, Pasha