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 B7931C54798 for ; Fri, 23 Feb 2024 17:14:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2456C6B0082; Fri, 23 Feb 2024 12:14:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F54E6B0083; Fri, 23 Feb 2024 12:14:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E4866B0085; Fri, 23 Feb 2024 12:14:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id F02E66B0082 for ; Fri, 23 Feb 2024 12:14:51 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id AE88E121146 for ; Fri, 23 Feb 2024 17:14:51 +0000 (UTC) X-FDA: 81823718382.14.4222189 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf02.hostedemail.com (Postfix) with ESMTP id 1E57880013 for ; Fri, 23 Feb 2024 17:14:47 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=YpgQJqfu; dmarc=none; spf=none (imf02.hostedemail.com: domain of BATV+56f54fee0dbaef9ed0f0+7488+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56f54fee0dbaef9ed0f0+7488+infradead.org+hch@bombadil.srs.infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708708490; 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=/BOPk2iS7Br1xX5zeG3rpD9r3RFQpg0wP8kaK+pzgpg=; b=CSiGbRVDgBaqDFL+TWOP8LbN6oqHVD3f6PCO3uwFk+7VTDn8tOBBwEjwSJoB1XyXcatBiO s9WDoCyKCaOXoCVYcxyDZmaVz1UIVaoSjsyGAww1N8u2AXlK1vg5GrkEm6yxkhYhxpQbR1 forwFcywx9Laq/ltPMty24aVlPVD+GQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=YpgQJqfu; dmarc=none; spf=none (imf02.hostedemail.com: domain of BATV+56f54fee0dbaef9ed0f0+7488+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+56f54fee0dbaef9ed0f0+7488+infradead.org+hch@bombadil.srs.infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708708490; a=rsa-sha256; cv=none; b=ud22kEpWaRH+rIt/NaLT+5w4+Ri0smwA/K6JA6c9425hzKvT/DR1MH8GNd36Awa0uuzsgG A9/IZhQ6z80wOdj6aL0230rJYrRAX5r9g7sRrM54s/kr9YRDAStejVCLCC1hQQswX1RqNr KQj/ghXPFXcIPD5bSf0AFzkl4xVch3A= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=/BOPk2iS7Br1xX5zeG3rpD9r3RFQpg0wP8kaK+pzgpg=; b=YpgQJqfuJ2nnIrdpxTnHAdWhmU 9Uf2cynx4zMmA1h0nI7Bsli1Wy6qWyUh3+dVJJPZzN901dsnTk0f9hu+hm1PgpgX5JHaiYHDX/hS9 Uia9Eu31Q9mhk7KKCrZMWnOBKiSlnJYbCj8DsVZLmxXPntqXxP8LsiC3xydyuN20uck2YuxQJHhdw 5n/347Fm1/en+6zJRbiTJjGdIiEyUytGjFY62mmU2IYR0tHMGg0vbmm0XpfFbCFGnNVlJ88iW7y8V m+O8buUagYJ0gVK7hPRGKnb7LS+jajAgubRak4unfIYCddb8SPVo0LPrx7tZnt6ZKq7QZP004TuqP h0lPNKJQ==; Received: from hch by bombadil.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rdZ89-0000000AQTr-1fNa; Fri, 23 Feb 2024 17:14:37 +0000 Date: Fri, 23 Feb 2024 09:14:37 -0800 From: Christoph Hellwig To: Alexei Starovoitov Cc: Christoph Hellwig , bpf , Daniel Borkmann , Andrii Nakryiko , Linus Torvalds , Barret Rhoden , Johannes Weiner , Lorenzo Stoakes , Andrew Morton , Uladzislau Rezki , linux-mm , Kernel Team Subject: Re: [PATCH bpf-next] mm: Introduce vm_area_[un]map_pages(). Message-ID: References: <20240220192613.8840-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 1E57880013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: zqgoh3fd7wznd1s9tibthp9zhm6m1qis X-HE-Tag: 1708708487-76505 X-HE-Meta: U2FsdGVkX1+P7YAiOWVjrFsPsbvU+WvgQd0mEuKtH6Ittv0unBcz2wLGgwV8LzxQBjVllfowFCTBjJ8TNpPY3UjKmQH/eiUf0eTrpX0h1sm1EM7Cr/BErb7aLLIXLmOFkqNRtpeUhrfLjO+VWgB5VntXA3BK0rzlkH6n3tQZFIxIG5lcb7lnQzyIL7ZjuR003hZmPSgB3y474+4e/Mk0H81BnXqPmaGUCIj4CdaOouC/MGTSsO3TSAOowU78CaMfCFmqRab9ld3QWTflvOI2pDG8e4A1GxUY92uJ+DvfLxnDpxcGGbyijpLK9Hax9FoiIxiAkJqQ7WXct4ocVRsEx5KdckOJMQcwdiwqzUFHFQxfgt7B1nub1wRXmdM6cRRKYeeBUZWW3sQNcB1/Mc+lPXPiCq13fsdadgZyuHyRCUu5VuGQr44KWzVSnVjz2MMQmdbV30ECRXC46571r9kvTyCoBSh/MmsFlQk1Eho4ahvM9B5XMnhTpQsf+uOFcaANeFdoqMTHxh9tsmIkP5TPdYt4lQrFcWgyB7v5TzIvF479PKbpvzQs2ixZvArf0lb7xiSq9tyGXOzK/jS1AP2Sbzo6bwAjLIFoBmTsE8Gk9LySp0FNc1qG+XsWjy/xclUMQ+9rVWg91RyC7olO0IrSqGBSTRLUQLY7zWAxiAPIALDr8Dzj5Qk49GXgpV9E2wSW26Ul0/Hb/+XcYOlnf6+SzggcFmrDENA97h8javtk60WMw5VyH1FxYysuMqcSSI9r9VFwOnSrnENNDTlaiTJCyPfoo7PMyBViI95xoHAoeGQCa2LCzJTclGWES4hevRIUigMT1bZmOW50Vd/q0qvbJKxiG9FgonA1dit8uMTbD9iUwCqK1qnAbpXzZYkOd7KMIdY4O0FljeVeHi60OMFxhPA2LCHpClzytDVYdGyrC8KK2OaqQlf0faVeV9T5B8k28rJgxV65okqil+lilwE RVpdPxKd jgziSB1yQRTHGQxumjkCB5YDlyjELThd2WxWIXBjlmqq7DN1kWE3XFwSUkrEQQ9OmTjhpdyvRP9UnhPknscedLD97DbgM2lBcXVCQWLaiF7P2Tc5CGURn7A4CcGyG9EoVy4d9D2DT64l+KV/EeJyPH7wEUO3HAV5991F50fX87Tf07HPPLPcNqD83xdddmcUwUKxgkO8YCE8FCe/tAGIA0kWJvHl0jUSU785FkTLoA7nPWFA= 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: List-Subscribe: List-Unsubscribe: On Wed, Feb 21, 2024 at 11:05:09AM -0800, Alexei Starovoitov wrote: > +#define VM_BPF 0x00000800 /* bpf_arena pages */ > > +static inline struct vm_struct *get_bpf_vm_area(unsigned long size) > +{ > + return get_vm_area(size, VM_BPF); > +} > > and enforce that flag in vm_area_[un]map_pages() ? > > vmallocinfo can display it or skip it. > Things like find_vm_area() can do something different with such an area > (if that was the concern). Well, a growing allocation is a generally useful feature. I'd rather not limit it to bpf if we can. > > For the dynamically growing part do you need a special allocator or > > can we just go straight to the page allocator and implement this > > in common code? > > It's a bit special allocator that is using maple tree to manage > range within 4G region and > alloc_pages_node(GFP_KERNEL | __GFP_ZERO | __GFP_ACCOUNT) > to grab pages. > With extra dance: > memcg = bpf_map_get_memcg(map); > old_memcg = set_active_memcg(memcg); > to make sure memcg accounting is done the common way for all bpf maps. Ok, so it's not just a growing allocation but actually sparse and all over the place? That doesn't really make it easier to come up with a good enough interface. How do you decide what gets placed where? > struct vm_struct *area = get_sparse_vm_area(size); > vm_area_alloc_pages(struct vm_struct *area, ulong addr, int page_cnt, > int numa_id); > > and vm_area_alloc_pages() will allocate pages and vmap_pages_range() > them while all code in mm/vmalloc.c ? My vague hope was that we could just start out with an area and grow it. But it sounds like you need something much more complex that that. But yes, a more specific API is probably a better idea. And maybe the cookie should be a VM area either but a structure dedicated to this.