From patchwork Mon Sep 10 12:55:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 10594121 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD797920 for ; Mon, 10 Sep 2018 12:56:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E6F228DA5 for ; Mon, 10 Sep 2018 12:56:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 930A128F76; Mon, 10 Sep 2018 12:56:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD3EB28DA5 for ; Mon, 10 Sep 2018 12:56:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CF938E0005; Mon, 10 Sep 2018 08:55:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 758258E0006; Mon, 10 Sep 2018 08:55:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 644558E0005; Mon, 10 Sep 2018 08:55:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 08CDC8E0006 for ; Mon, 10 Sep 2018 08:55:57 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id 57-v6so7210559edt.15 for ; Mon, 10 Sep 2018 05:55:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=I0hR/0E0KYQL2e73jyWIU2Glnbsw6oNe9h3qdbaIIfA=; b=dQQv0URcsw6vNRY1H6XMHTu9gaHSFeV1XKpSJRzXrmqm+dGZQHQU8fLle1IKdPlZVB UnXljeM9v3351yMCDSWcQMrguJMZWOylQhBksyFR0rdMt+yowszVh0Gmy6CKWD9WNuyd 1N2cNEDFHe/iilQ2nlDYir3ybLbl0VfESP/3QotyOxyGxfzehO7jx8Np4Jy/QJKvH1Zj tL5TNzZl7OCQQO4YYO0Fm5M6lm858cizMEP1Pf1v8cBAP3QrcLodNessgyzH/1ExWolE djyEDCRICLIQazDTBRvLZe3nmHH3Li4lAyq7p2yjlBPDQqafXQ3lCALGY2C1i3nMO2Rh FCqA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Gm-Message-State: APzg51Df99hU2jlcvz7GQbL/P5F4HgcLvJrLM39kMWPTxDtZOnsovXqy GfW9sja0JGpPHb/AErAk0a23nToaqBur0t7NPV+8so5KT1T1PnEog+uZnIVPx+mfIr2gSfuGLaV jOXyd+rjgatoeCGBYhXJWhCsbTt67ADeiJZjBMME4OtaVkdW8vtSByGORoUXJn+QXU8//wZp3f6 YdbF4IvuS2F6R2UqUNvGdTl1Ofh9NrHvVN0/GDI/npQMYX+XJLNf6SADrk6XvmbyoHoizPSHhFV 0dfKsGzEItZmoixV5M0djTnzTaIX9RTeX/ulGhAx9tb5QSli6mzzoDl1DWzIVqwC2FxTim9HJFl 5OQ0rduod8GkoZcy+f1/mGWUknYqaFFKTSl1XeELSMLCFfzvwF9qIG9QTcMeCp93TIGZOKWmLQ= = X-Received: by 2002:a50:a7e2:: with SMTP id i89-v6mr22262204edc.176.1536584156524; Mon, 10 Sep 2018 05:55:56 -0700 (PDT) X-Received: by 2002:a50:a7e2:: with SMTP id i89-v6mr22262134edc.176.1536584155506; Mon, 10 Sep 2018 05:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536584155; cv=none; d=google.com; s=arc-20160816; b=e6VjVvGOxm4N6mu17BXrVGdgf4BUKjoKmdTFFehyMVCazqnym9de7UrAd/WYzp4GBX olXs2d3IFaTUJnYZToBj1rFUg4CiEdCGh79c7VPC4WEevaDg88XFcqd2YjEV6HbqFF1L 8d3+5/aqu9yECOnq9O199bvicXi50wqHHlIKFCQ7AbqJRh0tpaNAJ6gbikmTOjD1JR4z 27W0NlprkmiaZvhRLSYirvIY3GoSGZ0XFMwJJWz+NBf+J5QiY6WBx8HgXvZ/OvvPne6v tZtEMARrBWphqG/xtP/G7tdBNC4pjt/ro/PEOcubHSGUiwwWKbC5cPRkwqcyATu8Ba8l CD1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=I0hR/0E0KYQL2e73jyWIU2Glnbsw6oNe9h3qdbaIIfA=; b=YXwQ8m4QryH6gzsLYL0Ges4BfIFw4WxI6smEK+izPlX2b/HAYL49NjdsLiYGZNtUuL 6cZikqQUWcpjfDsxEA0CdmiVW/+BgE+y3RGjOOxe/FfjEzdCQm78Kw7i6Sj4Dkh5VBor 1hRxv94XMgdpOPPY+w2xOZj2LRAvIFxHtVVhRPd6+RU4GXskuI40Z3tROZoeUNvboHw4 +2y4UAhClGQYdCIGMaWa/jXR+MS5KKRDoCvpNy/0ORhFl6v3JyMUk9zvIKfQnUSHcvH6 8Tn6oNt/yC8XtFdRtlpQRTbyahu+5pQYbx2BtfuYa4XV32yfjXKaj3QXqH0H+CzlgZkc PsSw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id y50-v6sor14275219edd.15.2018.09.10.05.55.55 for (Google Transport Security); Mon, 10 Sep 2018 05:55:55 -0700 (PDT) Received-SPF: pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Google-Smtp-Source: ANB0VdYLO6V8MsOferz/ypt0MZy1lkHcjKSqBTcU7CNWkFCmLGOL9XERUNi7LrBWcnf7QbTUVEkloQ== X-Received: by 2002:a05:6402:1652:: with SMTP id s18mr23342837edx.35.1536584154940; Mon, 10 Sep 2018 05:55:54 -0700 (PDT) Received: from tiehlicka.suse.cz (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id h40-v6sm8632245edh.88.2018.09.10.05.55.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Sep 2018 05:55:54 -0700 (PDT) From: Michal Hocko To: Cc: Tetsuo Handa , Roman Gushchin , Andrew Morton , Michal Hocko Subject: [RFC PATCH 2/3] mm, oom: keep retrying the oom_reap operation as long as there is substantial memory left Date: Mon, 10 Sep 2018 14:55:12 +0200 Message-Id: <20180910125513.311-3-mhocko@kernel.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180910125513.311-1-mhocko@kernel.org> References: <1536382452-3443-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> <20180910125513.311-1-mhocko@kernel.org> 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: X-Virus-Scanned: ClamAV using ClamSMTP From: Michal Hocko oom_reaper is not able to reap all types of memory. E.g. mlocked mappings or page tables. In some cases this might be a lot of memory and we do rely on exit_mmap to release that memory. Yet we cannot rely on exit_mmap to set MMF_OOM_SKIP right now because there are several places when sleeping locks are taken. This patch adds a simple heuristic to check for the amount of memory the mm is sitting on after oom_reaper is done with it. If this is still few megabytes (this is a subject for further tunning based on real world usecases) then simply keep retrying oom_reap_task_mm. Signed-off-by: Michal Hocko --- mm/oom_kill.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index f10aa5360616..049e67dc039b 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -189,6 +189,16 @@ static bool is_dump_unreclaim_slabs(void) return (global_node_page_state(NR_SLAB_UNRECLAIMABLE) > nr_lru); } +/* + * Rough memory consumption of the given mm which should be theoretically freed + * when the mm is removed. + */ +static unsigned long oom_badness_pages(struct mm_struct *mm) +{ + return get_mm_rss(mm) + get_mm_counter(mm, MM_SWAPENTS) + + mm_pgtables_bytes(mm) / PAGE_SIZE; +} + /** * oom_badness - heuristic function to determine which candidate task to kill * @p: task struct of which task we should calculate @@ -230,8 +240,7 @@ unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *memcg, * The baseline for the badness score is the proportion of RAM that each * task's rss, pagetable and swap space use. */ - points = get_mm_rss(p->mm) + get_mm_counter(p->mm, MM_SWAPENTS) + - mm_pgtables_bytes(p->mm) / PAGE_SIZE; + points = oom_badness_pages(p->mm); task_unlock(p); /* Normalize to oom_score_adj units */ @@ -532,6 +541,16 @@ bool __oom_reap_task_mm(struct mm_struct *mm) } } + /* + * If we still sit on a noticeable amount of memory even after successfully + * reaping the address space then keep retrying until exit_mmap makes some + * further progress. + * TODO: add a flag for a stage when the exit path doesn't block anymore + * and hand over MMF_OOM_SKIP handling there in that case + */ + if (ret && oom_badness_pages(mm) > 1024) + ret = false; + return ret; }