From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48ED1C433EF for ; Wed, 29 Sep 2021 07:52:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EC421613D0 for ; Wed, 29 Sep 2021 07:52:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EC421613D0 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 86F2B940013; Wed, 29 Sep 2021 03:52:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81ECD940011; Wed, 29 Sep 2021 03:52:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E649940013; Wed, 29 Sep 2021 03:52:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0206.hostedemail.com [216.40.44.206]) by kanga.kvack.org (Postfix) with ESMTP id 60358940011 for ; Wed, 29 Sep 2021 03:52:20 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 051DC1819108A for ; Wed, 29 Sep 2021 07:52:20 +0000 (UTC) X-FDA: 78639843240.14.FE57887 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf08.hostedemail.com (Postfix) with ESMTP id 8264030000A8 for ; Wed, 29 Sep 2021 07:52:19 +0000 (UTC) Received: from relay1.suse.de (relay1.suse.de [149.44.160.133]) by smtp-out2.suse.de (Postfix) with ESMTP id 4FCAA1FFD5; Wed, 29 Sep 2021 07:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1632901938; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nKJATqPQedgRX5cal1JGI6obKkcGL2h8yUla7SJy7q0=; b=iv2c9afdPj+6JUZRul0C2M5dm763OJMphokNYaCglmBOODSydDJhJLnhe9+JCVRGEOLzay Jykvm0RGzK+S1GUMktE39PiLhRyNuMosnt0dRav3nsBBZWhTnHwvIpMOnFaAaaNK+o4GNo QwNihs3cuG1J2MQ4/X5xZSywHcXjb6o= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay1.suse.de (Postfix) with ESMTPS id CD9B325D4F; Wed, 29 Sep 2021 07:52:17 +0000 (UTC) Date: Wed, 29 Sep 2021 09:52:17 +0200 From: Michal Hocko To: Nadav Amit Cc: David Hildenbrand , Andrew Morton , Linux-MM , Linux Kernel Mailing List , Peter Xu , Andrea Arcangeli , Minchan Kim , Colin Cross , Suren Baghdasarya , Mike Rapoport Subject: Re: [RFC PATCH 0/8] mm/madvise: support process_madvise(MADV_DONTNEED) Message-ID: References: <20210926161259.238054-1-namit@vmware.com> <7ce823c8-cfbf-cc59-9fc7-9aa3a79740c3@redhat.com> <6E8A03DD-175F-4A21-BCD7-383D61344521@gmail.com> <2753a311-4d5f-8bc5-ce6f-10063e3c6167@redhat.com> <0FC3F99A-9F77-484A-899B-EDCBEFBFAC5D@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <0FC3F99A-9F77-484A-899B-EDCBEFBFAC5D@gmail.com> X-Rspamd-Queue-Id: 8264030000A8 X-Stat-Signature: cf4gk4peqnfn1d5bakjrqqc1mko5j3ko Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=iv2c9afd; spf=pass (imf08.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com X-Rspamd-Server: rspam06 X-HE-Tag: 1632901939-336078 Content-Transfer-Encoding: quoted-printable 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: On Mon 27-09-21 12:12:46, Nadav Amit wrote: >=20 > > On Sep 27, 2021, at 5:16 AM, Michal Hocko wrote: > >=20 > > On Mon 27-09-21 05:00:11, Nadav Amit wrote: > > [...] > >> The manager is notified on memory regions that it should monitor > >> (through PTRACE/LD_PRELOAD/explicit-API). It then monitors these reg= ions > >> using the remote-userfaultfd that you saw on the second thread. When= it wants > >> to reclaim (anonymous) memory, it: > >>=20 > >> 1. Uses UFFD-WP to protect that memory (and for this matter I got a = vectored > >> UFFD-WP to do so efficiently, a patch which I did not send yet). > >> 2. Calls process_vm_readv() to read that memory of that process. > >> 3. Write it back to =E2=80=9Cswap=E2=80=9D. > >> 4. Calls process_madvise(MADV_DONTNEED) to zap it. > >=20 > > Why cannot you use MADV_PAGEOUT/MADV_COLD for this usecase? >=20 > Providing hints to the kernel takes you so far to a certain extent. > The kernel does not want to (for a good reason) to be completely > configurable when it comes to reclaim and prefetch policies. Doing > so from userspace allows you to be fully configurable. I am sorry but I do not follow. Your scenario is describing a user space driven reclaim. Something that MADV_{COLD,PAGEOUT} have been designed for. What are you missing in the existing functionality? > > MADV_DONTNEED on a remote process has been proposed in the past sever= al > > times and it has always been rejected because it is a free ticket to = all > > sorts of hard to debug problems as it is just a free ticket for a rem= ote > > memory corruption. An additional capability requirement might reduce = the > > risk to some degree but I still do not think this is a good idea. >=20 > I would argue that there is nothing bad that remote MADV_DONTNEED can d= o > that process_vm_writev() cannot do as well (putting aside ptrace). I am not arguing this would be the first syscall to allow tricky and hard to debug corruptions if used without care. > process_vm_writev() is checking: >=20 > mm =3D mm_access(task, PTRACE_MODE_ATTACH_REALCREDS) >=20 > Wouldn't adding such a condition suffice? This would be a minimum requirement. Another one is a sensible usecase that is not covered by an existing functionality. --=20 Michal Hocko SUSE Labs