Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6270615ybv; Tue, 18 Feb 2020 13:24:05 -0800 (PST) X-Google-Smtp-Source: APXvYqwaI6zXxSI0m2PeuFe+ol2P21cwdNw5deRKFS6dDudwRmxvOkGc8usRhYgIUh2Mvmq7zChg X-Received: by 2002:a05:6808:319:: with SMTP id i25mr2623156oie.128.1582061045005; Tue, 18 Feb 2020 13:24:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1582061044; cv=pass; d=google.com; s=arc-20160816; b=Vz1sn50NXdn9BkTGMwQvXdf7zIRLe4XYgp5A3pRnIRKOdXRr6jJVrOT+VXRnUbLoOD 3RA6kz/lDVvtsd2whDkKkXv3PakWxqSWDK0+omPhRSGNDQNEaE6HLCfYk0cBaOVbl0Mi 7Hj/vOZLQZnMAOXb46Dpvz078hWmsTFEDhxFetP8FcGaIpOqsu3zbuVmUvOo1b89IabD lY5+dM5ETT1iVEVuRtLsLVYrEc9rsXnOpXc5Q0XnEuqBG9xtzygktdo7HWZrwZMM3bfZ OCNK+i55YMTKCy3cNtD/qxqbDlCO5WXl8x/I05GW/WCRAFkjAs6qD1jtJxcZuJDvTs5b JE5A== 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=lQxpTjAkWx89ygQ5ENRSEiHkjTEr+4y1Pulmx1o55JY=; b=zWP4/5wLBqrmAzd+3kuNM43SBuyqW2cAhhjnL1HV6iPZsElKKo7lI5PkgaanF/qfnF Srn74bpNjzsD/UTF1IV2Lob9pXfm3NgHHGNlOsIicdZx1VUH13G0oiGPeiVA2wNJeLfD QyC0Z7mVJ9fW1SyxP1k569ZeorLuUKq9mNDjjFwjY6A1qyt9mP0NENCoH+k4g3PpiNFA QyN03IXmsyGkRlKcOIQ5Xh+1stR1PiMlm0UbKq+0BluX5SCojJOyuCSCLBzWDRair/Xz tJqDNbBOZgjivkIiowosTH5VZugfUNwWuVFXYzFTqGiIWg2M/nnQ7NDzt7hPs03Ky73h 76ww== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b="VJ129/vl"; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector2-fb-onmicrosoft-com header.b=KQCUF9gJ; 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 m19si13587otr.18.2020.02.18.13.23.53; Tue, 18 Feb 2020 13:24:04 -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="VJ129/vl"; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector2-fb-onmicrosoft-com header.b=KQCUF9gJ; 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 S1727125AbgBRVXi (ORCPT + 99 others); Tue, 18 Feb 2020 16:23:38 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:39104 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726352AbgBRVXh (ORCPT ); Tue, 18 Feb 2020 16:23:37 -0500 Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01ILET4V007498; Tue, 18 Feb 2020 13:23:21 -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=lQxpTjAkWx89ygQ5ENRSEiHkjTEr+4y1Pulmx1o55JY=; b=VJ129/vlcQ3lWudmuihqTcGCdL6eU6fqOkwrv963w6zx2H0X5bJPiUIHVl/hw5nL5w+j Jef9ZYzZXTFc32v4j5AkjC4W0tW8BVVdfMOVUWry0ChBciw9WpPHVLqj1a0HrPGLWThd qjZHVUB7r2NwQdnLjJT9JQ9iZtfJ4+hCmt8= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 2y6fbqnuy8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 18 Feb 2020 13:23:20 -0800 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (100.104.98.9) by o365-in.thefacebook.com (100.104.94.197) 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 13:23:19 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n4rwQOthQfNqcHWdYlV93AvzDaDONkciv+6xtW8i5FieKh+qRxWRMB9afOSjpI2etRWPZx5u62gzBxKKIHi8Qhwu0QPZ10aZaktvjQyUVpy+yihf+83kMmzeOkysonBl+tj7N4PEbaJ1XaCk3JoHKfp0Ay4Svu8+f0om/EbyKoUdty6fZKunNsbPoEPuCaDUDbjNg98d+JA7KekznZgGpALrGhvauOQd6uZHT2b4jkiktgTkoekSgjzaRYMo4t/DohoTCL+RD1Q2LnMoRvGf++8M72QGSQ58IHu1O3YiDq48AtiDY9JwYAeAQqNEhVPkaUn+kFP6h8yHtRlrlzx6EQ== 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=lQxpTjAkWx89ygQ5ENRSEiHkjTEr+4y1Pulmx1o55JY=; b=ZUrR19e4N/70Z6fkC6eLcVdLCgO/8wf9EMy5x64gxkPtEF9OI7Zy9EVpuka1ut4VyZ0hlhfTdyZDjDk3AFkssrkOJ7fr60tYIZ0FPLxvfoswwtsHNQx+rvQ+e8JuXwxc0gQzHRq1GBsz4SnL8cr1v38L6/40lIdUt5WbtqEeVfb5X9wcGLy4N7Q4Upg7Rgq4RnUgfN2KFGWP7FOr/woGOq6wjr5WcysP2pqm0KQtHExGM9jOdvYPVMlYjnudvkbdydU/Br97KwCd+xqoIkNMG89DAkyZDADjuG4vJx3BklUTL+l1XpltO6NnGBwmqFni9XGpRILF5ZbKjg3fQv55+A== 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=lQxpTjAkWx89ygQ5ENRSEiHkjTEr+4y1Pulmx1o55JY=; b=KQCUF9gJNpJ6nUNdSIEYoePkPpxacnTi3i5mtyGneEUasJTzpK/aftbP6faiT+gpYA2chlwTkAfyfAw5UaBCODNJsmTZRICdrNctz/UKquwCTfd70rp92YbQUzlWnx5MWG57A11D6J8NDvvPrloZuxRHZEXfLM0PXtWSJAYztUA= Received: from DM6PR15MB3001.namprd15.prod.outlook.com (20.178.231.16) by DM6PR15MB3452.namprd15.prod.outlook.com (20.179.50.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.25; Tue, 18 Feb 2020 21:23:18 +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 21:23:18 +0000 Subject: Re: [PATCH v2 bpf] bpf: Do not grab the bucket spinlock by default on htab batch ops To: Brian Vazquez , Brian Vazquez , Alexei Starovoitov , Daniel Borkmann , "David S . Miller" CC: , , References: <20200218172552.215077-1-brianvv@google.com> From: Yonghong Song Message-ID: Date: Tue, 18 Feb 2020 13:23:15 -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: <20200218172552.215077-1-brianvv@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: CO2PR04CA0160.namprd04.prod.outlook.com (2603:10b6:104:4::14) 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 CO2PR04CA0160.namprd04.prod.outlook.com (2603:10b6:104:4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.23 via Frontend Transport; Tue, 18 Feb 2020 21:23:17 +0000 X-Originating-IP: [2620:10d:c090:500::5:fd19] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 53b00de9-69b9-4986-8486-08d7b4b8c5fb X-MS-TrafficTypeDiagnostic: DM6PR15MB3452: X-Microsoft-Antispam-PRVS: X-FB-Source: Internal X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-Forefront-PRVS: 031763BCAF X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(366004)(39860400002)(396003)(376002)(136003)(346002)(189003)(199004)(4326008)(6486002)(316002)(6506007)(53546011)(36756003)(31686004)(19627235002)(52116002)(2906002)(110136005)(66556008)(16526019)(6512007)(186003)(66946007)(2616005)(66476007)(81166006)(478600001)(31696002)(8936002)(5660300002)(81156014)(8676002)(86362001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM6PR15MB3452;H:DM6PR15MB3001.namprd15.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A: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: NEeWPpM6nWikPxq+h42t3k//b6nPzQ7hnS8sBaehMS11e5IJhku43/E7AqkZBZ2luoBujoAx2eh1gP0PbcGnOZpB3Wi1j6YToEAhaPyU85VV4FOpR1aWLJvLnItjSavz4K1c8CRpoSc68392wZ2z1V27fAUcw/ie1JWpwEnUDiYAfKLkgNY8jNQxTGraz0oidcshrJaSAwOu1JNBCf3P9RVgfX/F5RDT5gLElP1pnv1/zEYIVJeHl+cb4gmUPuQNEb/5ixR7iLwsz0vcg852Mzs1jC0Kf7QZIW0t46dcgcQut8dAt5BywTQguD+UdEOZoERqPHFjMTczcJWIoQmU1IhBOGP5u26BJSzu2zQY4Bxq2xhfwC0xdSvf7YDOsi8fTl3jKuOGLKQpUUlO+NHiRnrzFq6Ba5QHeCwoJMFqObvJxt/h32rJ7pI5ZBeigkXx X-MS-Exchange-AntiSpam-MessageData: Q9xAiFJkMgtxx8h9NR4M9DEXSwdHtmm3BHdeuaufDhJwLnxwoVCqcoNZLWczaurNkTDFSSBy2oy7Wz5do8rFitNG8qWbUy4WkGaHdb11Xmu0SRtFfmoveVgazWKqZEDWBKyO1p88AveVQIXjzQCZJqYiPIk9RXyY/ShYOCu0bvbil5RdK3inDE6e5dlF0LK0 X-MS-Exchange-CrossTenant-Network-Message-Id: 53b00de9-69b9-4986-8486-08d7b4b8c5fb X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2020 21:23:18.6610 (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: eeok71UK0k3HjTwpUSOtjGZtBcGuMal/jTSSqNRT/v7dXGl6/v31i6tQT6CAPuFv X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR15MB3452 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-18_07:2020-02-18,2020-02-18 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 adultscore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 priorityscore=1501 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 mlxlogscore=961 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002180139 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 9:25 AM, 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 Thanks for the fix. Acked-by: Yonghong Song > --- > v1 -> v2: Skip hlist_nulls_for_each_entry_safe if lock is not held > > kernel/bpf/hashtab.c | 22 +++++++++++++++++++++- > 1 file changed, 21 insertions(+), 1 deletion(-)