From patchwork Tue Sep 21 16:57:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sultan Alsawaf (unemployed)" X-Patchwork-Id: 12508371 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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 841E7C433EF for ; Tue, 21 Sep 2021 16:58:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 16BF861183 for ; Tue, 21 Sep 2021 16:58:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 16BF861183 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kerneltoast.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7AD03900003; Tue, 21 Sep 2021 12:58:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 75C3B900002; Tue, 21 Sep 2021 12:58:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64B49900003; Tue, 21 Sep 2021 12:58:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id 58987900002 for ; Tue, 21 Sep 2021 12:58:41 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EF5E718019B06 for ; Tue, 21 Sep 2021 16:58:40 +0000 (UTC) X-FDA: 78612189600.18.200ACCA Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf19.hostedemail.com (Postfix) with ESMTP id 8FCDDB0000AD for ; Tue, 21 Sep 2021 16:58:40 +0000 (UTC) Received: by mail-pf1-f181.google.com with SMTP id w14so79836pfu.2 for ; Tue, 21 Sep 2021 09:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UKEwcbJEyUP0PqyzuU1jDgKq63XLBjLh4Ta6kc0XTvE=; b=PUqZB0dLwluGdzZQ4zV6cjuxUbh0c2kg+B3SeVT/lrJ1XbYCAhKV1VZtrAdLXONOxW nUcSGGIpjRpDvyVsZZDn4irjNUynHXB4c3UNObGKO95LknN+ZmW45CfUsc06Dm6+//kM OWnstcShvsSnaXvXOzSiKaw+XfhxnsKo9DnQp8+THp5oY8z0AvLBMgqUGGUmxikPJ69C DpdA591UCBC4s6bvd6HNkrHdzcReEk3jeJR5Jw91cBAwjpDMGjikq93/DJ3pLoQiCj9o fGpIbX+H1/o9R0yhAIyIiW15ycbzc5feAFJXQOfLzeQg0UorYhHbmKOz5f51Vt5HoYAg JQlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=UKEwcbJEyUP0PqyzuU1jDgKq63XLBjLh4Ta6kc0XTvE=; b=HuZ6H1urvO0JB0JXrCa0oiYbv0h8LeZJIX6gvuMFK2zvYEvyD5O+tKdtQ/UacQOx8l rKIFPKrbOWiohU5Ss+BSTmNajOYkA3cTABKD8nFtxmcnjLHYE/Ee8Cm0ZFMWmP8DwBfv AN3fSVz+oJ50mG7AzjLbxyiRNoF4HsDa/Fowgr+CPRBd0W4OaXW106vMe/N1IWr0qPk6 72pG8IWidVwsS6IKiCOmDeT6q9Zk8KyqmUD/HCw3T8ugI2IrJm9fl0h9i8hew995GJNN fcMIVK1bixp7nkbuCgy+oaJUOyHaZTLRqr9jG04w9FE15W7281+DV9+DlQ0xLiOZazsl cRZw== X-Gm-Message-State: AOAM533lAxCij0TKCDY+nwpjxzHNPKQKf3sneb0jIZswB9QShf40qthe enm/RFIwbu6WzjlBevovST4= X-Google-Smtp-Source: ABdhPJz6Y8VTto6N/f8XpSs196/Bx/hN5/wj5eYVotLR+BYvB69rKLFBGf/tchVE93j8JiRzHpHVCQ== X-Received: by 2002:aa7:97b2:0:b0:439:14a9:2bf5 with SMTP id d18-20020aa797b2000000b0043914a92bf5mr31535117pfq.45.1632243519433; Tue, 21 Sep 2021 09:58:39 -0700 (PDT) Received: from sultan-box.localdomain ([204.152.215.247]) by smtp.gmail.com with ESMTPSA id h6sm18237584pfr.121.2021.09.21.09.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 09:58:39 -0700 (PDT) From: Sultan Alsawaf X-Google-Original-From: Sultan Alsawaf To: sultan@kerneltoast.com Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mgorman@suse.de, mhocko@suse.com, rientjes@google.com Subject: [PATCH v2] mm: Mark the OOM reaper thread as freezable Date: Tue, 21 Sep 2021 09:57:58 -0700 Message-Id: <20210921165758.6154-1-sultan@kerneltoast.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210918233920.9174-1-sultan@kerneltoast.com> References: <20210918233920.9174-1-sultan@kerneltoast.com> MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8FCDDB0000AD X-Stat-Signature: 3hjdhqcfhrh95c63k7m7o3w4kjqkz8zn Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PUqZB0dL; spf=none (imf19.hostedemail.com: domain of mail-pf1-f181.google.com has no SPF policy when checking 209.85.210.181) smtp.helo=mail-pf1-f181.google.com; dmarc=none X-HE-Tag: 1632243520-572676 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000025, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Sultan Alsawaf The OOM reaper alters user address space which might theoretically alter the snapshot if reaping is allowed to happen after the freezer quiescent state. To this end, the reaper kthread uses wait_event_freezable() while waiting for any work so that it cannot run while the system freezes. However, the current implementation doesn't respect the freezer because all kernel threads are created with the PF_NOFREEZE flag, so they are automatically excluded from freezing operations. This means that the OOM reaper can race with system snapshotting if it has work to do while the system is being frozen. Fix this by adding a set_freezable() call which will clear the PF_NOFREEZE flag and thus make the OOM reaper visible to the freezer. Please note that the OOM reaper altering the snapshot this way is mostly a theoretical concern and has not been observed in practice. Fixes: aac453635549 ("mm, oom: introduce oom reaper") Signed-off-by: Sultan Alsawaf Acked-by: Michal Hocko --- mm/oom_kill.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 831340e7ad8b..46a742b57735 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -641,6 +641,8 @@ static void oom_reap_task(struct task_struct *tsk) static int oom_reaper(void *unused) { + set_freezable(); + while (true) { struct task_struct *tsk = NULL;