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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E40DC433F5 for ; Mon, 25 Oct 2021 19:59:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62D9060C4A for ; Mon, 25 Oct 2021 19:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239040AbhJYUB1 (ORCPT ); Mon, 25 Oct 2021 16:01:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:42704 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239542AbhJYT5J (ORCPT ); Mon, 25 Oct 2021 15:57:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 803D361152; Mon, 25 Oct 2021 19:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635191213; bh=r8cSDJtgsROUmIHtz5+qJhizqs/JF3DnIj86G3u4u8I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nk+3vvX641068w4FvV2E94vqVaoccjVmcfyjWX5NPyWcsKEVlYNh0XD+B1hIviom5 SwfvAcjHER9igAGyPDK0NGtj9oTRwO5SNT+JulrjjUW87ADUJ7Lf3XNzjIBFH9ylSK bijetQ2/9xxHVPkV2Ja+O1JZa9ljGwjeOiem91D8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marek Szyprowski , "Matthew Wilcox (Oracle)" , Yang Shi , sfoon.kim@samsung.com, Song Liu , Rik van Riel , "Kirill A . Shutemov" , Johannes Weiner , Hillf Danton , Hugh Dickins , William Kucharski , Oleg Nesterov , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.14 153/169] mm/thp: decrease nr_thps in files mapping on THP split Date: Mon, 25 Oct 2021 21:15:34 +0200 Message-Id: <20211025191036.865976319@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025191017.756020307@linuxfoundation.org> References: <20211025191017.756020307@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marek Szyprowski [ Upstream commit 1ca7554d05ac038c98271f8968ed821266ecaa9c ] Decrease nr_thps counter in file's mapping to ensure that the page cache won't be dropped excessively on file write access if page has been already split. I've tried a test scenario running a big binary, kernel remaps it with THPs, then force a THP split with /sys/kernel/debug/split_huge_pages. During any further open of that binary with O_RDWR or O_WRITEONLY kernel drops page cache for it, because of non-zero thps counter. Link: https://lkml.kernel.org/r/20211012120237.2600-1-m.szyprowski@samsung.com Signed-off-by: Marek Szyprowski Fixes: 09d91cda0e82 ("mm,thp: avoid writes to file with THP in pagecache") Fixes: 06d3eff62d9d ("mm/thp: fix node page state in split_huge_page_to_list()") Acked-by: Matthew Wilcox (Oracle) Reviewed-by: Yang Shi Cc: Cc: Song Liu Cc: Rik van Riel Cc: "Kirill A . Shutemov" Cc: Johannes Weiner Cc: Hillf Danton Cc: Hugh Dickins Cc: William Kucharski Cc: Oleg Nesterov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/huge_memory.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index afff3ac87067..163c2da2a654 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2724,12 +2724,14 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) if (mapping) { int nr = thp_nr_pages(head); - if (PageSwapBacked(head)) + if (PageSwapBacked(head)) { __mod_lruvec_page_state(head, NR_SHMEM_THPS, -nr); - else + } else { __mod_lruvec_page_state(head, NR_FILE_THPS, -nr); + filemap_nr_thps_dec(mapping); + } } __split_huge_page(page, list, end); -- 2.33.0