Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp896782rdb; Fri, 1 Dec 2023 01:11:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGR0reY4FbFrcd/Ste9tQoHgMOAhZ59Wr1xNboqcs615a0zQe+zrlMPEr1c50lxsqcj7JS X-Received: by 2002:a05:6a20:12c3:b0:187:df72:48ef with SMTP id v3-20020a056a2012c300b00187df7248efmr32715791pzg.0.1701421892915; Fri, 01 Dec 2023 01:11:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701421892; cv=none; d=google.com; s=arc-20160816; b=G/zeErP7KjYiBIVMPXqQ6lbYGk5GZJpH0+/DmM0NKvBESm/ya81cPwI0vhJmni0YEE tznk8sO1h5mGdSKYd3M1Lj0m0OihbVNjGhRLAfGeq2Jy7LarV2QKzopvXD6pFaH2e+HM RnhnQVCiNYn0ogkvX9TQSWejTeKP/hX2336tHS0F2ZgAKY00Yvq4MvfpL+lOLYRVkb4w gmydVw/jEtqoZ76x2dwpvb0y49IEmd7m07fcxozREqec1ucfTOl1PWTIu9hHQ7DzzPna HGdSKcy4wfLRhUjNGThtNybzZMpXo0O+qtAH/7EfGe/yc/9gkPYBBrQ+AHt/yqfPifX0 ZD/Q== 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=kw0R1IIry/oGs15Umww96Xqt0mM/p6UWTCuyWlkeb9Y=; fh=pxuE4D9f8+elEWfmXALwyOwUGTWa8FzFiBI6Zh/pHYM=; b=jMZ6Bx7PNmieLSF4F7CR90znq1eNgpvY23MCuJXpHCqF4SW13eSd1Q/b4UmQkvXXAe OaQJ3bEcp8SOEpdeQeNUN/wWMmdTz+PuUygeKCcBjl1b6gjAGnPyc7YF6HLu8Dv1ekDG /Kvk15AABOQZzjqiwHu50aGaf9egx7iu2CWKL5ahgmjWX3j/tZflHrhdexe2fQXTXgkN h37+8bGDqrpJDd+vFxxf+sT3d6ywj+YJmSI+LlAXSWtbxTL2ebr9kGT6shg7eHJRXum9 BSOlJzS8Jo7BZVVxe/J5gpWoRYxGAcGwcDMfo+EOycyvWGlLZ5h00N/VlMtStNSB7rGa Bz7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=q4K0dUSh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id lp3-20020a17090b4a8300b002857e8be0e7si3117411pjb.170.2023.12.01.01.11.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:11:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=q4K0dUSh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 9D83A8075580; Fri, 1 Dec 2023 01:10:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235242AbjLAJKP (ORCPT + 99 others); Fri, 1 Dec 2023 04:10:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjLAJKO (ORCPT ); Fri, 1 Dec 2023 04:10:14 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D489A12A for ; Fri, 1 Dec 2023 01:10:18 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-54c52baaa59so5018a12.0 for ; Fri, 01 Dec 2023 01:10:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701421817; x=1702026617; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kw0R1IIry/oGs15Umww96Xqt0mM/p6UWTCuyWlkeb9Y=; b=q4K0dUSh3w8QQibbWbfK98RVLkHIWDUm0ekqC8AWVUP6BXk4zwUOvZWVeCS61xMTXr HWfBEE6Oi/mWaZSEDT/MGMWxwtX3XPtG1eaQbikcboQwqbItWFT+N/jjoXtQzd69XNhC lCx9enLGLD/UxJbZaPJw6VAwFVSYCHGSPlJyhjjlZc/7tcf/AR1tN379JHr/TGEjJdJm Qf5FwYc+KzQeAYPkPjh6e02rEM8h9keW7pdEBNOwzBYhn2zQkjOS2fNIzGA+PmJp9mwP nOquSwZp3mm4GiuDHN00G2qiR0T/teBx/8aUN+GzOkTHjlcScN+Ef4cbQbxXqGM5UvMN HiWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701421817; x=1702026617; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kw0R1IIry/oGs15Umww96Xqt0mM/p6UWTCuyWlkeb9Y=; b=uAYV/AjUQ0qPLBVO7RZ3rV8UkwKSpLpQg4E1bDWRw5KWMQfSZWwisIp6oqAJZRIjbU 5s+SY5LKwW0PojFy+560ty8NuZWj+SBtri7/RX5ZOKzPdxfdQOwFe95QjfmTA05gxcN6 eCIcZVFk0CHpfXrXI7Ye+ZomHjEXpGV6xz4iahfAx6lPtHwjhqkf9xynYktdLfTIMqcV SEdGNzfA2yx/R25wJhaC3uBkhGGdWZweUyz49XvWUOrU9jO5wERAPuyntERNEqkX6DJ2 ObS0qxXsuFBj5QTEgx2SCjyk5bf/qujIABOlIj9F6lIJzgPF4w8nGqyxH+ndxEKSrH7F /hfw== X-Gm-Message-State: AOJu0YzanUV9Z4ynBqkI09ECtJkhRdGmYe1KVUqJf1hYLBS8m9jCydDQ R4uwCjX9pWFMz6ovCE8T0gTDjRqgoS+dMfuJkShxmA== X-Received: by 2002:a50:d49c:0:b0:543:fb17:1a8 with SMTP id s28-20020a50d49c000000b00543fb1701a8mr47255edi.3.1701421817064; Fri, 01 Dec 2023 01:10:17 -0800 (PST) MIME-Version: 1.0 References: <20231201083926.1817394-1-judyhsiao@chromium.org> In-Reply-To: <20231201083926.1817394-1-judyhsiao@chromium.org> From: Eric Dumazet Date: Fri, 1 Dec 2023 10:10:03 +0100 Message-ID: Subject: Re: [PATCH v1] neighbour: Don't let neigh_forced_gc() disable preemption for long To: Judy Hsiao Cc: David Ahern , Simon Horman , Douglas Anderson , Brian Haley , "David S. Miller" , Jakub Kicinski , Joel Granados , Julian Anastasov , Leon Romanovsky , Luis Chamberlain , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 01 Dec 2023 01:10:30 -0800 (PST) On Fri, Dec 1, 2023 at 9:39=E2=80=AFAM Judy Hsiao = wrote: > > We are seeing cases where neigh_cleanup_and_release() is called by > neigh_forced_gc() many times in a row with preemption turned off. > When running on a low powered CPU at a low CPU frequency, this has > been measured to keep preemption off for ~10 ms. That's not great on a > system with HZ=3D1000 which expects tasks to be able to schedule in > with ~1ms latency. This will not work in general, because this code runs with BH blocked. jiffies will stay untouched for many more ms on systems with only one CPU. I would rather not rely on jiffies here but ktime_get_ns() [1] Also if we break the loop based on time, we might be unable to purge the last elements in gc_list. We might need to use a second list to make sure to cycle over all elements eventually. [1] diff --git a/net/core/neighbour.c b/net/core/neighbour.c index df81c1f0a57047e176b7c7e4809d2dae59ba6be5..e2340e6b07735db8cf6e75d23ef= 09bb4b0db53b4 100644 --- a/net/core/neighbour.c +++ b/net/core/neighbour.c @@ -253,9 +253,11 @@ static int neigh_forced_gc(struct neigh_table *tbl) { int max_clean =3D atomic_read(&tbl->gc_entries) - READ_ONCE(tbl->gc_thresh2); + u64 tmax =3D ktime_get_ns() + NSEC_PER_MSEC; unsigned long tref =3D jiffies - 5 * HZ; struct neighbour *n, *tmp; int shrunk =3D 0; + int loop =3D 0; NEIGH_CACHE_STAT_INC(tbl, forced_gc_runs); @@ -279,10 +281,16 @@ static int neigh_forced_gc(struct neigh_table *tbl) if (shrunk >=3D max_clean) break; } + if (++loop =3D=3D 16) { + if (ktime_get_ns() > tmax) + goto unlock; + loop =3D 0; + } } WRITE_ONCE(tbl->last_flush, jiffies); +unlock: write_unlock_bh(&tbl->lock); return shrunk;