From patchwork Mon Oct 18 22:16:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12568209 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 AA362C433FE for ; Mon, 18 Oct 2021 22:16:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 61BBA60F57 for ; Mon, 18 Oct 2021 22:16:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 61BBA60F57 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0CAE5940014; Mon, 18 Oct 2021 18:16:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 053A9940007; Mon, 18 Oct 2021 18:16:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3604940014; Mon, 18 Oct 2021 18:16:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0046.hostedemail.com [216.40.44.46]) by kanga.kvack.org (Postfix) with ESMTP id CE532940007 for ; Mon, 18 Oct 2021 18:16:21 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 93BEE82499A8 for ; Mon, 18 Oct 2021 22:16:21 +0000 (UTC) X-FDA: 78710967762.12.4E84620 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf15.hostedemail.com (Postfix) with ESMTP id 57A38D00009A for ; Mon, 18 Oct 2021 22:16:18 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id C63396115A; Mon, 18 Oct 2021 22:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1634595380; bh=FCtV4rn/6sadmJF0aTEsgk1hqjFn5VJOJwh/dNESo0o=; h=Date:From:To:Subject:In-Reply-To:From; b=06d1jAX3902/IuyPNfCxU6SPQtwy8OF01SxN+Z3ppN3usmdi7twPBIXt7YFfrBgS/ nrMIWkUxIEG4dsdaw3JhfcXqACHGYocti+lLK0qiEsfx+gBwI284FIFvgF0ARn90a7 O5HucgCY3m+4GAT7tZCaKdbBJXADXNNsjvPAvVeA= Date: Mon, 18 Oct 2021 15:16:19 -0700 From: Andrew Morton To: akpm@linux-foundation.org, hannes@cmpxchg.org, hdanton@sina.com, hughd@google.com, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, m.szyprowski@samsung.com, mm-commits@vger.kernel.org, oleg@redhat.com, riel@surriel.com, sfoon.kim@samsung.com, shy828301@gmail.com, songliubraving@fb.com, torvalds@linux-foundation.org, william.kucharski@oracle.com, willy@infradead.org Subject: [patch 18/19] mm/thp: decrease nr_thps in file's mapping on THP split Message-ID: <20211018221619.39ukJuTKQ%akpm@linux-foundation.org> In-Reply-To: <20211018151438.f2246e2656c041b6753a8bdd@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 57A38D00009A X-Stat-Signature: y8mujxd8icayeudu3pze3hn7phcd3bpy Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=06d1jAX3; dmarc=none; spf=pass (imf15.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1634595378-371303 X-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: From: Marek Szyprowski Subject: mm/thp: decrease nr_thps in file's mapping on THP split 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, where one runs a big binary, kernel remaps it with THPs, then one forces 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 --- mm/huge_memory.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/mm/huge_memory.c~mm-thp-decrease-nr_thps-in-files-mapping-on-thp-split +++ a/mm/huge_memory.c @@ -2700,12 +2700,14 @@ int split_huge_page_to_list(struct page 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);