Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2400105yba; Thu, 25 Apr 2019 16:04:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqyclNMX0Fb9UGGkPkPFAld38ntvP4DNnrzVYnhTzLKUHapK8IIuEn8/isEd72hpZEb+qQkg X-Received: by 2002:a17:902:2aa8:: with SMTP id j37mr42850059plb.164.1556233499503; Thu, 25 Apr 2019 16:04:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556233499; cv=none; d=google.com; s=arc-20160816; b=ll6+xt0VVZJd1a06WO7dcuZWRFzQWgZ/OjRyJOWiMzK8g1ukwjHpI74oCevHn7XJm7 mRErvh+oFtHvgJr1xZBccYrLbNyajotvn+OIbP+E15rvIs2PA3CCJqtpVJD9/EqrusEn 2ELGQl17yAhPw/8ezNo4DOoBkxEYKYUALYT/mxfBy3IxEVumH/oJ7mi7Ex696MJuIAHS k0NiGqQKOnztSMF9aFvcHoojxAThFCNmWQ28alBfcYPyb/anNB95HBB7M7CmHGBdLAz5 LfPiiRSwWYwP2EOzCpVid/sJodY2JPX6ctBEd87yrsTYAfdv1m/8k/f/AqdTQsMO5S3k 24SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=GEgbleUXiftEFa1b6/nUBQ/7QI0Sg4jIX3OywJ4O6ss=; b=ekT5M/wTlEQQlo6UX+ZdQ/a4+mq3e9JHGVSXrVMtuOmLc6LZGAjLVzoz0mLJJ7G+gs PoPrWURDV4tXYDNSO9HUkTXwluMJT8DLhWMVL2dGknUA7Ecv2v5eZq3YmIWLjrRKfA88 fqV59pvsm1jQmrXK0yE/KHCRY/I1hqHr0H4v1wM4NUg/23yZMaveCC4yhB5jEuIsyhSg 6YKlBjlYkXO844tcMTjPcrVF+2+oPGVuNBzASHfT/yAAn5dHNWctIllrkc2VzUO6cg1B u3qDx3jJr1eU8gzufefVeAD8ljYE7oSihrWz7vL3NgvOKxB1ZVorCF47gBO6hErRnm4S mL/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="tcH6Or/a"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e14si5841132pgm.340.2019.04.25.16.04.39; Thu, 25 Apr 2019 16:04:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="tcH6Or/a"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730799AbfDYV4a (ORCPT + 99 others); Thu, 25 Apr 2019 17:56:30 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46487 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726150AbfDYV4a (ORCPT ); Thu, 25 Apr 2019 17:56:30 -0400 Received: by mail-wr1-f67.google.com with SMTP id t17so1395047wrw.13 for ; Thu, 25 Apr 2019 14:56:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GEgbleUXiftEFa1b6/nUBQ/7QI0Sg4jIX3OywJ4O6ss=; b=tcH6Or/aUj2gN2lZ+ilpm9QvEleYeL5nv+beBZyu5quvO7K0VU1A9U3qLFUEluKpEu Y1Ll+DSw/qgyJFUAUisuVrVxhkvCTOmW4gJeglXkWJggKF62oymkWwR+Ie5uRSFrjUF2 k8Wmel3W9KzeQ5RuK/SWkRgsB3pQaIQzk5lLkiKt0yYu3MmIyMK0PuPN0InqZrsKnfzm RzMxVSdFj48PUqcTlJgGpZupP3AmqzhLHoMmwN9hoB6LUywsovrRZGD2R53ON8S7GRft V+t4nQpJNlvZBhAhgFWaA/9qneaTzyviepc/XTlKG3nrV0j15Rlr0hojFhKsS36Jwl1q Iq6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GEgbleUXiftEFa1b6/nUBQ/7QI0Sg4jIX3OywJ4O6ss=; b=rNQ2cPbGThdRlA5ZCtE5CDXtN4Lt0CB8z2JQl2CbMxRUzTiTWmlgRdoZTPSi+XeZyD eKoUFpiVNsWcdFqAp7kPA9VKIupsL5K9G1sUFWYoeLow/zbu+G7Hb75JM1GXOwJvgfVy QIwlom/kHpMXSSo7iEucWGguU+naBkKjwGb7pHb7Pq8W2948wikPJleFSbERQ++W3RRY xTLE7bqpA2y/tic4yyZwWxCEm0ViNI7q2esJs7a1O4CBevaM31OMSItEX8x9BidOSAjs xb19Sb9iVcWLa8jUO3Zgh54VTBhdUy8fgCiGIS00VFH+WDBTGI2EQ4fwF6yAPPWC3vI1 lhZQ== X-Gm-Message-State: APjAAAW5uibKvSq8tdium+uHY9azZCVLIoACb6EtlN0Y0qGSOV3NBrmT oVn899sYDXh9jJ9DpEbNPmroHqV8gWH4b+uEKd7RHA== X-Received: by 2002:adf:9144:: with SMTP id j62mr29511655wrj.320.1556229387867; Thu, 25 Apr 2019 14:56:27 -0700 (PDT) MIME-Version: 1.0 References: <20190411014353.113252-1-surenb@google.com> <20190411014353.113252-2-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 25 Apr 2019 14:56:16 -0700 Message-ID: Subject: Re: [RFC 1/2] mm: oom: expose expedite_reclaim to use oom_reaper outside of oom_kill.c To: Tetsuo Handa Cc: Andrew Morton , Michal Hocko , David Rientjes , Matthew Wilcox , yuzhoujian@didichuxing.com, Souptick Joarder , Roman Gushchin , Johannes Weiner , "Eric W. Biederman" , Shakeel Butt , Christian Brauner , Minchan Kim , Tim Murray , Daniel Colascione , Joel Fernandes , Jann Horn , linux-mm , lsf-pc@lists.linux-foundation.org, LKML , kernel-team Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 25, 2019 at 2:13 PM Tetsuo Handa wrote: > > On 2019/04/11 10:43, Suren Baghdasaryan wrote: > > diff --git a/mm/oom_kill.c b/mm/oom_kill.c > > index 3a2484884cfd..6449710c8a06 100644 > > --- a/mm/oom_kill.c > > +++ b/mm/oom_kill.c > > @@ -1102,6 +1102,21 @@ bool out_of_memory(struct oom_control *oc) > > return !!oc->chosen; > > } > > > > +bool expedite_reclaim(struct task_struct *task) > > +{ > > + bool res = false; > > + > > + task_lock(task); > > + if (task_will_free_mem(task)) { > > mark_oom_victim() needs to be called under oom_lock mutex after > checking that oom_killer_disabled == false. Since you are trying > to trigger this function from signal handler, you might want to > defer until e.g. WQ context. Thanks for the tip! I'll take this into account in the new design. Just thinking out loud... AFAIU oom_lock is there to protect against multiple concurrent out_of_memory calls from different contexts and prevent overly-aggressive process killing. For my purposes when reaping memory of a killed process we don't have this concern (we did not initiate the killing, SIGKILL was explicitly requested). I'll probably need some synchronization there but not for purposes of preventing multiple concurrent reapers. In any case, thank you for the feedback! > > > + mark_oom_victim(task); > > + wake_oom_reaper(task); > > + res = true; > > + } > > + task_unlock(task); > > + > > + return res; > > +} > > + > > /* > > * The pagefault handler calls here because it is out of memory, so kill a > > * memory-hogging task. If oom_lock is held by somebody else, a parallel oom > >