From patchwork Tue Mar 9 05:16:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 12124117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F5F4C433E6 for ; Tue, 9 Mar 2021 05:16:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0016D6527B for ; Tue, 9 Mar 2021 05:16:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0016D6527B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 87F2A8D00B0; Tue, 9 Mar 2021 00:16:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 857F98D007F; Tue, 9 Mar 2021 00:16:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60CD68D00B0; Tue, 9 Mar 2021 00:16:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0032.hostedemail.com [216.40.44.32]) by kanga.kvack.org (Postfix) with ESMTP id 470438D007F for ; Tue, 9 Mar 2021 00:16:37 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 024E33637 for ; Tue, 9 Mar 2021 05:16:36 +0000 (UTC) X-FDA: 77899175634.24.5AAB18D Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf30.hostedemail.com (Postfix) with ESMTP id 62F93E0011EF for ; Tue, 9 Mar 2021 05:16:31 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id l2so7966401pgb.1 for ; Mon, 08 Mar 2021 21:16:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HORwLZBItmmfsgXHtTtePPTuVp6GLP2tVSIDV66WVpQ=; b=eYdb52HNI0m9k1dSzBzYPe/yrsDUeQf5/V4fbqkyN1tOZia9b3PlIFcT+8IAiPqp31 0EnqPEurKW/f5Wz2ZEOljJE6VotAKSGo8eyKcHfa3tdLyuSwT3vBgX9CBiUtempawwfM Fkq47xN1Ln/etM3HJSMe7V1aa7YjE4kAiXWRxfVHKTNN50lKeOlXszTj/gZvDwCycLpK en4dtCuovMRi7yLuj8x7cXw0K4BYIXtErvrP0b5CQMXjZfMqCbWpqUe9YSxbVcoHMc4W FF3kymnBFMVj60tpEl4e+kuk3bKIEqZdJywogZHISlt1opQjO6Pxytc4nS+ZTBXAK5gP L1nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=HORwLZBItmmfsgXHtTtePPTuVp6GLP2tVSIDV66WVpQ=; b=RgC7dhMx3HqSrwIVlXpI+G4FivK8uUSuFoyorJzWA8QpXQQ0T4iEigM9iRhKFatBbo 4jJ3Qqa+pj4mhQS+Etc0nFEMGcJMgqp/Mc54kH/dGGnp/VtSQcISZnTdlMH3knRtbZ0c JhrxIoFJpfywLXMWkPEBYCdrQrokiUfEG2RPLdQ0kNNLS8MUrul0hL/ULzE6OtKtqWbm s37ipDC/YQYKDFkj8xpeskhKsWOqSi3Cq3kkHHd47cWlRD7KSFx8mVEDAWsXM/hYBS+H qoTfStWWBFqzadCopQAIchG+yJ72mfS7t2UWLuMVb1VJyR3/9JLbE2RVcktvKkFb2NDJ 8SQw== X-Gm-Message-State: AOAM531TiH45Qc1BdAV8LfhvWlbHs0jDHPq8rQOzSc8D/nHFJwzSs5tw zRlwZMgLTEni0HFYir1WdNs= X-Google-Smtp-Source: ABdhPJxd5K5oogovLzgD2OZCi1I8c5sIi7DN9DXg2E/knjxADowEPx0V6diq32qsKGpQ1QeBNfYM4A== X-Received: by 2002:aa7:95b5:0:b029:1ef:272f:920c with SMTP id a21-20020aa795b50000b02901ef272f920cmr22146023pfk.21.1615266995451; Mon, 08 Mar 2021 21:16:35 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:4ccc:acdd:25da:14d1]) by smtp.gmail.com with ESMTPSA id b14sm1166576pji.14.2021.03.08.21.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Mar 2021 21:16:34 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: linux-mm , LKML , joaodias@google.com, surenb@google.com, cgoldswo@codeaurora.org, willy@infradead.org, mhocko@suse.com, david@redhat.com, vbabka@suse.cz, linux-fsdevel@vger.kernel.org, Minchan Kim Subject: [PATCH v2 2/2] mm: fs: Invalidate BH LRU during page migration Date: Mon, 8 Mar 2021 21:16:28 -0800 Message-Id: <20210309051628.3105973-2-minchan@kernel.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog In-Reply-To: <20210309051628.3105973-1-minchan@kernel.org> References: <20210309051628.3105973-1-minchan@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 62F93E0011EF X-Stat-Signature: 65555sbwdbw1xksimu5oomej3enpuc47 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf30; identity=mailfrom; envelope-from=""; helo=mail-pg1-f177.google.com; client-ip=209.85.215.177 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615266991-154489 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: Pages containing buffer_heads that are in one of the per-CPU buffer_head LRU caches will be pinned and thus cannot be migrated. This can prevent CMA allocations from succeeding, which are often used on platforms with co-processors (such as a DSP) that can only use physically contiguous memory. It can also prevent memory hot-unplugging from succeeding, which involves migrating at least MIN_MEMORY_BLOCK_SIZE bytes of memory, which ranges from 8 MiB to 1 GiB based on the architecture in use. Correspondingly, invalidate the BH LRU caches before a migration starts and stop any buffer_head from being cached in the LRU caches, until migration has finished. Signed-off-by: Chris Goldsworthy Signed-off-by: Minchan Kim Reported-by: kernel test robot --- fs/buffer.c | 12 ++++++++++-- include/linux/buffer_head.h | 3 +++ include/linux/swap.h | 1 + mm/swap.c | 5 ++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 96c7604f69b3..4492e9d4c9d3 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -1301,6 +1301,14 @@ static void bh_lru_install(struct buffer_head *bh) int i; check_irqs_on(); + /* + * buffer_head in bh_lru could increase refcount of the page + * until it will be invalidated. It causes page migraion failure. + * Skip putting upcoming bh into bh_lru until migration is done. + */ + if (lru_cache_disabled()) + return; + bh_lru_lock(); b = this_cpu_ptr(&bh_lrus); @@ -1446,7 +1454,7 @@ EXPORT_SYMBOL(__bread_gfp); * This doesn't race because it runs in each cpu either in irq * or with preempt disabled. */ -static void invalidate_bh_lru(void *arg) +void invalidate_bh_lru(void *arg) { struct bh_lru *b = &get_cpu_var(bh_lrus); int i; @@ -1458,7 +1466,7 @@ static void invalidate_bh_lru(void *arg) put_cpu_var(bh_lrus); } -static bool has_bh_in_lru(int cpu, void *dummy) +bool has_bh_in_lru(int cpu, void *dummy) { struct bh_lru *b = per_cpu_ptr(&bh_lrus, cpu); int i; diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 6b47f94378c5..3ae62f3f788e 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -194,6 +194,8 @@ void __breadahead_gfp(struct block_device *, sector_t block, unsigned int size, struct buffer_head *__bread_gfp(struct block_device *, sector_t block, unsigned size, gfp_t gfp); void invalidate_bh_lrus(void); +void invalidate_bh_lru(void *arg); +bool has_bh_in_lru(int cpu, void *dummy); struct buffer_head *alloc_buffer_head(gfp_t gfp_flags); void free_buffer_head(struct buffer_head * bh); void unlock_buffer(struct buffer_head *bh); @@ -406,6 +408,7 @@ static inline int inode_has_buffers(struct inode *inode) { return 0; } static inline void invalidate_inode_buffers(struct inode *inode) {} static inline int remove_inode_buffers(struct inode *inode) { return 1; } static inline int sync_mapping_buffers(struct address_space *mapping) { return 0; } +static inline void invalidate_bh_lru(void *arg) {} #define buffer_heads_over_limit 0 #endif /* CONFIG_BLOCK */ diff --git a/include/linux/swap.h b/include/linux/swap.h index aaa6b9cc3f8a..5386cce1a26d 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -341,6 +341,7 @@ extern void lru_cache_add(struct page *); extern void mark_page_accessed(struct page *); extern void lru_cache_disable(void); extern void lru_cache_enable(void); +extern bool lru_cache_disabled(void); extern void lru_add_drain(void); extern void lru_add_drain_cpu(int cpu); extern void lru_add_drain_cpu_zone(struct zone *zone); diff --git a/mm/swap.c b/mm/swap.c index fc8acccb882b..d599d6449154 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "internal.h" @@ -641,6 +642,7 @@ void lru_add_drain_cpu(int cpu) pagevec_lru_move_fn(pvec, lru_lazyfree_fn); activate_page_drain(cpu); + invalidate_bh_lru(NULL); } /** @@ -821,7 +823,8 @@ void __lru_add_drain_all(bool force_all_cpus) pagevec_count(&per_cpu(lru_pvecs.lru_deactivate_file, cpu)) || pagevec_count(&per_cpu(lru_pvecs.lru_deactivate, cpu)) || pagevec_count(&per_cpu(lru_pvecs.lru_lazyfree, cpu)) || - need_activate_page_drain(cpu)) { + need_activate_page_drain(cpu) || + has_bh_in_lru(cpu, NULL)) { INIT_WORK(work, lru_add_drain_per_cpu); queue_work_on(cpu, mm_percpu_wq, work); __cpumask_set_cpu(cpu, &has_work);