From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60311C43334 for ; Wed, 15 Jun 2022 15:11:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C96886B0071; Wed, 15 Jun 2022 11:11:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C46556B0074; Wed, 15 Jun 2022 11:11:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0F546B0078; Wed, 15 Jun 2022 11:11:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A2CD16B0071 for ; Wed, 15 Jun 2022 11:11:18 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 802E460435 for ; Wed, 15 Jun 2022 15:11:18 +0000 (UTC) X-FDA: 79580808636.14.6381621 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 2260E40013 for ; Wed, 15 Jun 2022 15:11:17 +0000 (UTC) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 22D8D614BF; Wed, 15 Jun 2022 15:11:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70D16C34115; Wed, 15 Jun 2022 15:11:15 +0000 (UTC) Date: Wed, 15 Jun 2022 16:11:11 +0100 From: Catalin Marinas To: Waiman Long Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song Subject: Re: [PATCH v2 3/3] mm/kmemleak: Prevent soft lockup in first object iteration loop of kmemleak_scan() Message-ID: References: <20220614220359.59282-1-longman@redhat.com> <20220614220359.59282-4-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220614220359.59282-4-longman@redhat.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655305878; a=rsa-sha256; cv=none; b=vKqBA1vlA30J+BhVTGyUyIrtgXMAZ3/voHUf1sZwwENCsR5ZrYpDal+Bry5hFb0FUmQyeO vmAVd6ykvynTv+/HAvrH2hxx9MoCgB9uld2sN/b07juvS6R9Utoiru0R4gO6K/0xNs5/XO ROIYLN2of45MuZBZ7627Q9frjpqa47E= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655305878; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sRq23f2DQ79Rsr/bnkLoJJEPiAMWxN8A6Q+8IA9I/IM=; b=UU03M6o5GPfQB1bOyNYuSXKbmk5LO1OI5ODFi+TrOeVIZNjCxDeFFdYSdllsc2g7BZuEPj RhWVkajqPXUhn66Qok8a2qmDRY+EcwUn9ZqsUWYN4uanPxepyf3T0tPWc0rLMKoyXxLgd0 vvz6qZqPvVc0g9+E7vQpeBrv2eaRAfQ= X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2260E40013 X-Stat-Signature: hep1iyd6p6rr3dzj7ys4y11tnj7no88o Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none) X-HE-Tag: 1655305877-984945 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jun 14, 2022 at 06:03:59PM -0400, Waiman Long wrote: > diff --git a/mm/kmemleak.c b/mm/kmemleak.c > index 7dd64139a7c7..abba063ae5ee 100644 > --- a/mm/kmemleak.c > +++ b/mm/kmemleak.c > @@ -1417,12 +1417,16 @@ static void kmemleak_scan(void) > struct zone *zone; > int __maybe_unused i; > int new_leaks = 0; > + int loop1_cnt = 0; > > jiffies_last_scan = jiffies; > > /* prepare the kmemleak_object's */ > rcu_read_lock(); > list_for_each_entry_rcu(object, &object_list, object_list) { > + bool obj_pinned = false; > + > + loop1_cnt++; > raw_spin_lock_irq(&object->lock); > #ifdef DEBUG > /* > @@ -1437,10 +1441,32 @@ 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); > + obj_pinned = true; > + } > > raw_spin_unlock_irq(&object->lock); > + > + /* > + * Do a cond_resched() to avoid soft lockup every 64k objects. > + * Make sure a reference has been taken so that the object > + * won't go away without RCU read lock. > + */ > + if (!(loop1_cnt & 0xffff)) { > + if (!obj_pinned && !get_object(object)) { > + /* Try the next object instead */ > + loop1_cnt--; > + continue; > + } With this trick we could probably get rid of rcu_read_lock() and take the kmemleak_lock instead. But that's for another patch. > + > + rcu_read_unlock(); > + cond_resched(); > + rcu_read_lock(); cond_resched_rcu() to save a couple of lines? > + > + if (!obj_pinned) > + put_object(object); > + } Reviewed-by: Catalin Marinas Thanks.