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 AF2D1C4332F for ; Mon, 12 Dec 2022 15:48:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FD448E0003; Mon, 12 Dec 2022 10:48:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8ACA48E0002; Mon, 12 Dec 2022 10:48:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7742D8E0003; Mon, 12 Dec 2022 10:48:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5C2398E0002 for ; Mon, 12 Dec 2022 10:48:14 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2B1E0140A21 for ; Mon, 12 Dec 2022 15:48:14 +0000 (UTC) X-FDA: 80234085708.28.DFDDC12 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf12.hostedemail.com (Postfix) with ESMTP id 46E4F40022 for ; Mon, 12 Dec 2022 15:48:10 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=a2W12krn; dmarc=none; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1670860092; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vaLl2lmaBY1A7ozGAH59ujZxWxDJ+CzoiCtu0mQiesw=; b=Mz6FH1GMFVwugLNlL3P1T26QCr4Pa5LUJf1r1LYWHrp6DapYJXpZVbpOP9lzZjJRaZ5fKf t89NLVdEaQr/+gPgUEzWsLQsdADXQ0zEA1o2gud4PgW2IGohFgRDJRD/2ehiute8PKub0T EF5EshXH0HmZrhxC1/0CuMyd9y2G8sc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=a2W12krn; dmarc=none; spf=none (imf12.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1670860092; a=rsa-sha256; cv=none; b=SeS90OZ7vOL7fCcQH9BrB4C2yZCAQtPM3FSwxmd5PED2vLtoTo62gM7IRnT6uB93g1Xmk6 zhzHmX7owsgavOYGOchrjBo7TFm0HWDcKGRFS/UCycEETjDmSMT+8JJaYrbRjSHrdxIFmG TlLrkw3p/aKR2i+XKjo4+m+Z9e+Yy64= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=vaLl2lmaBY1A7ozGAH59ujZxWxDJ+CzoiCtu0mQiesw=; b=a2W12krnsiY2NXtqCTv98uv6yB MGsPHbvqEcJapFUa9opC2ddhGoMNkTi5pXgnNVdNV2snBJRLrL8miGFMrgl8wmpl8Lni1XWv0LWR4 lSaG+c6oPxVzBSWMOa0PWuYDVNP6Grto1SNAT2oYUYz7KoNU+/ulXYGe3ZUdll9Rt7YX0gkKp/J3L CRWB/Qc0oO3NXsOSkQeQbf68kUXVJZ47/iEpzQAEZvkYV2w+1eNX0+XKCGBKDui58fC5vyQcgG56i uVL6Sgfw5FNtZlkKIGr/uXdXWXnwN0i4hOqmqOlSU51myUHN5MEabZ0JV/QpK75/AFjBFcGfKi8CL BBB1S+eQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1p4l2L-00BCCI-2K; Mon, 12 Dec 2022 15:48:13 +0000 Date: Mon, 12 Dec 2022 15:48:13 +0000 From: Matthew Wilcox To: Nhat Pham Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, bfoster@redhat.com, kernel-team@meta.com Subject: Re: [PATCH v3 3/4] cachestat: implement cachestat syscall Message-ID: References: <20221208202808.908690-1-nphamcs@gmail.com> <20221208202808.908690-4-nphamcs@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221208202808.908690-4-nphamcs@gmail.com> X-Rspamd-Queue-Id: 46E4F40022 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: m5o9qotqmdfp95nkugj44nm1rxhftizu X-HE-Tag: 1670860090-109978 X-HE-Meta: U2FsdGVkX19VSjOPf1ertvOR63Oq9c+UBACXtFviz8vdoXCsCzghePzWDcygisYXZqz9LWnl74/WbZOtCJxMSjQRJ60xLi0tpnmLBVex0ldDiQmWVpp05zd2aVq5AJQ3DpqcluMN8E1yB5bb2XA0/EM5xkNI6hpFlA6V8ghPoRGiITq1dkejJTD8TFy5bTUNdfMCDAV7ma0LNHk+ZUUrYl52QibyoFPPxTNT3FxA4/TCpGfWuwuGJV3SHAkJTQ0ukwlCx0Y4bnfDrGysPMOSdAeu0rQx7xjxXAJH9lXNpHVL6DWqyapm+/fj9Lw3+KAzMqrQ+pQ0VWB+FvuyVVMUYEjWF+L63LPXI+F7j6tZOV5iAk4XAzPIAIr89k6YWFW/kTKVfkNUuhugl2bKxbjB5WQ7/YLvmByMuSxXVCvBX/bGO9MDK9rLdTA8JvfuzrUHD+9skmHCh05kQ0hV6kpxZ1Y1SJLO7LHzOPR/G2qnbdrvGJe0AFoAiFkBq22EF+QWGxZxm0pdi4vmOhVugCYtXtKZAzM0bpg39VYcw/RQK3V6P6wJ20IiIowdDX2UJxzPwwdrqPk2b6llXaZFIE6ywBdDTk/jtz3pSICpXOBaDERGJ4bJryeGrGzlaBeepXEnU4huispT0D/6IYf1J6PFyKoSK/GedwHmzOVsh68ck9Id2sm0TY5ScHvPfTQvvO6KiPXal74hDRu/NKGeDXqeaa+x4ntMr+X3CnLIH5kNxxCqIPcV7S7qOMMc2YbhZgFwkFGqPGet5H2Qhg85xjGXxQGBoy1gwO/JAHarogGy7tunK+MkJRK7w1VXcuSNdhqNXpcQ4YS+ShwMAMH6QamsFw2z0XpM0p2X 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 Thu, Dec 08, 2022 at 12:28:07PM -0800, Nhat Pham wrote: > + struct address_space *mapping = f.file->f_mapping; > + pgoff_t first_index = off >> PAGE_SHIFT; > + pgoff_t last_index = > + len == 0 ? ULONG_MAX : (off + len - 1) >> PAGE_SHIFT; > + XA_STATE(xas, &mapping->i_pages, first_index); > + struct folio *folio; > + > + rcu_read_lock(); > + xas_for_each(&xas, folio, last_index) { > + if (xas_retry(&xas, folio) || !folio) > + continue; !folio can't be true. xas_for_each() terminates when folio is NULL. > + if (xa_is_value(folio)) { > + /* page is evicted */ > + void *shadow = (void *)folio; > + bool workingset; /* not used */ > + > + cs.nr_evicted += 1; > + > +#ifdef CONFIG_SWAP /* implies CONFIG_MMU */ > + if (shmem_mapping(mapping)) { > + /* shmem file - in swap cache */ > + swp_entry_t swp = radix_to_swp_entry(folio); > + > + shadow = get_shadow_from_swap_cache(swp); > + } > +#endif > + if (workingset_test_recent(shadow, true, &workingset)) > + cs.nr_recently_evicted += 1; > + > + continue; > + } > + > + /* page is in cache */ > + cs.nr_cache += 1; > + > + if (folio_test_dirty(folio)) > + cs.nr_dirty += 1; > + > + if (folio_test_writeback(folio)) > + cs.nr_writeback += 1; A folio may represent more than one page. That's the point of folios. So there should be something in here which does unsigned long nr = folio_nr_pages(); and then all these '1' should be 'nr'. Except that you may need to adjust nr if 'first_index' > folio->index, or 'last_index' < folio->index + nr. You should test this with XFS, AFS or erofs to be sure you're getting results that look right.