Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1238182lfc; Wed, 1 Jun 2022 12:42:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxl/JEtBVkfceDmow3zwWYIhcVaKEqymOAHrmkjxdEP8zJuxZYnkdU5wpiJyMwD5pojHkVX X-Received: by 2002:a63:1342:0:b0:3fc:8fca:a8a3 with SMTP id 2-20020a631342000000b003fc8fcaa8a3mr838036pgt.205.1654112540583; Wed, 01 Jun 2022 12:42:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654112540; cv=none; d=google.com; s=arc-20160816; b=Y8prfkeSqECM31NQxD8ktco8LM6AwfwL/rNz4IZn2+slsUHT1vIRnc3fo4nSIeKjNd PQqcZ99sO1gzRXRKNIKcDFDwZ6fogC0dyHZMrF0bVgNSZ+dsA1VC8AanIawpOxmo6Lst uR0G9FNqQ+kZwG9Hqvi/MHXw0bP2BxFLwc4NE0sLk/Y/iVRCXmenFCnP8Ti7Cl16tPuC PwCytnh7NSqaJlMqcykHH2df+hOECJNpdij60kf73dvnJoIIPC0SI3j/RQUyQq6BR90+ +/5iPqiNHQrjaI0mZ51AzgZMg7s00kln1ldYcUN6mqD8USXFbL+T77Tfi+c6Nv5ZiN4x UmcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=/pBPOinGtWLSH0tnCokdF/Kl/XTivemcUrlGpG+X7lE=; b=AqJu0hYBy4QA1c/OdCNvFiKNlSMjXaP9tfbpxLTfA/TlfFsMQkQCvrPfsaijTeZ2/v YRjgERFmDUzKjwHkc1ao0VRyxZy3V3AxRcZUJqeD/5aDghsBXg68S6gpZlhuf+QVae4p evt5Rbb8vaqrnKd1LNGrSqRXvU6rmWHZinENXSgh11otKQs0QQriKM16ir6bhygq5kco wn7b4g3aLQ5e8MoCzKIR8xFNGr2dMrLoKv+FUTBa9SUMT2Be2GAYq2EdOeo2ilYd6ZuG 0I+qoBzAgROvF4dHwuKD2cTmEwEhKY2U+EQMyFImmlccXwlW/eLw5VF81IdzrwRSrdah zWSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IKEbHE4W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id qe3-20020a17090b4f8300b001e33eebdb5asi3451056pjb.142.2022.06.01.12.42.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:42:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IKEbHE4W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D5B301CA5EF; Wed, 1 Jun 2022 12:08:18 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244990AbiFALfi (ORCPT + 99 others); Wed, 1 Jun 2022 07:35:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236784AbiFALfe (ORCPT ); Wed, 1 Jun 2022 07:35:34 -0400 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16C8D21806; Wed, 1 Jun 2022 04:35:33 -0700 (PDT) Received: by mail-ej1-x62f.google.com with SMTP id rs12so3086043ejb.13; Wed, 01 Jun 2022 04:35:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=/pBPOinGtWLSH0tnCokdF/Kl/XTivemcUrlGpG+X7lE=; b=IKEbHE4Wc5T+tzXdjWgU2qqm+VIhwmBP7Sme5ZXXXN3CJ3dd2ppLVWAOhhbpURD3nC H/MVQFZuZWYm730d7r2GtF9idFAvbo7+xI3z8DYZeHSvy0mA7gES9pp/fMXLQrlaTH9C EqhIOkjLIJTTu5A8V/kn0MsXo94Nf9R2dmV38cpjiSv16jJWLOOvPYRyjEv2TMY+ZJJG DAkAnlHO0+Xq4zjfcI5cN9AK2ixspikZu79en2tQufRYtK6iH3u3KuMa0KDFBuE8Hjjn bbE33IxrQCGbjhRuaZu7FtDIV54x94TgOxYlO1CM4DSEs/LUv/2WolH4UTiuAVwjdCjL QATA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=/pBPOinGtWLSH0tnCokdF/Kl/XTivemcUrlGpG+X7lE=; b=HoAzeKjGc6laWa2Kz/MgnVYgJ4cbIs3T6SW2x2SlemNeV+xkl9g4dHUisWQSglwcBZ kWrQfQrn/SPVFl+iGixAX0aimaRXNJ2hw5laL3FbzuUdoukCykgilGETz7mJEieD5BOn EEn4XKoau4BVT9wQYZpDoi3gid3CnQcHzUky2JZv4/P1xaiAohcWB0k/f1IpprZEORyE 4ZYTxboOF4unh1sXQZQYt+LUitB0Y76wR6iQoStPbNZafRfMZhrmAMh8qcFE5SU/HPng v7NTTbmENeBTmMhamMK3ptqDqRr8T8JY0U7Rc0ORXf3cZURa6n/FI3bu4DOFdrJb66u+ dRSA== X-Gm-Message-State: AOAM530O98M/o3YjsU8CCizFU+UrbhescVafE9pJLEB0J29SWJm1otdo N5xgxhoEbWvdoswfr5nWWLzhjtZB7w/9fGwcaN8= X-Received: by 2002:a17:906:b816:b0:708:2e56:97d7 with SMTP id dv22-20020a170906b81600b007082e5697d7mr1269087ejb.502.1654083331508; Wed, 01 Jun 2022 04:35:31 -0700 (PDT) MIME-Version: 1.0 References: <20220601084149.13097-1-zhoufeng.zf@bytedance.com> <20220601084149.13097-2-zhoufeng.zf@bytedance.com> <21ec90e3-2e89-09c1-fd22-de76e6794d68@bytedance.com> In-Reply-To: <21ec90e3-2e89-09c1-fd22-de76e6794d68@bytedance.com> From: Alexei Starovoitov Date: Wed, 1 Jun 2022 13:35:19 +0200 Message-ID: Subject: Re: [External] Re: [PATCH v4 1/2] bpf: avoid grabbing spin_locks of all cpus when no free elems To: Feng Zhou Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Network Development , bpf , LKML , Xiongchun Duan , Muchun Song , Dongdong Wang , Cong Wang , Chengming Zhou Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Wed, Jun 1, 2022 at 1:11 PM Feng Zhou wrote: > > =E5=9C=A8 2022/6/1 =E4=B8=8B=E5=8D=885:50, Alexei Starovoitov =E5=86=99= =E9=81=93: > > On Wed, Jun 1, 2022 at 10:42 AM Feng zhou w= rote: > >> static inline void ___pcpu_freelist_push(struct pcpu_freelist_head *= head, > >> @@ -130,14 +134,19 @@ static struct pcpu_freelist_node *___pcpu_freeli= st_pop(struct pcpu_freelist *s) > >> orig_cpu =3D cpu =3D raw_smp_processor_id(); > >> while (1) { > >> head =3D per_cpu_ptr(s->freelist, cpu); > >> + if (READ_ONCE(head->is_empty)) > >> + goto next_cpu; > >> raw_spin_lock(&head->lock); > >> node =3D head->first; > >> if (node) { > > extra bool is unnecessary. > > just READ_ONCE(head->first) > > As for why to add is_empty instead of directly judging head->first, my > understanding is this, head->first is frequently modified during updating > map, which will lead to invalid other cpus's cache, and is_empty is after > freelist having no free elems will be changed, the performance will be > better. maybe. pls benchmark it. imo wasting a bool for the corner case is not a good trade off.