Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1394662pxu; Mon, 23 Nov 2020 21:42:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCC1UCRjW/Vv2M9/e7mYbiqVdkJkUF/9ArdaZxVYsphTfrOv5XR+q3v7sJhbO4cIfsC661 X-Received: by 2002:aa7:c34c:: with SMTP id j12mr2440864edr.17.1606196533468; Mon, 23 Nov 2020 21:42:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606196533; cv=none; d=google.com; s=arc-20160816; b=F+uJhXXhPsr/v4aOvz1/0JtkUes/hjB9djYzcVh9SBlOksxTRLbzh944enFyk9tgU3 ZUjq5gZUHnE4gytPH8nTRebkTkBgWNXMGWpSTbK9OIz9dRH0uChsB5ImWxT/BUJphclK wtRot6VOxTeUBf5pRs+H3rr/fc+Rccft0k1HftUFRbfI35q3cYUyHkhfIkzVYX2S/xBA 35kyQGZS8e9dU683pL//nDUlt1/P+8cnYbJiT3ol3Ews2jGYtJnY6ehljnrKcEMPw1S7 1hr4pRUsk8uiyJbnwhXj8botcilumdwvYL7tHb6OOyxLgX3f5MgqwyqZnBL5Ykn8DBX7 xpEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :sender:dkim-signature; bh=mKYwXoA6RKca8Gj0Xk1sTxg7l//t2h1MecKeF/NRkRI=; b=PmOG5b5dq0lS2LlGaN+O2GDz0I1bSjkG710EEgAVEflsGgOvR/5A7Vz9Nq3/sa02r2 wHTyGat1N4Ymm44mfIhompLclEeqxHduR1+Czryre8qV5832kUjwHjZ8TcqHGDhTZ56V cZCMuFXY4a0VfRwUy+z3T+1buLG/bCQQF3v0n6goArBb9EwFK9X7X5nEuFEWHfQPMuP1 MV5j8YaOnUhjm/KlCE5MWPTXZs1qBeQzDAJ778MbkkxqLXeqQOQeUxMV2QQ2AhFi7Blt QGwgJxpLZB3iS24fow1wzGvRcmtdp9T6dO5Sw3G622h01+qQt7iHu83apkeKs1eKpVQe LXig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XzkAfhjQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id z4si2870802ejb.352.2020.11.23.21.41.50; Mon, 23 Nov 2020 21:42:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=XzkAfhjQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728906AbgKXFju (ORCPT + 99 others); Tue, 24 Nov 2020 00:39:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728874AbgKXFju (ORCPT ); Tue, 24 Nov 2020 00:39:50 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D27DCC0613D6 for ; Mon, 23 Nov 2020 21:39:48 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id 4so5534268pla.6 for ; Mon, 23 Nov 2020 21:39:48 -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=AM2iSub2hbpt9yefKzsdvkJ/vlCMXoKXv2ct/kZzdJC8g06p3yq6lrDKtWy5xnh/Sc FpczhqXSvz+q1elIEsytcbWvdejhBYco8sJ3S25Am1hh8Sp2U/VcgxOxl3lEOx2T77cs JHFim/bOOWMaEzfFRjPX7GEe5J5DB7O3IEFI9ZH8Qsl6el0tXhSwE8zrLh74Hrvcf/L3 HG7lESQCxLstBKUgOlMGTQlAhDKJ8CS+OWid8cE1czW1L8GtYnzajV3OJQ39CyiqKZuI BkmjaYeZYmxDt/LCbDiMOR8wC3rypqH/003jxGeh1imXUHefinpivYeIJIIx4JN5Nodk 7/QQ== X-Gm-Message-State: AOAM531XWYiWBI12meCLukVY9pZ7mHoQq4hPVQB39k54jirmSbK+9h6A uNyu+wWTrZFA5CqPycRESiWUXMhM14c= Sender: "surenb via sendgmr" 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.29.2.454.gaff20da3a2-goog