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 09D35C47DB3 for ; Fri, 2 Feb 2024 14:20:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 727F76B006E; Fri, 2 Feb 2024 09:20:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D64F6B0071; Fri, 2 Feb 2024 09:20:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C5F86B0072; Fri, 2 Feb 2024 09:20:58 -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 5071A6B006E for ; Fri, 2 Feb 2024 09:20:58 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2733FA1CE1 for ; Fri, 2 Feb 2024 14:20:58 +0000 (UTC) X-FDA: 81747075396.01.F8CFE07 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) by imf26.hostedemail.com (Postfix) with ESMTP id 45B6E140004 for ; Fri, 2 Feb 2024 14:20:56 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IT3gVBuP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.219.170 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=1706883656; 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=G2uxDw3rJ90QUP0VxxcGcpNUOmy7xFkn/uZBFq7Dat0=; b=59ywhFs9xzPVOWMZxy2X5dmPUDnXcs52xklMMsEeDpZYpC+MS0/CJhggeo3fntCaBH2LEs 9qy53pxryxVtu0w6hvXY1IVXAaaPPy3cZk0780487useUEScPoNj4hjUcC3Z6u8W4kVFV1 oN3ffx6QwLXcQMyV2ccK60l7EdPDFQQ= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IT3gVBuP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.219.170 as permitted sender) smtp.mailfrom=ioworker0@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706883656; a=rsa-sha256; cv=none; b=JW7/F2XLF85HQ7dPOEwbx92wCya1KkNTErXk04QNZ5GV7YlrBbzyl/a1ztu1iRXsN6aXDb 4mys0W6vRvSonmbEfwDSpirni9tLcWEXPSbAgAVC9JxCAm1JQl7dG9V0f4aedAsCrLsM0n 10HGC/+6X9zXr3yVOR3Axdve6z1kNws= Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-dc6d8bd618eso1779835276.3 for ; Fri, 02 Feb 2024 06:20:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706883655; x=1707488455; 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=G2uxDw3rJ90QUP0VxxcGcpNUOmy7xFkn/uZBFq7Dat0=; b=IT3gVBuP2IECVnhD3Maj+kZV2O4DjpXwolcAdUMSyCdbUxvRs9Q171i0AIfCSlW6Vc kXGeL0kSX6FGz6aAhuGzJhACxvURsuGuFXO2PvhoHLNZ40429V81jqDBr0ozeI3PUW9N 9sZaX24WdYCIWxoHupjr/x8tMaMMOiqL8+5t+eMfBd9qNcqGvYo3+xfSVgrwEKoGP1Z5 y1hb0kGJUc9TjCguhYNWCvfC8rU1aKOOdiN9IJHEZsHlFhhdteIYoAXBIBZTloFE+2Yk TN1rMtSo0jauhqY2xxTsVHXv+8AiIhv5pTmWnWMaPdex1Db5na4ApBmv/bYEnHqMFhPe fIaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706883655; x=1707488455; 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=G2uxDw3rJ90QUP0VxxcGcpNUOmy7xFkn/uZBFq7Dat0=; b=rCW9/pFFUUv/eL4R3is5S5fr7mSozt9Ram9Qduut9jB073+pivVRYIrhBbjnZPdsYU 8ipV5PVXftLn8IusaPDn7lodDuSwxR/MLAfp1qzrwse9UvPdN5jRgoKmakl6xPtPbFXX uCIkJUaKmcaxWbm4wTyuzy4JV4TVhcNqLMsQDhjnm+c4rFn1Q+EsUHoucfdA+xzPzNh8 YhKO0YiFnHixGT3JD+JXHIFL0pq/fzSOAUneLAfRjN4pb4wbfzklUlI2JOxXZG5f7gkz MlJY+tSll2klQmXj3qcR3OQpS6Ei5ERVx8dkctJXu3ZlmGSXiEJaE7J64U4KlRzcI3oj OzfA== X-Gm-Message-State: AOJu0YyIfrWIWwPQLeLj2/x4VIixZKWN39XJ3dEzYF/mK5BUsRzGU/Ay MyDfloeuYkzW3osLC7qEUQ8Xeb/snYtgDmRA+N4r5+bJ0ldnzw17D/M99svNJ5Z8iIg8xZJdh35 VYzx1erissk9LAmvE8y/b/MWoI3c= X-Google-Smtp-Source: AGHT+IEqf50LUjBPwdqZ6TbQazL+K8tUNpZi9E1X57Kcl7GuX7fVtf0lcgQoMT07e0dTsdejuuiLqXiT8bdHYXwZ2mQ= X-Received: by 2002:a25:ce43:0:b0:dc2:3c31:8f85 with SMTP id x64-20020a25ce43000000b00dc23c318f85mr8010365ybe.47.1706883655275; Fri, 02 Feb 2024 06:20:55 -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:20:40 +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: rspam12 X-Rspamd-Queue-Id: 45B6E140004 X-Stat-Signature: 6ickiz3bz9g58jtoq7jzz7pyh8y5fxjb X-HE-Tag: 1706883656-862120 X-HE-Meta: U2FsdGVkX19+pEYnyEIcQs6a61e9NV3rC9nVnfaSs7bbwrmc4uaRH2TCf3nFZGjzmsjeFGmJdmtMHe1EQHo68QPwBnu5TjlnX8jTC90Bdyil/TcRE5DvoZ4GFlZpB92sCbVT9VIz1y5wIKN7mTtnSRWZOFNxP/CSAWCrTq9PQhT9ANHomp41E7PTCkkcDyV4D/60TXK6VAIUBkxhDEhRTN871O8M+H0l/sRdW/dYLb4gKT4C0tmiO6bFKKPe4uahpwGmr+IEsuFmgA+26pjwRwWhFhU8/R+x3vlLinqxn5H2qWkN4sgnfLc7SjxMZ7h6KcBF3aRpzLkgla0qHtEzAkmHVhteRVMyHxTVSeF9Rn7i+VAlFcSy7ZeTUwqtXrBvpdmf9sMb4Vcrd700x9vQBxvH7cTIBsTfRmKBgXghcB9OCLaHmvMyo8XRpb+yZEqt7Jjpg8iHxcMflWam7O/oMnv3iMYg08WAWxmRBsbBgrcmKRastOBmz7JeJQ+ALOrbx0RUsrBLuZVb98NFKgqMfxM5RDkb3tQloFZYEW4BHa5S9DkWsG7TJ+C4UunmfQ/1xXJo7lmDa6E3EEc2CjPKSFAPy/z0ED/L6oIDQjulouLnZ0mVU42VMgb1KFbixEiVGTld3xAtrjnSnEvesehiKtle+CHO8HIbDXxvxU6Qgcvk4b0Bji+PyQt6hSBZdR/xIxSUNl0IJ09nQTRRpqMYBloe0itn+oBeHRHfBms+F2BVmLeIiud7sI5NzmvLpQeLyQi7ANnNAOFqxi9xqaCf0WhQ7IfUcKfaJJyUqdNQk1/ETNQNQcjVX5zq+3GC7wN9zVvMjQKZv0k5OpOa3ma6IFUIekY6JT90s7m+apAQId+khO+u4dzUT0+0pL8ghl+yTOyqv9NsyXKUuQQIIPFchhdtvXjcTR4QOs8BzMiWq/dup2yeXCX4RLkIVvaTpEWFF4NaKcnzx2+hMpG2bMc Vo/gNt5H 3+1Q8yoaAD4slEjVOnP8HgJu8lWUX9JdQmcKMdXssCw6jylo5LNTDeIvfjsvVHUNNfJNwHX1+CrY8oLUdIuS876ju0lAfTo99BDMydenScXhHuTJMQffdcx+Ax8Tsh/Vk7O6j9ntdScgcVH2icZIvz9/fPGq1af/lqweTjGRMNvl63gv1+5kVBSNdga4Q8h/2HWb7yhTkzuNDk4b88uaE5pegU0d+9O8DmCf0SqO+BWb63QLeCKNQ3yTuSiLsWmgIY4toafIPwc3xyTM6xWBYnD5/7PUEbXIchf6dBNFiJdJ1/Ua5pt7TOKE57EZ/H1dELPeb0esc6hi+7mGTJTYnTXjJpo+ao8xEm18RKCTTFKcyqXQAz6RwMzlk/PoHL/zUsnhiZq/DpNWujz3uyHATg/dV249i2xXISvhsBeFlnWpHjvAiwPKNEC3ong== X-Bogosity: Ham, tests=bogofilter, spamicity=0.001142, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: I'd like to add one more point. Users mark pages as lazyfree with MADV_FREE, expecting these pages to be reclaimed until memory pressure occurs. Currently, khugepaged treats lazyfree pages the same as pte_none, which seems reasonable. IMO, avoiding the copying of these pages to the new huge page during khugepaged collapse can better keep the semantics of MADV_FREE. It appears that lazyfree pages are reclaimed before khugepaged collapses them. Thanks, Lance On Fri, Feb 2, 2024 at 9:46=E2=80=AFPM Lance Yang wro= te: > > 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. 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. > > Thanks, > Lance > > On Fri, Feb 2, 2024 at 8:57=E2=80=AFPM Michal Hocko wro= te: > > > > On Fri 02-02-24 20:52:48, Lance Yang wrote: > > > On Fri, Feb 2, 2024 at 8:27=E2=80=AFPM Michal Hocko = wrote: > > > > > > > > On Fri 02-02-24 19:18:31, Lance Yang wrote: > > > > > IMO, since it's treated the same as pte_none, > > > > > perhaps lazyfree pages shouldn't be copied to > > > > > the new huge page. > > > > > > > > Why? The content of MADV_FREE page is valid until it is reclaimed. > > > > > > IMO, if MADV_FREE pages are considered valid until > > > reclaimed, treating them the same as pte_none might > > > pose a conflict. > > > > What kind of conflict? > > -- > > Michal Hocko > > SUSE Labs