From patchwork Tue Nov 28 05:07:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinayak Menon X-Patchwork-Id: 10078667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6D7F06056A for ; Tue, 28 Nov 2017 05:09:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EE0A29096 for ; Tue, 28 Nov 2017 05:09:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 621D5290A4; Tue, 28 Nov 2017 05:09:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B89C029096 for ; Tue, 28 Nov 2017 05:09:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=DFRQkVZjSmo8W9bW1dg/0JACxcljF3Mq3A/8SpSIm1Q=; b=B2W vRt8ACHrsdx+4u6nxkOIZCsUK+fS/9dUn9GvgboK56THyOn2hHEIEHsCrkZuX0pnPJLGdaBJgMTqp K8GYUX8eju0a9RF4nqvC8+Ybm1KNvDsRUejOSXcKqvZP4EWmjnX4EBnRQ6yCTBdg11bnftLh0mzvd oZfUm4Z78K36fXdONzDkVSSDaFEusz0s2DsFWTYSCJVFtnQxG4gD3AQ3Xqn/nSH00XcPWsAGf6IBV gpddt8UTBT+vlXFFuiHKLXGi9oylztTwu7JlxV9adSG7ZM2xYJNp7o/AwislGWDt5LEMW2NA1TIc1 ERW2tPGRlEwHiugTbzfY153QFTtj6kQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eJY8y-0002Ez-H7; Tue, 28 Nov 2017 05:09:16 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eJY8t-0002EW-KB for linux-arm-kernel@lists.infradead.org; Tue, 28 Nov 2017 05:09:14 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 4D5B46A382; Tue, 28 Nov 2017 05:08:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1511845730; bh=fy4GkGtM9cBaCxNRL35fie6nct4TIN2lwJyiczZGhe4=; h=From:To:Cc:Subject:Date:From; b=MyZSW+nyGeTApdj9Q0n98GUZ7k9YASQCBFg4L+oGfSY2B7liZ1R+n6ZS7WsIsV+Ql SccCzLdGMLxmanqEFmhdulFFXaDmgwnxLppKBM9EK5Clke2SRAZ5hNt6Hig8TWj7qv uJ+DTE3Kc5sjd8wCZcWCs+dLWnKq8/kimSEgZMPk= Received: from vinmenon-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vinmenon@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 1351E6A321; Tue, 28 Nov 2017 05:08:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1511845729; bh=fy4GkGtM9cBaCxNRL35fie6nct4TIN2lwJyiczZGhe4=; h=From:To:Cc:Subject:Date:From; b=iySGmHjYguBaNW/RnytJ9kaqnbSJFEkDelT9hnHba+t6XQwrZM82M0cu6t2Gn0PtY RoJYa28FMXYgxvoMD770qN2iezrWrBPkPj4Ff99Ej8wamtuvJsvSH9WZntjRZ5S4Am ivgAVJ+qJnm89ir49ZuDmREFFVDI3ilUIhtxjPws= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 1351E6A321 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vinmenon@codeaurora.org From: Vinayak Menon To: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Subject: [PATCH 1/2] mm: make faultaround produce old ptes Date: Tue, 28 Nov 2017 10:37:49 +0530 Message-Id: <1511845670-12133-1-git-send-email-vinmenon@codeaurora.org> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171127_210911_748120_F9076CE3 X-CRM114-Status: GOOD ( 16.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: riel@redhat.com, jack@suse.cz, catalin.marinas@arm.com, dave.hansen@linux.intel.com, will.deacon@arm.com, minchan@kernel.org, Vinayak Menon , mgorman@suse.de, ying.huang@intel.com, akpm@linux-foundation.org, torvalds@linux-foundation.org, kirill.shutemov@linux.intel.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Based on Kirill's patch [1]. Currently, faultaround code produces young pte. This can screw up vmscan behaviour[2], as it makes vmscan think that these pages are hot and not push them out on first round. During sparse file access faultaround gets more pages mapped and all of them are young. Under memory pressure, this makes vmscan swap out anon pages instead, or to drop other page cache pages which otherwise stay resident. Modify faultaround to produce old ptes, so they can easily be reclaimed under memory pressure. This can to some extend defeat the purpose of faultaround on machines without hardware accessed bit as it will not help us with reducing the number of minor page faults. Making the faultaround ptes old results in a unixbench regression for some architectures [3][4]. But on some architectures it is not found to cause any regression. So by default produce young ptes and provide an option for architectures to make the ptes old. [1] http://lkml.kernel.org/r/1463488366-47723-1-git-send-email-kirill.shutemov@linux.intel.com [2] https://lkml.kernel.org/r/1460992636-711-1-git-send-email-vinmenon@codeaurora.org [3] https://marc.info/?l=linux-kernel&m=146582237922378&w=2 [4] https://marc.info/?l=linux-mm&m=146589376909424&w=2 Signed-off-by: Vinayak Menon --- include/linux/mm-arch-hooks.h | 7 +++++++ include/linux/mm.h | 2 ++ mm/filemap.c | 4 ++++ mm/memory.c | 5 +++++ 4 files changed, 18 insertions(+) diff --git a/include/linux/mm-arch-hooks.h b/include/linux/mm-arch-hooks.h index 4efc3f56..0322b98 100644 --- a/include/linux/mm-arch-hooks.h +++ b/include/linux/mm-arch-hooks.h @@ -22,4 +22,11 @@ static inline void arch_remap(struct mm_struct *mm, #define arch_remap arch_remap #endif +#ifndef arch_faultaround_pte_mkold +static inline void arch_faultaround_pte_mkold(struct vm_fault *vmf) +{ +} +#define arch_faultaround_pte_mkold arch_faultaround_pte_mkold +#endif + #endif /* _LINUX_MM_ARCH_HOOKS_H */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 7661156..be689a0 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -302,6 +302,7 @@ extern int overcommit_kbytes_handler(struct ctl_table *, int, void __user *, #define FAULT_FLAG_USER 0x40 /* The fault originated in userspace */ #define FAULT_FLAG_REMOTE 0x80 /* faulting for non current tsk/mm */ #define FAULT_FLAG_INSTRUCTION 0x100 /* The fault was during an instruction fetch */ +#define FAULT_FLAG_MKOLD 0x200 /* Make faultaround ptes old */ #define FAULT_FLAG_TRACE \ { FAULT_FLAG_WRITE, "WRITE" }, \ @@ -330,6 +331,7 @@ struct vm_fault { gfp_t gfp_mask; /* gfp mask to be used for allocations */ pgoff_t pgoff; /* Logical page offset based on vma */ unsigned long address; /* Faulting virtual address */ + unsigned long fault_address; /* Saved faulting virtual address */ pmd_t *pmd; /* Pointer to pmd entry matching * the 'address' */ pud_t *pud; /* Pointer to pud entry matching diff --git a/mm/filemap.c b/mm/filemap.c index 693f622..63c7bf4 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "internal.h" #define CREATE_TRACE_POINTS @@ -2677,6 +2678,9 @@ void filemap_map_pages(struct vm_fault *vmf, if (vmf->pte) vmf->pte += iter.index - last_pgoff; last_pgoff = iter.index; + + arch_faultaround_pte_mkold(vmf); + if (alloc_set_pte(vmf, NULL, page)) goto unlock; unlock_page(page); diff --git a/mm/memory.c b/mm/memory.c index 24e9e1d..210dea3 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3398,6 +3398,10 @@ int alloc_set_pte(struct vm_fault *vmf, struct mem_cgroup *memcg, entry = mk_pte(page, vma->vm_page_prot); if (write) entry = maybe_mkwrite(pte_mkdirty(entry), vma); + + if (vmf->flags & FAULT_FLAG_MKOLD) + entry = pte_mkold(entry); + /* copy-on-write page */ if (write && !(vma->vm_flags & VM_SHARED)) { inc_mm_counter_fast(vma->vm_mm, MM_ANONPAGES); @@ -3527,6 +3531,7 @@ static int do_fault_around(struct vm_fault *vmf) pgoff_t end_pgoff; int off, ret = 0; + vmf->fault_address = address; nr_pages = READ_ONCE(fault_around_bytes) >> PAGE_SHIFT; mask = ~(nr_pages * PAGE_SIZE - 1) & PAGE_MASK;