Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4778981yba; Mon, 20 May 2019 03:42:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwl1jgXowSgLc0E/HGEExN1FtN6t91fhnT+S9WojrVQJDC/cDOQ7UEae3m2jOjd9wWfUyqa X-Received: by 2002:a65:624f:: with SMTP id q15mr74917673pgv.436.1558348934692; Mon, 20 May 2019 03:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558348934; cv=none; d=google.com; s=arc-20160816; b=LEhyMkhuGXJvjqDp+ZDml4pwFYRsMfACEF5L7U7uK0CsbEFu9/mRVnLuewpGU6wJtM 7OpGO4l6991a0y6zm3wxMlJnURd8q1LP6w/KvmmqvM5Nf3cdeSqPfd5i8y302WLNJpiV fsTc1a0BVbWJf1ZnaY2f7wFfnLXG6xXks8IDFYySgNCIdUzWxkcwhLvyugSaXJsYKvfz Rc4RGmxFY7UjEIuqr0qIeCRqWPB9X/6Hs7zNglzThecfgupB9s/tkkmsxctGK/nqOpnB iCB91GiEztI191CWpoA4xc7UNXG/Y+RxCBgO04bcBZfhgo9cpFolBP0WkR7SQVYV4/Pv Mb8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=LKR0MAyifomRJ/xjcwcaHNaLMMDx4Qc655jA2gOR6j8=; b=aeDC0lIXxX31qX8+76CT6NWUFTAnJrz3WmWAgLDiu4iePdo0QEDYM72RGLlqazq2zC g93XH+buh2TbDN9d84Vx/dYgF3wRdd/23k9VwpNo5Lo7eOYY/weoQVP4bzIOJQBPEj+V BF9dk+tvEVJPjrTrxTvLNINje8ZjXoxYgPOtnmtSI/mD0y8HGGxhqB+kGRCXeWhYx8gK M/6QCtDC2mNUBwEpYtljtDBJR/iQavvbNv7im5vKrDbhlINUsDtnicfUfUyBJOVAbED0 yb0jm23aFqqo7Jle7SONCtXYDHMPZggyL1kZyI2k9IeF1UNRl8+KbqAFKb1Y1bjbvW8t /K2Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si19733412pfh.200.2019.05.20.03.41.59; Mon, 20 May 2019 03:42:14 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732129AbfETJ2F (ORCPT + 99 others); Mon, 20 May 2019 05:28:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:40018 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731436AbfETJ2E (ORCPT ); Mon, 20 May 2019 05:28:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AAA62ABD7; Mon, 20 May 2019 09:28:02 +0000 (UTC) Date: Mon, 20 May 2019 11:28:01 +0200 From: Michal Hocko To: Minchan Kim Cc: Andrew Morton , LKML , linux-mm , Johannes Weiner , Tim Murray , Joel Fernandes , Suren Baghdasaryan , Daniel Colascione , Shakeel Butt , Sonny Rao , Brian Geffon , linux-api@vger.kernel.org Subject: Re: [RFC 7/7] mm: madvise support MADV_ANONYMOUS_FILTER and MADV_FILE_FILTER Message-ID: <20190520092801.GA6836@dhcp22.suse.cz> References: <20190520035254.57579-1-minchan@kernel.org> <20190520035254.57579-8-minchan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190520035254.57579-8-minchan@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [cc linux-api] On Mon 20-05-19 12:52:54, Minchan Kim wrote: > System could have much faster swap device like zRAM. In that case, swapping > is extremely cheaper than file-IO on the low-end storage. > In this configuration, userspace could handle different strategy for each > kinds of vma. IOW, they want to reclaim anonymous pages by MADV_COLD > while it keeps file-backed pages in inactive LRU by MADV_COOL because > file IO is more expensive in this case so want to keep them in memory > until memory pressure happens. > > To support such strategy easier, this patch introduces > MADV_ANONYMOUS_FILTER and MADV_FILE_FILTER options in madvise(2) like > that /proc//clear_refs already has supported same filters. > They are filters could be Ored with other existing hints using top two bits > of (int behavior). madvise operates on top of ranges and it is quite trivial to do the filtering from the userspace so why do we need any additional filtering? > Once either of them is set, the hint could affect only the interested vma > either anonymous or file-backed. > > With that, user could call a process_madvise syscall simply with a entire > range(0x0 - 0xFFFFFFFFFFFFFFFF) but either of MADV_ANONYMOUS_FILTER and > MADV_FILE_FILTER so there is no need to call the syscall range by range. OK, so here is the reason you want that. The immediate question is why cannot the monitor do the filtering from the userspace. Slightly more work, all right, but less of an API to expose and that itself is a strong argument against. > * from v1r2 > * use consistent check with clear_refs to identify anon/file vma - surenb > > * from v1r1 > * use naming "filter" for new madvise option - dancol > > Signed-off-by: Minchan Kim > --- > include/uapi/asm-generic/mman-common.h | 5 +++++ > mm/madvise.c | 14 ++++++++++++++ > 2 files changed, 19 insertions(+) > > diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h > index b8e230de84a6..be59a1b90284 100644 > --- a/include/uapi/asm-generic/mman-common.h > +++ b/include/uapi/asm-generic/mman-common.h > @@ -66,6 +66,11 @@ > #define MADV_WIPEONFORK 18 /* Zero memory on fork, child only */ > #define MADV_KEEPONFORK 19 /* Undo MADV_WIPEONFORK */ > > +#define MADV_BEHAVIOR_MASK (~(MADV_ANONYMOUS_FILTER|MADV_FILE_FILTER)) > + > +#define MADV_ANONYMOUS_FILTER (1<<31) /* works for only anonymous vma */ > +#define MADV_FILE_FILTER (1<<30) /* works for only file-backed vma */ > + > /* compatibility flags */ > #define MAP_FILE 0 > > diff --git a/mm/madvise.c b/mm/madvise.c > index f4f569dac2bd..116131243540 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -1002,7 +1002,15 @@ static int madvise_core(struct task_struct *tsk, unsigned long start, > int write; > size_t len; > struct blk_plug plug; > + bool anon_only, file_only; > > + anon_only = behavior & MADV_ANONYMOUS_FILTER; > + file_only = behavior & MADV_FILE_FILTER; > + > + if (anon_only && file_only) > + return error; > + > + behavior = behavior & MADV_BEHAVIOR_MASK; > if (!madvise_behavior_valid(behavior)) > return error; > > @@ -1067,12 +1075,18 @@ static int madvise_core(struct task_struct *tsk, unsigned long start, > if (end < tmp) > tmp = end; > > + if (anon_only && vma->vm_file) > + goto next; > + if (file_only && !vma->vm_file) > + goto next; > + > /* Here vma->vm_start <= start < tmp <= (end|vma->vm_end). */ > error = madvise_vma(tsk, vma, &prev, start, tmp, > behavior, &pages); > if (error) > goto out; > *nr_pages += pages; > +next: > start = tmp; > if (prev && start < prev->vm_end) > start = prev->vm_end; > -- > 2.21.0.1020.gf2820cf01a-goog > -- Michal Hocko SUSE Labs