From patchwork Wed Aug 10 01:32:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kassey Li quic X-Patchwork-Id: 12940101 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 7AF25C19F2D for ; Wed, 10 Aug 2022 01:32:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EED278E0002; Tue, 9 Aug 2022 21:32:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9C058E0001; Tue, 9 Aug 2022 21:32:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3D2B8E0002; Tue, 9 Aug 2022 21:32:28 -0400 (EDT) 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 BFD5F8E0001 for ; Tue, 9 Aug 2022 21:32:28 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9746D40645 for ; Wed, 10 Aug 2022 01:32:28 +0000 (UTC) X-FDA: 79781957976.28.8AF31AD Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf29.hostedemail.com (Postfix) with ESMTP id F3874120165 for ; Wed, 10 Aug 2022 01:32:27 +0000 (UTC) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27A16QW8017125; Wed, 10 Aug 2022 01:32:25 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=0TaMadHaWCi9+mkS7MPh/IpcAd/LeTbwsq5Cbob7Ieg=; b=VmXllawIyAQfTgUT0dEC4eIhIrYE6GS05yk5PISKE0hdCT3ODhhnoLRJqXYWxQT7q/Gf ZzsSfJ4q8SZZuNmIq0TRUXwxqKMy8m6nDTpLgXuXQk+alJwGOcWKrUi9FAZpGGbpu6+O UcD0jukIvDoDyXAFGxFNdbfpvhD7qOj4rg/MqrvmLl6fcLrabWAOjCjrxtQ6+E+9tHBj t+Eh4D+Mc1+mF50bLv5/c9U4n5vMyIw/n/hzZtt8MRkCM0RHuraBPfZPFIL9DqpnDnyy Je/+I+qslNl/4kAYzUhdI75tYddUIAzy5ok3tpuE8zbxdnYd3R9mxH2mzjDhqWVcfaIY XA== Received: from aptaippmta02.qualcomm.com (tpe-colo-wan-fw-bordernet.qualcomm.com [103.229.16.4]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3huwqe0s40-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Aug 2022 01:32:24 +0000 Received: from pps.filterd (APTAIPPMTA02.qualcomm.com [127.0.0.1]) by APTAIPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 27A1WMsn019869; Wed, 10 Aug 2022 01:32:22 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APTAIPPMTA02.qualcomm.com (PPS) with ESMTP id 3hshcntksh-1; Wed, 10 Aug 2022 01:32:22 +0000 Received: from APTAIPPMTA02.qualcomm.com (APTAIPPMTA02.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27A1WLbP019864; Wed, 10 Aug 2022 01:32:21 GMT Received: from maow2-gv.ap.qualcomm.com (maow2-gv.qualcomm.com [10.232.193.133]) by APTAIPPMTA02.qualcomm.com (PPS) with ESMTP id 27A1WLZS019862; Wed, 10 Aug 2022 01:32:21 +0000 Received: by maow2-gv.ap.qualcomm.com (Postfix, from userid 399080) id EE6F221029A4; Wed, 10 Aug 2022 09:32:19 +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 v6] mm/page_owner.c: add llseek for page_owner Date: Wed, 10 Aug 2022 09:32:18 +0800 Message-Id: <20220810013218.27416-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: 1JB7qkCbm5CSr-IodJRyN2v5pY907gv5 X-Proofpoint-ORIG-GUID: 1JB7qkCbm5CSr-IodJRyN2v5pY907gv5 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-10_01,2022-08-09_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 mlxscore=0 adultscore=0 impostorscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208100003 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660095148; 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=0TaMadHaWCi9+mkS7MPh/IpcAd/LeTbwsq5Cbob7Ieg=; b=vqSZZUAeVp940vlQBKOcOr4uajAM8ZrwJw+IW7T4UZ3qagCF0i5g958VyxWSX4pj3/Ell0 5+wZSDTDvC93+A4irWqOFCLBC5vaNvJrHHKSmL+1OOLfFcvjQXzXNmFbAKoS1omBAJfamY pqE7id2c1tGWta4v4uFxhQuU0aYZxgA= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=VmXllawI; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf29.hostedemail.com: domain of yingangl@qualcomm.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=yingangl@qualcomm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660095148; a=rsa-sha256; cv=none; b=PZEymzDW9Xa+yChQ3y9m/IB6hxApph9kYwp2zludWN2Y40mf8qrd31Y9EGUtFb1+sj3sMS te9zNr6LEu1NuH4b5bOXD+iec3iwTHDm9lqZSgPyBr3oj9j2SxTc7AFh/EJ+aff6L4hpDX acU03JE6oZVTp7FZhZt1OIDVUp5cKBk= X-Rspamd-Queue-Id: F3874120165 X-Rspamd-Server: rspam03 X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=VmXllawI; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf29.hostedemail.com: domain of yingangl@qualcomm.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=yingangl@qualcomm.com X-Stat-Signature: 8tujpjge55fzrewkz5syzzrn5kzdkfxb X-HE-Tag: 1660095147-89188 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 Reported-by: kernel test robot --- Documentation/vm/page_owner.rst | 6 ++++++ mm/page_owner.c | 10 +++++++--- 2 files changed, 13 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/page_owner.c b/mm/page_owner.c index e4c6f3f1695b..33832b5908e6 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -13,6 +13,7 @@ #include #include +#include "../fs/proc/internal.h" #include "internal.h" /* @@ -497,8 +498,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 +564,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 +663,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)