From patchwork Mon Apr 19 08:50:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12211213 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=-21.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, 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 2391DC433ED for ; Mon, 19 Apr 2021 08:50:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A711161151 for ; Mon, 19 Apr 2021 08:50:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A711161151 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 36AE76B0036; Mon, 19 Apr 2021 04:50:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 342046B006E; Mon, 19 Apr 2021 04:50:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E2F36B0070; Mon, 19 Apr 2021 04:50:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0211.hostedemail.com [216.40.44.211]) by kanga.kvack.org (Postfix) with ESMTP id 034076B0036 for ; Mon, 19 Apr 2021 04:50:55 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B922D365B for ; Mon, 19 Apr 2021 08:50:55 +0000 (UTC) X-FDA: 78048496470.15.F576DB9 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf13.hostedemail.com (Postfix) with ESMTP id 934F4E000104 for ; Mon, 19 Apr 2021 08:50:51 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id s9-20020a5d51090000b02901028ea30da6so8658933wrt.7 for ; Mon, 19 Apr 2021 01:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=VPfpXo1xSfALIUwFMBsi0FLx47EowiBPs3NWCkZXP+I=; b=Jqi15edE3SoTSO3W1bED5dPhh8cADbtvGhZha1HrraZ80eH2qjlIOJBqaJj/JkvKmL YCIJixwtWtrf770zGOp/yQ0YrvYivmLrJC/WRSTBVeSK++b+eRiZCWXBfqDOn5/p0ixW UEf5OSbnYh1ElUgdYkxnaDNfCkDhjPKpMEToSRzi4QRIsDZrGE+uuNGGnX3rBKVztOmd 65swUex2nYBf4E+chFavTDh3H2ERQzmFpmnp9HSe7S7KecrlYAyGyPIzBwE4PyErohTK Km+DG1v3TaNQxLITTfnUheK1jhjFk7L71YYphPnPKQdRSmn/Ta2P9v/mwtsnm+XgrR/R YYjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=VPfpXo1xSfALIUwFMBsi0FLx47EowiBPs3NWCkZXP+I=; b=BKCq7wQGYVeK3iCkUR8xhH+1lMug+XCeKBQQBo5aq3OHFDPdPdWTXqY9UdYHxb4Xj6 xD0zqZ6D1Mv+9mQf17uKB2spKB2cFjc66nTbDsVcvUZ91Dwrm2INhKl2Rqr3FpxMo7i2 vZODEz+yN0YMr1dm2BjgXaoEDVB7Qwtkgd4KXEyrGxUp9YGY6ZlOxe1OUc0NO/DO9b1N l76+bGCyesUWHUAz3GbsYqn4Px5/ITQaEv91cz3woc2Hf74hZs8mXYVSwDlJz3AD7wRK Gku+iJfBTPpou9GTuTFOa1v4MkrIuIpiUdxeVgB2QYrwyNIELkvXcCvNysx31AAtdn3V ymow== X-Gm-Message-State: AOAM532oZsmHFshqTbqUSZ1BnhpsA6v6wYhMsANOfpV7a0RzcK242Kfg 9od72Kf2CxJ6XAc5HJ/VRCNcgo+0WA== X-Google-Smtp-Source: ABdhPJwMgNBllV0CEdQPMGVfV0l0dDonTuTqSZkXzVJzL0IzpvF142CXs3Jp2+0muGVESO0nLgxZ/W3j8A== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:92f8:c03b:1448:ada5]) (user=elver job=sendgmr) by 2002:a05:600c:ac2:: with SMTP id c2mr21244847wmr.23.1618822253817; Mon, 19 Apr 2021 01:50:53 -0700 (PDT) Date: Mon, 19 Apr 2021 10:50:24 +0200 Message-Id: <20210419085027.761150-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog Subject: [PATCH 0/3] kfence: optimize timer scheduling 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-Queue-Id: 934F4E000104 X-Stat-Signature: cyxabednfy9gb6ccgwkpseb3qryaycgp X-Rspamd-Server: rspam02 Received-SPF: none (flex--elver.bounces.google.com>: No applicable sender policy available) receiver=imf13; identity=mailfrom; envelope-from="<3bUR9YAUKCPQahranckkcha.Ykihejqt-iigrWYg.knc@flex--elver.bounces.google.com>"; helo=mail-wr1-f74.google.com; client-ip=209.85.221.74 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1618822251-535634 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: We have observed that mostly-idle systems with KFENCE enabled wake up otherwise idle CPUs, preventing such to enter a lower power state. Debugging revealed that KFENCE spends too much active time in toggle_allocation_gate(). While the first version of KFENCE was using all the right bits to be scheduling optimal, and thus power efficient, by simply using wait_event() + wake_up(), that code was unfortunately removed. As KFENCE was exposed to various different configs and tests, the scheduling optimal code slowly disappeared. First because of hung task warnings, and finally because of deadlocks when an allocation is made by timer code with debug objects enabled. Clearly, the "fixes" were not too friendly for devices that want to be power efficient. Therefore, let's try a little harder to fix the hung task and deadlock problems that we have with wait_event() + wake_up(), while remaining as scheduling friendly and power efficient as possible. Crucially, we need to defer the wake_up() to an irq_work, avoiding any potential for deadlock. The result with this series is that on the devices where we observed a power regression, power usage returns back to baseline levels. Marco Elver (3): kfence: await for allocation using wait_event kfence: maximize allocation wait timeout duration kfence: use power-efficient work queue to run delayed work lib/Kconfig.kfence | 1 + mm/kfence/core.c | 71 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 17 deletions(-)