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 D6E27C4828F for ; Fri, 2 Feb 2024 14:42:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F08A6B0075; Fri, 2 Feb 2024 09:42:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A0ED6B0078; Fri, 2 Feb 2024 09:42:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 568416B007B; Fri, 2 Feb 2024 09:42:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 466306B0075 for ; Fri, 2 Feb 2024 09:42:55 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1C2B71C1948 for ; Fri, 2 Feb 2024 14:42:55 +0000 (UTC) X-FDA: 81747130710.04.1896173 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf03.hostedemail.com (Postfix) with ESMTP id C8B3D20012 for ; Fri, 2 Feb 2024 14:42:52 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=hnBgdeAN; dkim=pass header.d=suse.com header.s=susede1 header.b=hnBgdeAN; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf03.hostedemail.com: domain of mhocko@suse.com designates 195.135.223.130 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706884973; a=rsa-sha256; cv=none; b=MCfacmX4hFAmrusQOMxSE/Y6HZa7dCo2mZOaKy+Mg1kbWMAnM6ILE+pdmFHnsQUW1Nx95j dDzrL9EZJf/UQShvTzGqSJV0wHK2Kj8KSsFj+FuK6+o5ULrOPma3iawjXlIPKLlJuqSNTE yE+b3ocEw/ke7TYA3Pat04OZVoIL0wk= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=hnBgdeAN; dkim=pass header.d=suse.com header.s=susede1 header.b=hnBgdeAN; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf03.hostedemail.com: domain of mhocko@suse.com designates 195.135.223.130 as permitted sender) smtp.mailfrom=mhocko@suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706884973; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=f554nqusfs3KKOhoXmxK7o26/eSoxN9BndOK5ZeGsS4=; b=v+awHwZPARSk65FcYoBaVwtoZEq2wZf1VKzAnQgaGh34wuGWApB6G33+fmJZoWKO5xVX3C k3n6aB6R8nqZv5n4pYCZl2qfPZHxjWnuoGsDOSk3BOaOIVEmx1mKOXLH2fHG2UpOq1Gu4G NekI2As/IwDqpaTuleXc+YVUgMgRak0= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 06BF521F49; Fri, 2 Feb 2024 14:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1706884971; 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=f554nqusfs3KKOhoXmxK7o26/eSoxN9BndOK5ZeGsS4=; b=hnBgdeANdIxNb1X51SAKmhkMb0K5lkClFm4R9QOPalUdXwDyk0J39g3V2U9MeNua3S2cdf Qofd8rD3OD451w0Hei43bYg/af3GWthu05sAWcZbRcCroa/WRMaUqE/z3MLuhtuQ00H1/H ThrENSp6kes4A8McVgL1mAQj+Fc3jiA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1706884971; 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=f554nqusfs3KKOhoXmxK7o26/eSoxN9BndOK5ZeGsS4=; b=hnBgdeANdIxNb1X51SAKmhkMb0K5lkClFm4R9QOPalUdXwDyk0J39g3V2U9MeNua3S2cdf Qofd8rD3OD451w0Hei43bYg/af3GWthu05sAWcZbRcCroa/WRMaUqE/z3MLuhtuQ00H1/H ThrENSp6kes4A8McVgL1mAQj+Fc3jiA= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E357213A58; Fri, 2 Feb 2024 14:42:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id P2K3NWr/vGWsJAAAD6G6ig (envelope-from ); Fri, 02 Feb 2024 14:42:50 +0000 Date: Fri, 2 Feb 2024 15:42:50 +0100 From: Michal Hocko To: Lance Yang 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 Subject: Re: [PATCH 1/1] mm/khugepaged: skip copying lazyfree pages on collapse Message-ID: References: <20240201125226.28372-1-ioworker0@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C8B3D20012 X-Stat-Signature: 5jnceqndm7j8ff79eheoik5emx5fbtd6 X-HE-Tag: 1706884972-999963 X-HE-Meta: U2FsdGVkX1+5FrvnuMhZY9S/12+iimaUbGw09ca+SrsYzqXhfo+UdheTU049hDjMBzJO1Y3ajzY+RkE6n1APghcnMe7raKt+WomRsFd0sQ7I6f4CEM11SMC9098vJx6u1lptYEAaiRnFYXukaRYO1Lo1/Cb3DD29Xe16GNXZQpzR3wKRtuanzFFO7oD4uLphjFW/jIVwDlPFaBhYVCgIhr/Ij4uY57hVP33nVEQbmEVLLY/cVkIUhWpykKWvJxeb7daulTkz15s3C/HjbaIhJMH759vipjeVtkSpswdK+ytyQ2czzYwtQq3IKXHOYvOd2SOiBR44pDmtGgUwbOrPLIK61EXH+uU1cgmO5bv9gDD3TK7iIErtZifrsBEqZkDxUtUHBMFhRBx+1wJM4HCLLgroOMe2jtiCpQJ2Pnv9UVIh3W9sVvgZ2SMaBy06+9keO3xByJKQrjpuqYjZsxcowVQuIjTTjvJo4XbS7uvTUW/9JTRM2j4x/RZDhBUzj6NMHUj2cPuMf4X67+bc6w2itd8rKRvZ2QAvNv4ElwQknlfftApcDA9YuVjsS2D44MAx5wOx6KE9AV8mJesyNjDYYgQSamFIWgvrjKWJDKWRTaPWhUExqbfUYtmSyt3AO4VLXTovpw/QRLhAc80gnN7RJmZ4FOUzyAAXUU2d/Ckdp0HIXcd4R1EG2Wya4sdtI3i0q5j61Pzs7/MYC6hjXG+g6nCcpAbMIJZBR6PRFoKNgFMKUrCo6lUaGubspJVv9ApNbEXlMFTI48L9cSO+mq6Mzy3u4c2oMYuC9Js774nLhy3cfQutov3ehMkD6QEQiMAeB11X/GlvsnlZs6js+yd985QZy9ajeaesTAamTLubr0/01slwzFElKuESB9gkTTwVHhobb6R/UwSvl5IazJ66nmVgSnzb13oN8xWfpfHFDIvOjUP5cAwIH9yHbfMCPZmEuUt+1hLm1zFHTXzFd8O OKsyOqcR hkl8K7wQSXyFV7ehCML8AxxfW8SC4Iy2JYo47vqrBsifg8GedkXOreW6N7Qxd2CZxWFUQQf5z+ZcFKZAi5+O8Br80L7Dod1CB7X+cd+c7CAvAdUdgaE5yG/ppuhLp2Tm9XiIJPCKIxwvIe+iG1mjJH138zmkai9I/kdm5y79VDVIky3p8YFkSmlYNrCkaR2Ind68A2Wf+Z2C/iMYYJzM13hDoSQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000017, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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