From patchwork Thu Dec 14 22:27:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianfeng Wang X-Patchwork-Id: 178941 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8891675dys; Thu, 14 Dec 2023 14:28:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFAX2NZOQO0xtVAXG4wBXKosODe4Bgds3z6HGRK2W7KcC/2KnuUfWWoX6d1xsyMt/kX0P5a X-Received: by 2002:a05:6122:20a5:b0:4ab:f40f:c50 with SMTP id i37-20020a05612220a500b004abf40f0c50mr8467677vkd.10.1702592900714; Thu, 14 Dec 2023 14:28:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702592900; cv=none; d=google.com; s=arc-20160816; b=buU8fwcuwIrIIgILIAZHQx6qLQpmDDRX7CXE8zRbl9KIJcJqvJ1LjF+m1fsLwbTK7P Au1rJmgkrbWQlWMdnngGMOOoTZplqjGKbw5tjPapP2tQ/Rqz4qRjkU1sjKqHZ1cHwpH5 Qfv5GLcf0lV1heO94NHYAQE17GG4z5gx+/3DHclV8GZYRrH3ndHKqNfeK1qQnkgj5ibs EOwK568O3sojCQh8yjCM2Mv+IIzMu96PVdI7qqgSmaVivvzf7h3Qvpj8hC8yG+1mS4Jm uBfNGCfR5N6zVDIsoTZ0oED/QHIit1ZYwy8MUjRGc8wEoPWl/Zm7VfudAeLBE3aGawbE +dQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=vWebtL2rhfE1sZveziVMAIBgy0M/wp/MnldOKJtCGJA=; fh=mQjI9cbiCKBl8nxHY1zqw1wNKG+kPVhK81Xrlrz1z08=; b=yEkqwD76mddtZdRyT8aeoTQYJYG/taE8XGbDnY6y+4O6oXUy1bC3Chw2saVZfUjbWV aFTaSCBL1/NfYYWmW53Y7qb0da+XReK+RDN3NfNowX2dYp7ZDXz/MpNvpvOqAD9m0snT 1ORERQxn9RUhpPPFBZvxjpXAc29bEv6H/K7E/5x5cjCD2c1BNMh+6jgTnaEgE3CrCmPt e0DDnywGL8q3YPBl2lPWcJbTtemghBbcFtMC18ytH3tWxUqamYyx4Z0e8gnR1xqGhS1A eNAVLcT35nVImyH7UJlDz78kfD5wfGAA2oW6MZYW3kyWzkmxIbBO0yNIq4hrKtBdOJiD u8EA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=Gx18r61u; spf=pass (google.com: domain of linux-kernel+bounces-190-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id p6-20020a05620a22a600b007725a68ea34si5904504qkh.89.2023.12.14.14.28.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 14:28:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=Gx18r61u; spf=pass (google.com: domain of linux-kernel+bounces-190-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0CFE01C21DF6 for ; Thu, 14 Dec 2023 22:28:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B22622C69B; Thu, 14 Dec 2023 22:27:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Gx18r61u" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1614467216 for ; Thu, 14 Dec 2023 22:27:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BEMHP2J032548; Thu, 14 Dec 2023 22:27:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2023-11-20; bh=vWebtL2rhfE1sZveziVMAIBgy0M/wp/MnldOKJtCGJA=; b=Gx18r61ud07Dn6edn9pWwaJ7Z63e0Kz9zITNQAXzM0QfCuGWEI90KvM7sS4J0Dh5GxEL UGMtJreLR2/0op/a1T3XQ+z6JWTJrkLd61aj7rU6OajKxZ8siqrOkW73yEdN2T89ektb //FuSiaGwXxFikHP50hwbuFwWSzt+QY9q3U+zmaN2Vz6PwcHMsi0270MYEi6QL7n4ybv hUqlLV7pS+lencdsArH6e1iRvIwRgwwPO7BP7yWQWkXUvMOS5unrLiRC1tZz0o/KqoqK ljlY1leGL10IqEcKY4Im1bMXEp3w1KsGePr9jWaKyPrpMaFejUYZqQsehQXb3lk+osZH 7Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3uvgsum0rw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Dec 2023 22:27:20 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3BELD9D8008284; Thu, 14 Dec 2023 22:27:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3uvepaug4d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Dec 2023 22:27:19 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3BEMRImB001139; Thu, 14 Dec 2023 22:27:19 GMT Received: from jfwang-mac.us.oracle.com (dhcp-10-65-130-157.vpn.oracle.com [10.65.130.157]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3uvepaug41-1; Thu, 14 Dec 2023 22:27:18 +0000 From: Jianfeng Wang To: akpm@linux-foundation.org Cc: tim.c.chen@linux.intel.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Jianfeng Wang Subject: [PATCH v2] mm: remove redundant lru_add_drain() prior to unmapping pages Date: Thu, 14 Dec 2023 14:27:17 -0800 Message-ID: <20231214222717.50277-1-jianfeng.w.wang@oracle.com> X-Mailer: git-send-email 2.42.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-14_15,2023-12-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312140159 X-Proofpoint-ORIG-GUID: 7K-1cvQBvkGHX_8Z6IKaJyasvuhRD8p7 X-Proofpoint-GUID: 7K-1cvQBvkGHX_8Z6IKaJyasvuhRD8p7 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785150857765127288 X-GMAIL-MSGID: 1785298053495510424 When unmapping VMA pages, pages will be gathered in batch and released by tlb_finish_mmu() if CONFIG_MMU_GATHER_NO_GATHER is not set. The function tlb_finish_mmu() is responsible for calling free_pages_and_swap_cache(), which calls lru_add_drain() to drain cached pages in folio_batch before releasing gathered pages. Thus, it is redundant to call lru_add_drain() before gathering pages, if CONFIG_MMU_GATHER_NO_GATHER is not set. Remove lru_add_drain() prior to gathering and unmapping pages in exit_mmap() and unmap_region() if CONFIG_MMU_GATHER_NO_GATHER is not set. Note that the page unmapping process in oom_killer (e.g., in __oom_reap_task_mm()) also uses tlb_finish_mmu() and does not have redundant lru_add_drain(). So, this commit makes the code more consistent. Signed-off-by: Jianfeng Wang --- mm/mmap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index 1971bfffcc03..da0308eef435 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2330,7 +2330,10 @@ static void unmap_region(struct mm_struct *mm, struct ma_state *mas, struct mmu_gather tlb; unsigned long mt_start = mas->index; + /* Defer lru_add_drain() to tlb_finish_mmu() for the ifndef case. */ +#ifdef CONFIG_MMU_GATHER_NO_GATHER lru_add_drain(); +#endif tlb_gather_mmu(&tlb, mm); update_hiwater_rss(mm); unmap_vmas(&tlb, mas, vma, start, end, tree_end, mm_wr_locked); @@ -3300,7 +3303,10 @@ void exit_mmap(struct mm_struct *mm) return; } + /* Defer lru_add_drain() to tlb_finish_mmu() for the ifndef case. */ +#ifdef CONFIG_MMU_GATHER_NO_GATHER lru_add_drain(); +#endif flush_cache_mm(mm); tlb_gather_mmu_fullmm(&tlb, mm); /* update_hiwater_rss(mm) here? but nobody should be looking */