From patchwork Tue Nov 24 05:39:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 11927179 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=-11.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 46337C6379D for ; Tue, 24 Nov 2020 05:39:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8DEA32085B for ; Tue, 24 Nov 2020 05:39:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="XzkAfhjQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8DEA32085B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B93816B005D; Tue, 24 Nov 2020 00:39:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B451D6B0070; Tue, 24 Nov 2020 00:39:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5ADB6B0071; Tue, 24 Nov 2020 00:39:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 77AF76B005D for ; Tue, 24 Nov 2020 00:39:50 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 18CA7181AEF1F for ; Tue, 24 Nov 2020 05:39:50 +0000 (UTC) X-FDA: 77518210140.23.roll84_4c06be82736b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id F1A6D37604 for ; Tue, 24 Nov 2020 05:39:49 +0000 (UTC) X-HE-Tag: roll84_4c06be82736b X-Filterd-Recvd-Size: 5129 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Tue, 24 Nov 2020 05:39:49 +0000 (UTC) Received: by mail-pf1-f202.google.com with SMTP id q199so14802157pfc.21 for ; Mon, 23 Nov 2020 21:39:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=mKYwXoA6RKca8Gj0Xk1sTxg7l//t2h1MecKeF/NRkRI=; b=XzkAfhjQjZIxPRVXwpA+vCIjhw5D1ZiRcns0Bc6KRsXecXgR6WE+UjIk/QsFUxgPEv qFKR0peCFZBJldWweVU8+NHwexec5RFx46+wmvFf4HLH41eapps4tWM0Ndu1aUb80c1+ f5F6vLMfiDNxvAGfNSHYhn0vYmugKGHMnu8Ci8BIg1rDBsjxyH+CP+TmHcfJeYPymk5Q VCdIdtQichiTfQZst27cI85qMCj+GfANdP4VXQzBYQgxNHYX0qHFgwlYP7iRvEKtIZee yq0E5T1hQViO5kTU99IzxrrXTJxW++wms0tQQbOhW03Fb/jDJQXNZrbbFPvsufuvvhOt ZnNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=mKYwXoA6RKca8Gj0Xk1sTxg7l//t2h1MecKeF/NRkRI=; b=Pt2SsIrMBSr8c2AfIA02Gp4a/WkjmY1RrFqNEaGZWrLyhf6NHYbEouC/jYpppP+U00 7qK2Uk5b/dUfehINWwuahqBlYMMYKOjR2cDhFkaFiJvqUlTu7bgJ1al/SoFuRxX90c6Q 3qDSlVea0d10csoNjUkss4AwscY8hHrq8B1ldqcfyxZWmLwnQSbQ0Uc3xehatuzolq9o A7GhWRMyX1JcjKkvxK951Qb6Xo/L0nXVZzl1RReubjKld03IPhpVIHtDuO2nfVFjFH1I raqj9ltRFoEgTscDRZ89VcemCL0F6/JgfW6ahk25OeJREIcx5z4F9In2xXdJp9ti0elD nm8A== X-Gm-Message-State: AOAM531WKqytPhXmaeeF7xdQBm20BrsmxNEG6KyRqVK5JhivERrGDjjs mIp4gMto7w5GVIQvs1GsRiESlpVRxys= X-Google-Smtp-Source: ABdhPJyBKvuaa4qpP38cFI9DjLi4nvNVC7tUSSFiYtk5IXXU0B/4MP5WiMXgroEOAmEtsn8LYawAQWNVU3Y= X-Received: from surenb1.mtv.corp.google.com ([2620:15c:211:200:f693:9fff:fef4:2055]) (user=surenb job=sendgmr) by 2002:aa7:978d:0:b029:197:fd52:ee48 with SMTP id o13-20020aa7978d0000b0290197fd52ee48mr2613356pfp.13.1606196388178; Mon, 23 Nov 2020 21:39:48 -0800 (PST) Date: Mon, 23 Nov 2020 21:39:41 -0800 Message-Id: <20201124053943.1684874-1-surenb@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH 0/2] userspace memory reaping using process_madvise From: Suren Baghdasaryan To: surenb@google.com Cc: akpm@linux-foundation.org, mhocko@kernel.org, mhocko@suse.com, rientjes@google.com, willy@infradead.org, hannes@cmpxchg.org, guro@fb.com, riel@surriel.com, minchan@kernel.org, christian@brauner.io, oleg@redhat.com, timmurray@google.com, linux-api@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@android.com 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: When a process is being killed it might be in an uninterruptible sleep which leads to an unpredictable delay in its memory reclaim. In low memory situations, when it's important to free up memory quickly, such delay is problematic. Kernel solves this problem with oom-reaper thread which performs memory reclaim even when the victim process is not runnable. Userspace currently lacks such mechanisms and the need and potential solutions were discussed before (see links below). This patchset provides a mechanism to perform memory reclaim of an external process using process_madvise(MADV_DONTNEED). The chosen mechanism is the result of the latest discussion at [4]. The first patch adds PMADV_FLAG_RANGE flag for process_madvise to operate on large address ranges spanning multiple VMAs. Currently it supports only the entire memory of a process. This is done to keep things simple and since it's the only real usecase we currently know of. In the future this can be developed further to support other large ranges. One way to do that is suggested in [5]. The second patch enables MADV_DONTNEED behavior for process_madvise to perform memory reclaim of an external process. 1. https://patchwork.kernel.org/cover/10894999 2. https://lwn.net/Articles/787217 3. https://lore.kernel.org/linux-api/CAJuCfpGz1kPM3G1gZH+09Z7aoWKg05QSAMMisJ7H5MdmRrRhNQ@mail.gmail.com 4. https://lkml.org/lkml/2020/11/13/849 5. https://lkml.org/lkml/2020/11/18/1076 Suren Baghdasaryan (2): mm/madvise: allow process_madvise operations on entire memory range mm/madvise: add process_madvise MADV_DONTNEER support arch/alpha/include/uapi/asm/mman.h | 4 + arch/mips/include/uapi/asm/mman.h | 4 + arch/parisc/include/uapi/asm/mman.h | 4 + arch/xtensa/include/uapi/asm/mman.h | 4 + fs/io_uring.c | 2 +- include/linux/mm.h | 3 +- include/uapi/asm-generic/mman-common.h | 4 + mm/madvise.c | 81 ++++++++++++++++++-- tools/include/uapi/asm-generic/mman-common.h | 4 + 9 files changed, 101 insertions(+), 9 deletions(-)