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 278C4C00140 for ; Thu, 18 Aug 2022 19:00:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0ACED6B0073; Thu, 18 Aug 2022 15:00:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 05CF06B0074; Thu, 18 Aug 2022 15:00:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E42B66B0075; Thu, 18 Aug 2022 15:00:53 -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 D77E66B0073 for ; Thu, 18 Aug 2022 15:00:53 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 02A0E1A1CCD for ; Thu, 18 Aug 2022 16:25:19 +0000 (UTC) X-FDA: 79813238400.23.7AA8702 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf27.hostedemail.com (Postfix) with ESMTP id 8FB06418D4 for ; Thu, 18 Aug 2022 15:46:08 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3FFE05C0E6; Thu, 18 Aug 2022 14:43:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1660833781; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ehxxtYiT/7vGJ/TPD19SxbCiDD4CS1ffwYO+jD11F24=; b=x2Oooyr1rv5hXpbjYlHXDOOrE7K3hD6lAiVEA/XSyALwUdztMiSJmLy/KS/ZdGualdBWTt e/krfuSrm5lscR0XntpSI3/pHprH8hNZt/eLknXIuEzKfhpbu0cyb6e7VQmHAGONS1IeOv ytEJ2cMsMP8GH/7JrD6tFG8Pmvc2vE0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1660833781; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ehxxtYiT/7vGJ/TPD19SxbCiDD4CS1ffwYO+jD11F24=; b=moUWDkKjDbNLwr6Zj/MMtN8mOrAGY4g+PoTls3SPvljI+DDA29zMEAeHT0nC40swNDfHxf Nza99WP4WdzTTkAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C8032133B5; Thu, 18 Aug 2022 14:43:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zlr7LfRP/mJNAwAAMHmgww (envelope-from ); Thu, 18 Aug 2022 14:43:00 +0000 Message-ID: <9ef46ec0-f0fc-3712-b140-53e1471dd5d2@suse.cz> Date: Thu, 18 Aug 2022 16:41:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v9] mm/page_owner.c: add llseek for page_owner Content-Language: en-US To: Kassey Li , akpm@linux-foundation.org, vbabka@kernel.org Cc: minchan@kernel.org, iamjoonsoo.kim@lge.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20220818022425.31056-1-quic_yingangl@quicinc.com> From: Vlastimil Babka In-Reply-To: <20220818022425.31056-1-quic_yingangl@quicinc.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660837571; a=rsa-sha256; cv=none; b=ShYtEWAJIypHq2XMx5z5ybBna0rM+mnqigdQqsqFoLrmcnNbqnB1skOZpHP7u3JMKVrE0l VoDBPKgwrkXSj5ov+h5TIgxFu9H2amgdnLze6v2e5j5IobAz2YtzWjWc2a7cmFXN3e3Trg yBI1+VxZ4uRVL27yzisx0naZC/3orAo= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=x2Oooyr1; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=moUWDkKj; dmarc=none; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660837571; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ehxxtYiT/7vGJ/TPD19SxbCiDD4CS1ffwYO+jD11F24=; b=5TK/j79ZOFHyUtiYAysuRebUjP/eqaPGnxLe6SktclfA94qlJpbzk9sWxNglj4cBZ1Qss2 W1xhNs6w0mJ0F5fymzKbusZE4SlpBsJvlfSkQpOOU2LdixyFyLhL8xpTL+BSqH4gmRm0+7 W4FJaaqbJaCRQw9H+LKc0gyUUJHOJyM= Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=x2Oooyr1; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=moUWDkKj; dmarc=none; spf=pass (imf27.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: 57m6gbmoxfriuickrti3bo7z4zm4xhd3 X-Rspamd-Queue-Id: 8FB06418D4 X-HE-Tag: 1660837568-591850 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: On 8/18/22 04:24, Kassey Li wrote: > It is too slow to dump all the pages, in some usage we just want dump > a given start pfn, for example: CMA range or a single page. > > To speed up and save time, this change allows specify start pfn > by add llseek for page_onwer. > > Suggested-by: Vlastimil Babka > Signed-off-by: Kassey Li Acked-by: Vlastimil Babka > --- > Documentation/mm/page_owner.rst | 5 +++++ > mm/page_owner.c | 24 +++++++++++++++++++++--- > 2 files changed, 26 insertions(+), 3 deletions(-) > > diff --git a/Documentation/mm/page_owner.rst b/Documentation/mm/page_owner.rst > index f5c954afe97c..f18fd8907049 100644 > --- a/Documentation/mm/page_owner.rst > +++ b/Documentation/mm/page_owner.rst > @@ -94,6 +94,11 @@ Usage > Page allocated via order XXX, ... > 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 > diff --git a/mm/page_owner.c b/mm/page_owner.c > index e4c6f3f1695b..25720d81bc26 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); > @@ -570,6 +572,21 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos) > return 0; > } > > +static loff_t lseek_page_owner(struct file *file, loff_t offset, int orig) > +{ > + switch (orig) { > + case SEEK_SET: > + file->f_pos = offset; > + break; > + case SEEK_CUR: > + file->f_pos += offset; > + break; > + default: > + return -EINVAL; > + } > + return file->f_pos; > +} > + > static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone) > { > unsigned long pfn = zone->zone_start_pfn; > @@ -660,6 +677,7 @@ static void init_early_allocated_pages(void) > > static const struct file_operations proc_page_owner_operations = { > .read = read_page_owner, > + .llseek = lseek_page_owner, > }; > > static int __init pageowner_init(void)