Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6968824rwb; Mon, 12 Dec 2022 08:28:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5uWpBZ3AViNRcOufnSgbFYH5BJ1Jiujl3FAT6yqXr1BwnHdLPCUDloeZiYrygyPV0aSQWv X-Received: by 2002:a17:906:647:b0:7ad:d7f9:38b8 with SMTP id t7-20020a170906064700b007add7f938b8mr14363023ejb.57.1670862517377; Mon, 12 Dec 2022 08:28:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670862517; cv=none; d=google.com; s=arc-20160816; b=WFG7+q9xsR+L8/FKIfixL07MKKaO2LDor1johiWmoslEJLiB3hfTaNBZhx/WjDYkgx ++N2UKYIXShnYRlDf7YULzDWHCP1ns/SzVdbUnLxmHww2PyervET22QKDheoVQQfEaRx MiDATkjj/xTl9CEJjb4YxTDJh9DFFdsnS4GJF0Ufmt+Q743kmwuHiIRKEEzrtrkU2b2a bgd+zo7wjHtYVSrdmSAMbaAEaV8i75T1p1BRaDUUdN0FMIE4IQJhmha1wSLAY7O7Dsn3 770J/ANAsSxgs3zG9N4rnF2W1ccGVOs89LD/0jn8KIKvnI/Ilzj2gkKxxXhy82Yv6XPV gE2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vaLl2lmaBY1A7ozGAH59ujZxWxDJ+CzoiCtu0mQiesw=; b=sfTInDtDgdzfLXMcxHRay3epQ8zBdwm2kKI/A7pYuVvgyz/8T1zAn2RD58yhfPTjZd OAUyJNhlVoKfsHcUthAu23qwrn7eftQy/ADroStd8EJ4nPZfxQSKnxOPpTVBkmYQJSIu /ZO8rvpIe56MBLUedh5EdA/UH6mhADxIbAGX9GoVHyyEd/72gnYH5rITfiMR/0n35shn veoOpm8ZsQnbhM8cDR59LZXLQbGlOaqNjkJVx454BOcoYHRbTGnegqw/B3Q7WrWwMPVG qOcdvuDlunLX+g5++O/+tcT/QsN9MMIhL0wXpC8G6FTXa9r6/Wo0VhlZ6kIDGrdnsCsq 0f/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=a2W12krn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji5-20020a170907980500b0079ddb52369bsi6939021ejc.61.2022.12.12.08.28.19; Mon, 12 Dec 2022 08:28:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=a2W12krn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232582AbiLLPsN (ORCPT + 74 others); Mon, 12 Dec 2022 10:48:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231827AbiLLPsM (ORCPT ); Mon, 12 Dec 2022 10:48:12 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7ABD6363 for ; Mon, 12 Dec 2022 07:48:10 -0800 (PST) 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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.