Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1543045pxb; Thu, 16 Sep 2021 09:35:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTMaLO7aGw1d64DgrSxWyrcL1kh6z36dYV3UB5RwweImTxYvAbstBuZMyv47bcCVZGDhFq X-Received: by 2002:a05:6e02:6c4:: with SMTP id p4mr4663907ils.182.1631810108416; Thu, 16 Sep 2021 09:35:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631810108; cv=none; d=google.com; s=arc-20160816; b=CRFsHsq4Csq6QWT30Oo5P5/iP/JQdUeMKa7giBJn7ktYD3wASM8UfXeIyxgfa2/CHL jJW1vmpGa1Rom4LcAYs8+Am4r3a2Uw/OQfzSCtNLorHp1axLitBXC4/wuC8+62YfIg1J 5vmdS+96QJGHQNyIQT45GJ2/TPWiy4AU0Gv6yfZzRXHn3cIueq0cen/s+LnfY4nTUgj3 nqaYy3oHpm7xyRTtajTlo9OtU5/+U+ef7uD/G2yvpNsfVP4mZlFxwb3h7vmqwlZSH8Dq dG59pDmYhp8oJLMQznexr/gGwnhz79cqgrKzn/z8BZXXCpGa7DDW849QXAjt/OVlV41E dzJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tb3RTlYV0ol9yVRas+zyS5td3nJri3g2v8EljQdPdAg=; b=T+jOWsw94DJF4iOvIA+XOdSyyUVq9b+FYAnDbmfnRHe4wMN35hEJzJ4I8FVI87dKfm nG1+Z/AGjUJxYfju0ayWzLmHOu0nhzvUL7eK3RkNNH1s9GZ1+oB0xYnRcMIg2D2GbAFQ JWjkRUDe/eAzaIMvTq4XsFdi0qdVDNFt8u5JavShfw8siD+WGArNR9wIn/BDy4Cf4dxK aJH+Sa+KGnDTu2vAxfOBz6XooK26ehpMhgaI4Jqnh8X1ON4m4WWUKLPipfsO7XfRjjoX o3rY9VqvjK2ZUpfxqpmD3ot5czFe3DYfq/N8cVhHQTAO9yn3VdclPrxB2EOatmU05ZZO gM7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K5JFjlh4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n4si3249518ilo.88.2021.09.16.09.34.52; Thu, 16 Sep 2021 09:35:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K5JFjlh4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243699AbhIPQeG (ORCPT + 99 others); Thu, 16 Sep 2021 12:34:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:38284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241715AbhIPQZt (ORCPT ); Thu, 16 Sep 2021 12:25:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C6B006135F; Thu, 16 Sep 2021 16:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809015; bh=AqjpVczbWhjKyLE7PDyMzNLU9SOVZx6lJP4vKwpG/gU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K5JFjlh44OvmUsMy4Ry7D1ILwurEvoyow6OaqBjT7bGyttNTciHaKcyQnzDJ1N70Q YySCjhzz/K7ZvZxgWlZst11Zq5dir8l59Q/h5bdFarRr/rTUI7e8y6Z1RDQQWKD/AY EHad0PLR6QoP/XSfp6BiSWQHo1S7PzL9StEGXjFo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Amir Goldstein , Jan Kara Subject: [PATCH 5.10 306/306] fanotify: limit number of event merge attempts Date: Thu, 16 Sep 2021 18:00:51 +0200 Message-Id: <20210916155804.511117474@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Amir Goldstein commit b8cd0ee8cda68a888a317991c1e918a8cba1a568 upstream. Event merges are expensive when event queue size is large, so limit the linear search to 128 merge tests. [Stable backport notes] The following statement from upstream commit is irrelevant for backport: - -In combination with 128 size hash table, there is a potential to merge -with up to 16K events in the hashed queue. - [Stable backport notes] The problem is as old as fanotify and described in the linked cover letter "Performance improvement for fanotify merge". This backported patch fixes the performance issue at the cost of merging fewer potential events. Fixing the performance issue is more important than preserving the "event merge" behavior, which was not predictable in any way that applications could rely on. Link: https://lore.kernel.org/r/20210304104826.3993892-6-amir73il@gmail.com Signed-off-by: Amir Goldstein Signed-off-by: Jan Kara Cc: Link: https://lore.kernel.org/linux-fsdevel/20210202162010.305971-1-amir73il@gmail.com/ Link: https://lore.kernel.org/linux-fsdevel/20210915163334.GD6166@quack2.suse.cz/ Signed-off-by: Amir Goldstein Signed-off-by: Greg Kroah-Hartman --- fs/notify/fanotify/fanotify.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -129,11 +129,15 @@ static bool fanotify_should_merge(struct return false; } +/* Limit event merges to limit CPU overhead per event */ +#define FANOTIFY_MAX_MERGE_EVENTS 128 + /* and the list better be locked by something too! */ static int fanotify_merge(struct list_head *list, struct fsnotify_event *event) { struct fsnotify_event *test_event; struct fanotify_event *new; + int i = 0; pr_debug("%s: list=%p event=%p\n", __func__, list, event); new = FANOTIFY_E(event); @@ -147,6 +151,8 @@ static int fanotify_merge(struct list_he return 0; list_for_each_entry_reverse(test_event, list, list) { + if (++i > FANOTIFY_MAX_MERGE_EVENTS) + break; if (fanotify_should_merge(test_event, event)) { FANOTIFY_E(test_event)->mask |= new->mask; return 1;