From patchwork Tue Nov 8 19:41:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 17185 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2912360wru; Tue, 8 Nov 2022 11:43:05 -0800 (PST) X-Google-Smtp-Source: AMsMyM4/TQetrGJCjzMfORI2ipj9QdCgB4os+MUvIaxiCaixKrhEj61V4e63LDbpuRjs9A5fTyXO X-Received: by 2002:a17:902:e84f:b0:187:11a7:b1b with SMTP id t15-20020a170902e84f00b0018711a70b1bmr53290675plg.110.1667936585424; Tue, 08 Nov 2022 11:43:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667936585; cv=none; d=google.com; s=arc-20160816; b=nuOqEyMJJTBACuasKNppeFrMWjmikNkoGMxdQb3DcicOyhqH6IPr4ygKBJT/nJuRuv HHBZtttE5I8UIF4ExbNd2RA2raQFhxxbGVP8HjSGek7nQgMImdv6LtgKVfGSeSillMdx sIW3/j1Lqs4wwxEputGALaj8Ar5G7FdPnavRWnqFnQXaNXX2aSItomzy/Ip9qdavEgjV Cgs7vQyeFBO+i04fCxkrCSdm9Q5Rx0/+PS+Tkue8ovbry5+t1b+YB0BW0gv14e5t/+8F L1uEl12RNFJptkWuXBNeGWyyE7klibVnsUl37TXUBGnwG5TOKeMmDN86QOaCyHLwz5R3 pTMQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8OI8czoi2mMUk9oMqCzHuAbL+4plIcZ8aIr0PXVvTsQ=; b=xN6HWa7SDtHgCAElQD2eLPfmsiAEPUvbdQnvMIAHNnDuKU6tA9OCvewPYCJ0yOHirS Yfc7XCKTk2/fn5kKMkVIgImM7gkvZnmCRun9/rzPgY9KmPOyHctrqLTL4g/TDTcMC3aY guIFBGttbZ32FQjHL9PSiHt8P+cBK2Cf49xJKE3/5gNJBeQ+n0w8Rg64q+xesmcBDql5 ePpAKASeQ5z3zWib7Mb30yRCpIl9Wkps14xcIs1vPzJ8iLQtA1WfkEa5Qa1s77BzWwEp gvtsddp3gJgWB2qdNwKz8aRbGk29YjzW3fG0mGEiJo/Gd5FqR2zso3hwJvNtGN8AscM0 rSFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=YFGak0II; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h1-20020a170902f54100b00186ef861484si18388833plf.500.2022.11.08.11.42.51; Tue, 08 Nov 2022 11:43:05 -0800 (PST) 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=@linux-foundation.org header.s=korg header.b=YFGak0II; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229593AbiKHTln (ORCPT + 99 others); Tue, 8 Nov 2022 14:41:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbiKHTlm (ORCPT ); Tue, 8 Nov 2022 14:41:42 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C9B27057F for ; Tue, 8 Nov 2022 11:41:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 12F3661778 for ; Tue, 8 Nov 2022 19:41:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A040C433D6; Tue, 8 Nov 2022 19:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1667936500; bh=RaRVKzz9Se8UHTQHVas3xIYN6fbXJd+owd3hvoJX9dA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YFGak0IIB8Z5v2pn7OjlJtEcV0XXhvmCHnNCNbLCzZ6G1whB9cFSvgeUhqv5SuDma P+4d868qE3obUsgf8P8GfisLxpybgkUMc691B5zG7EOEdcWmOsYtuQvIQMlOSXHEFG nKrvrW3TQmBTfeLCpKJ2Tpw9NnbfS61++EIdjMvA= From: Linus Torvalds To: Hugh Dickins , Johannes Weiner , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/4] mm: introduce 'encoded' page pointers with embedded extra bits Date: Tue, 8 Nov 2022 11:41:36 -0800 Message-Id: <20221108194139.57604-1-torvalds@linux-foundation.org> X-Mailer: git-send-email 2.38.1.284.gfd9468d787 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748958273313708342?= X-GMAIL-MSGID: =?utf-8?q?1748958273313708342?= We already have this notion in parts of the MM code (see the mlock code with the LRU_PAGE and NEW_PAGE) bits, but I'm going to introduce a new case, and I refuse to do the same thing we've done before where we just put bits in the raw pointer and say it's still a normal pointer. So this introduces a 'struct encoded_page' pointer that cannot be used for anything else than to encode a real page pointer and a couple of extra bits in the low bits. That way the compiler can trivially track the state of the pointer and you just explicitly encode and decode the extra bits. Signed-off-by: Linus Torvalds --- include/linux/mm_types.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 500e536796ca..b5cffd250784 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -67,7 +67,7 @@ struct mem_cgroup; #ifdef CONFIG_HAVE_ALIGNED_STRUCT_PAGE #define _struct_page_alignment __aligned(2 * sizeof(unsigned long)) #else -#define _struct_page_alignment +#define _struct_page_alignment __aligned(sizeof(unsigned long)) #endif struct page { @@ -241,6 +241,37 @@ struct page { #endif } _struct_page_alignment; +/** + * struct encoded_page - a nonexistent type marking this pointer + * + * An 'encoded_page' pointer is a pointer to a regular 'struct page', but + * with the low bits of the pointer indicating extra context-dependent + * information. Not super-common, but happens in mmu_gather and mlock + * handling, and this acts as a type system check on that use. + * + * We only really have two guaranteed bits in general, although you could + * play with 'struct page' alignment (see CONFIG_HAVE_ALIGNED_STRUCT_PAGE) + * for more. + * + * Use the supplied helper functions to endcode/decode the pointer and bits. + */ +struct encoded_page; +#define ENCODE_PAGE_BITS 3ul +static inline struct encoded_page *encode_page(struct page *page, unsigned long flags) +{ + return (struct encoded_page *)(flags | (unsigned long)page); +} + +static inline bool encoded_page_flags(struct encoded_page *page) +{ + return ENCODE_PAGE_BITS & (unsigned long)page; +} + +static inline struct page *encoded_page_ptr(struct encoded_page *page) +{ + return (struct page *)(~ENCODE_PAGE_BITS & (unsigned long)page); +} + /** * struct folio - Represents a contiguous set of bytes. * @flags: Identical to the page flags. From patchwork Tue Nov 8 19:41:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 17187 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2912538wru; Tue, 8 Nov 2022 11:43:39 -0800 (PST) X-Google-Smtp-Source: AMsMyM7xBSvlsHBxfeaOFNudZHdoWW4gCazOTPsixaUngZX29xcEX760b7tQXQxuhPKWAQCNazf3 X-Received: by 2002:a17:902:e84d:b0:186:e777:982a with SMTP id t13-20020a170902e84d00b00186e777982amr58055984plg.83.1667936619141; Tue, 08 Nov 2022 11:43:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667936619; cv=none; d=google.com; s=arc-20160816; b=wgC8Pv/Gizy8tferUSjH3nF8/2Vbn9lE6f4yMPHYvNalevn00SYeGMLDL3RptJOx7L nZWtLilAB1TEI2SMYfs0cqNGSXf96vz0mVAPgwQ+vbw8WOgYH0uyYYYatTCkV+Obuj/x rjyZeIopQmlPWAm6G2d/5BBonjqgIgaHgM6BG+Ys9YLDxKXMfzUcqwBO3mqxzJ3fFobu gq1/EWT+sqCkSMFfFsf+RJb9VO8VTLTIKNgIDnJzBlaP2Lb+KxMP351ZOgpk+jJXjvmQ JWapGDtEtg27pdwY8sNNd2ufHbvG0AN0DwcmzwuMCaisEaF7GXWnjJoTBZEuqGYolKk6 BSjQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Hmz0BPz5K3mm7/cFxcxshgj5LagSPu177E0OJnHGgRM=; b=UrvPkBryFJb/BlPJq5JmYfn33xXGu/5y9QQjJhoOW5erY4OKRdDC/HKX5+gg9MkMzo JMLeDrX5x11B/Y1XpBFySwq3NLU8fFJ7BMjjT077Wcpig/fHi9E71H1N07Jni1/MnQPp aspcpiiUoVJcdMoDvQXApThAfaRWvwGYLsGtzMEw1D/EMkj+KnKnHr+8dALT9lkOPeVC Uh1qBm1RdmNGSAgKSd9Ua7r+rpq65HWptxFryH4xWLOzAw9rt7qwkdG78AHvL3dUOF5h nsufMPlao3F+VXag1D5BXVtqhFpIHOowmAocPYoDmalbwdom+nO7EdKTwe36RiQ+YZkL WCTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=yqjVAyZd; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j1-20020a170902c3c100b0018685c33ec2si13197529plj.7.2022.11.08.11.43.26; Tue, 08 Nov 2022 11:43:39 -0800 (PST) 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=@linux-foundation.org header.s=korg header.b=yqjVAyZd; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbiKHTlz (ORCPT + 99 others); Tue, 8 Nov 2022 14:41:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbiKHTlo (ORCPT ); Tue, 8 Nov 2022 14:41:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DB07716CA for ; Tue, 8 Nov 2022 11:41:43 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0B946B81C1F for ; Tue, 8 Nov 2022 19:41:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8D899C433D7; Tue, 8 Nov 2022 19:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1667936500; bh=bgbt2enUCqI8iRJ3RLKDZTlxwyLbgJ8OtsM1oeqQotc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yqjVAyZd9QMNx7zvF9RtUrYl2DUpE3QM9v79JHlipIOyabYoezYTfg7mvFoKlO5HA u+Be86X/jvDj085UDR3r30GnW1oO8qZQUTKVkgquJotczGNAYXFFbsqWbny7SRK37i dvVjGLO4A8tis77odWALXcqs8tdGEWCYKv256b/U= From: Linus Torvalds To: Hugh Dickins , Johannes Weiner , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/4] mm: teach release_pages() to take an array of encoded page pointers too Date: Tue, 8 Nov 2022 11:41:37 -0800 Message-Id: <20221108194139.57604-2-torvalds@linux-foundation.org> X-Mailer: git-send-email 2.38.1.284.gfd9468d787 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748958308406208174?= X-GMAIL-MSGID: =?utf-8?q?1748958308406208174?= release_pages() already could take either an array of page pointers, or an array of folio pointers. Expand it to also accept an array of encoded page pointers, which is what both the existing mlock() use and the upcoming mmu_gather use of encoded page pointers wants. Note that release_pages() won't actually use, or react to, any extra encoded bits. Instead, this is very much a case of "I have walked the array of encoded pages and done everything the extra bits tell me to do, now release it all". Also, while the "either page or folio pointers" dual use was handled with a cast of the pointer in "release_folios()", this takes a slightly different approach and uses the "transparent union" attribute to describe the set of arguments to the function: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html which has been supported by gcc forever, but the kernel hasn't used before. That allows us to avoid using various wrappers with casts, and just use the same function regardless of use. Signed-off-by: Linus Torvalds --- include/linux/mm.h | 21 +++++++++++++++++++-- mm/swap.c | 16 ++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 8bbcccbc5565..d9fb5c3e3045 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1179,7 +1179,24 @@ static inline void folio_put_refs(struct folio *folio, int refs) __folio_put(folio); } -void release_pages(struct page **pages, int nr); +/** + * release_pages - release an array of pages or folios + * + * This just releases a simple array of multiple pages, and + * accepts various different forms of said page array: either + * a regular old boring array of pages, an array of folios, or + * an array of encoded page pointers. + * + * The transparent union syntax for this kind of "any of these + * argument types" is all kinds of ugly, so look away. + */ +typedef union { + struct page **pages; + struct folio **folios; + struct encoded_page **encoded_pages; +} release_pages_arg __attribute__ ((__transparent_union__)); + +void release_pages(release_pages_arg, int nr); /** * folios_put - Decrement the reference count on an array of folios. @@ -1195,7 +1212,7 @@ void release_pages(struct page **pages, int nr); */ static inline void folios_put(struct folio **folios, unsigned int nr) { - release_pages((struct page **)folios, nr); + release_pages(folios, nr); } static inline void put_page(struct page *page) diff --git a/mm/swap.c b/mm/swap.c index 955930f41d20..596ed226ddb8 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -968,22 +968,30 @@ void lru_cache_disable(void) /** * release_pages - batched put_page() - * @pages: array of pages to release + * @arg: array of pages to release * @nr: number of pages * - * Decrement the reference count on all the pages in @pages. If it + * Decrement the reference count on all the pages in @arg. If it * fell to zero, remove the page from the LRU and free it. + * + * Note that the argument can be an array of pages, encoded pages, + * or folio pointers. We ignore any encoded bits, and turn any of + * them into just a folio that gets free'd. */ -void release_pages(struct page **pages, int nr) +void release_pages(release_pages_arg arg, int nr) { int i; + struct encoded_page **encoded = arg.encoded_pages; LIST_HEAD(pages_to_free); struct lruvec *lruvec = NULL; unsigned long flags = 0; unsigned int lock_batch; for (i = 0; i < nr; i++) { - struct folio *folio = page_folio(pages[i]); + struct folio *folio; + + /* Turn any of the argument types into a folio */ + folio = page_folio(encoded_page_ptr(encoded[i])); /* * Make sure the IRQ-safe lock-holding time does not get From patchwork Tue Nov 8 19:41:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 17186 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2912369wru; Tue, 8 Nov 2022 11:43:08 -0800 (PST) X-Google-Smtp-Source: AMsMyM4a9GXOE6UyIWWptvkKpxnoUQHHO9uP6aro8JTIBcn81JQ/KsKlvzS+NTkvSNpsPatsH2aj X-Received: by 2002:a05:6a00:1a0f:b0:56e:32a2:abcf with SMTP id g15-20020a056a001a0f00b0056e32a2abcfmr32174511pfv.35.1667936588380; Tue, 08 Nov 2022 11:43:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667936588; cv=none; d=google.com; s=arc-20160816; b=jo1OHWrohhIjKdL78r/bXRvBXedM4Xs2YKpnc8t6SFQ9NCzZa63xH8OfR7pZLCRyo3 1YrqMeiqGGv3R5XzPrTaqwUw2eer4/j1Em0oKrJCKzXa8/sk3MnIOA2rxf/2Eo5UElmt isR7Xhc/UnBWo1T48hXfZkVLtcNwFiqdyBVH5NYlx2wb4QUMVTKZvqqIbIFGNEHGqDlA b99gNR46gwFo1NZbIKGw84CHedII3QWl27Au4VMYl3Kcqi0FKOBvvD9rIFZxkZpZxl/V 5dLOVXMWMHEfLpCHq/Euqv1BZnB7s0BTDdtsTqubRkI20DtdxW0/51Pxf6NZ4ntuzcQO 1JbQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0U8h3wXAFvQjOZ2F23Z8+zJsbCg1m8KawRjv1q819mw=; b=NkkjhV2yLn3eonF+FvHFcLiQzrTQMdeyRikAsz8ERGBKrAf85ae6yPdkcAqiIodGtt 9z8Y0eKHxch/bQGFo253xK2J2Dg/T4SI/frWq1w/KdyoRyngWuPdalKRwDcM07nASpMM /LpNHV0PlRF/kkiPMjAvXAeKlbMyhTmP+H296UdBGY/eaSlqRzPS8j+dSDw+A/WSM3AA nQgYb72eaWPepW+LT/JyVk35k2RgwmHtsQsJt74HcRCJX+ftN6Fz6veHUjAeWim1E0rZ XL7CJ7jpeAnZNbsWIH+aiCZYg86t9TXHfaxm9xjkn8A/uuiWBp7rFjJh+C7IzYojgC2P QIiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=Puc8twx3; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a655841000000b0046fb6e0b960si15386928pgr.210.2022.11.08.11.42.55; Tue, 08 Nov 2022 11:43:08 -0800 (PST) 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=@linux-foundation.org header.s=korg header.b=Puc8twx3; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229602AbiKHTlp (ORCPT + 99 others); Tue, 8 Nov 2022 14:41:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiKHTlm (ORCPT ); Tue, 8 Nov 2022 14:41:42 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A722716CA for ; Tue, 8 Nov 2022 11:41:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C9F316177A for ; Tue, 8 Nov 2022 19:41:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C42FAC433B5; Tue, 8 Nov 2022 19:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1667936501; bh=KtnZVT0YbwzWMG53hT3URF7/oRWr49RGvTuDrC8WUTY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Puc8twx3+crexM3+XlAfoAfXJdSqnXG5mTkZTE+eK9SWgd99KLHzzfjSjbwlSR9rG vIvyljiUS7yb8ThC0QbXeHTUFZEce/ro/TougawWiPy/s00uFg52Nlje34u8jvC+9q toltFhsioCZg7qZXVfUpy2pFWEDN+3iUD9ECCCus= From: Linus Torvalds To: Hugh Dickins , Johannes Weiner , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/4] mm: mmu_gather: prepare to gather encoded page pointers with flags Date: Tue, 8 Nov 2022 11:41:38 -0800 Message-Id: <20221108194139.57604-3-torvalds@linux-foundation.org> X-Mailer: git-send-email 2.38.1.284.gfd9468d787 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748958276081198464?= X-GMAIL-MSGID: =?utf-8?q?1748958276081198464?= This is purely a preparatory patch that makes all the data structures ready for encoding flags with the mmu_gather page pointers. The code currently always sets the flag to zero and doesn't use it yet, but now it's tracking the type state along. The next step will be to actually start using it. Signed-off-by: Linus Torvalds --- include/asm-generic/tlb.h | 2 +- include/linux/swap.h | 2 +- mm/mmu_gather.c | 4 ++-- mm/swap_state.c | 11 ++++------- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 492dce43236e..faca23e87278 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -242,7 +242,7 @@ struct mmu_gather_batch { struct mmu_gather_batch *next; unsigned int nr; unsigned int max; - struct page *pages[]; + struct encoded_page *encoded_pages[]; }; #define MAX_GATHER_BATCH \ diff --git a/include/linux/swap.h b/include/linux/swap.h index a18cf4b7c724..40e418e3461b 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -470,7 +470,7 @@ static inline unsigned long total_swapcache_pages(void) extern void free_swap_cache(struct page *page); extern void free_page_and_swap_cache(struct page *); -extern void free_pages_and_swap_cache(struct page **, int); +extern void free_pages_and_swap_cache(struct encoded_page **, int); /* linux/mm/swapfile.c */ extern atomic_long_t nr_swap_pages; extern long total_swap_pages; diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index add4244e5790..57b7850c1b5e 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -48,7 +48,7 @@ static void tlb_batch_pages_flush(struct mmu_gather *tlb) struct mmu_gather_batch *batch; for (batch = &tlb->local; batch && batch->nr; batch = batch->next) { - struct page **pages = batch->pages; + struct encoded_page **pages = batch->encoded_pages; do { /* @@ -92,7 +92,7 @@ bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_ * Add the page and check if we are full. If so * force a flush. */ - batch->pages[batch->nr++] = page; + batch->encoded_pages[batch->nr++] = encode_page(page, 0); if (batch->nr == batch->max) { if (!tlb_next_batch(tlb)) return true; diff --git a/mm/swap_state.c b/mm/swap_state.c index 438d0676c5be..8bf08c313872 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -303,15 +303,12 @@ void free_page_and_swap_cache(struct page *page) * Passed an array of pages, drop them all from swapcache and then release * them. They are removed from the LRU and freed if this is their last use. */ -void free_pages_and_swap_cache(struct page **pages, int nr) +void free_pages_and_swap_cache(struct encoded_page **pages, int nr) { - struct page **pagep = pages; - int i; - lru_add_drain(); - for (i = 0; i < nr; i++) - free_swap_cache(pagep[i]); - release_pages(pagep, nr); + for (int i = 0; i < nr; i++) + free_swap_cache(encoded_page_ptr(pages[i])); + release_pages(pages, nr); } static inline bool swap_use_vma_readahead(void) From patchwork Tue Nov 8 19:41:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 17188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2912816wru; Tue, 8 Nov 2022 11:44:24 -0800 (PST) X-Google-Smtp-Source: AMsMyM7kKVlutbTLb3E9FZ2y7Pq2e6wu2U3V0hrLkAkFzR3jxvxqGbpz2DVC5AbGxY2ZIDBJPA1s X-Received: by 2002:a65:6b81:0:b0:461:4049:7df7 with SMTP id d1-20020a656b81000000b0046140497df7mr49614385pgw.593.1667936664661; Tue, 08 Nov 2022 11:44:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667936664; cv=none; d=google.com; s=arc-20160816; b=WS2Yc2IpVNv1vsxzET9x3rwk7qEJUMeD7c+nXCUrvrE/BvddnwCr8mBP5BO7Av8/n5 VpUtrLkzNZKPJJu82ITkOLNrrCN/tJItujmkv7yFQJ6VOoLgJu7rFhpG9BDuYUraUi7R SY7zhhxiZp5XA10iTmGx37pgJPw19t/hZBUjTrW79geGH7Wgt7k28MB9Ij7VVhC+dB+2 eanFyOHzTwQloAqCJ26R41z5f33+cA9Fnh1GJvdn3KicVSkz7FIKuGFQo8vVdXpAfzv+ AnXvfx6Qp+SobF5XzQ2Jr9C3ILZ4eCSuNcweh3oQldxDVocLQxbXdxE6wtlo4UirGY06 AVjg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yMnoBuLqdDqNK4ES6VVqdhgoRUgogQ9wTzbuenv9ajE=; b=PEa6OxbKQizJhFmh+ixoBJgJXQJsPUOHVrke2LmRTJlW0gP2rPgoBAgYmevtt8OtZ9 6wqtYbvpUSHzsFzdVJkeBRr0ER1itU+l5J1rdXlPO7TVlv/WSeDvaMAlTFjgR0QzPM32 vJiNL7YNHSNe4oSCGnjl7i4435CWoTS3GOij1KzFoCv6ZM3LCAVprYWjoxt4IkXB4PMy e33KDDqGlI7d9H4JrFk5HPqEPLFdQgaqlvTvO6TBsJ49oQcv3ekId9P2rjF/vjQmkTYW TgUrHHfo7xsI0nyq7wS6rbIcGmA2TNc4JhGTzzZOwxFIbtXNyhEpdxF3OKzItwAaehQX /osw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=z07aI4M7; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 78-20020a630051000000b0046f0ae1bb8fsi15948430pga.785.2022.11.08.11.44.10; Tue, 08 Nov 2022 11:44:24 -0800 (PST) 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=@linux-foundation.org header.s=korg header.b=z07aI4M7; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbiKHTls (ORCPT + 99 others); Tue, 8 Nov 2022 14:41:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiKHTlo (ORCPT ); Tue, 8 Nov 2022 14:41:44 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADF0A7057F for ; Tue, 8 Nov 2022 11:41:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4D07F6173F for ; Tue, 8 Nov 2022 19:41:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59062C433D6; Tue, 8 Nov 2022 19:41:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1667936502; bh=h11BLOABoRmeXTPU3NUF80nlJbZBLsLoS32EJ3aGj64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z07aI4M7Omdci6AhIi1Bee8aSVhAyN6srxOMIGaK70Vzw8ghAoUJW/H/x0TOxTGBp Muw8GdFF+7I7cNqqPG3yjFtHAgutHZHWGP3xLI3xlSZ64ODp0E60utlU3igmnX6PXq W6BHQUPqSpbe8u0Yqh1lQX6N9+qY7tmM/3I0h6Iw= From: Linus Torvalds To: Hugh Dickins , Johannes Weiner , Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Nadav Amit , Will Deacon , Aneesh Kumar , Nick Piggin , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Peter Zijlstra , Gerald Schaefer Subject: [PATCH 4/4] mm: delay page_remove_rmap() until after the TLB has been flushed Date: Tue, 8 Nov 2022 11:41:39 -0800 Message-Id: <20221108194139.57604-4-torvalds@linux-foundation.org> X-Mailer: git-send-email 2.38.1.284.gfd9468d787 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748958356467136967?= X-GMAIL-MSGID: =?utf-8?q?1748958356467136967?= When we remove a page table entry, we are very careful to only free the page after we have flushed the TLB, because other CPUs could still be using the page through stale TLB entries until after the flush. However, we have removed the rmap entry for that page early, which means that functions like folio_mkclean() would end up not serializing with the page table lock because the page had already been made invisible to rmap. And that is a problem, because while the TLB entry exists, we could end up with the following situation: (a) one CPU could come in and clean it, never seeing our mapping of the page (b) another CPU could continue to use the stale and dirty TLB entry and continue to write to said page resulting in a page that has been dirtied, but then marked clean again, all while another CPU might have dirtied it some more. End result: possibly lost dirty data. This extends our current TLB gather infrastructure to optionally track a "should I do a delayed page_remove_rmap() for this page after flushing the TLB". It uses the newly introduced 'encoded page pointer' to do that without having to keep separate data around. Note, this is complicated by a couple of issues: - s390 has its own mmu_gather model that doesn't delay TLB flushing, and as a result also does not want the delayed rmap - we want to delay the rmap removal, but not past the page table lock - we can track an enormous number of pages in our mmu_gather structure, with MAX_GATHER_BATCH_COUNT batches of MAX_TABLE_BATCH pages each, all set up to be approximately 10k pending pages. We do not want to have a huge number of batched pages that we then need to check for delayed rmap handling inside the page table lock. Particularly that last point results in a noteworthy detail, where the normal page batch gathering is limited once we have delayed rmaps pending, in such a way that only the last batch (the so-called "active batch") in the mmu_gather structure can have any delayed entries. NOTE! While the "possibly lost dirty data" sounds catastrophic, for this all to happen you need to have a user thread doing either madvise() with MADV_DONTNEED or a full re-mmap() of the area concurrently with another thread continuing to use said mapping. So arguably this is about user space doing crazy things, but from a VM consistency standpoint it's better if we track the dirty bit properly even when user space goes off the rails. Reported-by: Nadav Amit Link: https://lore.kernel.org/all/B88D3073-440A-41C7-95F4-895D3F657EF2@gmail.com/ Cc: Will Deacon Cc: Aneesh Kumar Cc: Andrew Morton Cc: Nick Piggin Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Alexander Gordeev Cc: Christian Borntraeger Cc: Sven Schnelle Acked-by: Peter Zijlstra (Intel) Acked-by: Gerald Schaefer # s390 Signed-off-by: Linus Torvalds --- arch/s390/include/asm/tlb.h | 21 +++++++++++++++++++-- include/asm-generic/tlb.h | 21 +++++++++++++++++---- mm/memory.c | 23 +++++++++++++++++------ mm/mmu_gather.c | 35 +++++++++++++++++++++++++++++++++-- 4 files changed, 86 insertions(+), 14 deletions(-) diff --git a/arch/s390/include/asm/tlb.h b/arch/s390/include/asm/tlb.h index 3a5c8fb590e5..e5903ee2f1ca 100644 --- a/arch/s390/include/asm/tlb.h +++ b/arch/s390/include/asm/tlb.h @@ -25,7 +25,8 @@ void __tlb_remove_table(void *_table); static inline void tlb_flush(struct mmu_gather *tlb); static inline bool __tlb_remove_page_size(struct mmu_gather *tlb, - struct page *page, int page_size); + struct page *page, int page_size, + unsigned int flags); #define tlb_flush tlb_flush #define pte_free_tlb pte_free_tlb @@ -36,13 +37,24 @@ static inline bool __tlb_remove_page_size(struct mmu_gather *tlb, #include #include +/* + * s390 never needs to delay page_remove_rmap, because + * the ptep_get_and_clear_full() will have flushed the + * TLB across CPUs + */ +static inline bool tlb_delay_rmap(struct mmu_gather *tlb) +{ + return false; +} + /* * Release the page cache reference for a pte removed by * tlb_ptep_clear_flush. In both flush modes the tlb for a page cache page * has already been freed, so just do free_page_and_swap_cache. */ static inline bool __tlb_remove_page_size(struct mmu_gather *tlb, - struct page *page, int page_size) + struct page *page, int page_size, + unsigned int flags) { free_page_and_swap_cache(page); return false; @@ -53,6 +65,11 @@ static inline void tlb_flush(struct mmu_gather *tlb) __tlb_flush_mm_lazy(tlb->mm); } +static inline void tlb_flush_rmaps(struct mmu_gather *tlb, struct vm_area_struct *vma) +{ + /* Nothing to do, s390 does not delay rmaps */ +} + /* * pte_free_tlb frees a pte table and clears the CRSTE for the * page table from the tlb. diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index faca23e87278..9df513e5ad28 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -257,7 +257,15 @@ struct mmu_gather_batch { #define MAX_GATHER_BATCH_COUNT (10000UL/MAX_GATHER_BATCH) extern bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, - int page_size); + int page_size, unsigned int flags); +extern void tlb_flush_rmaps(struct mmu_gather *tlb, struct vm_area_struct *vma); + +/* + * This both sets 'delayed_rmap', and returns true. It would be an inline + * function, except we define it before the 'struct mmu_gather'. + */ +#define tlb_delay_rmap(tlb) (((tlb)->delayed_rmap = 1), true) + #endif /* @@ -290,6 +298,11 @@ struct mmu_gather { */ unsigned int freed_tables : 1; + /* + * Do we have pending delayed rmap removals? + */ + unsigned int delayed_rmap : 1; + /* * at which levels have we cleared entries? */ @@ -431,13 +444,13 @@ static inline void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb) static inline void tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_size) { - if (__tlb_remove_page_size(tlb, page, page_size)) + if (__tlb_remove_page_size(tlb, page, page_size, 0)) tlb_flush_mmu(tlb); } -static inline bool __tlb_remove_page(struct mmu_gather *tlb, struct page *page) +static inline bool __tlb_remove_page(struct mmu_gather *tlb, struct page *page, unsigned int flags) { - return __tlb_remove_page_size(tlb, page, PAGE_SIZE); + return __tlb_remove_page_size(tlb, page, PAGE_SIZE, flags); } /* tlb_remove_page diff --git a/mm/memory.c b/mm/memory.c index f88c351aecd4..60a0f44f6e72 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1432,6 +1432,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, break; if (pte_present(ptent)) { + unsigned int delay_rmap; + page = vm_normal_page(vma, addr, ptent); if (unlikely(!should_zap_page(details, page))) continue; @@ -1443,20 +1445,26 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, if (unlikely(!page)) continue; + delay_rmap = 0; if (!PageAnon(page)) { if (pte_dirty(ptent)) { - force_flush = 1; set_page_dirty(page); + if (tlb_delay_rmap(tlb)) { + delay_rmap = 1; + force_flush = 1; + } } if (pte_young(ptent) && likely(!(vma->vm_flags & VM_SEQ_READ))) mark_page_accessed(page); } rss[mm_counter(page)]--; - page_remove_rmap(page, vma, false); - if (unlikely(page_mapcount(page) < 0)) - print_bad_pte(vma, addr, ptent, page); - if (unlikely(__tlb_remove_page(tlb, page))) { + if (!delay_rmap) { + page_remove_rmap(page, vma, false); + if (unlikely(page_mapcount(page) < 0)) + print_bad_pte(vma, addr, ptent, page); + } + if (unlikely(__tlb_remove_page(tlb, page, delay_rmap))) { force_flush = 1; addr += PAGE_SIZE; break; @@ -1513,8 +1521,11 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, arch_leave_lazy_mmu_mode(); /* Do the actual TLB flush before dropping ptl */ - if (force_flush) + if (force_flush) { tlb_flush_mmu_tlbonly(tlb); + if (tlb->delayed_rmap) + tlb_flush_rmaps(tlb, vma); + } pte_unmap_unlock(start_pte, ptl); /* diff --git a/mm/mmu_gather.c b/mm/mmu_gather.c index 57b7850c1b5e..136f5fad43e3 100644 --- a/mm/mmu_gather.c +++ b/mm/mmu_gather.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,10 @@ static bool tlb_next_batch(struct mmu_gather *tlb) { struct mmu_gather_batch *batch; + /* No more batching if we have delayed rmaps pending */ + if (tlb->delayed_rmap) + return false; + batch = tlb->active; if (batch->next) { tlb->active = batch->next; @@ -43,6 +48,31 @@ static bool tlb_next_batch(struct mmu_gather *tlb) return true; } +/** + * tlb_flush_rmaps - do pending rmap removals after we have flushed the TLB + * @tlb: the current mmu_gather + * + * Note that because of how tlb_next_batch() above works, we will + * never start new batches with pending delayed rmaps, so we only + * need to walk through the current active batch. + */ +void tlb_flush_rmaps(struct mmu_gather *tlb, struct vm_area_struct *vma) +{ + struct mmu_gather_batch *batch; + + batch = tlb->active; + for (int i = 0; i < batch->nr; i++) { + struct encoded_page *enc = batch->encoded_pages[i]; + + if (encoded_page_flags(enc)) { + struct page *page = encoded_page_ptr(enc); + page_remove_rmap(page, vma, false); + } + } + + tlb->delayed_rmap = 0; +} + static void tlb_batch_pages_flush(struct mmu_gather *tlb) { struct mmu_gather_batch *batch; @@ -77,7 +107,7 @@ static void tlb_batch_list_free(struct mmu_gather *tlb) tlb->local.next = NULL; } -bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_size) +bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_size, unsigned int flags) { struct mmu_gather_batch *batch; @@ -92,7 +122,7 @@ bool __tlb_remove_page_size(struct mmu_gather *tlb, struct page *page, int page_ * Add the page and check if we are full. If so * force a flush. */ - batch->encoded_pages[batch->nr++] = encode_page(page, 0); + batch->encoded_pages[batch->nr++] = encode_page(page, flags); if (batch->nr == batch->max) { if (!tlb_next_batch(tlb)) return true; @@ -286,6 +316,7 @@ static void __tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, tlb->active = &tlb->local; tlb->batch_count = 0; #endif + tlb->delayed_rmap = 0; tlb_table_init(tlb); #ifdef CONFIG_MMU_GATHER_PAGE_SIZE