From patchwork Wed Sep 21 03:17:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 12983106 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 22F40C54EE9 for ; Wed, 21 Sep 2022 03:18:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B0D1080007; Tue, 20 Sep 2022 23:18:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ABD7B6B0073; Tue, 20 Sep 2022 23:18:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 984D880007; Tue, 20 Sep 2022 23:18:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 898AB6B0072 for ; Tue, 20 Sep 2022 23:18:38 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 61242AAC6E for ; Wed, 21 Sep 2022 03:18:38 +0000 (UTC) X-FDA: 79934635116.29.8E812B5 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by imf25.hostedemail.com (Postfix) with ESMTP id 39D75A00D4 for ; Wed, 21 Sep 2022 03:18:36 +0000 (UTC) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTPS id 28L3HnXk067053 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Wed, 21 Sep 2022 11:17:50 +0800 (CST) (envelope-from zhaoyang.huang@unisoc.com) Received: from bj03382pcu.spreadtrum.com (10.0.74.65) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 21 Sep 2022 11:17:49 +0800 From: "zhaoyang.huang" To: Andrew Morton , Catalin Marinas , Matthew Wilcox , Zhaoyang Huang , , , , Subject: [PATCHv2] mm: introduce NR_BAD_PAGES and track them via kmemleak Date: Wed, 21 Sep 2022 11:17:26 +0800 Message-ID: <1663730246-11968-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.74.65] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 28L3HnXk067053 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663730318; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=aMC5usRkdBUVswHQTVR8sXoA/VyXFxaccgMI8nBuj+8=; b=zp4s1zr6Yg17AONoi7S4vkVyQOZNVN8kmyDNeRiQeHR6VDL6OeG85u4C0532b/c0+W6khO QdBjtakZUgRxJSIISXgMoI6fnVwIe+O2ZMjCz4dZDEFd4hPWYcUkxzoj1jH9PNuENlzi3j iKx/ZnCiGy49DWdzha+uQ+Ma43B/uHM= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf25.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663730318; a=rsa-sha256; cv=none; b=aPm94YWc45mBxyUUmeQy6/aKKQ2imwwCdBygks159ZCOWYYeRIszcIL9sigHtvjElSpdOR TIQ434OGFIbnGlNWA20yZdOZNsG1BFiRsYXKnySRH05+dAM93YXYCTXP0F3qf18+w0e5Gr 5XYk1M1v/IRqb1Lrdc1k1oXLpMIXiiw= Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf25.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com X-Rspam-User: X-Rspamd-Server: rspam01 X-Stat-Signature: 9b7n87tfqrurb8pn19hur5hk8qdxzcus X-Rspamd-Queue-Id: 39D75A00D4 X-HE-Tag: 1663730316-605888 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: From: Zhaoyang Huang Bad pages could be introduced by extra reference among high order pages or compound tail pages which cause the pages failed go back to allocator and leaved as orphan pages. Booking them down and tracking them via kmemleak. Signed-off-by: Zhaoyang Huang --- change of v2: add booking for bad pages --- --- include/linux/mmzone.h | 1 + mm/page_alloc.c | 13 ++++++++++--- mm/vmstat.c | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index e24b40c..11c1422 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -166,6 +166,7 @@ enum zone_stat_item { NR_ZSPAGES, /* allocated in zsmalloc */ #endif NR_FREE_CMA_PAGES, + NR_BAD_PAGES, NR_VM_ZONE_STAT_ITEMS }; enum node_stat_item { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e5486d4..a3768c96 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1408,7 +1408,7 @@ static __always_inline bool free_pages_prepare(struct page *page, __memcg_kmem_uncharge_page(page, order); reset_page_owner(page, order); page_table_check_free(page, order); - return false; + goto err; } /* @@ -1442,7 +1442,7 @@ static __always_inline bool free_pages_prepare(struct page *page, if (check_free) bad += check_free_page(page); if (bad) - return false; + goto err; page_cpupid_reset_last(page); page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; @@ -1486,6 +1486,11 @@ static __always_inline bool free_pages_prepare(struct page *page, debug_pagealloc_unmap_pages(page, 1 << order); return true; +err: + __mod_zone_page_state(page_zone(page), NR_BAD_PAGES, 1 << order); + kmemleak_alloc(page_address(page), PAGE_SIZE << order, 1, GFP_KERNEL); + return false; + } #ifdef CONFIG_DEBUG_VM @@ -1587,8 +1592,10 @@ static void free_pcppages_bulk(struct zone *zone, int count, count -= nr_pages; pcp->count -= nr_pages; - if (bulkfree_pcp_prepare(page)) + if (bulkfree_pcp_prepare(page)) { + __mod_zone_page_state(page_zone(page), NR_BAD_PAGES, 1 << order); continue; + } /* MIGRATE_ISOLATE page should not go to pcplists */ VM_BUG_ON_PAGE(is_migrate_isolate(mt), page); diff --git a/mm/vmstat.c b/mm/vmstat.c index 90af9a8..d391352 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1193,6 +1193,7 @@ int fragmentation_index(struct zone *zone, unsigned int order) "nr_zspages", #endif "nr_free_cma", + "nr_bad_pages", /* enum numa_stat_item counters */ #ifdef CONFIG_NUMA