From patchwork Fri Jul 21 09:40:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yin Fengwei X-Patchwork-Id: 13321706 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 9B9F8C0015E for ; Fri, 21 Jul 2023 09:41:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0AC7C2801AA; Fri, 21 Jul 2023 05:41:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 05C4B2801A0; Fri, 21 Jul 2023 05:41:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E65082801AA; Fri, 21 Jul 2023 05:41:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D44432801A0 for ; Fri, 21 Jul 2023 05:41:36 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9CD90A01F8 for ; Fri, 21 Jul 2023 09:41:36 +0000 (UTC) X-FDA: 81035126592.03.3B02C44 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf11.hostedemail.com (Postfix) with ESMTP id C13604000E for ; Fri, 21 Jul 2023 09:41:33 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TaEZ6oBe; spf=pass (imf11.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689932494; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=3bumhKFXrfyvrg7KghAQ8mN9tzuOPDO6zjZ0tUbtuGs=; b=3g321NjAuX9VP2NfU3YQEjtlxEN70kkdPzY6i8DkQVvT65bqXexS0oCUbcL3Z3FlJzaf9Y BniOFZ8kfB3vBSbB1W9RLragBY3C0gIV8RnfGRutvCsKy/KCteWvH7SpwyR8PIF+h+xkoy 2eRa4gBHkWqXkdjmDTn5jkwi6Fw8i8Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689932494; a=rsa-sha256; cv=none; b=6ZpzndmIC1GMHBf0AgnFRyjL05trZTh/YBewkURT+rZgsu8AHXOqX4U0N8+YQ92Plr9SY8 mKS3IIPUZIvtk5m7azzk5WXPh4lHgrm5YKeAYJxeFXbOj1BvVIs0ge/Yjeq96qwUFUZbsm 7fCu9tLh6T7viQqakssoEfe5aTnUPsU= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=TaEZ6oBe; spf=pass (imf11.hostedemail.com: domain of fengwei.yin@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=fengwei.yin@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689932493; x=1721468493; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=H304vXECtyRsfk6v2x0l77glnv4jXjPUELnt58/Aiuk=; b=TaEZ6oBeUp6lqyOgsuaSg373OJENmU9NPhkomt8OupABafsm3tFaRveI vkuw3gvijU/9dZyqpCrJbrFF7biSh8NaVKOgKKFD+PgjuWXqYd/dOSe16 PTIsVQzJih4CsiR0+iRmHDSUYLxlmEazaMrk2DTQuc1zEzycR6FS1YzIR QkusEuBRJfy488yuL4AskDGcw/C3uw06EkTEXaf3euywOIGZivA+Yg8VZ p9VSCL2PEcR+fk39l/Dub1rIxyh1aRXDpgHmLPNISj2Uga/2wk3LCamQq FRM4yTt6a0xOfSxIQNjTWxncD9ngm6T39bMHF5Czi6X2EEAiF2NV/nvRu g==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="397874272" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="397874272" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 02:40:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="898660994" X-IronPort-AV: E=Sophos;i="6.01,220,1684825200"; d="scan'208";a="898660994" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by orsmga005.jf.intel.com with ESMTP; 21 Jul 2023 02:40:32 -0700 From: Yin Fengwei To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, minchan@kernel.org, yuzhao@google.com, willy@infradead.org, david@redhat.com, ryan.roberts@arm.com, shy828301@gmail.com Cc: fengwei.yin@intel.com Subject: [RFC PATCH v2 0/4] fix large folio for madvise_cold_or_pageout() Date: Fri, 21 Jul 2023 17:40:39 +0800 Message-Id: <20230721094043.2506691-1-fengwei.yin@intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Rspamd-Queue-Id: C13604000E X-Rspam-User: X-Stat-Signature: i7zex79cf4yz5t9649ob5j94auu5dbe8 X-Rspamd-Server: rspam03 X-HE-Tag: 1689932493-740773 X-HE-Meta: U2FsdGVkX1/zBW4GGACM2+zL+WW3nnSVOFcMzkx5FsdUTKISLs8mrhWsqLGJ3U+Gr1Po9eLhkSoIrPOoXnWcED8XhKdG4FHxtRYMBxSIYGhfnVg38JKwpO8aG5vk45aQJm+RWbLz/LGNaFLiuTRFZcNZsfREu9QAVUXKY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-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Current madvise_cold_or_pageout_pte_range() has two problems to deal with large folio: - Using folio_mapcount() with large folio prevent large folio from picking up. - always try to split large folio to normal 4K page. Try to address these two problems by: - Use folio_estimated_sharers() with large folio. With assumption that the estimated result of whether the large folio is shared or not is enough here. - If the large folio is in the range, don't split it. Leave to page reclaim as page reclaim can support swap large folio out as whole in the future. - Only split the large folio if it crosses the boundaries of the range. If folio splitting fails, just skip the folio as madvise allows some pages in the range are ignored. Patch1 uses folio_estimated_sharers() to replace folio_mapcount(). Patch2 uses API pmdp_clear_flush_young_notify() to clear A bit of page table. It also notifies the mm subscripter about the A bit clearing. Patch3 introduce help function to check whether the folio crosses range boundary. Patch4 avoid splitting large folio if folio is in the range. Changes from V1: - Split patch1 out as Yu's suggestion - Split patch2 out as Yu's suggestion - Handle cold case correctly (cold operation was broken in V1 patch) - rebase the patchset to latest mm-unstable Testing done: - mm selftest without new regression. V1's link: https://lore.kernel.org/linux-mm/20230713150558.200545-1-fengwei.yin@intel.com/ Yin Fengwei (4): madvise: not use mapcount() against large folio for sharing check madvise: Use notify-able API to clear and flush page table entries mm: add functions folio_in_range() and folio_within_vma() madvise: avoid trying to split large folio always in cold_pageout mm/internal.h | 42 ++++++++++++++++ mm/madvise.c | 136 +++++++++++++++++++++++++++++++------------------- 2 files changed, 127 insertions(+), 51 deletions(-)