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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DFEAC433F5 for ; Wed, 11 May 2022 00:49:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC6866B0071; Tue, 10 May 2022 20:49:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A77506B0072; Tue, 10 May 2022 20:49:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 916096B0073; Tue, 10 May 2022 20:49:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 82E8D6B0071 for ; Tue, 10 May 2022 20:49:27 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 4E6118103D for ; Wed, 11 May 2022 00:49:27 +0000 (UTC) X-FDA: 79451628774.09.ECE6432 Received: from out30-54.freemail.mail.aliyun.com (out30-54.freemail.mail.aliyun.com [115.124.30.54]) by imf03.hostedemail.com (Postfix) with ESMTP id D56E820097 for ; Wed, 11 May 2022 00:49:17 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R811e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=rongwei.wang@linux.alibaba.com;NM=1;PH=DS;RN=34;SR=0;TI=SMTPD_---0VCt6qYh_1652230157; Received: from 192.168.31.179(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0VCt6qYh_1652230157) by smtp.aliyun-inc.com(127.0.0.1); Wed, 11 May 2022 08:49:20 +0800 Message-ID: <502a3ced-f3c6-7117-3b24-d80d204d66ee@linux.alibaba.com> Date: Wed, 11 May 2022 08:49:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Thunderbird/101.0 Subject: Re: [PATCH v5 10/13] mm/madvise: add MADV_COLLAPSE to process_madvise() Content-Language: en-US To: Zach O'Keefe , Alex Shi , David Hildenbrand , David Rientjes , Matthew Wilcox , Michal Hocko , Pasha Tatashin , Peter Xu , SeongJae Park , Song Liu , Vlastimil Babka , Yang Shi , Zi Yan , linux-mm@kvack.org Cc: Andrea Arcangeli , Andrew Morton , Arnd Bergmann , Axel Rasmussen , Chris Kennelly , Chris Zankel , Helge Deller , Hugh Dickins , Ivan Kokshaysky , "James E.J. Bottomley" , Jens Axboe , "Kirill A. Shutemov" , Matt Turner , Max Filippov , Miaohe Lin , Minchan Kim , Patrick Xia , Pavel Begunkov , Thomas Bogendoerfer , calling@linux.alibaba.com References: <20220504214437.2850685-1-zokeefe@google.com> <20220504214437.2850685-11-zokeefe@google.com> From: Rongwei Wang In-Reply-To: <20220504214437.2850685-11-zokeefe@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: D56E820097 X-Stat-Signature: drktkbsjnni998n58azmcm5itw15wn3b Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf03.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.54 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com X-HE-Tag: 1652230157-253671 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: Hi, Zach Thanks for your great patchset! Recently, We also try to collapse THP in this way, likes performance degradation due to using too much hugepages in our scenes. And there is a doubt about process_madvise(MADV_COLLAPSE) when we test this patchset:. It seems that process_madvise(MADV_COLLAPSE) rely on madvise(MADV_HUGEPAGE)? If the vma wasn't marked with 'hg', process_madvise(MADV_COLLAPSE) will fail to collapse. And if I miss something, please let me know. If so, how about introducing process_madvise(MADV_HUGEPAGE) or process_madvise(MADV_NOHUGEPAGE)? The former helps to mark the target vma with 'hg', and the collapse process can be finished completely with the help of other processes. the latter could let some special vma avoid collapsing when setting 'THP=always'. Best regards, -wrw On 5/5/22 5:44 AM, Zach O'Keefe wrote: > Allow MADV_COLLAPSE behavior for process_madvise(2) if caller has > CAP_SYS_ADMIN or is requesting collapse of it's own memory. > > Signed-off-by: Zach O'Keefe > --- > mm/madvise.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/mm/madvise.c b/mm/madvise.c > index 638517952bd2..08c11217025a 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -1168,13 +1168,15 @@ madvise_behavior_valid(int behavior) > } > > static bool > -process_madvise_behavior_valid(int behavior) > +process_madvise_behavior_valid(int behavior, struct task_struct *task) > { > switch (behavior) { > case MADV_COLD: > case MADV_PAGEOUT: > case MADV_WILLNEED: > return true; > + case MADV_COLLAPSE: > + return task == current || capable(CAP_SYS_ADMIN); > default: > return false; > } > @@ -1452,7 +1454,7 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, > goto free_iov; > } > > - if (!process_madvise_behavior_valid(behavior)) { > + if (!process_madvise_behavior_valid(behavior, task)) { > ret = -EINVAL; > goto release_task; > }