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 2350BC47DB3 for ; Fri, 2 Feb 2024 14:53:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 830226B0071; Fri, 2 Feb 2024 09:53:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E0AC6B0074; Fri, 2 Feb 2024 09:53:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 681496B0075; Fri, 2 Feb 2024 09:53:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 563556B0071 for ; Fri, 2 Feb 2024 09:53:07 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 271EAA0198 for ; Fri, 2 Feb 2024 14:53:07 +0000 (UTC) X-FDA: 81747156414.05.71EC2F1 Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) by imf12.hostedemail.com (Postfix) with ESMTP id 63C0740020 for ; Fri, 2 Feb 2024 14:53:05 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iYH5eaBn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.219.169 as permitted sender) smtp.mailfrom=ioworker0@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706885585; a=rsa-sha256; cv=none; b=Ccg6BpAOR7OfAy35Z4N5+ZI0im2K7svpRooT6S0v0DujjvctZhmZX99RGI1LXlSgZH2zZX vhR4NaVbNe5z8Zx1AS2WAz8do5+1NVaUT/rL6H3FOwUt7gIfslAxxq89+wEurKPmKt8b7E Ha7yfDThDroxXOpkZy0noivo3KGldRA= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iYH5eaBn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.219.169 as permitted sender) smtp.mailfrom=ioworker0@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706885585; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=p7uCEIue/vRXtk5xoPvtw6k0UBZtBQleKzh1H1rbml0=; b=UclWPzxXvC4YJaUbh/fZCrIbRUaH9oR93V1TY8g2ARtD24tuvOKxqPaw/oFhk50wy970mC aKlvIhom4ET9BkC0hqVIevOd9kO/4/rTdwZ/J9+lu6RJ/HzyjaFF+LGVngb50Ud3ZSZXTO 0hcsEVcPBQ7INlMqP5OqiQ5AKZBCGIs= Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-dc6d24737d7so2086791276.0 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=kvack.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=iYH5eaBnchHa4uLkOgM4bh5nE9XB/vFkKn82NlFlSJ21XUZNsjYCetlFuku4d4sc81 pIwSRznGxXoSu3EYDkSynqQHhYpZB2RyKV5ozR9hxEjq8s/frp1dncd+DfA2Jj+4ADIb FD8RAmNLEEUpGsvetBE6fGdaXFb3e7QfD5xhRZ82LaFbRBFNxldEZYqzk/3/XwKwGJDV eNTW8ky37bI2bqJmWDtkgLRIiFN+67jia9EB6KuCGt2gOUczk2XfET/NB9YZFEZeQDwX L/AndpXFqG55kqWK9h6Zw4CdEQJzCL0ZgvwqOWapGsRWydiddSvWoIgpTIwCRkLCUiHL a3eQ== 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=mci2kKiRXqY15k0YEnlIbKd8houfa37QLgg1qo34eRsZA1NWldxlh6nfTzSNvR/idw kOJk92T5GioAvJpfJM4KSKShOXhOotGQ1RMbm+ZlWFP+6oZAsCm91BEksNi0ZeNifhHS pA6vRrOfSkkHhX7W1zj+VbrV+Yf7EV9AaiIOLBE7cQWL9NhTmY3z6cqMvHgGoDk/NBnc UT0whBJiQQm6RNcZ+iXmboRZJHFZojYeT70c/xo6rjXcEoKBch5BIDRR6vFt26ZMd86S 3tZB7010lUI27yd96F4+Asp1il62d7tIVud54JNAXewrcjPkZGZA8ipHWBRDoJe6TeNj 1b5g== X-Gm-Message-State: AOJu0YyJ14X7hIdDHdJWpXwOoNxoBhHkGaStr8EQuljHDEtfAPim4CbC Fb4T8vPz+J/1573MMgJpi7aQq2UFN46cZ58p8JoA0gwthrkBehOzmWhOa+QCr9RNxLjJlu6reqW 2tUxPG7WcAC4XUGQhqcRfGKw/rhA= X-Google-Smtp-Source: AGHT+IGxRWU1t838GRLlDK4UGgYqjiicH6Z9Fpk+v5YhZjb/sQilVodpYHxZGTSvCWxUyGMDLU9A+g8HXqpK6cR5TOI= 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) 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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 63C0740020 X-Stat-Signature: tefm1ccykrjnfat4ps3gd3gotuaqaua3 X-HE-Tag: 1706885585-61569 X-HE-Meta: U2FsdGVkX1+mumecwIcOZw6ANL/4baQuEu1hKf/7rHRSzv+LaFoCA/+WrTv5IeCD8DaZOOPUHtTrCO/jZ9JsS+XewSdtomff7hK3geEZjkoXPdD10GsB/zKFwpyiGM5iQUAvIYB0la20VC/mdyLo0C609JZNZ9xOe0CmikgXkgIFecz7x8e2bB5HiTFbR14ldEBpbIPrX0niboZcFIO/g9d4AAoeUJpyfVJm6oXp2Pe5TFWEGUUNFhiWGLyDQPRx7pGPjZREv33Z+DKrcuROTAjHjahkygpiz0FVK1EFI4WgSn1PSYfchujipTUAXB9O7G7Ca29SAHchOSra0b+IjCLHzTU7DtU1SdvGC5VmP+sq8wZqzCsWnSBD8tyAhOWWFeFDLyz387n+/AA6vuZJEcTh+y4YNImyKYcVkIP4lu8/F0mNUQADL1EZ2QuNELWRHMOMi0IbopeN27Fykv4VrWG9wLfJEJv6S3cP2/KJ5UmDifLXG1geFYMqvfS3KVyunMkP+axZK7kVL+uT3pnPAJMLd3DdnRo0Xt6d1KGOwCAWt4RUFDye3bbFiNolxAtCUZxa05obcGgqQcs9+mAQk9ejPnAjupSC0098hC89SR2/6ix+zzUMVSA012iLIyfFgaMsszboedBnzau2qMJg1I2wswg76Fh2Lx8I8M7OdT8M8PLJ8vpVEZr1vqGXQUP0x34LkIMgZfPeryJRj6ORyf/HtlkNs9OgFA2x1uNVi1DSHEwBSj51vDqyABTKWEjxigFV0YPSJILokvv+tp/l53qGECFfH14s/gDB+VEQhEmayvvu1RrH3hDF9c+u5p1x7UckVO2IskvcsoyWpN2FIJt4ujzc5LGALW2GqT0Kr0mZlWaRydt8Baq+5GZQKzxM9Mnjms1zZtxzrtijgCVDgXan2EynMPIhDT6FSZKHoznfBN/rzoEbCT0bXHnyFrq5JtcLNOTf3QwuP1GW2RI PyCY4cJd zqLpZXkyjqnAvYFa5ym2BfjdgrRIgFfK7orGq0yDv0+dcPN5q2fxcIsN2qpCqY1TF24koHSoGuTtch1RyCLZvNpegc9L6LdHKFNmRjgjyR1h0pox6qoZ77YRX7qWqsDofwmbSrfFGhceQyNyd7H4gQ3qMoUuePY9r0ZBX+tOjHX+jF4vVMIkFbyq1Ejy/fMQjlvyXHK+ol3tw3w9er41JnxEfBqR5Vsj47Oi1TNLfiWtoKiwWTOIx8/fTIFCe2NrURm+sPxwtRfEUPVEIab5RotbAgwEI8iXwEdmRCv3jh7dyxeoJY7jadwDhYa9Kv+GZsJ2n X-Bogosity: Ham, tests=bogofilter, spamicity=0.000362, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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