Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4368239pxj; Tue, 8 Jun 2021 12:34:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGEIsp3IqG1fCbHC54uFQBCWQP+velGfMihIjCAS5zjHNgDUnHXsCele4Pu7KUCuQG5DOU X-Received: by 2002:a17:906:d97:: with SMTP id m23mr25101281eji.392.1623180888832; Tue, 08 Jun 2021 12:34:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623180888; cv=none; d=google.com; s=arc-20160816; b=rCt218mtvCu1uj97/wj6R6z8Y9YDOaKy0S0FGqOyBG9iCqNS2d3amUHZGjpFkgj6J9 Oep7UZ1ZQPyUhQ3OsZGIGc/+7z79ouWoKL7uLzjGhGnV/OZ29XkaLZzUqaZ5FaK5dTeO pINKZCXXOYyGNye//ZbVjNaF35ux2lieQV91k+0uNWMLlkyzCdhlEpYl6C8k1XRM6nNY g+P1sTWmm+Pn5uZTHsiqWbzNppp/axG2fYxRhrCfgvJOIjRUe7OTb63NX+asrN7Z6ivH nZa2edo1/EVqrwHxLIkhPSYD/PvWgVsomcG6hQKgrvfTTsXaTzvSVwII7pJrJIGOqLfw 1B2g== 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=wwhBqv0RREBtvKS814MA2X1ZihMwKoGi3B3L1M8ywS8=; b=VUqA1LCiuVrZkdGVolWzfSfpFpKEXGMKHCxZcMWQxS2AUsTOS0uUweIC26dNuroshw BYMpOo58HrKyDOobDS/2pmCghhC5FAtvTMek6jSktwRhKe6UrgnWwo5GJmeNSC3D1kAz XzV0IPZRMbVd2qme/5ZTTnEMpvesASfThBB93u1De8EfnuZqJPHLN0at71aaCCGMm+4r DCHwxhY8V78HZLFzoEl6gsAQmSEe8uzYrdMvawhVN7d3HfeUiuxUFjia+6iEMEljwUUN Pw+A9FVUX/spWLi0t7QShWOJM/MYGxFK+ySuv0mjWA+E1A/WJonUOjLEY29Dd/B4KeKm pb8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1GJy3x2c; 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 nb10si487514ejc.344.2021.06.08.12.34.25; Tue, 08 Jun 2021 12:34:48 -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=1GJy3x2c; 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 S237405AbhFHTd6 (ORCPT + 99 others); Tue, 8 Jun 2021 15:33:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:39612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237956AbhFHTSK (ORCPT ); Tue, 8 Jun 2021 15:18:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2422B6140F; Tue, 8 Jun 2021 18:51:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623178314; bh=WBaDR/3bp+5KoI+MO9Nv5iU1JRrzhFLaNPv4RszXNUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1GJy3x2cFrNgYsC8eYs6uW7asCLJSIJbUIACTqsztP3eRIW0bZnt2wDjIMzqBy+3m YvaVpt88XJmahkY/7Fp8ABVSwqw2+cksqm98AGwzLn3Kjjj1kcRyZMZckuE8b9Bis0 daRW3RZN+A4VkWU98EgDDz5PM8HTce6MwJq1ffVU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marco Elver , Alexander Potapenko , Dmitry Vyukov , Hillf Danton , Jann Horn , Mark Rutland , Andrew Morton , Linus Torvalds Subject: [PATCH 5.12 123/161] kfence: maximize allocation wait timeout duration Date: Tue, 8 Jun 2021 20:27:33 +0200 Message-Id: <20210608175949.600600450@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175945.476074951@linuxfoundation.org> References: <20210608175945.476074951@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: Marco Elver commit 37c9284f6932b915043717703d6496dfd59c85f5 upstream. The allocation wait timeout was initially added because of warnings due to CONFIG_DETECT_HUNG_TASK=y [1]. While the 1 sec timeout is sufficient to resolve the warnings (given the hung task timeout must be 1 sec or larger) it may cause unnecessary wake-ups if the system is idle: https://lkml.kernel.org/r/CADYN=9J0DQhizAGB0-jz4HOBBh+05kMBXb4c0cXMS7Qi5NAJiw@mail.gmail.com Fix it by computing the timeout duration in terms of the current sysctl_hung_task_timeout_secs value. Link: https://lkml.kernel.org/r/20210421105132.3965998-3-elver@google.com Signed-off-by: Marco Elver Cc: Alexander Potapenko Cc: Dmitry Vyukov Cc: Hillf Danton Cc: Jann Horn Cc: Mark Rutland Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/kfence/core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -620,7 +621,16 @@ static void toggle_allocation_gate(struc /* Enable static key, and await allocation to happen. */ static_branch_enable(&kfence_allocation_key); - wait_event_timeout(allocation_wait, atomic_read(&kfence_allocation_gate), HZ); + if (sysctl_hung_task_timeout_secs) { + /* + * During low activity with no allocations we might wait a + * while; let's avoid the hung task warning. + */ + wait_event_timeout(allocation_wait, atomic_read(&kfence_allocation_gate), + sysctl_hung_task_timeout_secs * HZ / 2); + } else { + wait_event(allocation_wait, atomic_read(&kfence_allocation_gate)); + } /* Disable static key and reset timer. */ static_branch_disable(&kfence_allocation_key);