From patchwork Thu Apr 21 19:05:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 12822281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 423A7C433EF for ; Thu, 21 Apr 2022 19:06:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4A896B0074; Thu, 21 Apr 2022 15:06:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD2FD6B0075; Thu, 21 Apr 2022 15:06:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4CEF6B0078; Thu, 21 Apr 2022 15:06:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 8BA106B0074 for ; Thu, 21 Apr 2022 15:06:01 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6254921547 for ; Thu, 21 Apr 2022 19:06:01 +0000 (UTC) X-FDA: 79381816122.09.836E9A5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 661082002F for ; Thu, 21 Apr 2022 19:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650567960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rCckTxEGpZ1EVMsAo2ha3TZ2uY37q9vb0mlqr9I+LWs=; b=ZH5NfegcnpjpOMGJp4ebjVdkrE/BV/BrUJl84y9Zi+CWErCo/hkDItqqsCIGAcxTdAKb1P N2QpgvF5g0VdFMvlspIlqh6Z2Ud3r7pGl9qrIlHSXsucEnT+gS9z0ys9HAgxCInydQ0WGW J4N4C6NSGIV0yEuVOW2AYT4gJyomfEY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-133-RCwAzGfcNrObe1TDu-_vuA-1; Thu, 21 Apr 2022 15:05:53 -0400 X-MC-Unique: RCwAzGfcNrObe1TDu-_vuA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 61D49811E9B; Thu, 21 Apr 2022 19:05:50 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.22.16.253]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04D7EC27E81; Thu, 21 Apr 2022 19:05:48 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Rientjes , Michal Hocko , Andrea Arcangeli Subject: [RFC 3/3] exit: Check for MMF_OOM_SKIP in exit_mmap Date: Thu, 21 Apr 2022 15:05:33 -0400 Message-Id: <20220421190533.1601879-4-npache@redhat.com> In-Reply-To: <20220421190533.1601879-1-npache@redhat.com> References: <20220421190533.1601879-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZH5Nfegc; spf=none (imf13.hostedemail.com: domain of npache@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 4shcqnr14f4tbw34rn5effroq1p7xtjf X-Rspamd-Queue-Id: 661082002F X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1650567958-253752 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 MMF_OOM_SKIP bit is used to indicate weather a mm_struct can not be invalided or has already been invalided. exit_mmap currently calls __oom_reap_task_mm unconditionally despite the fact that the oom reaper may have already called this. Add a check for the MMF_OOM_SKIP bit being set in exit_mmap to avoid unnessary calls to the invalidate code. A slight race can occur on the MMF_OOM_SKIP bit that will still allow this to run twice. My testing has shown an ~66% decrease in double calls to _oom_reap_task_mm. Fixes: 27ae357fa82b ("mm, oom: fix concurrent munlock and oom reaper unmap, v3") Cc: David Rientjes Cc: Michal Hocko Cc: Andrea Arcangeli Signed-off-by: Nico Pache --- mm/mmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mmap.c b/mm/mmap.c index a2968669fd4e..b867f408dacd 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3113,7 +3113,8 @@ void exit_mmap(struct mm_struct *mm) /* mm's last user has gone, and its about to be pulled down */ mmu_notifier_release(mm); - if (unlikely(mm_is_oom_victim(mm))) { + if (unlikely(mm_is_oom_victim(mm)) && + !test_bit(MMF_OOM_SKIP, &mm->flags)) { /* * Manually reap the mm to free as much memory as possible. * Then, as the oom reaper does, set MMF_OOM_SKIP to disregard