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 83C75C433EF for ; Fri, 27 May 2022 09:46:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C79AC8D0003; Fri, 27 May 2022 05:46:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C054D8D0002; Fri, 27 May 2022 05:46:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA1518D0003; Fri, 27 May 2022 05:46:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9B9358D0002 for ; Fri, 27 May 2022 05:46:29 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5DD6A20974 for ; Fri, 27 May 2022 09:46:29 +0000 (UTC) X-FDA: 79511042898.08.458CC96 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf05.hostedemail.com (Postfix) with ESMTP id 59ED3100058 for ; Fri, 27 May 2022 09:45:58 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 6520B1F96C; Fri, 27 May 2022 09:46:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1653644787; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZmnV8kSYkwTpRzfcIZ/WMJ4ExJMtvNv0OW0a9rQ3UbE=; b=ThQxSnkIMsUFBVPODfQLHByT23JH4N1fnWkQuYPg710FNzlG1KkpWOE+L6znbW7Tq3ftnx 9SAagDIbOp03JADx6bk6qZwgCfgRs4DLhBPnDDdzBVEJdS0/zpI5yCdE4PtC+AUc8HnPld GZx7nXnU+YCOjsVUJr1xx5kX66thITg= 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 relay2.suse.de (Postfix) with ESMTPS id DCC592C141; Fri, 27 May 2022 09:46:25 +0000 (UTC) Date: Fri, 27 May 2022 11:46:25 +0200 From: Michal Hocko To: Yang Shi Cc: Zach O'Keefe , Alex Shi , David Hildenbrand , David Rientjes , Matthew Wilcox , Peter Xu , Song Liu , Linux MM , Rongwei Wang , Andrea Arcangeli , Axel Rasmussen , Hugh Dickins , "Kirill A. Shutemov" , Minchan Kim , SeongJae Park , Pasha Tatashin Subject: Re: [RFC] mm: MADV_COLLAPSE semantics Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=ThQxSnkI; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf05.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 59ED3100058 X-Stat-Signature: 5pnhomrchfopkzi8xif1uzhpnqiwk9gb X-HE-Tag: 1653644758-737421 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 Thu 26-05-22 10:39:42, Yang Shi wrote: > On Thu, May 26, 2022 at 12:12 AM Michal Hocko wrote: > > > > On Wed 25-05-22 10:32:44, Yang Shi wrote: > > > On Wed, May 25, 2022 at 1:24 AM Michal Hocko wrote: > > > > > > > > On Mon 23-05-22 17:18:32, Zach O'Keefe wrote: > > > > [...] > > > > > Idea: MADV_COLLAPSE should respect VM_NOHUGEPAGE and "never" THP mode, > > > > > but otherwise would attempt to collapse. > > > > > > > > I do agree that {process_}madvise should fail on VM_NOHUGEPAGE. The > > > > process has explicitly noted that THP shouldn't be used on such a VMA > > > > and seeing THP could be observed as not complying with that contract. > > > > > > > > I am not so sure about the global "never" policy, though. The global > > > > policy controls _kernel_ driven THPs. As the request to collapse memory > > > > comes from the userspace I do not think it should be limited by the > > > > kernel policy. I also think it can be beneficial to implement userspace > > > > based THP policies and exclude any kernel interference and that could be > > > > achieved by global kernel "never" policy and implement the whole > > > > functionality by process_madvise. > > > > > > I'd prefer to respect "never" for now since it is typically used to > > > disable THP globally even though the mappings are madvised > > > (MADV_HUGEPAGE). IMHO I treat MADV_COLLAPSE as weaker MADV_HUGEPAGE > > > (take effect for non-madvised mappings but not flip VM_NOHUGEPAGE) + > > > best-effort synchronous THP collapse. > > > > MADV_HUGEPAGE is a way to tell the kernel what and how to do in future > > time by the kernel. MADV_COLLAPSE is a way tell what the userspace want > > at the moment of the call. So I do not really think they are directly > > related in any way except they somehow control THP. > > > > The primary question here is whether we want to support usecases which > > want to completely rule out THP handling by the kernel and only rely on > > the userspace. If yes, I do not see other way than using never global > > policy and rely on MADV_COLLAPSE from the userspace. Or am I missing > > something? > > I'm not sure whether we want to reach that eventually. My experience tells me that sooner or later somebody comes with a usecase for that. We are are not sure that is just a sign somebody will have that idea. So either we have very good reasons to not allow that possibility now and ideally we also document that or we should simply assume it will happen. > But isn't > "madvise" good enough? "madvise" also means to give the delegation to > the users IMHO. The users decide whether huge page is preferred or > not. The users could implement policies: > > No - MADV_NOHUGEPAGE > Yes - MADV_HUGEPAGE > > But the THP allocation is deferred to real access (page fault) or > khugepaged. So I treated MADV_COLLAPSE as weaker MAD_HUGEPAGE + > synchronous THP allocation. I really do not see any good reason to tightly couple kernel and user policies. Hints like MADV_{NO}HUGEPAGE are one thing and both kernel and userspace might decide to interpret them. But binding MADV_COLLAPSE to in kernel THP tunables just seems like pushing ourselves into the corner. -- Michal Hocko SUSE Labs