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 X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA0F8C433DB for ; Thu, 18 Feb 2021 08:39:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 27DD964D9F for ; Thu, 18 Feb 2021 08:39:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27DD964D9F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 91A086B0006; Thu, 18 Feb 2021 03:39:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C8D96B006C; Thu, 18 Feb 2021 03:39:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 791F66B006E; Thu, 18 Feb 2021 03:39:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 61AFD6B0006 for ; Thu, 18 Feb 2021 03:39:38 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 233CA8249980 for ; Thu, 18 Feb 2021 08:39:38 +0000 (UTC) X-FDA: 77830740036.08.7657DBE Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf26.hostedemail.com (Postfix) with ESMTP id AB7F7407F8F1 for ; Thu, 18 Feb 2021 08:39:34 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613637576; 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=DBMYblLrEsQFhRN2m635S4SLoXw63tSAA1O97qFL/Lk=; b=L8nxBdkVMggG4RAKrtj7i1lnGx9S/EB9xBKz8XnvlCwput6yZwsnyUVvbdW08oCzG06to/ zT4dvdgwKVGYk1GGDyTPtG5yREGSaSbEqpl7TezHgt0/olDW9edM/evTPpYdB68Pot+lLm xP/GfxLTVp63i+CLPy234a4btk5hgKI= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 463C1AC6E; Thu, 18 Feb 2021 08:39:36 +0000 (UTC) Date: Thu, 18 Feb 2021 09:39:35 +0100 From: Michal Hocko To: Song Liu Cc: David Rientjes , Alex Shi , Hugh Dickins , Andrea Arcangeli , "Kirill A. Shutemov" , Matthew Wilcox , Minchan Kim , Vlastimil Babka , Chris Kennelly , Linux MM , Linux API Subject: Re: [RFC] Hugepage collapse in process context Message-ID: References: <9B5BFA9A-E945-4665-B335-A0B8E36D4463@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9B5BFA9A-E945-4665-B335-A0B8E36D4463@fb.com> X-Stat-Signature: 4xm83gro8bhynkkpp3bekbxfgwdzwbn9 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: AB7F7407F8F1 Received-SPF: none (suse.com>: No applicable sender policy available) receiver=imf26; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613637574-519447 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 18-02-21 08:11:13, Song Liu wrote: > > > > On Feb 16, 2021, at 8:24 PM, David Rientjes wrote: > > > > Hi everybody, > > > > Khugepaged is slow by default, it scans at most 4096 pages every 10s. > > That's normally fine as a system-wide setting, but some applications would > > benefit from a more aggressive approach (as long as they are willing to > > pay for it). > > > > Instead of adding priorities for eligible ranges of memory to khugepaged, > > temporarily speeding khugepaged up for the whole system, or sharding its > > work for memory belonging to a certain process, one approach would be to > > allow userspace to induce hugepage collapse. > > > > The benefit to this approach would be that this is done in process context > > so its cpu is charged to the process that is inducing the collapse. > > Khugepaged is not involved. > > > > Idea was to allow userspace to induce hugepage collapse through the new > > process_madvise() call. This allows us to collapse hugepages on behalf of > > current or another process for a vectored set of ranges. > > > > This could be done through a new process_madvise() mode *or* it could be a > > flag to MADV_HUGEPAGE since process_madvise() allows for a flag parameter > > to be passed. For example, MADV_F_SYNC. > > > > When done, this madvise call would allocate a hugepage on the right node > > and attempt to do the collapse in process context just as khugepaged would > > otherwise do. > > This is very interesting idea. One question, IIUC, the user process will > block until all small pages in given ranges are collapsed into THPs. Do you mean that PF would be blocked due to exclusive mmap_sem? Or is there anything else oyu have in mind? > What > would happen if the memory is so fragmented that we cannot allocate that > many huge pages? Do we need some fail over mechanisms? IIRC khugepaged preallocates pages without holding any locks and I would expect the same will be done for madvise as well. -- Michal Hocko SUSE Labs