From patchwork Thu Jul 1 12:54:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 12354093 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.6 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,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 29FCBC11F64 for ; Thu, 1 Jul 2021 12:54:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 94FDE61400 for ; Thu, 1 Jul 2021 12:54:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 94FDE61400 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B8E928D02A1; Thu, 1 Jul 2021 08:54:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B3E838D0001; Thu, 1 Jul 2021 08:54:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B7CE8D02A1; Thu, 1 Jul 2021 08:54:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0166.hostedemail.com [216.40.44.166]) by kanga.kvack.org (Postfix) with ESMTP id 74FBF8D0001 for ; Thu, 1 Jul 2021 08:54:39 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 222FD18041CF1 for ; Thu, 1 Jul 2021 12:54:39 +0000 (UTC) X-FDA: 78314013078.31.C01021F Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) by imf27.hostedemail.com (Postfix) with ESMTP id D5D69700009D for ; Thu, 1 Jul 2021 12:54:38 +0000 (UTC) Received: by mail-ot1-f54.google.com with SMTP id 59-20020a9d0ac10000b0290462f0ab0800so6355214otq.11 for ; Thu, 01 Jul 2021 05:54:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ki9YLtCfQTGb7pej90Hp/SMduHeqHAJeUuadkg/p5L4=; b=s3n2fzzLNhl+Pbqbh0ngHQxfy01ZkHQnyaNLJo/HLUru6FGx7hXzu5+0i6mGL3vC6W EwaWvSOTW1bWmFrQK9GJmJC5mK8qKGpKd82bplpKhjurGUXTkTBra2zy7YoyTvxXsMdT +vvV6gIWlzzUwesN4RkmVIqgSU2V0IQNeO4KXjzepNERqmPxiJH13oHglCFb96ZOf5fT GgAuwr7EW4CwHnjS4P+cRufJrS1N+tSoh6VVCgXrS/7BGiFsEwfrLINC9XcnJtJm0un8 cff+FG44MBUhSi0Oo6vY8VMyLRFttxXbDGANQGabvqPPfnO54krYawYQYitBDnQn45yn oO0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=ki9YLtCfQTGb7pej90Hp/SMduHeqHAJeUuadkg/p5L4=; b=uJnzN9DlJwCCoPpNrDzDnJl2LDDWwewsN5dbyUxjsAO1qloZi/3gfjTpI0h3ATHCvf 4EeH4w2zwWVRl5nnL+UDN2HKH3kbemBJzrL7T4M5jpnGmmpaAk29ZK25NRnByg/gHAJl 4Tyk9KE8bUa4+STku6HkvoS8uYn1G+M2dECcY32Rz98cEGxAMUy/lt8RfaEEC3NC8A2a b44PczEqqFERTq70tR7pyoSapSPZGwvREQXJ/lM5W2UzVcnDbIOZE8pxFQAy0A/JabyF mDMPYaH4nLV7j+JLIDtMVYQ1/h7z0C1zOQTmmK0z+iydg7IpvZgwlr/YFZSV0csdaI0/ 8f5w== X-Gm-Message-State: AOAM530Nc3MxnpibPgFe2NkuNqtGEQvRgfv2xFrFjHYuO8kQCrlU4hJY rVU4euBrsoyEAWsvRUdsVMmTtO0bbQ== X-Google-Smtp-Source: ABdhPJxl+F7Gc0AYbf9HXcFQqyvOQetib16gmTVy73GLRr7aAkyPgpcvNKBJyVggtX7F7LKjaF/Qnw== X-Received: by 2002:a9d:4c08:: with SMTP id l8mr3538972otf.149.1625144077782; Thu, 01 Jul 2021 05:54:37 -0700 (PDT) Received: from serve.minyard.net ([47.184.156.158]) by smtp.gmail.com with ESMTPSA id q203sm3631578oig.1.2021.07.01.05.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 05:54:36 -0700 (PDT) Received: from t560.minyard.net (unknown [IPv6:2001:470:b8f6:1b:2948:9e00:9282:8e98]) by serve.minyard.net (Postfix) with ESMTPA id 6E05718010F; Thu, 1 Jul 2021 12:54:35 +0000 (UTC) From: minyard@acm.org To: Andrew Morton , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Corey Minyard Subject: [PATCH] oom_kill: oom_score_adj broken for processes with small memory usage Date: Thu, 1 Jul 2021 07:54:30 -0500 Message-Id: <20210701125430.836308-1-minyard@acm.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=s3n2fzzL; spf=pass (imf27.hostedemail.com: domain of tcminyard@gmail.com designates 209.85.210.54 as permitted sender) smtp.mailfrom=tcminyard@gmail.com; dmarc=none X-Stat-Signature: egr94o5o9yzq35fpn8wow5o8etifkuti X-Rspamd-Queue-Id: D5D69700009D X-Rspamd-Server: rspam06 X-HE-Tag: 1625144078-960903 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: From: Corey Minyard If you have a process with less than 1000 totalpages, the calculation: adj = (long)p->signal->oom_score_adj; ... adj *= totalpages / 1000; will always result in adj being zero no matter what oom_score_adj is, which could result in the wrong process being picked for killing. Fix by adding 1000 to totalpages before dividing. Signed-off-by: Corey Minyard --- I ran across this trying to diagnose another problem where I set up a cgroup with a small amount of memory and couldn't get a test program to work right. I'm not sure this is quite right, to keep closer to the current behavior you could do: if (totalpages >= 1000) adj *= totalpages / 1000; but that would map 0-1999 to the same value. But this at least shows the issue. I can provide a test program the shows the issue, but I think it's pretty obvious from the code. mm/oom_kill.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index eefd3f5fde46..4ae0b6193bcd 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -233,8 +233,11 @@ long oom_badness(struct task_struct *p, unsigned long totalpages) mm_pgtables_bytes(p->mm) / PAGE_SIZE; task_unlock(p); - /* Normalize to oom_score_adj units */ - adj *= totalpages / 1000; + /* + * Normalize to oom_score_adj units. You should never + * multiply by zero here, or oom_score_adj will not work. + */ + adj *= (totalpages + 1000) / 1000; points += adj; return points;