From patchwork Mon Oct 4 06:13:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 12533213 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4E60C433FE for ; Mon, 4 Oct 2021 06:13:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4ADCB6136F for ; Mon, 4 Oct 2021 06:13:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4ADCB6136F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E82DE6B006C; Mon, 4 Oct 2021 02:13:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E354D940007; Mon, 4 Oct 2021 02:13:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D214D6B0072; Mon, 4 Oct 2021 02:13:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0046.hostedemail.com [216.40.44.46]) by kanga.kvack.org (Postfix) with ESMTP id C5D896B006C for ; Mon, 4 Oct 2021 02:13:57 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 77EFE2DD6C for ; Mon, 4 Oct 2021 06:13:57 +0000 (UTC) X-FDA: 78657739314.05.96F02F1 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf04.hostedemail.com (Postfix) with ESMTP id 23DDC5002560 for ; Mon, 4 Oct 2021 06:13:57 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1633328036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3zybDAbiFx8eNx5Xj1zigIuKK40gVXN3QG9GqRjgOCg=; b=rYPPc49RliyGGQtOMJyEcO9RqQkzxDopSpMvcRrD4d/GqzvRu+8TvlwsqjvSzg5QGHMAif pPMUHeSzLaDa0XG0O7AOt2u8TyZuA14D/B8a0d0RZjPEQoxViUS1qLNaMYbOqxHYTqutEt DwJ3R14NxEOF9Kzn/bdaH9xeQtqXGc8= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , Konstantin Khlebnikov , Christian Hansen , Changbin Du , Bin Wang , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v1 1/3] tools/vm/page-types.c: make walk_file() aware of address range option Date: Mon, 4 Oct 2021 15:13:23 +0900 Message-Id: <20211004061325.1525902-2-naoya.horiguchi@linux.dev> In-Reply-To: <20211004061325.1525902-1-naoya.horiguchi@linux.dev> References: <20211004061325.1525902-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: naoya.horiguchi@linux.dev X-Rspamd-Queue-Id: 23DDC5002560 X-Stat-Signature: 17cmmwoe8y5xs8km7er4bce7398331rm Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=rYPPc49R; spf=pass (imf04.hostedemail.com: domain of naoya.horiguchi@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=naoya.horiguchi@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspamd-Server: rspam06 X-HE-Tag: 1633328037-777354 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: Naoya Horiguchi -a|--addr option is used to limit the range of address to be scanned for page status. It works now for physical address space (dafult mode) or for virtual address space (with -p option), but not for file address space (with -f option). So make walk_file() aware of -a option. Signed-off-by: Naoya Horiguchi --- tools/vm/page-types.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git v5.15-rc3/tools/vm/page-types.c v5.15-rc3_patched/tools/vm/page-types.c index f62f10c988db..b14376af1f16 100644 --- v5.15-rc3/tools/vm/page-types.c +++ v5.15-rc3_patched/tools/vm/page-types.c @@ -967,22 +967,19 @@ static struct sigaction sigbus_action = { .sa_flags = SA_SIGINFO, }; -static void walk_file(const char *name, const struct stat *st) +static void walk_file_range(const char *name, int fd, + unsigned long off, unsigned long end) { uint8_t vec[PAGEMAP_BATCH]; uint64_t buf[PAGEMAP_BATCH], flags; uint64_t cgroup = 0; uint64_t mapcnt = 0; unsigned long nr_pages, pfn, i; - off_t off, end = st->st_size; - int fd; ssize_t len; void *ptr; int first = 1; - fd = checked_open(name, O_RDONLY|O_NOATIME|O_NOFOLLOW); - - for (off = 0; off < end; off += len) { + for (; off < end; off += len) { nr_pages = (end - off + page_size - 1) / page_size; if (nr_pages > PAGEMAP_BATCH) nr_pages = PAGEMAP_BATCH; @@ -1043,6 +1040,21 @@ static void walk_file(const char *name, const struct stat *st) flags, cgroup, mapcnt, buf[i]); } } +} + +static void walk_file(const char *name, const struct stat *st) +{ + int i; + int fd; + + fd = checked_open(name, O_RDONLY|O_NOATIME|O_NOFOLLOW); + + if (!nr_addr_ranges) + add_addr_range(0, st->st_size / page_size); + + for (i = 0; i < nr_addr_ranges; i++) + walk_file_range(name, fd, opt_offset[i] * page_size, + (opt_offset[i] + opt_size[i]) * page_size); close(fd); }