From patchwork Wed Feb 19 01:44:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 11390187 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B39DF92A for ; Wed, 19 Feb 2020 01:44:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6E93A2467B for ; Wed, 19 Feb 2020 01:44:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OOtOyOOi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E93A2467B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A700F6B0003; Tue, 18 Feb 2020 20:44:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A21846B0006; Tue, 18 Feb 2020 20:44:39 -0500 (EST) 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 8E8336B0007; Tue, 18 Feb 2020 20:44:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0145.hostedemail.com [216.40.44.145]) by kanga.kvack.org (Postfix) with ESMTP id 779266B0003 for ; Tue, 18 Feb 2020 20:44:39 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0E229513 for ; Wed, 19 Feb 2020 01:44:39 +0000 (UTC) X-FDA: 76505182278.08.eyes53_62bb982397c51 X-Spam-Summary: 2,0,0,e8349437513ac17d,d41d8cd98f00b204,minchan.kim@gmail.com,:akpm@linux-foundation.org:linux-kernel@vger.kernel.org::linux-api@vger.kernel.org:oleksandr@redhat.com:surenb@google.com:timmurray@google.com:dancol@google.com:sspatil@google.com:sonnyrao@google.com:bgeffon@google.com:mhocko@suse.com:hannes@cmpxchg.org:shakeelb@google.com:joaodias@google.com:joel@joelfernandes.org:sj38.park@gmail.com:alexander.h.duyck@linux.intel.com:jannh@google.com:minchan@kernel.org,RULES_HIT:41:355:379:541:800:967:973:982:988:989:1260:1311:1314:1345:1437:1515:1535:1544:1711:1730:1747:1777:1792:1801:2194:2198:2199:2200:2393:2525:2559:2567:2570:2682:2685:2693:2703:2859:2892:2911:2915:2933:2937:2939:2942:2945:2947:2951:2954:3022:3355:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4118:4250:4321:4425:4605:5007:6119:6261:7875:7903:8957:9025:10004:11658:13141:13206:13229:13230,0,RBL:209.85.216.65:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66 .100.201 X-HE-Tag: eyes53_62bb982397c51 X-Filterd-Recvd-Size: 7599 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Feb 2020 01:44:38 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id ep11so1860395pjb.2 for ; Tue, 18 Feb 2020 17:44:38 -0800 (PST) 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=jexvvsJg+MaDHz4Tc7pcFF//GHPzAbjYjk1o03WxMjk=; b=OOtOyOOiA/Z2sEg/9aLi0DEKLDWgMMh0gloywbMYa0ILzbiUUwIiNhq9/UmbTaKmN1 fHvjq++7nDH89D9L/zUWlcWbDaUZ77cSQ1FLA8bHVVHDqBcvA7HDC/dzjGwTo9UTydB8 oGCSX7p3/ykmkgnUlhOrPIy9NG8TGJLvT0fh0xqgIKi+kIFllCpzN8shnF6XXHa29Jpk owOEf5MIcd1jBbBTehuxfxDAu40WX3QPMzKj9QnidLPDBsHND2lYL82hjXp9r5k2LeUJ o6MYQxk4C/GFDCapJAaHhDCsjAIc/wz96owcRuNe/Qg4QiA/JmiyOlT7YoBGuag74qYF OCYg== 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=jexvvsJg+MaDHz4Tc7pcFF//GHPzAbjYjk1o03WxMjk=; b=YxPO3BqvGwb5YtQJ86ZihzShb5W6+F8ZepnYwVsG8dUH1DTKueO5KxVhFcqtnmGhYt PEgimfWvv8tlZap91R3pj4JasRDW2wOnaegP02nil2JCs/zK9k2kXZuvG/MwZC72uN0d cZNcRr61nLkm1R9crDnrTnZstfSwhn8pUN5LRiGht+7c6iCR+lF5K2s9NAMQuwVJGjYV wDRTsHzQP2DVvQ3srdDAKPh+r5xQI7LhazFcjbqPi4uNZX2dqG9s9BTwn1Cog/bxXAEL kCqHWgGe155DrT8XK8wuOyJ/hcjOaYfjU/qgrByeOTM1dO1QJStrmCBxCRVYmAyz9dKW VB+g== X-Gm-Message-State: APjAAAX9km1C5au47UNl17JygMO98AK491UKNx2K34mp2uE3P66lWXIK RK8+YCuBWqo7ZEe/p4BlKLA= X-Google-Smtp-Source: APXvYqzSzVk5xtTCn6Y0eWG7homfmpB0LfjG1wXXG9Gh5SqfXEE4253LF8S/uxor/szQK15/b1qCnw== X-Received: by 2002:a17:90a:8b82:: with SMTP id z2mr6336196pjn.59.1582076677219; Tue, 18 Feb 2020 17:44:37 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:1:3e01:2939:5992:52da]) by smtp.gmail.com with ESMTPSA id t186sm221192pgd.26.2020.02.18.17.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Feb 2020 17:44:36 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: LKML , linux-mm , linux-api@vger.kernel.org, oleksandr@redhat.com, Suren Baghdasaryan , Tim Murray , Daniel Colascione , Sandeep Patil , Sonny Rao , Brian Geffon , Michal Hocko , Johannes Weiner , Shakeel Butt , John Dias , Joel Fernandes , sj38.park@gmail.com, alexander.h.duyck@linux.intel.com, Jann Horn , Minchan Kim Subject: [PATCH v6 0/7] introduce memory hinting API for external process Date: Tue, 18 Feb 2020 17:44:26 -0800 Message-Id: <20200219014433.88424-1-minchan@kernel.org> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog MIME-Version: 1.0 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: Now, we have MADV_PAGEOUT and MADV_COLD as madvise hinting API. With that, application could give hints to kernel what memory range are preferred to be reclaimed. However, in some platform(e.g., Android), the information required to make the hinting decision is not known to the app. Instead, it is known to a centralized userspace daemon(e.g., ActivityManagerService), and that daemon must be able to initiate reclaim on its own without any app involvement. To solve the concern, this patch introduces new syscall - process_madvise(2). Bascially, it's same with madvise(2) syscall but it has some differences. 1. It needs pidfd of target process to provide the hint 2. It supports only MADV_{COLD|PAGEOUT|MERGEABLE|UNMEREABLE} at this moment. Other hints in madvise will be opened when there are explicit requests from community to prevent unexpected bugs we couldn't support. 3. Only privileged processes can do something for other process's address space. For more detail of the new API, please see "mm: introduce external memory hinting API" description in this patchset. * from v5 - https://lore.kernel.org/linux-mm/20200214170520.160271-1-minchan@kernel.org/ * use null task and requestor's mm for io_madvise - Jann and Jens * use right commit description for moving pidfd_get_pid - Christoph * from v4 - https://lore.kernel.org/linux-mm/20200212233946.246210-1-minchan@kernel.org/ * pass mm down to functions, not accessing task->mm - Jann * clean up - Alexander * add Reviewed-by - Alexander, SeongJae * patch reordering * from v3 - https://lore.kernel.org/linux-mm/20200128001641.5086-1-minchan@kernel.org/ * verify task->mm aftere access_mm - Oleg * split some patches for easy review - Alexander * clean up fatal signal checking - Suren * from v2 - https://lore.kernel.org/linux-mm/20200116235953.163318-1-minchan@kernel.org/ * check signal callee and caller to bail out - Kirill Tkhai * put more clarification for justification of new API * from v1 - https://lore.kernel.org/linux-mm/20200110213433.94739-1-minchan@kernel.org/ * fix syscall number - SeongJae * use get_pid_task - Kirill Tkhai * extend API to support pid as well as pidfd - Kirill Tkhai Minchan Kim (5): mm: pass task and mm to do_madvise mm: introduce external memory hinting API mm: check fatal signal pending of target process pid: move pidfd_get_pid function to pid.c mm: support both pid and pidfd for process_madvise Oleksandr Natalenko (2): mm/madvise: employ mmget_still_valid for write lock mm/madvise: allow KSM hints for remote API arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + fs/io_uring.c | 2 +- include/linux/mm.h | 3 +- include/linux/pid.h | 1 + include/linux/syscalls.h | 3 + include/uapi/asm-generic/unistd.h | 4 +- kernel/exit.c | 17 --- kernel/pid.c | 17 +++ kernel/sys_ni.c | 1 + mm/madvise.c | 144 ++++++++++++++++---- 26 files changed, 167 insertions(+), 44 deletions(-)