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 0C066C00140 for ; Tue, 9 Aug 2022 02:47:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4140F8E0001; Mon, 8 Aug 2022 22:47:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39BD46B0072; Mon, 8 Aug 2022 22:47:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 215938E0001; Mon, 8 Aug 2022 22:47:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0C6686B0071 for ; Mon, 8 Aug 2022 22:47:37 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CBF0D801BC for ; Tue, 9 Aug 2022 02:47:36 +0000 (UTC) X-FDA: 79778518512.28.B37BBA6 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf22.hostedemail.com (Postfix) with ESMTP id 2C375C005A for ; Tue, 9 Aug 2022 02:47:34 +0000 (UTC) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2792iq9R032199; Tue, 9 Aug 2022 02:47:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id; s=qcppdkim1; bh=NDL5eqQWb493Q35OIi+aiikJfYXEG7IvNW4qAU80DAM=; b=C1gq2N9Gr5Bv23OIn2UOEcFWM12IL5VBydRpfI6WzW1P+RZWAp/ARqrQHVfcNFblEkle jEN1117wOmAgjIrE+DoGKfqPnvqOMIxae5dgvdCgx5RAjNw+Cnbq8xo3N5EUwb2Sq6Z3 Ww4x5dA93Sb7cb9ofR8QrfvGcEri8FoSmiKeu4YomUIRtQAWlaZEIEcFV4wEfTTzouFl 7h45xJFDlE75EbHHNGmraMTgCBLQbsETSKdfVJszvhMr+Xctl0VgISd35MF0VrISiUP/ x5JAvS+crxEXL7SRajlOdWXRMduFznodK0mmG5J4oCwXKMAhM7PXGD9hLHyRoCvObvsv Cw== Received: from aptaippmta01.qualcomm.com (tpe-colo-wan-fw-bordernet.qualcomm.com [103.229.16.4]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3hudun83df-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 Aug 2022 02:47:31 +0000 Received: from pps.filterd (APTAIPPMTA01.qualcomm.com [127.0.0.1]) by APTAIPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 2792lSN0014090; Tue, 9 Aug 2022 02:47:28 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APTAIPPMTA01.qualcomm.com (PPS) with ESMTP id 3hshcpr0q1-1; Tue, 09 Aug 2022 02:47:28 +0000 Received: from APTAIPPMTA01.qualcomm.com (APTAIPPMTA01.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2792lSGc014083; Tue, 9 Aug 2022 02:47:28 GMT Received: from maow2-gv.ap.qualcomm.com (maow2-gv.qualcomm.com [10.232.193.133]) by APTAIPPMTA01.qualcomm.com (PPS) with ESMTP id 2792lR36014080; Tue, 09 Aug 2022 02:47:28 +0000 Received: by maow2-gv.ap.qualcomm.com (Postfix, from userid 399080) id 7B79A21029A4; Tue, 9 Aug 2022 10:47:26 +0800 (CST) From: Kassey Li To: akpm@linux-foundation.org, vbabka@kernel.org Cc: Kassey Li , minchan@kernel.org, vbabka@suse.cz, iamjoonsoo.kim@lge.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v5] mm/page_owner.c: add llseek for page_owner Date: Tue, 9 Aug 2022 10:47:25 +0800 Message-Id: <20220809024725.31980-1-quic_yingangl@quicinc.com> X-Mailer: git-send-email 2.17.1 X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: stfFisL2DWbhsuVwzePPS6p4677Jx-5d X-Proofpoint-ORIG-GUID: stfFisL2DWbhsuVwzePPS6p4677Jx-5d X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-08_14,2022-08-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1011 bulkscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 impostorscore=0 adultscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2208090012 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660013255; a=rsa-sha256; cv=none; b=Ah0KruT/DM0sQ2G9DefROxRF7zouqqQ/58VsZUIFhJwjVtNH/rDfV4OI1lxMOORH6KpF7Y 7MH4ll5MoNhHtXbtYNrCQWZrspARcCEjuavAdrQydKevxUkxeoEVOIhfDI+ewhBnd3YM8i wULaV10+8epgedgiI+xb4U6z7Ls6/YE= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=C1gq2N9G; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf22.hostedemail.com: domain of yingangl@qualcomm.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=yingangl@qualcomm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660013255; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=NDL5eqQWb493Q35OIi+aiikJfYXEG7IvNW4qAU80DAM=; b=OTGgB1AFXbxWTniGk/vAD/ZpSgZJ02U+b+QkozkcFv+ecRU9fmeeWiH4QOAkGFxaknIJ5W Prk93mvpiNWucDicDqh7XOJRjKUE65XZLKMI98rvqluN6GlyCWuWui4xKCevkYCNl+j9NB 8SKEuYrde1s0XgFMhCkvq6fNerwndYE= X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2C375C005A Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=C1gq2N9G; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf22.hostedemail.com: domain of yingangl@qualcomm.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=yingangl@qualcomm.com X-Rspam-User: X-Stat-Signature: zs7omyqnxo5gzscadcpkzwwzrh3xk8mj X-HE-Tag: 1660013254-484720 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: There is usage to dump a given cma region page_owner instead of all page's. This change allows to specify a ppos as start_pfn by fseek. Any invalid ppos will be skipped, so it did not broken the origin dump feature. Suggested-by: Vlastimil Babka Signed-off-by: Kassey Li --- Documentation/vm/page_owner.rst | 6 ++++++ mm/internal.h | 5 +++++ mm/page_owner.c | 9 ++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Documentation/vm/page_owner.rst b/Documentation/vm/page_owner.rst index f5c954afe97c..8d33d976da8a 100644 --- a/Documentation/vm/page_owner.rst +++ b/Documentation/vm/page_owner.rst @@ -95,6 +95,12 @@ Usage PFN XXX ... // Detailed stack + By default, it will do full pfn dump, to start with a given pfn, + page_owner supports fseek. + + FILE *fp = fopen("/sys/kernel/debug/page_owner", "r"); + fseek(fp, pfn_start, SEEK_SET); + The ``page_owner_sort`` tool ignores ``PFN`` rows, puts the remaining rows in buf, uses regexp to extract the page order value, counts the times and pages of buf, and finally sorts them according to the parameter(s). diff --git a/mm/internal.h b/mm/internal.h index c0f8fbe0445b..1ad8f86e6e33 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -189,6 +189,11 @@ extern void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reason */ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address); +/* + * in mm/page_owner.c: + */ +extern loff_t mem_lseek(struct file *, loff_t, int); + /* * in mm/page_alloc.c */ diff --git a/mm/page_owner.c b/mm/page_owner.c index e4c6f3f1695b..dcbe05e206e1 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -497,8 +497,10 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos) return -EINVAL; page = NULL; - pfn = min_low_pfn + *ppos; - + if (*ppos == 0) + pfn= min_low_pfn; + else + pfn = *ppos; /* Find a valid PFN or the start of a MAX_ORDER_NR_PAGES area */ while (!pfn_valid(pfn) && (pfn & (MAX_ORDER_NR_PAGES - 1)) != 0) pfn++; @@ -561,7 +563,7 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos) continue; /* Record the next PFN to read in the file offset */ - *ppos = (pfn - min_low_pfn) + 1; + *ppos = pfn + 1; return print_page_owner(buf, count, pfn, page, page_owner, handle); @@ -660,6 +662,7 @@ static void init_early_allocated_pages(void) static const struct file_operations proc_page_owner_operations = { .read = read_page_owner, + .llseek = mem_lseek, }; static int __init pageowner_init(void) -- 2.17.1