Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3746034rwb; Mon, 7 Aug 2023 20:18:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdUuFEgN2JvL1kZgaF3IiI9INjfVDXMc7bNnQRjMhePYzFMai4ChNecuxk+roN3T0dE6GS X-Received: by 2002:a05:6402:7d1:b0:522:30cc:a1eb with SMTP id u17-20020a05640207d100b0052230cca1ebmr7760422edy.0.1691464685397; Mon, 07 Aug 2023 20:18:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691464685; cv=none; d=google.com; s=arc-20160816; b=ZMXxw2YVhyYvn+0g/cdQwXh/ACM5gh+1ZSl0e8duZrOwQNI4ydhvopPpi9VC02QtPG sP9v2B96tsk3Zp/8+hkzZzt1eQZcOorbLCYxmZQMaTJ6mOC60/YxfToESdZdRAhDghpy mpFCpxFNX65XI9OieHMA5QcWAVtuE0cGVM0AthxRmWXIOJfSmkXN3WdvbgFMWaDOwM6E qn9ppNUOa6v2Wupt8eRAD9ROFLAOdG/Ycq9EZET+3kYEs6wcnfoqD+g1V317BnrMa07d 8kfiRIbiB7tb6g2dmRL4evYn7+qWMtCzeK/9kLaJQEWQQs1V0GsW/DLOboDIzHBbByB8 hudw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=nxIcTJJIcuoAgpAn/H1eWO64VvlSIo1Dt/soZB9CeDA=; fh=LgrQy7mqd4cTuAw7dlguzqzf4K4OZS27s5hhhI8E0EA=; b=eD64ViyFgOcfrengAbedeeNGQUTFo31S84BzD1wE4Zun8Nm0enHuuczIYQfKRyq4DZ fZe5D1qUN86Jj2BKugEDSE+nqXmoXKNDb6c/FPpvCofP6eB1XUKedke2lkM3oVkCnU07 4FgvV0SM1ZfVzygmAYown/nwcdTTpXBcmUtZrch0+B3t8B6xDRmSURsoG1ZbwfjyA6YE W70pln02fYAFIHzQvRSUehAaWGo02WTyxywjm5TFEqizjsmpC6V0sZIUi5FHTCZy8QeO jhRIZ4KhK/sr3YwNUMKXoo5HW2UC0DsGhhnbO+Iu4wMr47/tI0l2W53NWXQ+Q4ocIcZH 354A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DcCY8Bn9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g16-20020a50ee10000000b005233795f440si2458225eds.359.2023.08.07.20.17.40; Mon, 07 Aug 2023 20:18:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DcCY8Bn9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230003AbjHHCKl (ORCPT + 99 others); Mon, 7 Aug 2023 22:10:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbjHHCKk (ORCPT ); Mon, 7 Aug 2023 22:10:40 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61F471705; Mon, 7 Aug 2023 19:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691460639; x=1722996639; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=uG3NDhRuxMTWT3J/vbhAok1ojRTKKVWwCGRMvfusbWg=; b=DcCY8Bn9iHb5VsmXZA25CMrZDFlZ6g2R15J4fM825oa8AdoVmmf7MaOG qMj3CB11vvBap5fLTZEBYFNOWa28WBWy3vtoG0M41D1IkpUqEo/diM/Ro 1PHeTPaCcPmn2hQnnyaLJuP8Zc5BIVTyFYv5wIfOeB2r8e9g/QM7JBJOz /D735laJ1QTvbD8etAJDItBT9TzRuGNripRDz//qvMzm5j1ca5pckwR5a zUGCBDb8C89DS8TbDJdtooeXY7a2U4XLnOLQA3v+7xcz9HDfZvTn2bKAX ZS134BT9366UIwBmav4NZ9a88Sq/oeVYx/lOhcf7xdgJQtudx6gylzmp8 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="360786307" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="360786307" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Aug 2023 19:10:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10795"; a="1061813239" X-IronPort-AV: E=Sophos;i="6.01,263,1684825200"; d="scan'208";a="1061813239" Received: from fyin-dev.sh.intel.com ([10.239.159.32]) by fmsmga005.fm.intel.com with ESMTP; 07 Aug 2023 19:10:35 -0700 From: Yin Fengwei To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, akpm@linux-foundation.org, willy@infradead.org, vishal.moola@gmail.com, wangkefeng.wang@huawei.com, minchan@kernel.org, yuzhao@google.com, david@redhat.com, ryan.roberts@arm.com, shy828301@gmail.com Cc: fengwei.yin@intel.com Subject: [PATCH v2 0/3] don't use mapcount() to check large folio sharing Date: Tue, 8 Aug 2023 10:09:14 +0800 Message-Id: <20230808020917.2230692-1-fengwei.yin@intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In madvise_cold_or_pageout_pte_range() and madvise_free_pte_range(), folio_mapcount() is used to check whether the folio is shared. But it's not correct as folio_mapcount() returns total mapcount of large folio. Use folio_estimated_sharers() here as the estimated number is enough. This patchset will fix the cases: User space application call madvise() with MADV_FREE, MADV_COLD and MADV_PAGEOUT for specific address range. There are THP mapped to the range. Without the patchset, the THP is skipped. With the patch, the THP will be split and handled accordingly. David reported the cow self test skip some cases because of MADV_PAGEOUT skip THP: https://lore.kernel.org/linux-mm/9e92e42d-488f-47db-ac9d-75b24cd0d037@intel.com/T/#mbf0f2ec7fbe45da47526de1d7036183981691e81 and I confirmed this patchset make it work again. Changelog from v1: - Avoid two Fixes tags make backport harder. Thank Andrew for pointing this out. - Add note section to mention this is a temporary fix which is fine to reduce user-visble effects. For long term fix, we should wait for David's solution. Thank Ryan and David for pointing this out. - Spell user-visible effects out. Then people could decide whether these patches are necessary for stable branch. Thank Andrew for pointing this out. V1: https://lore.kernel.org/linux-mm/9e92e42d-488f-47db-ac9d-75b24cd0d037@intel.com/T/#med74caad0cbd0049641cfddc5b9fe793b4b50276 Yin Fengwei (3): madvise:madvise_cold_or_pageout_pte_range(): don't use mapcount() against large folio for sharing check madvise:madvise_free_huge_pmd(): don't use mapcount() against large folio for sharing check madvise:madvise_free_pte_range(): don't use mapcount() against large folio for sharing check mm/huge_memory.c | 2 +- mm/madvise.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) -- 2.39.2