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 X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 692C0C433B4 for ; Thu, 8 Apr 2021 06:14:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E1BD3610CF for ; Thu, 8 Apr 2021 06:14:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E1BD3610CF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0C9E66B0080; Thu, 8 Apr 2021 02:14:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 052FB6B0081; Thu, 8 Apr 2021 02:14:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0EE36B0082; Thu, 8 Apr 2021 02:14:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0229.hostedemail.com [216.40.44.229]) by kanga.kvack.org (Postfix) with ESMTP id BBBD06B0080 for ; Thu, 8 Apr 2021 02:14:27 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7CB424DDF for ; Thu, 8 Apr 2021 06:14:27 +0000 (UTC) X-FDA: 78008185374.18.979574D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP id 967CA3C1 for ; Thu, 8 Apr 2021 06:14:25 +0000 (UTC) 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=0yv3MJ3oAVnJYQ+0/a4f1v89qsCDdNpeUxyalRyWzAQ=; b=PPdSlFGNFYyVM+AMh7mv3DAoY9 cy8zdEJ428v0rYh8BpeJN/IUVMvi49c/VnWqQHMGg9RdxW6fM9ZiPh4dtmxLAt+vb0UcAQdOZs1CZ 2qxwSUk6WQtsdwnZqO+Z91tQN14jogtTGkTmOmgvNRnWR5Xlhdf6K5fzdOG06tjaEYOdC2a0vjgan wcRVm8chosZ8O2B5gU0H5UrZlvpI7+XVHvW0mm4fQF5l6rDnsyAgAaY/re5HHaAJ+sy4devHdJbD/ L+IrHDt09CyNTEMw4EGmh0XHSfQd7bKtly0bizh6DFnXqYTUi+AWaKdkXwKelOqpr2iPcNA/ExjhT vNWrQu4g==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lUNvV-00FfxS-L9; Thu, 08 Apr 2021 06:14:09 +0000 Date: Thu, 8 Apr 2021 07:14:01 +0100 From: Matthew Wilcox To: Daniel Xu Cc: bpf@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, jolsa@kernel.org, hannes@cmpxchg.org, yhs@fb.com Subject: Re: [RFC bpf-next 1/1] bpf: Introduce iter_pagecache Message-ID: <20210408061401.GI2531743@casper.infradead.org> References: <22bededbd502e0df45326a54b3056941de65a101.1617831474.git.dxu@dxuuu.xyz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <22bededbd502e0df45326a54b3056941de65a101.1617831474.git.dxu@dxuuu.xyz> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 967CA3C1 X-Stat-Signature: cg1tpjzdc9eqkokwssexiyr81xzyjpqb Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf04; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617862465-354636 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 Wed, Apr 07, 2021 at 02:46:11PM -0700, Daniel Xu wrote: > +struct bpf_iter_seq_pagecache_info { > + struct mnt_namespace *ns; > + struct radix_tree_root superblocks; Why are you adding a new radix tree? Use an XArray instead. > +static struct page *goto_next_page(struct bpf_iter_seq_pagecache_info *info) > +{ > + struct page *page, *ret = NULL; > + unsigned long idx; > + > + rcu_read_lock(); > +retry: > + BUG_ON(!info->cur_inode); > + ret = NULL; > + xa_for_each_start(&info->cur_inode->i_data.i_pages, idx, page, > + info->cur_page_idx) { > + if (!page_cache_get_speculative(page)) > + continue; Why do you feel the need to poke around in i_pages directly? Is there something wrong with find_get_entries()? > +static int __pagecache_seq_show(struct seq_file *seq, struct page *page, > + bool in_stop) > +{ > + struct bpf_iter_meta meta; > + struct bpf_iter__pagecache ctx; > + struct bpf_prog *prog; > + > + meta.seq = seq; > + prog = bpf_iter_get_info(&meta, in_stop); > + if (!prog) > + return 0; > + > + meta.seq = seq; > + ctx.meta = &meta; > + ctx.page = page; > + return bpf_iter_run_prog(prog, &ctx); I'm not really keen on the idea of random BPF programs being able to poke at pages in the page cache like this. From your initial description, it sounded like all you needed was a list of which pages are present. > + INIT_RADIX_TREE(&info->superblocks, GFP_KERNEL); > + > + spin_lock(&info->ns->ns_lock); > + list_for_each_entry(mnt, &info->ns->list, mnt_list) { > + sb = mnt->mnt.mnt_sb; > + > + /* The same mount may be mounted in multiple places */ > + if (radix_tree_lookup(&info->superblocks, (unsigned long)sb)) > + continue; > + > + err = radix_tree_insert(&info->superblocks, > + (unsigned long)sb, (void *)1); > + if (err) > + goto out; > + } > + > + radix_tree_for_each_slot(slot, &info->superblocks, &iter, 0) { > + sb = (struct super_block *)iter.index; > + atomic_inc(&sb->s_active); > + } Uh. What on earth made you think this was a good way to use the radix tree? And, no, the XArray doesn't change that. If you don't understand why this is so bad, call xa_dump() on it after constructing it. I'll wait.