From patchwork Sat Dec 17 10:58:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13075815 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 6EC10C3DA6E for ; Sat, 17 Dec 2022 10:58:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 663D38E0005; Sat, 17 Dec 2022 05:58:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 613A48E0001; Sat, 17 Dec 2022 05:58:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48CC48E0005; Sat, 17 Dec 2022 05:58:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3C3138E0001 for ; Sat, 17 Dec 2022 05:58:58 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1A4B680936 for ; Sat, 17 Dec 2022 10:58:58 +0000 (UTC) X-FDA: 80251500756.30.9983797 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf26.hostedemail.com (Postfix) with ESMTP id 76816140002 for ; Sat, 17 Dec 2022 10:58:56 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gmNhZUpz; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671274736; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zGtcBIBUfhLfuojWh++ev934zIQlEdFczfQrOY5ttcA=; b=HrzXAYFzgXGRqihtuwlfTTSDlnokYFG3VVu/4TdqSEeUBVG9LBqr30pXEBo9KKGoelzzX5 l6ZLlsKrxoPTzjkXTrXHY2xoBH4pwNSB/6Qd7J5Woq3bV+hharhygg7WH+a1ja63WPJ5bk oMJ1mVhsfeu3vii/qfZPgQo7IgmG6oc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gmNhZUpz; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671274736; a=rsa-sha256; cv=none; b=FqHNLg11UZsK/sdZlIqFlR4R9DmaDZa6W/wSioGMPmpIEiJGBvsFMIMccNarPWCS/KefV1 hgCwTF6sPG9mUCkFt3F5JAiFy6Jv2RLqlwjneGOAwAsH9SOB8JUxUrWdoIR8Uqsbb1Zc8u vPmAYPq95QPxjpQdyHRePf8v0ONttjE= Received: by mail-pj1-f54.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so8560451pjj.2 for ; Sat, 17 Dec 2022 02:58:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zGtcBIBUfhLfuojWh++ev934zIQlEdFczfQrOY5ttcA=; b=gmNhZUpzp6hloXgPDrdYm+js8KM8oGUz4RoEPL8qMd5uk7RrsoS1YZ6uIO2DdXGx16 9GgmpmXbgPxf/HwpF9u3qbZxjhhzNwri4geXIi6jjYkW/iYYIIP31X5Mc3KKNXJsxB1/ S+Gt3KH/38IY0EJx3P5ji2beeqsHRgl8mOknhviq0tYTP5L8NSnPiWZSZ2KQkEqE/87q m7AmKzME5Hf8zDC2coAFkagXqRu9Uy/6mIsi6PtvZATbMi/O6NZVT+n7YAesHp0LvlGN yZrkBgzLoUPZMVLCgucQOdk5Z+6WDex9HfMsjM2TVI3ITuyT8TwqS6rRWvF1TRtNNLM/ +USA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=zGtcBIBUfhLfuojWh++ev934zIQlEdFczfQrOY5ttcA=; b=GGwZ6h5yKiyns9rH/9O506O7jf8rsaW9tS97AINipontzs8bLkeGB2RiRO6URNEw+j grPr2lRGFHdB5fcT6u+TARpMF9GKqoj3KhyHSTM3Qz4q+F5z74AVbBre1NV5vUVE2FS/ 6dTkjt1NrAJ46qWj5kGHyYETNRReAt2qk+W/Ss+UYh65qeZCmzCEirSirpE4IHWFdPk7 9WVQMmMYYinLvUsu3SvJSZ9us+9Wukxunxt9nHuZCnRo5TErs3q78VbMQ+f9gGUfB7FJ hye2qzjFs7WDCak9OIkZbNiDTemeboUdTOej/V88YdPUsA8qpRvjhlR0zE8xO8AgnN3P /gdg== X-Gm-Message-State: ANoB5pnXoxUApwU3w92BlOj8C2ntUNWbohSxjrE7ArzGj63E+BpNKSCw fdQxY5Gh6+NHxd2iT9QkWNA= X-Google-Smtp-Source: AA0mqf63o4O9RBsUnT44aWN6VWkFYvgMGQRxDyC41gIYrjFVkr5YHiKtTiG9UKOp5FXybj5c/nXA8g== X-Received: by 2002:a17:902:d4c3:b0:189:c322:df3a with SMTP id o3-20020a170902d4c300b00189c322df3amr49501096plg.43.1671274735433; Sat, 17 Dec 2022 02:58:55 -0800 (PST) Received: from vultr.guest ([2001:19f0:7001:12a1:5400:4ff:fe3e:f0b8]) by smtp.gmail.com with ESMTPSA id q10-20020a170902daca00b00185402cfedesm3226690plx.246.2022.12.17.02.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Dec 2022 02:58:54 -0800 (PST) From: Yafang Shao To: akpm@linux-foundation.org Cc: vbabka@suse.cz, 42.hyeyoo@gmail.com, willy@infradead.org, linux-mm@kvack.org, Yafang Shao Subject: [PATCH -mm 1/2] mm: page_owner: split page_owner's flag from the comm flags Date: Sat, 17 Dec 2022 10:58:32 +0000 Message-Id: <20221217105833.24851-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221217105833.24851-1-laoar.shao@gmail.com> References: <20221217105833.24851-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 76816140002 X-Rspam-User: X-Stat-Signature: uiofxx5dhcbtfaosaikoibkbscfi35pm X-HE-Tag: 1671274736-804329 X-HE-Meta: U2FsdGVkX18sdIK6rGOjnnIvWpsrM57ptEwc+YxjjXYpmPHvkfnzufZTr/4MwhR0OSmLzTZG5FMaDp6isOgqIGxz8ldJqLb1VtXy+pwG4TX7mvXH1KGQOUEmSY+q/RJR3m0dm3xvnxafxFqw6hcyixvtE2J+T7u4TFiCUMmDd71ELUeDKKaAefEYZ5vcdP8HUD7Gv3P/Ke292IIufZCKs2l9OsO0Qjps3e8Wd1lyCJGdRHcyVuaxwIXDutlYwMcaafyRDOyDM7ZlnCYAbe1H2hrn4ed4Upz6BxOnk8KmZG/wfUrG1kQGOy5OQmnlEWmbtjUwL3w0tryRXq8mGW5uaIiQMwOE4dhMCuf1se/aX0TberGhTDxvc6enLLCKKtmCXqIYIkJPxTFHW9sEKUwuOoDPTycB96H1/9tzpjuOS+H0JI2w6PQX0ImKNctw/3XlZDnythtiw4iibT2UjY0yMl5mBC1oHfP6GXoefaIEGAXTSlqa7dPqDDyf1b/JV9IvV0GgMpHuDskgEBlyaJ3eWRtvrBuOQQHlFtA+kRQKUPk0a9EOjsW4V0hmCvLN5uJPfbPdg7tWHfNJibz6t9juRbv3sHPU2kieKlJkS8SgCuQHnMoNyCqaTmGatiOry5ZO682egOQhLtbkL8820OshoprkWZu/eZqDQtg3qM6CZF2UwfJG2CHKLz8XaCQyjs8aTOGhGZ0jw2tdxsmuPsOjOFavtKlXp342upRZOFeNgdeSwDppaKNgWkoJkpvQ9XIMv3aZxHhHX5W9bEZg83efTBUmWS7pC+GlW93/i9vvWko8AohtXP+vr90y+gHm9iqJzP5QMVR1bZ9ZjrDwpk6gwfhZp7+m7jUcLYLSNjxm06Sa6xWERiwiDMKWxqE9qjf6iP6sY61wb52Tp2lHONaIkWUdDTB2v4Sg8au3/fgNq7vQVmLJ9QkKx4YipQBFRhgpxxKyPR5ISTUYi2+Mrfr EGOELKPS qUbt/sS5wbyJAYjYKZbIkOz7qT9CX8VgDA7FelX0MBduH047F0xWUIs3mMChMM/WzGRFYoD6igcvpXMcWUVToqc54x08rRNVatPuSuq5aGmZYDujMuCrVkvWK2LjkwiFa1rC5/7aM7F8IWn1QPNDr2XTLHw/PfNUWSRYSyCj2EAawxCw1YfHEOuqCwPWDhWVcDWdTX0BAEIALvQEk+uU9lC/8NKMpjAQ6/qfRk+v42SE2n1OeyNhRhIBjLIdYQ4yXrGmIFxpn0FidT/Ikk1HCjI41bg== 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: We split page_owner's flag from the common page_ext's flag, temporarily this patch will increase the memory overhead of page owner. But considering the page owner is for debugging purpose only, it is acceptable. After we split all page exts' flags from the comm flags, we can reduce the memory overhead for the page ext which wants to run on production environment. Signed-off-by: Yafang Shao --- include/linux/page_ext.h | 6 ++---- mm/page_owner.c | 36 ++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index 22be4582faae..c8ca4954145c 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -16,14 +16,12 @@ struct page_ext_operations { #ifdef CONFIG_PAGE_EXTENSION -enum page_ext_flags { - PAGE_EXT_OWNER, - PAGE_EXT_OWNER_ALLOCATED, #if defined(CONFIG_PAGE_IDLE_FLAG) && !defined(CONFIG_64BIT) +enum page_ext_flags { PAGE_EXT_YOUNG, PAGE_EXT_IDLE, -#endif }; +#endif /* * Page Extension can be considered as an extended mem_map. diff --git a/mm/page_owner.c b/mm/page_owner.c index 2d27f532df4c..f6e8ee8fa9c5 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -21,6 +21,11 @@ */ #define PAGE_OWNER_STACK_DEPTH (16) +enum page_owner_flag { + PAGE_EXT_OWNER, + PAGE_EXT_OWNER_ALLOCATED, +}; + struct page_owner { unsigned short order; short last_migrate_reason; @@ -32,6 +37,7 @@ struct page_owner { char comm[TASK_COMM_LEN]; pid_t pid; pid_t tgid; + unsigned long flags; }; static bool page_owner_enabled __initdata; @@ -147,8 +153,8 @@ void __reset_page_owner(struct page *page, unsigned short order) handle = save_stack(GFP_NOWAIT | __GFP_NOWARN); for (i = 0; i < (1 << order); i++) { - __clear_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); page_owner = get_page_owner(page_ext); + __clear_bit(PAGE_EXT_OWNER_ALLOCATED, &page_owner->flags); page_owner->free_handle = handle; page_owner->free_ts_nsec = free_ts_nsec; page_ext = page_ext_next(page_ext); @@ -174,8 +180,8 @@ static inline void __set_page_owner_handle(struct page_ext *page_ext, page_owner->ts_nsec = local_clock(); strscpy(page_owner->comm, current->comm, sizeof(page_owner->comm)); - __set_bit(PAGE_EXT_OWNER, &page_ext->flags); - __set_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags); + __set_bit(PAGE_EXT_OWNER, &page_owner->flags); + __set_bit(PAGE_EXT_OWNER_ALLOCATED, &page_owner->flags); page_ext = page_ext_next(page_ext); } @@ -264,8 +270,8 @@ void __folio_copy_owner(struct folio *newfolio, struct folio *old) * in that case we also don't need to explicitly clear the info from * the new page, which will be freed. */ - __set_bit(PAGE_EXT_OWNER, &new_ext->flags); - __set_bit(PAGE_EXT_OWNER_ALLOCATED, &new_ext->flags); + __set_bit(PAGE_EXT_OWNER, &new_page_owner->flags); + __set_bit(PAGE_EXT_OWNER_ALLOCATED, &new_page_owner->flags); page_ext_put(new_ext); page_ext_put(old_ext); } @@ -325,10 +331,10 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m, if (unlikely(!page_ext)) continue; - if (!test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags)) + page_owner = get_page_owner(page_ext); + if (!test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_owner->flags)) goto ext_put_continue; - page_owner = get_page_owner(page_ext); page_mt = gfp_migratetype(page_owner->gfp_mask); if (pageblock_mt != page_mt) { if (is_migrate_cma(pageblock_mt)) @@ -467,13 +473,13 @@ void __dump_page_owner(const struct page *page) gfp_mask = page_owner->gfp_mask; mt = gfp_migratetype(gfp_mask); - if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) { + if (!test_bit(PAGE_EXT_OWNER, &page_owner->flags)) { pr_alert("page_owner info is not present (never set?)\n"); page_ext_put(page_ext); return; } - if (test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags)) + if (test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_owner->flags)) pr_alert("page_owner tracks the page as allocated\n"); else pr_alert("page_owner tracks the page as freed\n"); @@ -556,22 +562,22 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos) if (unlikely(!page_ext)) continue; + page_owner = get_page_owner(page_ext); + /* * Some pages could be missed by concurrent allocation or free, * because we don't hold the zone lock. */ - if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) + if (!test_bit(PAGE_EXT_OWNER, &page_owner->flags)) goto ext_put_continue; /* * Although we do have the info about past allocation of free * pages, it's not relevant for current memory usage. */ - if (!test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_ext->flags)) + if (!test_bit(PAGE_EXT_OWNER_ALLOCATED, &page_owner->flags)) goto ext_put_continue; - page_owner = get_page_owner(page_ext); - /* * Don't print "tail" pages of high-order allocations as that * would inflate the stats. @@ -640,6 +646,7 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone) for (; pfn < block_end_pfn; pfn++) { struct page *page = pfn_to_page(pfn); + struct page_owner *page_owner; struct page_ext *page_ext; if (page_zone(page) != zone) @@ -667,8 +674,9 @@ static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone) if (unlikely(!page_ext)) continue; + page_owner = get_page_owner(page_ext); /* Maybe overlapping zone */ - if (test_bit(PAGE_EXT_OWNER, &page_ext->flags)) + if (test_bit(PAGE_EXT_OWNER, &page_owner->flags)) goto ext_put_continue; /* Found early allocated page */