From patchwork Thu Dec 15 16:02:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 13074312 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 11B08C2D0CC for ; Thu, 15 Dec 2022 16:03:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 899228E0002; Thu, 15 Dec 2022 11:03:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8150B8E0006; Thu, 15 Dec 2022 11:03:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5536D8E0003; Thu, 15 Dec 2022 11:03:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3C6CB8E0002 for ; Thu, 15 Dec 2022 11:03:19 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DD6F180FB0 for ; Thu, 15 Dec 2022 16:03:18 +0000 (UTC) X-FDA: 80245010076.13.B254EF4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id F09C1180055 for ; Thu, 15 Dec 2022 16:03:13 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WMTDqiuW; spf=pass (imf06.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671120196; a=rsa-sha256; cv=none; b=6EH1WNITJS4/U+bIkv0eJp/g0tl8q24FZNbGr2IoF6qCMuDMxfDiuLqyVBLXtIedAWnOAX svxX2tpolwsihjOH52yIpfwvmBrjR7BWHMceM3S8LwhyfG3fKyVFtgvzwrl7uskMuV4A8m QEXg5B7KbCqWuCDA1mc8lMESnlAsbTM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WMTDqiuW; spf=pass (imf06.hostedemail.com: domain of longman@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671120196; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YFRn2G3kICVUTv0CVX/GON7X4LfKNre2jK8Ma2QSF+o=; b=M5QTAurX6ikbn8SjRcPs6LkM71sg8or7RhwzUgFKYEGYTuI5XXPSp15YBgIo1D7HCDglha qslDvNj/tVNvFCquRi8npG+YAgyvXYVSTqlINRwF05l5iNVW7vgnyMnQjXVByZIRHP16S0 /UqaFtiwi56L8V0OBuoILffmUhrDBFk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671120193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YFRn2G3kICVUTv0CVX/GON7X4LfKNre2jK8Ma2QSF+o=; b=WMTDqiuWmKCTPoNxzpWhsVYxai7Ffd09BRzmYKqL18fg0OfrwRh/J7Kz7j6Z7A8s6I1CNl rP7+EOQGtQFV40nmQ6zpQNL3FcIs6Q4aNuxbTHZtYiOJiYKNZBSyBbODonCJcWrDZi8R4l 4RtDRCep4uDBGHYlrHK0TadgUknbC0o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-453-b2qMVZfhMqyIfPZeJDNE2g-1; Thu, 15 Dec 2022 11:03:09 -0500 X-MC-Unique: b2qMVZfhMqyIfPZeJDNE2g-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7EF8100F901; Thu, 15 Dec 2022 16:03:08 +0000 (UTC) Received: from llong.com (unknown [10.22.9.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4BBE4085720; Thu, 15 Dec 2022 16:03:08 +0000 (UTC) From: Waiman Long To: Catalin Marinas , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Waiman Long Subject: [PATCH v2 1/2] mm/kmemleak: Simplify kmemleak_cond_resched() usage Date: Thu, 15 Dec 2022 11:02:58 -0500 Message-Id: <20221215160259.261136-2-longman@redhat.com> In-Reply-To: <20221215160259.261136-1-longman@redhat.com> References: <20221215160259.261136-1-longman@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Queue-Id: F09C1180055 X-Rspamd-Server: rspam01 X-Stat-Signature: 7a3epggj4k85ca9nm7dc3typafmyi8s9 X-HE-Tag: 1671120193-109946 X-HE-Meta: U2FsdGVkX19Ivyrp03AyFsJ21c7qqwADSOCBkMSvL6ELOvHFJz9FOorjs9ApYxQAiWZ2cPfjgrQXxSSxL5/qPut8VRFH+E4zOON5LCflp2GyRbVSBgZOe1TxEVqR6bzE3f70IHgsllnmBI/5ueM03Fk7yxCli65ntib/tPeSV9CK51W5gmzhlJab+6Y/3pOBwMHRRgmB7pCApFuKr7GRDCf71irgEygUugyNMEHGiISKWg1318r80E/Y8/xdWBoSI/MAa07LgqwrideAfHvsNHDTDkd7bmYNz0f2wuXKYW7xc8fhwGmfYGBMvpCMAKoNULRYTJr8WvPvSY17mo+jr/frX5N7VY2BTd5iMc3WsaCPWySfu4gFW9M1XE7cKUZmd6LpJwBqcuiA/EeSWV2GCOrfk3ljeemjZ/VkgiBrdwIUOHRBzJMJK7tx0baVKAc5H0uoQgUrFNbLIJcdFufFj4DExl+QWK02blrDrX57qejp22Gw36eZtp3G6I1rLQpW2ajkyzxhp6C1rDeUKUERkmf4YiVtR+BIstxcCO1hoGbgWSzs4wfdQV1sDxdFP4yL+GnYvpzgks8+sPaZWsaxGCMY7gMmgdtxmtBdQjgIz9QD9JCeZ45SQ86C7w/skWkC6EAnFmgq31qeD2jJ2AI9cayYZaGcMXtKMEWmWM3l91iGu2RlJGsJxTfKOXQ+1IDgQKNloccgkOdxPmlSGAYgJ3wR7FsO8UXH8QdwiMhEjhvlCIkKs5TzRNyhjk4ryrJjMbA4nQwEcvdBNqhDBMN9LPAope2FMgKK4N/ozKzOF58BsYicSzf2DpJ4wknJlD3CayvYYdjLkycTgVr4MwUtB8z9NI7UStnekFYa1ZssX9WCtBRSe1NfJRZWvtPBVi0DUyiKS8CVwMes7nZkGwoJp59MctKHAdV/HEJZu1H5t9OWtszynfcbofJShcpzQKgmAHhJgRmCZMg+CKnWGNv Uvw== 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: The presence of a pinned argument and the 64k loop count make kmemleak_cond_resched() a bit more complex to read. The pinned argument is used only by first kmemleak_scan() loop. Simplify the usage of kmemleak_cond_resched() by removing the pinned argument and always do a get_object()/put_object() sequence. In addition, the 64k loop is removed by using need_resched() to decide if kmemleak_cond_resched() should be called. Signed-off-by: Waiman Long Reviewed-by: Catalin Marinas --- mm/kmemleak.c | 48 ++++++++++++------------------------------------ 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 267332904354..e7cb521236bf 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1463,22 +1463,17 @@ static void scan_gray_list(void) /* * Conditionally call resched() in an object iteration loop while making sure * that the given object won't go away without RCU read lock by performing a - * get_object() if !pinned. - * - * Return: false if can't do a cond_resched() due to get_object() failure - * true otherwise + * get_object() if necessaary. */ -static bool kmemleak_cond_resched(struct kmemleak_object *object, bool pinned) +static void kmemleak_cond_resched(struct kmemleak_object *object) { - if (!pinned && !get_object(object)) - return false; + if (!get_object(object)) + return; /* Try next object */ rcu_read_unlock(); cond_resched(); rcu_read_lock(); - if (!pinned) - put_object(object); - return true; + put_object(object); } /* @@ -1492,15 +1487,12 @@ static void kmemleak_scan(void) struct zone *zone; int __maybe_unused i; int new_leaks = 0; - int loop_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; - raw_spin_lock_irq(&object->lock); #ifdef DEBUG /* @@ -1526,19 +1518,13 @@ static void kmemleak_scan(void) /* 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() every 64k objects to avoid soft lockup. - */ - if (!(++loop_cnt & 0xffff) && - !kmemleak_cond_resched(object, obj_pinned)) - loop_cnt--; /* Try again on next object */ + if (need_resched()) + kmemleak_cond_resched(object); } rcu_read_unlock(); @@ -1605,14 +1591,9 @@ static void kmemleak_scan(void) * scan and color them gray until the next scan. */ rcu_read_lock(); - loop_cnt = 0; list_for_each_entry_rcu(object, &object_list, object_list) { - /* - * Do a cond_resched() every 64k objects to avoid soft lockup. - */ - if (!(++loop_cnt & 0xffff) && - !kmemleak_cond_resched(object, false)) - loop_cnt--; /* Try again on next object */ + if (need_resched()) + kmemleak_cond_resched(object); /* * This is racy but we can save the overhead of lock/unlock @@ -1647,14 +1628,9 @@ static void kmemleak_scan(void) * Scanning result reporting. */ rcu_read_lock(); - loop_cnt = 0; list_for_each_entry_rcu(object, &object_list, object_list) { - /* - * Do a cond_resched() every 64k objects to avoid soft lockup. - */ - if (!(++loop_cnt & 0xffff) && - !kmemleak_cond_resched(object, false)) - loop_cnt--; /* Try again on next object */ + if (need_resched()) + kmemleak_cond_resched(object); /* * This is racy but we can save the overhead of lock/unlock