From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94418CA6C for ; Fri, 20 Oct 2023 07:09:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60CB69F for ; Fri, 20 Oct 2023 00:09:19 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4SBbKx0V9zz4f3s6D for ; Fri, 20 Oct 2023 15:09:09 +0800 (CST) Received: from [10.174.176.117] (unknown [10.174.176.117]) by APP1 (Coremail) with SMTP id cCh0CgC3NaaWJzJlDukWDQ--.46806S2; Fri, 20 Oct 2023 15:09:14 +0800 (CST) Subject: Re: [PATCH bpf-next v2 2/7] mm/percpu.c: introduce pcpu_alloc_size() To: Alexei Starovoitov , Dennis Zhou Cc: bpf , linux-mm , Martin KaFai Lau , Andrii Nakryiko , Song Liu , Hao Luo , Yonghong Song , Daniel Borkmann , KP Singh , Stanislav Fomichev , Jiri Olsa , John Fastabend , Hou Tao , Tejun Heo , Christoph Lameter , Andrew Morton References: <20231018113343.2446300-1-houtao@huaweicloud.com> <20231018113343.2446300-3-houtao@huaweicloud.com> From: Hou Tao Message-ID: <3b502d3e-db22-f3d8-94de-f6294afcde5c@huaweicloud.com> Date: Fri, 20 Oct 2023 15:09:10 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8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wI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf 9x07UZ18PUUUUU= X-CM-SenderInfo: xkrx3t3r6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected Hi, On 10/20/2023 12:16 PM, Alexei Starovoitov wrote: > On Thu, Oct 19, 2023 at 9:09 PM Dennis Zhou wrote: >> On Wed, Oct 18, 2023 at 07:33:38PM +0800, Hou Tao wrote: >>> From: Hou Tao >>> >>> Introduce pcpu_alloc_size() to get the size of the dynamic per-cpu >>> area. It will be used by bpf memory allocator in the following patches. >>> BPF memory allocator maintains per-cpu area caches for multiple area >>> sizes and its free API only has the to-be-freed per-cpu pointer, so it >>> needs the size of dynamic per-cpu area to select the corresponding cache >>> when bpf program frees the dynamic per-cpu pointer. >>> >>> Signed-off-by: Hou Tao >>> --- >>> include/linux/percpu.h | 1 + >>> mm/percpu.c | 30 ++++++++++++++++++++++++++++++ >>> 2 files changed, 31 insertions(+) >>> >>> diff --git a/include/linux/percpu.h b/include/linux/percpu.h >>> index 68fac2e7cbe6..8c677f185901 100644 >>> --- a/include/linux/percpu.h >>> +++ b/include/linux/percpu.h >>> @@ -132,6 +132,7 @@ extern void __init setup_per_cpu_areas(void); >>> extern void __percpu *__alloc_percpu_gfp(size_t size, size_t align, gfp_t gfp) __alloc_size(1); >>> extern void __percpu *__alloc_percpu(size_t size, size_t align) __alloc_size(1); >>> extern void free_percpu(void __percpu *__pdata); >>> +extern size_t pcpu_alloc_size(void __percpu *__pdata); >>> >>> DEFINE_FREE(free_percpu, void __percpu *, free_percpu(_T)) >>> >>> diff --git a/mm/percpu.c b/mm/percpu.c >>> index 76b9c5e63c56..b0cea2dc16a9 100644 >>> --- a/mm/percpu.c >>> +++ b/mm/percpu.c >>> @@ -2244,6 +2244,36 @@ static void pcpu_balance_workfn(struct work_struct *work) >>> mutex_unlock(&pcpu_alloc_mutex); >>> } >>> >>> +/** >>> + * pcpu_alloc_size - the size of the dynamic percpu area >>> + * @ptr: pointer to the dynamic percpu area >>> + * >>> + * Return the size of the dynamic percpu area @ptr. >>> + * >> Alexei, can you modify the above comment to: >> >> Returns the size of the @ptr allocation. This is undefined for statically >> defined percpu variables as there is no corresponding chunk->bound_map. > Good point! Will do. I will post v3 to update the API document. > > Thanks for the quick review! > > .