From patchwork Mon Apr 19 08:50:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12211217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 605E8C433ED for ; Mon, 19 Apr 2021 08:51:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 022D461107 for ; Mon, 19 Apr 2021 08:51:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 022D461107 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8C3636B0070; Mon, 19 Apr 2021 04:51:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89B6B6B0071; Mon, 19 Apr 2021 04:51:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 714846B0072; Mon, 19 Apr 2021 04:51:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id 58EBE6B0070 for ; Mon, 19 Apr 2021 04:51:00 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1D609180AD830 for ; Mon, 19 Apr 2021 08:51:00 +0000 (UTC) X-FDA: 78048496680.37.ED409D4 Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf02.hostedemail.com (Postfix) with ESMTP id AD0BA40002CF for ; Mon, 19 Apr 2021 08:50:38 +0000 (UTC) Received: by mail-qt1-f201.google.com with SMTP id z5-20020a05622a0285b02901b943be06b5so496527qtw.17 for ; Mon, 19 Apr 2021 01:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=1R4Jr4Y0fNVqtFmGdn7fmPgc472QE3HJBlQ1cDdhzt4=; b=TMBkauBIAfAP9XjeDFGJnDsoFke73tSPJe4f2mEkud+WWPz6Mmq/1Nmg9lVrWBd39+ wVZW66TOGiC/4Ki0pXPQjVxoAR3nGwKHALc1Ct9l34Kt0v1OvcKspHmEYuiTNhUHlDoc GdRPD0UYmpqr3hdeh3FftJau7nFiZGQrtf6jjq7py7gEI0eNQZCPn4wYZcki74Z99Jqu I2rECNJ42gZOOteD2/QXjDdO2WkkqubnFqYsY3bVuIb8W90FgIa4Pxxd5Bue+mLBI+yq JAaaAr30YToUOB+CPUGwKJ9GaqomjYg3czrf7Zu+35YAkKMEoWrKlDLTIVYnKeDKZQPK sgWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1R4Jr4Y0fNVqtFmGdn7fmPgc472QE3HJBlQ1cDdhzt4=; b=JuRj/OLa0C3Cs0LiXWLXjVUUo+qCcG4AcAXGZnNyV6ehKJ6SBYAmQoUamC//g/mqCD G5fP9r4zBt7z5VuGJr7cFF+xt7l5uOLUE93FkQyiPWLc61SZc9LixS+FLejyFb0VG6lw oZ94au3bk+n44AT4wgB78kKKm5sROsieyWy9nwiWL3gufshd0q1Ey3k8R+/5VxgJHJ2H mk8mH0h+Kwp3w88LAZV3CJWaAm1Qovsodq3/S4LdTF81h8tmdo221wWrS7piygQRU2sC oE4qExWfTJ9WnSTj2JzOvWk+dj2aztDGzDY+DYRNg0bIhyMFY/pCrXkThbaFdi8LFHnG LsRQ== X-Gm-Message-State: AOAM532nb+/vRJTMCiTq4QasGVA2hNlSpGNeJRkZXdi40jNhEgcnUUwH 2AbYu3sgSxZvJOOcYs1hZV+yxM5PiA== X-Google-Smtp-Source: ABdhPJyfu1Y3YRhkFKwn8cRYHRc0nLt0o6kvgfbB8Wf5OVUUnfByumSzTxb1FCZL47h5AmiWMHIJhPJIaA== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:92f8:c03b:1448:ada5]) (user=elver job=sendgmr) by 2002:a0c:a98d:: with SMTP id a13mr4682439qvb.39.1618822258947; Mon, 19 Apr 2021 01:50:58 -0700 (PDT) Date: Mon, 19 Apr 2021 10:50:26 +0200 In-Reply-To: <20210419085027.761150-1-elver@google.com> Message-Id: <20210419085027.761150-3-elver@google.com> Mime-Version: 1.0 References: <20210419085027.761150-1-elver@google.com> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog Subject: [PATCH 2/3] kfence: maximize allocation wait timeout duration From: Marco Elver To: elver@google.com, akpm@linux-foundation.org Cc: glider@google.com, dvyukov@google.com, jannh@google.com, mark.rutland@arm.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: AD0BA40002CF X-Stat-Signature: on3wdgcdboieex743qohet717597ttwu Received-SPF: none (flex--elver.bounces.google.com>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from="<3ckR9YAUKCPkfmwfshpphmf.dpnmjovy-nnlwbdl.psh@flex--elver.bounces.google.com>"; helo=mail-qt1-f201.google.com; client-ip=209.85.160.201 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618822238-819152 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 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 5f0a56041549..73e7b621fb36 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -626,7 +627,16 @@ static void toggle_allocation_gate(struct work_struct *work) WRITE_ONCE(kfence_timer_waiting, true); smp_mb(); /* See comment in __kfence_alloc(). */ - 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)); + } smp_store_release(&kfence_timer_waiting, false); /* Order after wait_event(). */ /* Disable static key and reset timer. */