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 37BFDC19F29 for ; Wed, 3 Aug 2022 13:28:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 99A546B0072; Wed, 3 Aug 2022 09:28:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 949FA6B0073; Wed, 3 Aug 2022 09:28:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EAF16B0074; Wed, 3 Aug 2022 09:28:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6F32D6B0072 for ; Wed, 3 Aug 2022 09:28:37 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3C7BF141544 for ; Wed, 3 Aug 2022 13:28:37 +0000 (UTC) X-FDA: 79758361074.12.E70979D Received: from mail-vs1-f45.google.com (mail-vs1-f45.google.com [209.85.217.45]) by imf12.hostedemail.com (Postfix) with ESMTP id D2F0A4011E for ; Wed, 3 Aug 2022 13:28:36 +0000 (UTC) Received: by mail-vs1-f45.google.com with SMTP id m67so10253894vsc.12 for ; Wed, 03 Aug 2022 06:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=d4CMEGQnU+S9ZYP05NLfCafbO2suR8T26hcKhvZuoaw=; b=ZvIb+0C1qehTMi24B7yGhqa99SBgp/GVNYmrBlByJqiMvXiYYacZsVBTgeRmFfKrE7 Kcp2l/7ydf4FNWFsiBoBzFU1jLiyfPzseMEePRWYD/GvsjvLl41mEAJTUfE9BQgZYb85 Z2GBA+uAYNixhh2ZmCyzOqfI9BUNGYRQu/GZwl/H5PmlKdhXldqe2U+BsEPdAGKalc7X k9vDr9/a1zOae6c+iHFnCBfc9YVPHtdVp2UqwPRvU5m+mSNaAeyiyj+Dno2nKCv4D60A jdcrvZEnxqipK1g4h5sCiC21eN3NLMDvK7m6fsF/yJkoU2hhHiFuZtrM+Ucv+SnGb0iH mvMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=d4CMEGQnU+S9ZYP05NLfCafbO2suR8T26hcKhvZuoaw=; b=UkK/3L1+wVWAmp3RFOYpftiHtCXhrYSCAbhb0wLogy7EFJieFSe/rb8cbpPYj+mxM6 5uQ8YCbdCPKsUUflZLSZoCQNuN/PLkaimzHVzCSfyAIS+XNIX7gfY+q5HNx1Tte8ISAO YlC1DiIUVjpok2vZZfc5eWE3Ge9lsXLhgej3cRtTlUhOJkYM0pGvjbLCA1R6pqPQnPRe TZVSiwpffTiueAi+MARyAchvirHNZXEQwlkSt1pPnh1XepJMkI3yVHyPphAAGDRDDr5B OTkjuhNyQoX1verDApV+pQaP8C9yh00/zEEem5uQQefN7IcKo1hGj/2pf/usID39opWF ItvQ== X-Gm-Message-State: ACgBeo3yPyhKYk/LI4n8KEBTS2Ei4XbO/pUznNOMYMP++w4Huo2VSw+T /L0yTepCflOwEjDCyqWeoT/oxy6Q5O64UDtqQTY= X-Google-Smtp-Source: AA6agR7fssyMEPL+0GEoOPDewD5mH1gILM/Q0lLDfqi9TugsYxRKmx7COVHqe1jBD5Wr3DA8T//+hr0gSeSsFEpRPy4= X-Received: by 2002:a05:6102:441c:b0:378:fcdd:d951 with SMTP id df28-20020a056102441c00b00378fcddd951mr7831366vsb.22.1659533316066; Wed, 03 Aug 2022 06:28:36 -0700 (PDT) MIME-Version: 1.0 References: <20220729152316.58205-1-laoar.shao@gmail.com> <20220729152316.58205-11-laoar.shao@gmail.com> In-Reply-To: From: Yafang Shao Date: Wed, 3 Aug 2022 21:27:59 +0800 Message-ID: Subject: Re: [RFC PATCH bpf-next 10/15] bpf: Use bpf_map_pages_alloc in ringbuf To: Andrii Nakryiko Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , Stanislav Fomichev , Hao Luo , jolsa@kernel.org, Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , netdev , bpf , Linux MM Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659533316; 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=d4CMEGQnU+S9ZYP05NLfCafbO2suR8T26hcKhvZuoaw=; b=IA4Bslm6ggHuX3KFfwsPnO8EqyTpZaYJf2mL3tApO3t6xL3Tx1jme0jB+5fC24oAbfKN9C OeDdnnlEtrtNOINQsNELMlD/p8dC2NyY71Gedf1wbDdpiIe5znRHo44vPcIFDQttOAEzkz oxNYfHzpJLHw0fVvk36s+ZLhYM6NGhg= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZvIb+0C1; spf=pass (imf12.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.217.45 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659533316; a=rsa-sha256; cv=none; b=ggOdm6KNvSvPywan0rfByB8OXqbp4nbm3o8afrfjmrowPi+BHCUoYmd1ceNTJ5xZwr6Z4g ZUKH7+JXY8e3FbiIwdMzsOR1L6EvkWjbdDCX+due8eNSGhXGXm+24dF/FmBRnCKvrq2BBq HLCs3t7gWGw/H1U26ceCNEeMxlE1ObI= X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ZvIb+0C1; spf=pass (imf12.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.217.45 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D2F0A4011E X-Stat-Signature: a3khfq4o8snc6wa6cw9omatdrjpkpm5i X-HE-Tag: 1659533316-2537 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, Aug 3, 2022 at 2:00 AM Andrii Nakryiko wrote: > > On Tue, Aug 2, 2022 at 6:31 AM Yafang Shao wrote: > > > > On Tue, Aug 2, 2022 at 7:17 AM Andrii Nakryiko > > wrote: > > > > > > On Fri, Jul 29, 2022 at 8:23 AM Yafang Shao wrote: > > > > > > > > Introduce new helper bpf_map_pages_alloc() for this memory allocation. > > > > > > > > Signed-off-by: Yafang Shao > > > > --- > > > > include/linux/bpf.h | 4 ++++ > > > > kernel/bpf/ringbuf.c | 27 +++++++++------------------ > > > > kernel/bpf/syscall.c | 41 +++++++++++++++++++++++++++++++++++++++++ > > > > 3 files changed, 54 insertions(+), 18 deletions(-) > > > > > > > > > > [...] > > > > > > > /* Each data page is mapped twice to allow "virtual" > > > > * continuous read of samples wrapping around the end of ring > > > > @@ -95,16 +95,10 @@ static struct bpf_ringbuf *bpf_ringbuf_area_alloc(struct bpf_map *map, > > > > if (!pages) > > > > return NULL; > > > > > > > > - for (i = 0; i < nr_pages; i++) { > > > > - page = alloc_pages_node(numa_node, flags, 0); > > > > - if (!page) { > > > > - nr_pages = i; > > > > - goto err_free_pages; > > > > - } > > > > - pages[i] = page; > > > > - if (i >= nr_meta_pages) > > > > - pages[nr_data_pages + i] = page; > > > > - } > > > > + ptr = bpf_map_pages_alloc(map, pages, nr_meta_pages, nr_data_pages, > > > > + numa_node, flags, 0); > > > > + if (!ptr) > > > > > > bpf_map_pages_alloc() has some weird and confusing interface. It fills > > > out pages (second argument) and also returns pages as void *. Why not > > > just return int error (0 or -ENOMEM)? You are discarding this ptr > > > anyways. > > > > > > > I will change it. > > > > > > > > But also thinking some more, bpf_map_pages_alloc() is very ringbuf > > > specific (which other map will have exactly the same meaning for > > > nr_meta_pages and nr_data_pages, where we also allocate 2 * > > > nr_data_pages, etc). > > > > > > I don't think it makes sense to expose it as a generic internal API. > > > Why not keep all that inside kernel/bpf/ringbuf.c instead? > > > > > > > Right, it is used in ringbuf.c only currently. I will keep it inside ringbuf.c. > > > > In such case you might as well put pages = bpf_map_area_alloc(); part > into this function and return struct page ** as a result, so that > everything related to pages is handled as a single unit. And then > bpf_map_pages_free() will free not just each individual page, but also > struct page*[] array. > Good suggestion. I will do it. > Also please call it something ringbuf specific, e.g., > bpf_ringbuf_pages_{alloc,free}()? > It Makes sense to me. -- Regards Yafang