Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6034204ybv; Tue, 18 Feb 2020 08:36:12 -0800 (PST) X-Google-Smtp-Source: APXvYqyhXNn2KEeuVxNbUzaOAseUzm/6S+Xe0ew4RK8GoCMjHov02RZ2hDfGmhNWHlUOMkK2uLgN X-Received: by 2002:a54:4f14:: with SMTP id e20mr1735764oiy.84.1582043772838; Tue, 18 Feb 2020 08:36:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1582043772; cv=pass; d=google.com; s=arc-20160816; b=TNU6u85V986VOBgDHho6sRtAX1YtS3htSGu9xpQM+iH1db8lXX8qISFJ4jahWnsUHW PXs6FxqqXz55tO7jA6TljGar2x6ZiNE4A9QYf4LIO8KbHFklYhWObQEqI7CtDVZrl6Rd lZUIFsLlknngJcJgeOMS12gN5/893mmzGPznzQChc/jfk5py+MtVZtxE5C9drG2L1oWL FBm5BXGnTwZ1Gp1cjirl/gomsOWYIVWNJxjjjIEPbg7+K/mt94Sh0aH9NyK8drt0YNzI EQrckQTzXKSg/oiCxNznXDN6qznKRfxmg4P2Sob3L11tvnRnmGZFb6s8z5OhGEA+7ENT HsEA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject:dkim-signature:dkim-signature; bh=8/4gOYKri87PQAvEaG7shEOGsl2sj+gq/tmiQH6h+Gg=; b=tdcTfsuWQE6NcznKkn/gH7Risw81hsXdexoaqlJUWA2kxXUaPt64pah7PFdEvQz1jH Iop4uBgzRLeiiDZHTqmjaYfkeBREAyiUXHku33ZwViKuCiPwyi2lG2/4mUGQyTSPMq9B bA84BNXjqd/olooobHJ/cTzR2OFI1LyHrZv04M/pez/hvmsq4Bo4UM5vHA4Mz1e+FJk6 nBlbG/s4LWrHgFdGabXL8Gkx45ONBwgYK5hQDHyxpf+a3KwIQ9TdlAv9DTW4HivB17pw 8VlZ674siRijazuWMIR3+Szr3iAPAyPG7z6yKEjYpM/vs/eX8UFZpzzlJXn53eng2I00 xp+A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=o45iIGvr; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector2-fb-onmicrosoft-com header.b=LHxKzFoe; arc=pass (i=1 spf=pass spfdomain=fb.com dkim=pass dkdomain=fb.com dmarc=pass fromdomain=fb.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e23si8189624oie.105.2020.02.18.08.36.00; Tue, 18 Feb 2020 08:36:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=o45iIGvr; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector2-fb-onmicrosoft-com header.b=LHxKzFoe; arc=pass (i=1 spf=pass spfdomain=fb.com dkim=pass dkdomain=fb.com dmarc=pass fromdomain=fb.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726645AbgBRQfA (ORCPT + 99 others); Tue, 18 Feb 2020 11:35:00 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:50184 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726403AbgBRQfA (ORCPT ); Tue, 18 Feb 2020 11:35:00 -0500 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01IGPubm028884; Tue, 18 Feb 2020 08:34:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=subject : to : cc : references : from : message-id : date : in-reply-to : content-type : content-transfer-encoding : mime-version; s=facebook; bh=8/4gOYKri87PQAvEaG7shEOGsl2sj+gq/tmiQH6h+Gg=; b=o45iIGvrHbYPdAns7+t0PoK4m/R+Ob60irf/J38gssTwwe5S4/goth4uML85HLZPeqYt bbrnGjl4TITiCOaOespLwciTcRvZnr1qFNiqtKrNOM4gaJiZsqLYGh5dUV92xzCuUDXV PDC9+cmGSsCjC/TlhODujw9R5h//ODEVdGg= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 2y713w1vm7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 18 Feb 2020 08:34:41 -0800 Received: from NAM04-BN3-obe.outbound.protection.outlook.com (100.104.98.9) by o365-in.thefacebook.com (100.104.94.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1779.2; Tue, 18 Feb 2020 08:34:40 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T7Ezi5y1KR6anbynw1pCvDp68VBPuqtGEtwmQiJlSI2+G2AGv5JTEjdP9Plvoe9gltrAGuwe1n1LUle7bWaF5FaXmDm6tXZmI+P6Ib9X1mwqBLYLHXhofxDxYZb4+ECbRbEDhTKFfQs9zOvrEReHMvYf3Q14xmYSW9E3/k0FwNRi4DtTftF5ij+l4ufp0zlk/IfYNBi8T8BAqaT0MRXPOcP/vHkvgNzdigx25/H+tiC/drhNx5T4j3QCbDNer9yCagM9boIrFu85xbOkAfITOG0nQhKgvsqxQPaYEg191OvRNitnKZuK/AbJyBGCxa67v9iOE7WRNEVGiFKqsAIVmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8/4gOYKri87PQAvEaG7shEOGsl2sj+gq/tmiQH6h+Gg=; b=fbAmeL0LpnQFLjOQpGBXr7gs03uWlXw2ZO+25PMKWHL8wTyYBbNMoKejMVEIh3foL/5tP90zL0ZVtROTIoIq0bdwN/WTZzVZZpZByTf0TGVvCGiIsEomASF1Lzmv03AYsenc62F2lwo8kjoetHwGnqgCCKZZS8U1CObCmHhDqPsi+CFEo42hBPDvYotXda9xf2EvykwRq6aGp0UNvD+cxJcUAeLkpQo/7OZThPvedmERFnvUS+ezMvCpzRo1GKaeUMvW4xBZhmWZT9sRV8I/UPROaM0ycySE1gpQcbt0PfLoMmrpTxMOEr2gTGwyKZZdCs4PnfU+OjUezp0v+6VqIg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fb.com; dmarc=pass action=none header.from=fb.com; dkim=pass header.d=fb.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector2-fb-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8/4gOYKri87PQAvEaG7shEOGsl2sj+gq/tmiQH6h+Gg=; b=LHxKzFoeOgSbi0BBgfpb9niI1h0cSpbrPevZr5id+jai4HClpVd2ZlG5o7hjyHG3i4X5YwFHMhFnzlyA0tfOLW5+I8Se7/xjTTsWlTdxZkP62onSsMaEfHc0bOCyMajOkutB1GWxVSdNU3lIUObwZQvn2vhisIbyQU7URthp0XM= Received: from DM6PR15MB3001.namprd15.prod.outlook.com (20.178.231.16) by DM6PR15MB3354.namprd15.prod.outlook.com (20.179.52.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22; Tue, 18 Feb 2020 16:34:39 +0000 Received: from DM6PR15MB3001.namprd15.prod.outlook.com ([fe80::294e:884:76fd:743c]) by DM6PR15MB3001.namprd15.prod.outlook.com ([fe80::294e:884:76fd:743c%4]) with mapi id 15.20.2729.032; Tue, 18 Feb 2020 16:34:39 +0000 Subject: Re: [PATCH bpf] bpf: Do not grab the bucket spinlock by default on htab batch ops To: Daniel Borkmann , Brian Vazquez , Brian Vazquez , Alexei Starovoitov , "David S . Miller" CC: , , References: <20200214224302.229920-1-brianvv@google.com> <8ac06749-491f-9a77-3899-641b4f40afe2@fb.com> <63fa17bf-a109-65c1-6cc5-581dd84fc93b@iogearbox.net> From: Yonghong Song Message-ID: Date: Tue, 18 Feb 2020 08:34:36 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 In-Reply-To: <63fa17bf-a109-65c1-6cc5-581dd84fc93b@iogearbox.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-ClientProxiedBy: CO2PR05CA0082.namprd05.prod.outlook.com (2603:10b6:102:2::50) To DM6PR15MB3001.namprd15.prod.outlook.com (2603:10b6:5:13c::16) MIME-Version: 1.0 Received: from macbook-pro-52.dhcp.thefacebook.com (2620:10d:c090:500::5:fd19) by CO2PR05CA0082.namprd05.prod.outlook.com (2603:10b6:102:2::50) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2750.6 via Frontend Transport; Tue, 18 Feb 2020 16:34:38 +0000 X-Originating-IP: [2620:10d:c090:500::5:fd19] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 79618f12-1b5a-4663-f908-08d7b49072ed X-MS-TrafficTypeDiagnostic: DM6PR15MB3354: X-Microsoft-Antispam-PRVS: X-FB-Source: Internal X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-Forefront-PRVS: 031763BCAF X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(376002)(396003)(136003)(366004)(199004)(189003)(66946007)(478600001)(16526019)(186003)(4326008)(53546011)(5660300002)(6506007)(52116002)(31686004)(86362001)(66556008)(66476007)(2616005)(81156014)(81166006)(8676002)(8936002)(316002)(110136005)(36756003)(31696002)(2906002)(6486002)(6512007)(19627235002);DIR:OUT;SFP:1102;SCL:1;SRVR:DM6PR15MB3354;H:DM6PR15MB3001.namprd15.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: fb.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fczdOg8jTvc12lajNisnGHu2AUg8E6GaFSbD4BAqGyWHJOg2lJ2PntgR5LwD3XbpWnRS0Li/m9/8cmd0N0H6GSQpp7vFp92cdlk1S6FLjsVTMI1Ob30RjJcoz+jk2ChTUPUpnSfN2tksNBbvPyDBtsm8ZP5/kpQLcismbmUC4JibUEWUXjoJ/Ni6Ad2POZW7RWsT6UwuGpkKt3Afi6qIUiyQOU+PCwLFkcrnBbwks0bcIAuOybqDDsp9Ed5SFBQYnMCWl1/InFSsroMBH0S/zdV2hp1Ksa9ULLIUMJ+zn8QviMDOJNtumnPKEUCLFVClnUBrAIhqaTuBGPMp7sl7xxTNpTYS8S8bUBRUgxTGsVrIf+XkTfgWXhSQBJdysJIlC01WkdjDV2kr8MsOGEfRBmeeNo4Aaj0dsV8WvEOeuGA2D5HNB6tlxqHwG84V3V/P X-MS-Exchange-AntiSpam-MessageData: xGO+ZSeKPtquNCUtR/jVoRYix4bFzyt5BZn8tiK5wjRitkQV1PqhVJMKh5YchCWn5CW4XkXuMDXkkWuGu1gKLdrQOjzlf0qrMeEXk8NGFsrIscUTMCF0jCBA+vq9DzGCC8s2UcuGlJE8ydKqf2bTmgvcCjZwHRKtduV8OVENFPh9kGefgIiA2eweFq+XJSKg X-MS-Exchange-CrossTenant-Network-Message-Id: 79618f12-1b5a-4663-f908-08d7b49072ed X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2020 16:34:39.3582 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3j2o0nneNHq5F4baGGepmJyIJ4Gaq8lvl7Wj1BiA/xwshxaGuEhrz5p06o6v/NJu X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR15MB3354 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-18_04:2020-02-18,2020-02-18 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 adultscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002180121 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/18/20 7:56 AM, Daniel Borkmann wrote: > On 2/18/20 4:43 PM, Yonghong Song wrote: >> On 2/14/20 2:43 PM, Brian Vazquez wrote: >>> Grabbing the spinlock for every bucket even if it's empty, was causing >>> significant perfomance cost when traversing htab maps that have only a >>> few entries. This patch addresses the issue by checking first the >>> bucket_cnt, if the bucket has some entries then we go and grab the >>> spinlock and proceed with the batching. >>> >>> Tested with a htab of size 50K and different value of populated entries. >>> >>> Before: >>>    Benchmark             Time(ns)        CPU(ns) >>>    --------------------------------------------- >>>    BM_DumpHashMap/1       2759655        2752033 >>>    BM_DumpHashMap/10      2933722        2930825 >>>    BM_DumpHashMap/200     3171680        3170265 >>>    BM_DumpHashMap/500     3639607        3635511 >>>    BM_DumpHashMap/1000    4369008        4364981 >>>    BM_DumpHashMap/5k     11171919       11134028 >>>    BM_DumpHashMap/20k    69150080       69033496 >>>    BM_DumpHashMap/39k   190501036      190226162 >>> >>> After: >>>    Benchmark             Time(ns)        CPU(ns) >>>    --------------------------------------------- >>>    BM_DumpHashMap/1        202707         200109 >>>    BM_DumpHashMap/10       213441         210569 >>>    BM_DumpHashMap/200      478641         472350 >>>    BM_DumpHashMap/500      980061         967102 >>>    BM_DumpHashMap/1000    1863835        1839575 >>>    BM_DumpHashMap/5k      8961836        8902540 >>>    BM_DumpHashMap/20k    69761497       69322756 >>>    BM_DumpHashMap/39k   187437830      186551111 >>> >>> Fixes: 057996380a42 ("bpf: Add batch ops to all htab bpf map") >>> Cc: Yonghong Song >>> Signed-off-by: Brian Vazquez >> >> Acked-by: Yonghong Song > > I must probably be missing something, but how is this safe? Presume we > traverse in the walk with bucket_cnt = 0. Meanwhile a different CPU added > entries to this bucket since not locked. Same reader on the other CPU with > bucket_cnt = 0 then starts to traverse the second > hlist_nulls_for_each_entry_safe() unlocked e.g. deleting entries? Thanks for pointing this out. Yes, you are correct. If bucket_cnt is 0 and buck->lock is not held, we should skip the hlist_nulls_for_each_entry_safe(l, n, head, hash_node) { ... } as another cpu may traverse the bucket in parallel by adding/deleting the elements.