Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1668232iog; Tue, 14 Jun 2022 10:30:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0c+pdUo6TQs2x8hWOzCvstiyIVeswpFFw6h9IbdtzQ5YIj9flZ32qYyhe0ZbefhVOO+aP X-Received: by 2002:a63:89c1:0:b0:3fc:6001:e871 with SMTP id v184-20020a6389c1000000b003fc6001e871mr5503483pgd.14.1655227827755; Tue, 14 Jun 2022 10:30:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655227827; cv=none; d=google.com; s=arc-20160816; b=WsI5JxN3VzkB4zMYgsij7ipdEZfE3R5SmqoQmw7tJcjKc42/KILe8VhO5wn/IeM3BQ jNNAeRRiHu4SCobvJ2GgMEEJZftvvB25yrWFuncKbdv7HMngSqQJIPOed5ugOO0DbIY3 H6TcXhVE46UJV3PG54LQODtiCroZ5rIgI0GlpNziLjgjD1AQ7eLpvJIj6gR92qF8VhML B5uxguLxuJ/OhFu05jqUCZVetX+cUlAecWTL81sMK5vFkp73Fywf0SRq9TqSyp1bBpZe JpZjj8rkwQ3pXzctTq8FmgfRLfysUBerUq1N1lWi2StjToXQ6qi5MmbvxeFEJSlxoQjI rpzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=JJewp66f+hnkUfGiI+PYWo/gajuDMon54PRlnizSb3Q=; b=guDYaeDAdPE/sgbfPbthNdBJHVGe0uxFejOuFs567py9kctT7zLLgh3dIPAtpC5g0e GRHnqhkNe5kGqT17mS1lxgqZqLysAmy9u0c4Mg9tdAqZzuY0uFd06DdVWcbO3ZnUeFSM fePhZTAOg3dmx9F45ZlAs8uWP2d7F4FZ2y9KSIpKsYIyd/Idlxd2FFKSRa3CZKWSeIZE ZpmaJTiaco6Ok+R+fUw78NpBHkmjlsRCFswBkzRxifcBat8lo6bZ3+CGtI3k6M0H1QuD KuEa+jcIpVOmdMmGdiZ0NtpkeBsiuBhAZMO7rIalRGph/VLxg7V8hsxKQGh3JvCGy4Zg 7svA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7-20020aa79ec7000000b0050d2ac6b8b6si13197958pfq.226.2022.06.14.10.30.15; Tue, 14 Jun 2022 10:30:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350585AbiFNR2M (ORCPT + 99 others); Tue, 14 Jun 2022 13:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346818AbiFNR2F (ORCPT ); Tue, 14 Jun 2022 13:28:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5999636E08 for ; Tue, 14 Jun 2022 10:28:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 12B66B81A25 for ; Tue, 14 Jun 2022 17:28:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A36EEC3411B; Tue, 14 Jun 2022 17:28:00 +0000 (UTC) Date: Tue, 14 Jun 2022 18:27:56 +0100 From: Catalin Marinas To: Waiman Long Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] mm/kmemleak: Prevent soft lockup in first object iteration loop of kmemleak_scan() Message-ID: References: <20220612183301.981616-1-longman@redhat.com> <20220612183301.981616-4-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Tue, Jun 14, 2022 at 06:15:14PM +0100, Catalin Marinas wrote: > On Sun, Jun 12, 2022 at 02:33:01PM -0400, Waiman Long wrote: > > @@ -1437,10 +1440,25 @@ static void kmemleak_scan(void) > > #endif > > /* reset the reference count (whiten the object) */ > > object->count = 0; > > - if (color_gray(object) && get_object(object)) > > + if (color_gray(object) && get_object(object)) { > > list_add_tail(&object->gray_list, &gray_list); > > + gray_list_cnt++; > > + object_pinned = true; > > + } > > > > raw_spin_unlock_irq(&object->lock); > > + > > + /* > > + * With object pinned by a positive reference count, it > > + * won't go away and we can safely release the RCU read > > + * lock and do a cond_resched() to avoid soft lockup every > > + * 64k objects. > > + */ > > + if (object_pinned && !(gray_list_cnt & 0xffff)) { > > + rcu_read_unlock(); > > + cond_resched(); > > + rcu_read_lock(); > > + } > > I'm not sure this gains much. There should be very few gray objects > initially (those passed to kmemleak_not_leak() for example). The > majority should be white objects. > > If we drop the fine-grained object->lock, we could instead take > kmemleak_lock outside the loop with a cond_resched_lock(&kmemleak_lock) > within the loop. I think we can get away with not having an > rcu_read_lock() at all for list traversal with the big lock outside the > loop. Actually this doesn't work is the current object in the iteration is freed. Does list_for_each_rcu_safe() help? -- Catalin