Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp958966pxb; Wed, 15 Sep 2021 18:03:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsrYVirG7khTd6Jz4FRe0TqQ4xdUwjG95naFL9rqQkjGAAeBKRagHfT6aUVXyZXxwNHEy3 X-Received: by 2002:a5d:850f:: with SMTP id q15mr2380335ion.118.1631754210944; Wed, 15 Sep 2021 18:03:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631754210; cv=none; d=google.com; s=arc-20160816; b=xrGj8lgMZLu0+hOkXlH9CUALd3F/yqI81imRnz/5clwCQFuBIznf6NBTqtoLqBGyCZ sRei2UK4HUZvhf23abVGLqwSop98StTmfoRPY/0vnAACq04z3CpMsNXs0Jw3flK+kJYA J731YnOekfVOFfJAj4/t5BUfz14yvQHkRSiXSnsTPpu+vB3zLNLDRGWVpBseRaDSqBoG BfZqYr7KOcP1IiPI0AJncGZag+t38kicJa8r61pBRTWnhPQz4JA54ROl6jv66IM7ssRU SRpAszY901nnQZ4GeatuQS7pBz2sZHbzsXdzdGBKI3FD2lma9UsoYM+Llvl42igtYbr8 kL1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=PiN3wS5uwcKdZgKoV6iO6EUvp7tAUNAP2m2oJ5AcUK4=; b=HLKtcdBeLDYTHZW6i54GYZeBoqRzpGtfuFf/5jSpn7wTTvJ9NAGF80qQLDHnUtM8Qe HnCjiH+w3JN7+DKnDB/XTKXTWJY4XPzDjZ1OA7epzhZDCg00D2Qe5SIiKVNAeLP7DgFl S/PE8k3MYLH2NqeDiPg+78xc0yKGoXuvXvnXf4YlcMTBvQR83b/h1RGlobXDlTqIrIIT bVEfwvhWEVaYOJ331tmbO/dNxs7U3VHeaF4sK8AiWloF3JnIPYpoyIq6jUdzEop3+XtR A6Zrh6IsIPMBN0hQtk+6r+CIIpBR6kzrMe7bEH68+AXmgGyxld7F/DIChN35OOycy+Ij kKCg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b9si1357214ion.34.2021.09.15.18.03.18; Wed, 15 Sep 2021 18:03:30 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233429AbhIPBDz (ORCPT + 99 others); Wed, 15 Sep 2021 21:03:55 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:9880 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233284AbhIPBDx (ORCPT ); Wed, 15 Sep 2021 21:03:53 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H8zGM50MFz8yZ6; Thu, 16 Sep 2021 08:58:03 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 16 Sep 2021 09:02:29 +0800 Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Thu, 16 Sep 2021 09:02:28 +0800 Subject: Re: [PATCH v2 2/3] kfence: maximize allocation wait timeout duration To: Marco Elver , CC: , , , , , , , References: <20210421105132.3965998-1-elver@google.com> <20210421105132.3965998-3-elver@google.com> From: Kefeng Wang Message-ID: <6c0d5f40-5067-3a59-65fa-6977b6f70219@huawei.com> Date: Thu, 16 Sep 2021 09:02:27 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20210421105132.3965998-3-elver@google.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/4/21 18:51, Marco Elver wrote: > 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. > [1] 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. > > Signed-off-by: Marco Elver > --- > mm/kfence/core.c | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/mm/kfence/core.c b/mm/kfence/core.c > index 235d726f88bc..9742649f3f88 100644 > --- a/mm/kfence/core.c > +++ b/mm/kfence/core.c > @@ -20,6 +20,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -621,7 +622,16 @@ static void toggle_allocation_gate(struct work_struct *work) > /* 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);