Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp878622rdb; Fri, 2 Feb 2024 06:53:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1ZtA9AzJDrx4BnbTSQzh9XQZZZJtQYH4vs1Mts5EczhntFEaXJM/1qQhYmTyNTItB87FS X-Received: by 2002:a17:906:7fc9:b0:a36:8b9b:bc1c with SMTP id r9-20020a1709067fc900b00a368b9bbc1cmr5377117ejs.71.1706885596359; Fri, 02 Feb 2024 06:53:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706885596; cv=pass; d=google.com; s=arc-20160816; b=UZ2Q1hCV/jMZfSCSTPogHb+IQc+vyBrAiCils6obgGS1CnEmXimeSNgJivlkwljttb lHT9HJt5ULCFpkWZydyS83SLXKwrsGq5QV24tBSUV5QLsfB3KE6CfL47Ph5Lwl9RNCyE pq/ZdpuHZWDsamOOZ3NndADOydLTerFNQZ8WuS45xCs5wqq84+/Wl8ablPN8x2tUSEZo 5LG39cIJojinWdjMXpbbfEAoLPlY0s0MIL3mL4pOtElf3ld9DvIfz4beOO0t67qPgX3k 2jP9e2V34ShJCdDxzjSfNy/ZmZcVGzq5bbHgp2fV2xY0Sq8OC0ITbSCZnyjsnd3wgc5O KPGQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=p7uCEIue/vRXtk5xoPvtw6k0UBZtBQleKzh1H1rbml0=; fh=flFd5OaDp8xHBDJd/mUhYrPM56kK4T1ShBeWRVgu4SY=; b=cOXL7HlPpXtPx2mOnvH+GU8+fTH44FsRf65sglAJCZ7uYKRPtq5DGEmm1O1C9tn+Ez 6djJam3Yf3ZcfdCPdPYrljQOJmy6Py9tHNNidm5PZqmUSc8Wzj/cfQNbAesDzbxUlQxL sDVHgPEnXfAs6sgqLJhS6AVZ5CALhicd7YFY9I8zByYSlDqlV2wcnLmr9zXEhNnu5XHB vXVZ/SiNSDWM2HQAI94DQ6YnmBxhWMx0FDoGl8idIMXDOlcg0ZPmqSOELutUheJQ185k LvIx1SUMkscz8hpYMASkMucu2JS1Y9eKNsHjh/nqFjMGObfy5/zop/1PITVnwxJVPveJ SSpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="NcPGU/cl"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-49968-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49968-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCX3TIYM6GYfQy0d12NZtEg0WPYS1AAGH06s+mRtiF1gpbVPMaJpv7obN8OTUoQmExATmQ2CYlfkEJpaVKay24iAL9Cxis5KwDqnLDbTJw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l11-20020a1709060e0b00b00a35da9d2193si877908eji.405.2024.02.02.06.53.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 06:53:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49968-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="NcPGU/cl"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-49968-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49968-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id E3FDE1F29383 for ; Fri, 2 Feb 2024 14:53:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAD62140771; Fri, 2 Feb 2024 14:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NcPGU/cl" Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76B0B2B9A1 for ; Fri, 2 Feb 2024 14:53:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706885586; cv=none; b=amTkBFNWMmhD9kMrAXBoGAfdnzV2F7xMqQ2Z1+ksVylEvCUSquyyx9XARzbWdv/3wBcc9Ppk4ArwZefdho2Ag+ikZvF0ijKYhjaso4AvOs5rpQTKwp/ZhU0s/CeEJ3hysPo1rgu3yRp0djeuFKYnd4UKH0yAnXu9HQpDxE0z86s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706885586; c=relaxed/simple; bh=p7uCEIue/vRXtk5xoPvtw6k0UBZtBQleKzh1H1rbml0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=PtsFkVbudzgp0VbhBmmctO2N0jJ6AgtNfXC5dZEaxHhgAdnFZgrpOXHwIDoOmIPKT8/VZqeH/u0f69019GI4cH/IEO+ujPBCu532BLQM6BLNg6eumqkjpaBtOSQ6jO5nla2e1C9pU+nlJoj3TVo96WFgyQeLjsMugSuQSkiSHLc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NcPGU/cl; arc=none smtp.client-ip=209.85.219.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-dc6dcd91364so1592659276.2 for ; Fri, 02 Feb 2024 06:53:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706885584; x=1707490384; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=p7uCEIue/vRXtk5xoPvtw6k0UBZtBQleKzh1H1rbml0=; b=NcPGU/cl2diu7eqMQOOaGr2spdcVeDZ2ATRY5q9QZwWR0Kr8iiEYBk+v279qUgy747 /4FOtLQm8yCj1EWk9BEIi72AOTYW9LyejHAFwWY7Vb+DI83vAHLHVKtbn9Xhbse8Ftue 42Li8AAu7muVerX32H3fd8K2dHMpqPkG8UaWtleOH/Kb3VxTMHF2dA4aiRa630kL3WL8 G1b1/eE9UQH488Cgtx8zh/E9qZwU6hKno+LL70jEAsAQL26GWAjmX0vxYFmhXiWbaHHH il8qI2JCJhBcwb4WpGAckcBLpSQ9Q/AzDjzEakfJK3rKPaXoCjSZhIwiziDTLeL8GAVs cncQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706885584; x=1707490384; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=p7uCEIue/vRXtk5xoPvtw6k0UBZtBQleKzh1H1rbml0=; b=RbRLHPq53vZfKKPHxfR5lNo4E2k2idlOB57hwHzsbokLzQpVPCfa3z7tIwqNIJyvzP XrNBHG6vmgKF2dLUc04ctvYiBkqNN3NJrCAgG8oQjSnhQNXvIeF5pKhU/N3J4iZNAmxz TOJh+0RZOW5Gn/ik0VxmZoEkyKlNWFuQepfWDETVzWuAOwIjF6SSwt5XBOrx5sz8i6u4 Weq4Z3P08VarJrJwtYqS9e7HE5ixHfrBo8xyoHi3i9uX0tsb4kTNFfb1cV7/rwM8Q4lt 7ZBzck8MWEs37BFYvVh4AEAW8fdGrShp/PcCpWDzQ3jAUmhyroCW3yKTQlzk4kYLLEes 3Jgg== X-Gm-Message-State: AOJu0YzEj5KexRVu290hOvBZtxmvVLLiu3UcQ4f/7HwqCOWLKmfBlsil 7+QZACys3hjgIdL406H2oY8V7m0Qzscclbfpr/Le1VwERt0nFMjR95TsPCzVcpUEUuQrTRlcUXR n2NG4IV4j7Sw/ZhEmbpBUhc6OX9c= X-Received: by 2002:a25:2f56:0:b0:dc6:9ea:3d5d with SMTP id v83-20020a252f56000000b00dc609ea3d5dmr8113368ybv.34.1706885584427; Fri, 02 Feb 2024 06:53:04 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240201125226.28372-1-ioworker0@gmail.com> In-Reply-To: From: Lance Yang Date: Fri, 2 Feb 2024 22:52:49 +0800 Message-ID: Subject: Re: [PATCH 1/1] mm/khugepaged: skip copying lazyfree pages on collapse To: Michal Hocko Cc: akpm@linux-foundation.org, zokeefe@google.com, david@redhat.com, songmuchun@bytedance.com, shy828301@gmail.com, peterx@redhat.com, minchan@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable How about blocking khugepaged from collapsing lazyfree pages? This way, is it not better to keep the semantics of MADV_FREE? What do you think? Thanks, Lance On Fri, Feb 2, 2024 at 10:42=E2=80=AFPM Michal Hocko wrot= e: > > On Fri 02-02-24 21:46:45, Lance Yang wrote: > > Here is a part from the man page explaining > > the MADV_FREE semantics: > > > > The kernel can thus free thesepages, but the > > freeing could be delayed until memory pressure > > occurs. For each of the pages that has been > > marked to be freed but has not yet been freed, > > the free operation will be canceled if the caller > > writes into the page. If there is no subsequent > > write, the kernel can free the pages at any time. > > > > IIUC, if there is no subsequent write, lazyfree > > pages will eventually be reclaimed. > > If there is no memory pressure then this might not > ever happen. User cannot make any assumption about > their content once madvise call has been done. The > content has to be considered lost. Sure the userspace > might have means to tell those pages from zero pages > and recheck after the write but that is about it. > > > khugepaged > > treats lazyfree pages the same as pte_none, > > avoiding copying them to the new huge page > > during collapse. It seems that lazyfree pages > > are reclaimed before khugepaged collapses them. > > This aligns with user expectations. > > > > However, IMO, if the content of MADV_FREE pages > > remains valid during collapse, then khugepaged > > treating lazyfree pages the same as pte_none > > might not be suitable. > > Why? > > Unless I am missing something (which is possible of > course) I do not really see why dropping the content > of those pages and replacing them with a THP is any > difference from reclaiming those pages and then faulting > in a non-THP zero page. > > Now, if khugepaged reused the original content of MADV_FREE > pages that would be a slightly different story. I can > see why users would expect zero pages to back madvised > area. > -- > Michal Hocko > SUSE Labs