Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp1118553rdb; Fri, 19 Jan 2024 08:41:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1Qm5NOZxsO6qzhTSkceLgoQGq+ocPS4tnCvDsE7p4DK8tiycbUO/ZSU9iy5YEoeYEszEy X-Received: by 2002:a05:6a00:228f:b0:6d9:b075:a7d6 with SMTP id f15-20020a056a00228f00b006d9b075a7d6mr111730pfe.19.1705682482018; Fri, 19 Jan 2024 08:41:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705682482; cv=pass; d=google.com; s=arc-20160816; b=EqopnwAqcAZXdaXGz4206PqAuHsZtYYOtnAYcqbdEtmbBurgETUHBOfZIPZ6rjslpG cp+F46yEhbQbBuD2m6pMJEJdoO21StDkYFWRt/t7+Pc4236h5vSUSpBWGLPuC6atXhS1 HYs8oTO2hOZwMAY3GnV5bms2GWt+XrqZ5sIl9lK8Y/D8lXQ6PmKV/ilop+4WOoW6e6Po PqRxEcRrRhezKyGLhkjdLMduZrQXsprT/0lX2nwE7hO3nGDpcYhWM9j32VFhxaKghmg4 ng+ajT7XtJu1EYuj+GDZFHxfaRwKyfttbOhgvzNuCi0PLibry5XAjmmM+uXMZBQpJXTE 8FGw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:date:references:in-reply-to:subject:cc:to :from:dkim-signature; bh=a0lNdiGqJGzTgYirDwvNUCa4oTicsxd5wNupHFDNJ+g=; fh=BBnLKwlMUpOkyFJQUUGtIBJZ7VuoRUc8MP78vk4VMyQ=; b=JSJLLX2sz/HkCYbzScx9EvV7LrUVxs692sL48mk+pusrGXjDhl/l69NbzmMfoeBhnu Ui8/eKDk5cbbsdyZRJ9mNASY2S9hrp2ZeYFv8auCpL811rNqMpp3np0/+qgsY2BywZpF r6i+3wvI7qbiMQ6gZibXhl70WqpeB44DP2IjDSwiT7HdF7cQ4k1w1H+VdmeURffeATJG piOJ2fSi7FGZadKsE80dILpoqBg2EFVvUqE+G7r6+8UDwtLuGidFNk4DMhpjCLwgfI26 soF3uPmg2VV7457vHqbBRzCiSRksykq4B4uiGYne3rlVvUtIKv9ncnjEbDCse31bRcDz yb6w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=e4hKaqae; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-31212-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31212-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h11-20020a65638b000000b005cdf55cb5b5si3675748pgv.840.2024.01.19.08.41.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 08:41:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31212-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=e4hKaqae; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-31212-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31212-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3DC4C283655 for ; Fri, 19 Jan 2024 13:41:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57A1452F7D; Fri, 19 Jan 2024 13:41:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="e4hKaqae" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E905524BF for ; Fri, 19 Jan 2024 13:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705671671; cv=none; b=rmbRdsnsUEQcADzASh0+TObbP/k5pGtW2FGFaduxbjGiILWDTF19aNGNPqKNw/YaNZzbtOjKHT74uhPJ2oh9wI++wlOuFRCkF/8XZYa5/FNkcrvIXX9lGfAj1lkdXaV84IG2preFwi3Y0BYU+CmX+I3oOOFkC1bZnLQy9Pgq1f4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705671671; c=relaxed/simple; bh=a0lNdiGqJGzTgYirDwvNUCa4oTicsxd5wNupHFDNJ+g=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=YqkVcGzCSa0lwZxdVKcBGhHM0pscTfZ7jz2fib8XZiD1oFIpFedsGJdBP07SqsMStRNmi2oT+aePU5cUohOe3H3x8r7WcHQMn9SQk+zbY78rQ2g9RbCPlHhTAM5XC3dKYG9kscCHq71w5AIDBtuHIj4Cd/YuAfeItNiSwFRltEw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=e4hKaqae; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705671669; x=1737207669; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=a0lNdiGqJGzTgYirDwvNUCa4oTicsxd5wNupHFDNJ+g=; b=e4hKaqaetRKIWte/1qPGo8qZYyEfa/GeDQqX7rcqRSZ597zI+frUCErS ky0B2EcciJvYDqLdqy0ajXFiPxTAZrOAQHv5K/GwDAb8eSReudkaKlaDN ukE52wMe36DvtTdPGnTCQieTIyv4x/a4i7KkHJr7RVb07kVvT4N9TekmG IVwIbnYf3EJLK32cOKWTTFHN/TBfg1/Am/yghoOfD/ZM/4N6460EpjB5A p0U41CVQ95TQL7A4GefdU7Vf2bwLxnrkwViJ89KaMfbrixqP+SH99lasg cSH6Dq9h+21mBmVwVOjPToUoX+CJQChsI4TnfqX5783qX0SljsloBx0pp w==; X-IronPort-AV: E=McAfee;i="6600,9927,10956"; a="8119742" X-IronPort-AV: E=Sophos;i="6.05,204,1701158400"; d="scan'208";a="8119742" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2024 05:41:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10956"; a="777993378" X-IronPort-AV: E=Sophos;i="6.05,204,1701158400"; d="scan'208";a="777993378" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.54.38.190]) by orsmga007.jf.intel.com with ESMTP; 19 Jan 2024 05:41:08 -0800 Received: by tassilo.localdomain (Postfix, from userid 1000) id 81007302B79; Fri, 19 Jan 2024 05:41:08 -0800 (PST) From: Andi Kleen To: Lance Yang Cc: akpm@linux-foundation.org, zokeefe@google.com, songmuchun@bytedance.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 1/2] mm/madvise: introduce MADV_TRY_COLLAPSE for attempted synchronous hugepage collapse In-Reply-To: <20240117050217.43610-1-ioworker0@gmail.com> (Lance Yang's message of "Wed, 17 Jan 2024 13:02:16 +0800") References: <20240117050217.43610-1-ioworker0@gmail.com> Date: Fri, 19 Jan 2024 05:41:08 -0800 Message-ID: <87ededl9u3.fsf@linux.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Lance Yang writes: > This idea was inspired by MADV_COLLAPSE introduced by Zach O'Keefe[1]. > > Introduce a new madvise mode, MADV_TRY_COLLAPSE, that allows users to > make a least-effort attempt at a synchronous collapse of memory at > their own expense. > > The only difference from MADV_COLLAPSE is that the new hugepage allocation > avoids direct reclaim and/or compaction, quickly failing on allocation errors. > > The benefits of this approach are: > > * CPU is charged to the process that wants to spend the cycles for the THP > * Avoid unpredictable timing of khugepaged collapse > * Prevent unpredictable stalls caused by direct reclaim and/or > compaction I haven't completely followed the discussion, but it seem your second and third point could be addressed by a asynchronous THP fault without any new APIs: allocate 2MB while failing quickly, then on failure get a 4K page and provide it to the process, while asking khugepaged to convert the page ASAP in the background, but only after it managed to allocate a fresh 2MB page to minimize the process visible down time. I suppose that would be much more predictable, although there would be a slightly risk of overwhelming khugepaged. The later could be addressed by using a scalable workqueue that allocates more threads when needed. -Andi