From patchwork Sun Nov 5 07:19:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13445659 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 86550C4332F for ; Sun, 5 Nov 2023 07:20:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7673A6B027C; Sun, 5 Nov 2023 02:20:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 718156B027D; Sun, 5 Nov 2023 02:20:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 606C26B027E; Sun, 5 Nov 2023 02:20:07 -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 507CA6B027C for ; Sun, 5 Nov 2023 02:20:07 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id ECDE314037D for ; Sun, 5 Nov 2023 07:20:06 +0000 (UTC) X-FDA: 81423051612.01.D9D6F66 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by imf05.hostedemail.com (Postfix) with ESMTP id 399F0100004 for ; Sun, 5 Nov 2023 07:20:05 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aWtV+74w; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.167.173 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699168805; 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:references:dkim-signature; bh=wkBJYB+0amHU7Uh6j8q6rO4qnVt0jhVk588GzDZ5r/s=; b=TtYrf/OUT7Cujo2WpbcW2S2CfPaYVJyqvlrGcSIwSMfOllVCHMrOegyeV0RlaZN42OV7X1 zrWF8njtnuCkPaWBY5tNkleUAzzOIjgE1OzSRbniq/KLordAdADa/zM4s932qwX7zkCsFQ XFjHCRyDHEQZtf2+3SDZ6aQy89Xm3Eo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aWtV+74w; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.167.173 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699168805; a=rsa-sha256; cv=none; b=GmAyl0V6NHG9BUmvTDQOlICUGRsRS9tKtVwnPHjua8mqvjCjqr3IdjhaMwgPtfXsL6RolL rMJf3fNo/QHU0nr/OKD/RvFYT0wnOguDD1S0pmwoxcHXC+0r6e9RIpTL9hRY+uNrdjMJCP wdZInQ3Qec7UVIDRqR5X87OQYXVM3NY= Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3b2ea7cca04so2274583b6e.2 for ; Sun, 05 Nov 2023 00:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699168804; x=1699773604; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wkBJYB+0amHU7Uh6j8q6rO4qnVt0jhVk588GzDZ5r/s=; b=aWtV+74wSHObTdtdBQrVivL6yd6huvT6GvegpR3FL0wToOIQQVsK2WZTHt/cpuCd6U D9r79foqI2pcjmKrXIzpdkKpmwJNKIu1bl+ni0KVPoz31hJbihE42B6N5osyyPyGolB+ An+YomZupzjOn36j1WDXMAbB5Sk2n4MQZvA6o0AluyaRCI3R4Bubkif07kpqQUGAvCH0 VvEBpSmQ863JIdDr9uxdRVWl3tB6YycaDJ45dbmWJvWXEKmTNpHCaOImD7InpfsSWYyj S4IGAkxdq0S1YzZeApcpuoDKndONcY391NrZ3DquptKZaSC23k6trwXa2r8VARFRc7W9 +lAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699168804; x=1699773604; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wkBJYB+0amHU7Uh6j8q6rO4qnVt0jhVk588GzDZ5r/s=; b=EzJCTdfoEqlUZf32tSqpsp9Yu3YMGTBggEV/mjpYNdcdPYglhGVKqAa9HJQBFrD2I6 8x8o6ocYiLo9Bm8tbK+gIoC7FGXFBuRI98vAuwQ79+5PsaGP+yo0wwWc/xRL24OdffMj AQGG+ZAoep5sYBVuOq5w2UxiUS8qg5ZmuQU2Wc3cnv8Z4BxN/XlI2nuik+z3Sf+UQhV4 1EaeRyZQiaDGXQw0bLoUmjkBKI4H+SGw7oKUhbGd6hJ4cgA9tpDS4Pf/bhLJsbcpVxIG Amjpiz4vn/7fepRr0nXDgTuq7u1g3JZOHUoWiDJKT/dRzcR5/6KcqzuPYGF2zqE2Yt8p JVzA== X-Gm-Message-State: AOJu0Yz1EtDFpxzve4xoK9492VhS7ru/hKUCK4p4IFFy9H5vSDpzk0iE ATUUeQcU0hZXdXNgsdTDrxM= X-Google-Smtp-Source: AGHT+IGeZs1dYM5jzBN7R9cDEt1OZ4CuAZXg8IqiD3aV4gOf9Rpc0yNTlTG8Cp9K4cRfEoZzsbPVRQ== X-Received: by 2002:a54:4883:0:b0:3b2:f2e0:1ecd with SMTP id r3-20020a544883000000b003b2f2e01ecdmr29246556oic.4.1699168804264; Sun, 05 Nov 2023 00:20:04 -0700 (PDT) Received: from barry-desktop.hub ([2407:7000:8942:5500:d1f4:b6cb:ff09:d775]) by smtp.gmail.com with ESMTPSA id u8-20020aa78388000000b0068fe5a5a566sm3813324pfm.142.2023.11.05.00.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 00:20:03 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> X-Google-Original-From: Barry Song To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Barry Song Subject: [PATCH] mm/page_owner: record and dump free_pid and free_tgid Date: Sun, 5 Nov 2023 20:19:48 +1300 Message-Id: <20231105071948.44079-1-v-songbaohua@oppo.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 399F0100004 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: pi1kbnrtfnwhfpzgdb8wij761d38h6ch X-HE-Tag: 1699168805-818436 X-HE-Meta: U2FsdGVkX1+c9U7sClKKlnFAXN3ldJ+eDEjQqD66XcxkNk+oInMtbM2L5hg0Hg9hUgcc/Ncr4S/23BvBYG4j4dNUQ8QDRMzQ8Jrkjl8R5KvyQwPF1ASevqWyzM3HHmf8hjP0r8DUjcmwmk4KfumNlyGUZs7IVzrEopgDFbCntPpO1D75TWNrcj5vKfeULl/QzmbGPC0BrcBx1uKjZm9Diuz06AacUPX/u4QHxuVjaXAkHcLQ7K2CmjDRfFmeM+Xt9ldAA+PKmfyChLlAbwPF3UhMFPkWLwlzkUY6Afb/VwNwrBd+Sbk9ao85D3ubM21IbaY2qESkszAU/6I7t4rh6BEoRtY/tvEYkIYb4ytSLBxug7ahxTinz3h/5DcTzWUTAQf2OJzt3XEqwul/zRbVH/APo4IyUqPeet8uD5vjPjNEY88VXiBlxbXj9rc7kk9HrgTQonX2YUJsCG3qvq36/MvbZWUfFjqq6YERDEqq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ulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: While investigating some complex memory allocation and free bugs especially in multi-processes and multi-threads cases, from time to time, I feel the free stack isn't sufficient as a page can be freed by processes or threads other than the one allocating it. And other processes and threads which free the page often have the exactly same free stack with the one allocating the page. We can't know who free the page only through the free stack though the current page_owner does tell us the pid and tgid of the one allocating the page. This makes the bug investigation often hard. Thus, This patch adds free pid and tgid in page_owner, so that we can easily figure out if the freeing is crossing processes or threads. Signed-off-by: Barry Song --- mm/page_owner.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 4f13ce7d2452..767ec15da8da 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -32,6 +32,8 @@ struct page_owner { char comm[TASK_COMM_LEN]; pid_t pid; pid_t tgid; + pid_t free_pid; + pid_t free_tgid; }; static bool page_owner_enabled __initdata; @@ -152,6 +154,8 @@ void __reset_page_owner(struct page *page, unsigned short order) page_owner = get_page_owner(page_ext); page_owner->free_handle = handle; page_owner->free_ts_nsec = free_ts_nsec; + page_owner->free_pid = current->pid; + page_owner->free_tgid = current->tgid; page_ext = page_ext_next(page_ext); } page_ext_put(page_ext); @@ -495,7 +499,8 @@ void __dump_page_owner(const struct page *page) if (!handle) { pr_alert("page_owner free stack trace missing\n"); } else { - pr_alert("page last free stack trace:\n"); + pr_alert("page last free pid %d tgid %d stack trace:\n", + page_owner->free_pid, page_owner->free_tgid); stack_depot_print(handle); }